From 0ecf46034e82875c4308993ccbbca1d2e34a8d55 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 16 Feb 2022 14:35:33 +0200 Subject: [PATCH] knetattach: enable protocols based on slaves availability Signed-off-by: Ivailo Monev --- knetattach/knetattach.cpp | 404 +++++++++++++++++++------------------- knetattach/knetattach.ui | 138 +++++-------- 2 files changed, 255 insertions(+), 287 deletions(-) diff --git a/knetattach/knetattach.cpp b/knetattach/knetattach.cpp index 28cbc877..4901a23a 100644 --- a/knetattach/knetattach.cpp +++ b/knetattach/knetattach.cpp @@ -35,12 +35,18 @@ #include #include #include +#include KNetAttach::KNetAttach( QWidget* parent ) : QWizard( parent ), Ui_KNetAttach() { setupUi( this ); + _webfolder->setEnabled(KProtocolInfo::isKnownProtocol("webdav")); + _ftp->setEnabled(KProtocolInfo::isKnownProtocol("ftp")); + _smb->setEnabled(KProtocolInfo::isKnownProtocol("smb")); + _sftp->setEnabled(KProtocolInfo::isKnownProtocol("sftp")); + connect(_recent, SIGNAL(toggled(bool)), _recentConnectionName, SLOT(setEnabled(bool))); connect(_connectionName, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus())); connect(_user, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus())); @@ -58,13 +64,13 @@ KNetAttach::KNetAttach( QWidget* parent ) KConfigGroup recent(&crecent, "General"); QStringList idx = recent.readEntry("Index",QStringList()); if (idx.isEmpty()) { - _recent->setEnabled(false); - if (_recent->isChecked()) { - _webfolder->setChecked(true); - } + _recent->setEnabled(false); + if (_recent->isChecked()) { + _webfolder->setChecked(true); + } } else { - _recent->setEnabled(true); - _recentConnectionName->addItems(idx); + _recent->setEnabled(true); + _recentConnectionName->addItems(idx); } _encoding->clear(); _encoding->addItems(KGlobal::charsets()->descriptiveEncodingNames()); @@ -87,9 +93,9 @@ void KNetAttach::setInformationText( const QString &type ) QString text; if (type=="WebFolder") { - text = i18n("Enter a name for this WebFolder as well as a server address, port and folder path to use and press the Save & Connect button."); - } else if (type=="Fish") { - text = i18n("Enter a name for this Secure shell connection as well as a server address, port and folder path to use and press the Save & Connect button."); + text = i18n("Enter a name for this WebFolder 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 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") { 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=="SMB") { @@ -102,164 +108,164 @@ void KNetAttach::setInformationText( const QString &type ) void KNetAttach::updateParametersPageStatus() { button(FinishButton)->setEnabled( - !_host->text().trimmed().isEmpty() && - !_path->text().trimmed().isEmpty() && - !_connectionName->text().trimmed().isEmpty()); + !_host->text().trimmed().isEmpty() && + !_path->text().trimmed().isEmpty() && + !_connectionName->text().trimmed().isEmpty() + ); } bool KNetAttach::validateCurrentPage() { if (currentPage() == _folderType){ - _host->setFocus(); - _connectionName->setFocus(); + _host->setFocus(); + _connectionName->setFocus(); - if (_webfolder->isChecked()) { - setInformationText("WebFolder"); - updateForProtocol("WebFolder"); - _port->setValue(80); - } else if (_fish->isChecked()) { - setInformationText("Fish"); - updateForProtocol("Fish"); - _port->setValue(22); - } else if (_ftp->isChecked()) { - setInformationText("FTP"); - updateForProtocol("FTP"); - _port->setValue(21); - if (_path->text().isEmpty()) { - _path->setText("/"); - } - } else if (_smb->isChecked()) { - setInformationText("SMB"); - updateForProtocol("SMB"); - } else { //if (_recent->isChecked()) { - KConfig recent( "krecentconnections", KConfig::NoGlobals ); - if (!recent.hasGroup(_recentConnectionName->currentText())) { - KConfigGroup group = recent.group("General"); - QStringList idx = group.readEntry("Index",QStringList()); - if (idx.isEmpty()) { - _recent->setEnabled(false); - if (_recent->isChecked()) { - _webfolder->setChecked(true); - } - } else { - _recent->setEnabled(true); - _recentConnectionName->addItems(idx); - } - return false; - } - KConfigGroup group = recent.group(_recentConnectionName->currentText()); - _type = group.readEntry("Type"); - setInformationText(_type); - if (!updateForProtocol(_type)) { - // FIXME: handle error - } - KUrl u(group.readEntry("URL")); - _host->setText(u.host()); - _user->setText(u.user()); - _path->setText(u.path()); - if (group.hasKey("Port")) { - _port->setValue(group.readEntry("Port",0)); - } else { - _port->setValue(u.port()); - } - _connectionName->setText(_recentConnectionName->currentText()); - _createIcon->setChecked(false); - } - updateParametersPageStatus(); + if (_webfolder->isChecked()) { + setInformationText("WebFolder"); + updateForProtocol("WebFolder"); + _port->setValue(80); + } else if (_sftp->isChecked()) { + setInformationText("SFTP"); + updateForProtocol("SFTP"); + _port->setValue(22); + if (_path->text().isEmpty()) { + _path->setText("/"); + } + } else if (_ftp->isChecked()) { + setInformationText("FTP"); + updateForProtocol("FTP"); + _port->setValue(21); + if (_path->text().isEmpty()) { + _path->setText("/"); + } + } else if (_smb->isChecked()) { + setInformationText("SMB"); + updateForProtocol("SMB"); + } else { //if (_recent->isChecked()) { + KConfig recent( "krecentconnections", KConfig::NoGlobals ); + if (!recent.hasGroup(_recentConnectionName->currentText())) { + KConfigGroup group = recent.group("General"); + QStringList idx = group.readEntry("Index",QStringList()); + if (idx.isEmpty()) { + _recent->setEnabled(false); + if (_recent->isChecked()) { + _webfolder->setChecked(true); + } + } else { + _recent->setEnabled(true); + _recentConnectionName->addItems(idx); + } + return false; + } + KConfigGroup group = recent.group(_recentConnectionName->currentText()); + _type = group.readEntry("Type"); + setInformationText(_type); + if (!updateForProtocol(_type)) { + // FIXME: handle error + } + KUrl u(group.readEntry("URL")); + _host->setText(u.host()); + _user->setText(u.user()); + _path->setText(u.path()); + if (group.hasKey("Port")) { + _port->setValue(group.readEntry("Port",0)); + } else { + _port->setValue(u.port()); + } + _connectionName->setText(_recentConnectionName->currentText()); + _createIcon->setChecked(false); + } + updateParametersPageStatus(); + } else { + button(BackButton)->setEnabled(false); + button(FinishButton)->setEnabled(false); + KUrl url; + if (_type == "WebFolder") { + if (_useEncryption->isChecked()) { + url.setProtocol("webdavs"); + } else { + url.setProtocol("webdav"); + } + url.setPort(_port->value()); + } else if (_type == "SFTP") { + url.setProtocol("sftp"); + url.setPort(_port->value()); + } else 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 == "SMB") { + url.setProtocol("smb"); + } else { // recent + } - }else{ - button(BackButton)->setEnabled(false); - button(FinishButton)->setEnabled(false); - KUrl url; - if (_type == "WebFolder") { - if (_useEncryption->isChecked()) { - url.setProtocol("webdavs"); - } else { - url.setProtocol("webdav"); - } - url.setPort(_port->value()); - } else if (_type == "Fish") { - KConfig config("kio_fishrc"); - KConfigGroup cg(&config, _host->text().trimmed()); - cg.writeEntry("Charset", KGlobal::charsets()->encodingForName(_encoding->currentText())); - url.setProtocol(_protocolText->currentText()); - url.setPort(_port->value()); - } else 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 == "SMB") { - url.setProtocol("smb"); - } else { // recent - } + url.setHost(_host->text().trimmed()); + url.setUser(_user->text().trimmed()); + QString path = _path->text().trimmed(); + // could a relative path really be made absolute by simply prepending a '/' ? + if (!path.startsWith('/')) { + path = QString("/") + path; + } + url.setPath(path); + _folderParameters->setEnabled(false); + bool success = doConnectionTest(url); + _folderParameters->setEnabled(true); + if (!success) { + KMessageBox::sorry(this, i18n("Unable to connect to server. Please check your settings and try again.")); + button(BackButton)->setEnabled(true); + return false; + } - url.setHost(_host->text().trimmed()); - url.setUser(_user->text().trimmed()); - QString path = _path->text().trimmed(); - // could a relative path really be made absolute by simply prepending a '/' ? - if (!path.startsWith('/')) { - path = QString("/") + path; - } - url.setPath(path); - _folderParameters->setEnabled(false); - bool success = doConnectionTest(url); - _folderParameters->setEnabled(true); - if (!success) { - KMessageBox::sorry(this, i18n("Unable to connect to server. Please check your settings and try again.")); - button(BackButton)->setEnabled(true); - return false; - } + KRun::runUrl(url, "inode/directory", this); - KRun::runUrl(url, "inode/directory", this); + QString name = _connectionName->text().trimmed(); - QString name = _connectionName->text().trimmed(); + if (_createIcon->isChecked()) { + KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview"); - if (_createIcon->isChecked()) { - KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview"); + QString path = KGlobal::dirs()->saveLocation("remote_entries"); + path += name + ".desktop"; + KConfig _desktopFile( path, KConfig::SimpleConfig ); + KConfigGroup desktopFile(&_desktopFile, "Desktop Entry"); + desktopFile.writeEntry("Icon", "folder-remote"); + desktopFile.writeEntry("Name", name); + desktopFile.writeEntry("Type", "Link"); + desktopFile.writeEntry("URL", url.prettyUrl()); + desktopFile.writeEntry("Charset", url.fileEncoding()); + desktopFile.sync(); + org::kde::KDirNotify::emitFilesAdded( "remote:/" ); + } - QString path = KGlobal::dirs()->saveLocation("remote_entries"); - path += name + ".desktop"; - KConfig _desktopFile( path, KConfig::SimpleConfig ); - KConfigGroup desktopFile(&_desktopFile, "Desktop Entry"); - desktopFile.writeEntry("Icon", "folder-remote"); - desktopFile.writeEntry("Name", name); - desktopFile.writeEntry("Type", "Link"); - desktopFile.writeEntry("URL", url.prettyUrl()); - desktopFile.writeEntry("Charset", url.fileEncoding()); - desktopFile.sync(); - org::kde::KDirNotify::emitFilesAdded( "remote:/" ); - } - - if (!name.isEmpty()) { - KConfig _recent("krecentconnections", KConfig::NoGlobals); - KConfigGroup recent(&_recent, "General"); - QStringList idx = recent.readEntry("Index",QStringList()); - _recent.deleteGroup(name); // erase anything stale - if (idx.contains(name)) { - idx.removeAll(name); - idx.prepend(name); - recent.writeEntry("Index", idx); - } else { - QString last; - if (!idx.isEmpty()) { - last = idx.last(); - idx.pop_back(); - } - idx.prepend(name); - _recent.deleteGroup(last); - recent.writeEntry("Index", idx); - } - recent = KConfigGroup(&_recent,name); - recent.writeEntry("URL", url.prettyUrl()); - if (_type == "WebFolder" || _type == "Fish" || _type == "FTP") { - recent.writeEntry("Port", _port->value()); - } - recent.writeEntry("Type", _type); - recent.sync(); - } + if (!name.isEmpty()) { + KConfig _recent("krecentconnections", KConfig::NoGlobals); + KConfigGroup recent(&_recent, "General"); + QStringList idx = recent.readEntry("Index",QStringList()); + _recent.deleteGroup(name); // erase anything stale + if (idx.contains(name)) { + idx.removeAll(name); + idx.prepend(name); + recent.writeEntry("Index", idx); + } else { + QString last; + if (!idx.isEmpty()) { + last = idx.last(); + idx.pop_back(); + } + idx.prepend(name); + _recent.deleteGroup(last); + recent.writeEntry("Index", idx); + } + recent = KConfigGroup(&_recent,name); + recent.writeEntry("URL", url.prettyUrl()); + if (_type == "WebFolder" || _type == "SFTP" || _type == "FTP") { + recent.writeEntry("Port", _port->value()); + } + recent.writeEntry("Type", _type); + recent.sync(); + } } return true; } @@ -268,11 +274,11 @@ bool KNetAttach::validateCurrentPage() void KNetAttach::updatePort(bool encryption) { if (_webfolder->isChecked()) { - if (encryption) { - _port->setValue(443); - } else { - _port->setValue(80); - } + if (encryption) { + _port->setValue(443); + } else { + _port->setValue(80); + } } } @@ -281,8 +287,8 @@ bool KNetAttach::doConnectionTest(const KUrl& url) { KIO::UDSEntry entry; if (KIO::NetAccess::stat(url, entry, this)) { - // Anything to test here? - return true; + // Anything to test here? + return true; } return false; } @@ -292,48 +298,40 @@ bool KNetAttach::updateForProtocol(const QString& protocol) { _type = protocol; if (protocol == "WebFolder") { - _useEncryption->show(); - _portText->show(); - _port->show(); - _protocol->hide(); - _protocolText->hide(); - _userText->show(); - _user->show(); - _encodingText->hide(); - _encoding->hide(); - } else if (protocol == "Fish") { - _useEncryption->hide(); - _portText->show(); - _port->show(); - _protocol->show(); - _protocolText->show(); - _userText->show(); - _user->show(); - _encodingText->show(); - _encoding->show(); + _useEncryption->show(); + _portText->show(); + _port->show(); + _userText->show(); + _user->show(); + _encodingText->hide(); + _encoding->hide(); + } else if (protocol == "SFTP") { + _useEncryption->hide(); + _portText->show(); + _port->show(); + _userText->show(); + _user->show(); + _encodingText->hide(); + _encoding->hide(); } else if (protocol == "FTP") { - _useEncryption->hide(); - _portText->show(); - _port->show(); - _protocol->hide(); - _protocolText->hide(); - _userText->show(); - _user->show(); - _encodingText->show(); - _encoding->show(); + _useEncryption->hide(); + _portText->show(); + _port->show(); + _userText->show(); + _user->show(); + _encodingText->show(); + _encoding->show(); } else if (protocol == "SMB") { - _useEncryption->hide(); - _portText->hide(); - _port->hide(); - _protocol->hide(); - _protocolText->hide(); - _userText->hide(); - _user->hide(); - _encodingText->hide(); - _encoding->hide(); + _useEncryption->hide(); + _portText->hide(); + _port->hide(); + _userText->hide(); + _user->hide(); + _encodingText->hide(); + _encoding->hide(); } else { - _type = ""; - return false; + _type = ""; + return false; } return true; } @@ -342,9 +340,9 @@ bool KNetAttach::updateForProtocol(const QString& protocol) void KNetAttach::updateFinishButtonText(bool save) { if (save) { - button(FinishButton)->setText(i18n("Save && C&onnect")); + button(FinishButton)->setText(i18n("Save && C&onnect")); } else { - button(FinishButton)->setText(i18n("C&onnect")); + button(FinishButton)->setText(i18n("C&onnect")); } } diff --git a/knetattach/knetattach.ui b/knetattach/knetattach.ui index 717328a9..3b954be8 100644 --- a/knetattach/knetattach.ui +++ b/knetattach/knetattach.ui @@ -77,9 +77,9 @@ - + - &Secure shell (ssh) + &SSH File Transfer Protocol (sftp) false @@ -108,14 +108,14 @@ - FT&P + &File Transfer Protocol (ftp) - &Microsoft® Windows® network drive + &Microsoft® Windows® network drive (smb) @@ -145,6 +145,22 @@ Network Folder Information + + + + &Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + _connectionName + + + @@ -158,6 +174,22 @@ + + + + &User: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + _user + + + @@ -174,51 +206,9 @@ - - - - &Name: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - _connectionName - - - - - - - &User: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - _user - - - - - - - - 10 - 0 - - - - @@ -235,8 +225,8 @@ - - + + 10 @@ -261,6 +251,16 @@ + + + + + 10 + 0 + + + + @@ -281,36 +281,6 @@ - - - &Protocol: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - _port - - - - - - - - sftp - - - - - fish - - - - - &Folder: @@ -326,10 +296,10 @@ - + - + true @@ -345,10 +315,10 @@ - + - + Cr&eate an icon for this remote folder @@ -358,14 +328,14 @@ - + &Use encryption - + Qt::Vertical