knetattach: add NFS share support

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-02-16 16:21:45 +02:00
parent 17cf6caa0e
commit 8c33590ed1
2 changed files with 76 additions and 52 deletions

View file

@ -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 <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") {
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.");
} else if (type=="SFTP") {
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=="SFTP") {
text = i18n("Enter a name for this <i>Network File System</i> as well as a server address, port and folder path to use and press the <b>Save & Connect</b> button.");
} else if (type=="SMB") {
text = i18n("Enter a name for this <i>Microsoft Windows network drive</i> as well as a server address and folder path to use and press the <b>Save & Connect</b> 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();

View file

@ -47,6 +47,40 @@
</property>
</spacer>
</item>
<item>
<widget class="QRadioButton" name="_ftp">
<property name="text">
<string>&amp;File Transfer Protocol (ftp)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="_sftp">
<property name="text">
<string>&amp;SSH File Transfer Protocol (sftp)</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="_nfs">
<property name="text">
<string>N&amp;etwork File System (nfs)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="_smb">
<property name="text">
<string>&amp;Microsoft® Windows® network drive (smb)</string>
</property>
</widget>
</item>
<item>
<widget class="KButtonGroup" name="buttonGroup1">
<property name="title">
@ -85,33 +119,6 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QRadioButton" name="_sftp">
<property name="text">
<string>&amp;SSH File Transfer Protocol (sftp)</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="_smb">
<property name="text">
<string>&amp;Microsoft® Windows® network drive (smb)</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="_ftp">
<property name="text">
<string>&amp;File Transfer Protocol (ftp)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>