knetattach: enable protocols based on slaves availability

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-02-16 14:35:33 +02:00
parent e28216c4e0
commit 0ecf46034e
2 changed files with 255 additions and 287 deletions

View file

@ -35,12 +35,18 @@
#include <KDebug> #include <KDebug>
#include <KRun> #include <KRun>
#include <KToolInvocation> #include <KToolInvocation>
#include <KProtocolInfo>
KNetAttach::KNetAttach( QWidget* parent ) KNetAttach::KNetAttach( QWidget* parent )
: QWizard( parent ), Ui_KNetAttach() : QWizard( parent ), Ui_KNetAttach()
{ {
setupUi( this ); 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(_recent, SIGNAL(toggled(bool)), _recentConnectionName, SLOT(setEnabled(bool)));
connect(_connectionName, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus())); connect(_connectionName, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
connect(_user, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus())); connect(_user, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
@ -88,8 +94,8 @@ void KNetAttach::setInformationText( const QString &type )
if (type=="WebFolder") { if (type=="WebFolder") {
text = i18n("Enter a name for this <i>WebFolder</i> as well as a server address, port and folder path to use and press the <b>Save & Connect</b> button."); text = i18n("Enter a name for this <i>WebFolder</i> as well as a server address, port and folder path to use and press the <b>Save & Connect</b> button.");
} else if (type=="Fish") { } else if (type=="SFTP") {
text = i18n("Enter a name for this <i>Secure shell connection</i> as well as a server address, port and folder path to use and press the <b>Save & Connect</b> button."); text = i18n("Enter a name for this <i>SSH File Transfer Protocol</i> as well as a server address, port and folder path to use and press the <b>Save & Connect</b> button.");
} else if (type=="FTP") { } else if (type=="FTP") {
text = i18n("Enter a name for this <i>File Transfer Protocol connection</i> as well as a server address and folder path to use and press the <b>Save & Connect</b> button."); text = i18n("Enter a name for this <i>File Transfer Protocol connection</i> as well as a server address and folder path to use and press the <b>Save & Connect</b> button.");
} else if (type=="SMB") { } else if (type=="SMB") {
@ -104,7 +110,8 @@ void KNetAttach::updateParametersPageStatus()
button(FinishButton)->setEnabled( button(FinishButton)->setEnabled(
!_host->text().trimmed().isEmpty() && !_host->text().trimmed().isEmpty() &&
!_path->text().trimmed().isEmpty() && !_path->text().trimmed().isEmpty() &&
!_connectionName->text().trimmed().isEmpty()); !_connectionName->text().trimmed().isEmpty()
);
} }
bool KNetAttach::validateCurrentPage() bool KNetAttach::validateCurrentPage()
@ -117,10 +124,13 @@ bool KNetAttach::validateCurrentPage()
setInformationText("WebFolder"); setInformationText("WebFolder");
updateForProtocol("WebFolder"); updateForProtocol("WebFolder");
_port->setValue(80); _port->setValue(80);
} else if (_fish->isChecked()) { } else if (_sftp->isChecked()) {
setInformationText("Fish"); setInformationText("SFTP");
updateForProtocol("Fish"); updateForProtocol("SFTP");
_port->setValue(22); _port->setValue(22);
if (_path->text().isEmpty()) {
_path->setText("/");
}
} else if (_ftp->isChecked()) { } else if (_ftp->isChecked()) {
setInformationText("FTP"); setInformationText("FTP");
updateForProtocol("FTP"); updateForProtocol("FTP");
@ -166,7 +176,6 @@ bool KNetAttach::validateCurrentPage()
_createIcon->setChecked(false); _createIcon->setChecked(false);
} }
updateParametersPageStatus(); updateParametersPageStatus();
} else { } else {
button(BackButton)->setEnabled(false); button(BackButton)->setEnabled(false);
button(FinishButton)->setEnabled(false); button(FinishButton)->setEnabled(false);
@ -178,11 +187,8 @@ bool KNetAttach::validateCurrentPage()
url.setProtocol("webdav"); url.setProtocol("webdav");
} }
url.setPort(_port->value()); url.setPort(_port->value());
} else if (_type == "Fish") { } else if (_type == "SFTP") {
KConfig config("kio_fishrc"); url.setProtocol("sftp");
KConfigGroup cg(&config, _host->text().trimmed());
cg.writeEntry("Charset", KGlobal::charsets()->encodingForName(_encoding->currentText()));
url.setProtocol(_protocolText->currentText());
url.setPort(_port->value()); url.setPort(_port->value());
} else if (_type == "FTP") { } else if (_type == "FTP") {
url.setProtocol("ftp"); url.setProtocol("ftp");
@ -254,7 +260,7 @@ bool KNetAttach::validateCurrentPage()
} }
recent = KConfigGroup(&_recent,name); recent = KConfigGroup(&_recent,name);
recent.writeEntry("URL", url.prettyUrl()); recent.writeEntry("URL", url.prettyUrl());
if (_type == "WebFolder" || _type == "Fish" || _type == "FTP") { if (_type == "WebFolder" || _type == "SFTP" || _type == "FTP") {
recent.writeEntry("Port", _port->value()); recent.writeEntry("Port", _port->value());
} }
recent.writeEntry("Type", _type); recent.writeEntry("Type", _type);
@ -295,28 +301,22 @@ bool KNetAttach::updateForProtocol(const QString& protocol)
_useEncryption->show(); _useEncryption->show();
_portText->show(); _portText->show();
_port->show(); _port->show();
_protocol->hide();
_protocolText->hide();
_userText->show(); _userText->show();
_user->show(); _user->show();
_encodingText->hide(); _encodingText->hide();
_encoding->hide(); _encoding->hide();
} else if (protocol == "Fish") { } else if (protocol == "SFTP") {
_useEncryption->hide(); _useEncryption->hide();
_portText->show(); _portText->show();
_port->show(); _port->show();
_protocol->show();
_protocolText->show();
_userText->show(); _userText->show();
_user->show(); _user->show();
_encodingText->show(); _encodingText->hide();
_encoding->show(); _encoding->hide();
} else if (protocol == "FTP") { } else if (protocol == "FTP") {
_useEncryption->hide(); _useEncryption->hide();
_portText->show(); _portText->show();
_port->show(); _port->show();
_protocol->hide();
_protocolText->hide();
_userText->show(); _userText->show();
_user->show(); _user->show();
_encodingText->show(); _encodingText->show();
@ -325,8 +325,6 @@ bool KNetAttach::updateForProtocol(const QString& protocol)
_useEncryption->hide(); _useEncryption->hide();
_portText->hide(); _portText->hide();
_port->hide(); _port->hide();
_protocol->hide();
_protocolText->hide();
_userText->hide(); _userText->hide();
_user->hide(); _user->hide();
_encodingText->hide(); _encodingText->hide();

View file

@ -77,9 +77,9 @@
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="_fish"> <widget class="QRadioButton" name="_sftp">
<property name="text"> <property name="text">
<string>&amp;Secure shell (ssh)</string> <string>&amp;SSH File Transfer Protocol (sftp)</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
@ -108,14 +108,14 @@
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="_ftp"> <widget class="QRadioButton" name="_ftp">
<property name="text"> <property name="text">
<string>FT&amp;P</string> <string>&amp;File Transfer Protocol (ftp)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QRadioButton" name="_smb"> <widget class="QRadioButton" name="_smb">
<property name="text"> <property name="text">
<string>&amp;Microsoft® Windows® network drive</string> <string>&amp;Microsoft® Windows® network drive (smb)</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -145,6 +145,22 @@
<string>Network Folder Information</string> <string>Network Folder Information</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout1"> <layout class="QGridLayout" name="gridLayout1">
<item row="2" column="0">
<widget class="QLabel" name="textLabel4_2">
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_connectionName</cstring>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3"> <item row="0" column="0" colspan="3">
<widget class="QLabel" name="_informationText"> <widget class="QLabel" name="_informationText">
<property name="text"> <property name="text">
@ -158,6 +174,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="_userText">
<property name="text">
<string>&amp;User:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_user</cstring>
</property>
</widget>
</item>
<item row="1" column="2"> <item row="1" column="2">
<spacer name="spacer20_2"> <spacer name="spacer20_2">
<property name="orientation"> <property name="orientation">
@ -174,51 +206,9 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="textLabel4_2">
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_connectionName</cstring>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2"> <item row="2" column="1" colspan="2">
<widget class="KLineEdit" name="_connectionName"/> <widget class="KLineEdit" name="_connectionName"/>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="_userText">
<property name="text">
<string>&amp;User:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_user</cstring>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="KLineEdit" name="_user">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="textLabel1"> <widget class="QLabel" name="textLabel1">
<property name="text"> <property name="text">
@ -235,8 +225,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1" colspan="2"> <item row="3" column="1" colspan="2">
<widget class="KLineEdit" name="_host"> <widget class="KLineEdit" name="_user">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch> <horstretch>10</horstretch>
@ -261,6 +251,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1" colspan="2">
<widget class="KLineEdit" name="_host">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="KIntSpinBox" name="_port"> <widget class="KIntSpinBox" name="_port">
<property name="sizePolicy"> <property name="sizePolicy">
@ -281,36 +281,6 @@
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QLabel" name="_protocol">
<property name="text">
<string>&amp;Protocol:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_port</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="KComboBox" name="_protocolText">
<item>
<property name="text">
<string notr="true">sftp</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">fish</string>
</property>
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="textLabel3"> <widget class="QLabel" name="textLabel3">
<property name="text"> <property name="text">
<string>&amp;Folder:</string> <string>&amp;Folder:</string>
@ -326,10 +296,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1" colspan="2"> <item row="6" column="1" colspan="2">
<widget class="KLineEdit" name="_path"/> <widget class="KLineEdit" name="_path"/>
</item> </item>
<item row="8" column="0"> <item row="7" column="0">
<widget class="QLabel" name="_encodingText"> <widget class="QLabel" name="_encodingText">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -345,10 +315,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1"> <item row="7" column="1">
<widget class="KComboBox" name="_encoding"/> <widget class="KComboBox" name="_encoding"/>
</item> </item>
<item row="9" column="1" colspan="2"> <item row="8" column="1" colspan="2">
<widget class="QCheckBox" name="_createIcon"> <widget class="QCheckBox" name="_createIcon">
<property name="text"> <property name="text">
<string>Cr&amp;eate an icon for this remote folder</string> <string>Cr&amp;eate an icon for this remote folder</string>
@ -358,14 +328,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="1"> <item row="9" column="1">
<widget class="QCheckBox" name="_useEncryption"> <widget class="QCheckBox" name="_useEncryption">
<property name="text"> <property name="text">
<string>&amp;Use encryption</string> <string>&amp;Use encryption</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="0" colspan="3"> <item row="10" column="0" colspan="3">
<spacer name="spacer5"> <spacer name="spacer5">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>