From 8c33590ed162ec5987b7491eb37bddd9b8686a97 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 16 Feb 2022 16:21:45 +0200 Subject: [PATCH] knetattach: add NFS share support Signed-off-by: Ivailo Monev --- knetattach/knetattach.cpp | 67 ++++++++++++++++++++++++--------------- knetattach/knetattach.ui | 61 +++++++++++++++++++---------------- 2 files changed, 76 insertions(+), 52 deletions(-) diff --git a/knetattach/knetattach.cpp b/knetattach/knetattach.cpp index 37432315..5173e774 100644 --- a/knetattach/knetattach.cpp +++ b/knetattach/knetattach.cpp @@ -43,8 +43,9 @@ KNetAttach::KNetAttach( QWidget* parent ) setupUi( this ); _ftp->setEnabled(KProtocolInfo::isKnownProtocol("ftp")); - _smb->setEnabled(KProtocolInfo::isKnownProtocol("smb")); _sftp->setEnabled(KProtocolInfo::isKnownProtocol("sftp")); + _nfs->setEnabled(KProtocolInfo::isKnownProtocol("nfs")); + _smb->setEnabled(KProtocolInfo::isKnownProtocol("smb")); connect(_recent, SIGNAL(toggled(bool)), _recentConnectionName, SLOT(setEnabled(bool))); connect(_connectionName, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus())); @@ -87,10 +88,12 @@ void KNetAttach::setInformationText(const QString &type) { QString text; - if (type=="SFTP") { - text = i18n("Enter a name for this SSH File Transfer Protocol as well as a server address, port and folder path to use and press the Save & Connect button."); - } else if (type=="FTP") { + if (type=="FTP") { text = i18n("Enter a name for this File Transfer Protocol connection as well as a server address and folder path to use and press the Save & Connect button."); + } else if (type=="SFTP") { + text = i18n("Enter a name for this SSH File Transfer Protocol as well as a server address, port and folder path to use and press the Save & Connect button."); + } else if (type=="SFTP") { + text = i18n("Enter a name for this Network File System as well as a server address, port and folder path to use and press the Save & Connect button."); } else if (type=="SMB") { text = i18n("Enter a name for this Microsoft Windows network drive as well as a server address and folder path to use and press the Save & Connect button."); } @@ -113,20 +116,24 @@ bool KNetAttach::validateCurrentPage() _host->setFocus(); _connectionName->setFocus(); - if (_sftp->isChecked()) { - setInformationText("SFTP"); - updateForProtocol("SFTP"); - _port->setValue(22); - if (_path->text().isEmpty()) { - _path->setText("/"); - } - } else if (_ftp->isChecked()) { + if (_ftp->isChecked()) { setInformationText("FTP"); updateForProtocol("FTP"); _port->setValue(21); if (_path->text().isEmpty()) { _path->setText("/"); } + } else if (_sftp->isChecked()) { + setInformationText("SFTP"); + updateForProtocol("SFTP"); + _port->setValue(22); + if (_path->text().isEmpty()) { + _path->setText("/"); + } + } else if (_nfs->isChecked()) { + setInformationText("NFS"); + updateForProtocol("NFS"); + _port->setValue(2049); } else if (_smb->isChecked()) { setInformationText("SMB"); updateForProtocol("SMB"); @@ -166,16 +173,19 @@ bool KNetAttach::validateCurrentPage() button(BackButton)->setEnabled(false); button(FinishButton)->setEnabled(false); KUrl url; - if (_type == "SFTP") { - url.setProtocol("sftp"); - url.setPort(_port->value()); - } else if (_type == "FTP") { + if (_type == "FTP") { url.setProtocol("ftp"); url.setPort(_port->value()); KConfig config("kio_ftprc"); KConfigGroup cg(&config, _host->text().trimmed()); cg.writeEntry("Charset", KGlobal::charsets()->encodingForName(_encoding->currentText())); config.sync(); + } else if (_type == "SFTP") { + url.setProtocol("sftp"); + url.setPort(_port->value()); + } else if (_type == "NFS") { + url.setProtocol("nfs"); + url.setPort(_port->value()); } else if (_type == "SMB") { url.setProtocol("smb"); } else { // recent @@ -239,7 +249,7 @@ bool KNetAttach::validateCurrentPage() } recent = KConfigGroup(&_recent,name); recent.writeEntry("URL", url.prettyUrl()); - if ( _type == "SFTP" || _type == "FTP") { + if (_type == "FTP" || _type == "SFTP" || _type == "NFS") { recent.writeEntry("Port", _port->value()); } recent.writeEntry("Type", _type); @@ -262,20 +272,27 @@ bool KNetAttach::doConnectionTest(const KUrl& url) bool KNetAttach::updateForProtocol(const QString& protocol) { _type = protocol; - if (protocol == "SFTP") { - _portText->show(); - _port->show(); - _userText->show(); - _user->show(); - _encodingText->hide(); - _encoding->hide(); - } else if (protocol == "FTP") { + if (protocol == "FTP") { _portText->show(); _port->show(); _userText->show(); _user->show(); _encodingText->show(); _encoding->show(); + } else if (protocol == "SFTP") { + _portText->show(); + _port->show(); + _userText->show(); + _user->show(); + _encodingText->hide(); + _encoding->hide(); + } else if (protocol == "NFS") { + _portText->show(); + _port->show(); + _userText->show(); + _user->show(); + _encodingText->hide(); + _encoding->hide(); } else if (protocol == "SMB") { _portText->hide(); _port->hide(); diff --git a/knetattach/knetattach.ui b/knetattach/knetattach.ui index fcc25a34..15069bff 100644 --- a/knetattach/knetattach.ui +++ b/knetattach/knetattach.ui @@ -47,6 +47,40 @@ + + + + &File Transfer Protocol (ftp) + + + true + + + + + + + &SSH File Transfer Protocol (sftp) + + + false + + + + + + + N&etwork File System (nfs) + + + + + + + &Microsoft® Windows® network drive (smb) + + + @@ -85,33 +119,6 @@ - - - - &SSH File Transfer Protocol (sftp) - - - false - - - - - - - &Microsoft® Windows® network drive (smb) - - - - - - - &File Transfer Protocol (ftp) - - - true - - -