00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 void KNetAttach::init()
00014 {
00015 setIcon(SmallIcon("knetattach"));
00016 disconnect(finishButton(), TQT_SIGNAL(clicked()), (TQDialog*)this, TQT_SLOT(accept()));
00017 connect(finishButton(), TQT_SIGNAL(clicked()), this, TQT_SLOT(finished()));
00018 finishButton()->setText(i18n("Save && C&onnect"));
00019
00020 setFinishEnabled(_folderParameters, false);
00021 KConfig recent("krecentconnections", true, false);
00022 recent.setGroup("General");
00023 TQStringList idx = recent.readListEntry("Index");
00024 if (idx.isEmpty()) {
00025 _recent->setEnabled(false);
00026 if (_recent->isChecked()) {
00027 _webfolder->setChecked(true);
00028 }
00029 } else {
00030 _recent->setEnabled(true);
00031 _recentConnectionName->insertStringList(idx);
00032 }
00033 }
00034
00035 void KNetAttach::setInformationText( const TQString &type )
00036 {
00037 TQString text;
00038
00039 if (type=="WebFolder") {
00040 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.");
00041 } else if (type=="Fish") {
00042 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.");
00043 } else if (type=="FTP") {
00044 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.");
00045 } else if (type=="SMB") {
00046 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.");
00047 }
00048
00049 _informationText->setText(text);
00050 }
00051
00052 void KNetAttach::showPage( TQWidget *page )
00053 {
00054 if (page == _folderType) {
00055 } else if (page == _folderParameters) {
00056 _host->setFocus();
00057 _connectionName->setFocus();
00058
00059 if (_webfolder->isChecked()) {
00060 setInformationText("WebFolder");
00061 updateForProtocol("WebFolder");
00062 _port->setValue(80);
00063 } else if (_fish->isChecked()) {
00064 setInformationText("Fish");
00065 updateForProtocol("Fish");
00066 _port->setValue(22);
00067 } else if (_ftp->isChecked()) {
00068 setInformationText("FTP");
00069 updateForProtocol("FTP");
00070 _port->setValue(21);
00071 if (_path->text().isEmpty()) {
00072 _path->setText("/");
00073 }
00074 } else if (_smb->isChecked()) {
00075 setInformationText("SMB");
00076 updateForProtocol("SMB");
00077 } else {
00078 KConfig recent("krecentconnections", true, false);
00079 if (!recent.hasGroup(_recentConnectionName->currentText())) {
00080 recent.setGroup("General");
00081 TQStringList idx = recent.readListEntry("Index");
00082 if (idx.isEmpty()) {
00083 _recent->setEnabled(false);
00084 if (_recent->isChecked()) {
00085 _webfolder->setChecked(true);
00086 }
00087 } else {
00088 _recent->setEnabled(true);
00089 _recentConnectionName->insertStringList(idx);
00090 }
00091 showPage(_folderType);
00092 return;
00093 }
00094 recent.setGroup(_recentConnectionName->currentText());
00095 _type = recent.readEntry("Type");
00096 setInformationText(_type);
00097 if (!updateForProtocol(_type)) {
00098
00099 }
00100 KURL u(recent.readEntry("URL"));
00101 _host->setText(u.host());
00102 _user->setText(u.user());
00103 _path->setText(u.path());
00104 if (recent.hasKey("Port")) {
00105 _port->setValue(recent.readNumEntry("Port"));
00106 } else {
00107 _port->setValue(u.port());
00108 }
00109 _connectionName->setText(_recentConnectionName->currentText());
00110 _createIcon->setChecked(false);
00111 }
00112 updateParametersPageStatus();
00113 }
00114
00115 TQWizard::showPage(page);
00116 }
00117
00118
00119 void KNetAttach::updateParametersPageStatus()
00120 {
00121 setFinishEnabled(_folderParameters,
00122 !_host->text().stripWhiteSpace().isEmpty() &&
00123 !_path->text().stripWhiteSpace().isEmpty() &&
00124 !_connectionName->text().stripWhiteSpace().isEmpty());
00125 }
00126
00127 void KNetAttach::finished()
00128 {
00129 setBackEnabled(_folderParameters,false);
00130 setFinishEnabled(_folderParameters, false);
00131 KURL url;
00132 if (_type == "WebFolder") {
00133 if (_useEncryption->isChecked()) {
00134 url.setProtocol("webdavs");
00135 } else {
00136 url.setProtocol("webdav");
00137 }
00138 url.setPort(_port->value());
00139 } else if (_type == "Fish") {
00140 url.setProtocol("fish");
00141 url.setPort(_port->value());
00142 } else if (_type == "FTP") {
00143 url.setProtocol("ftp");
00144 url.setPort(_port->value());
00145 } else if (_type == "SMB") {
00146 url.setProtocol("smb");
00147 } else {
00148 }
00149
00150 url.setHost(_host->text().stripWhiteSpace());
00151 url.setUser(_user->text().stripWhiteSpace());
00152 TQString path = _path->text().stripWhiteSpace();
00153 if (!path.startsWith("/")) {
00154 path = TQString("/") + path;
00155 }
00156 url.setPath(path);
00157 _folderParameters->setEnabled(false);
00158 bool success = doConnectionTest(url);
00159 _folderParameters->setEnabled(true);
00160 if (!success) {
00161 KMessageBox::sorry(this, i18n("Unable to connect to server. Please check your settings and try again."));
00162 showPage(_folderParameters);
00163 setBackEnabled(_folderParameters, true);
00164 return;
00165 }
00166
00167 kapp->invokeBrowser(url.url());
00168
00169 TQString name = _connectionName->text().stripWhiteSpace();
00170
00171 if (_createIcon->isChecked()) {
00172 KGlobal::dirs()->addResourceType("remote_entries",
00173 KStandardDirs::kde_default("data") + "remoteview");
00174
00175 TQString path = KGlobal::dirs()->saveLocation("remote_entries");
00176 path += name + ".desktop";
00177 KSimpleConfig desktopFile(path, false);
00178 desktopFile.setGroup("Desktop Entry");
00179 desktopFile.writeEntry("Icon", "package_network");
00180 desktopFile.writeEntry("Name", name);
00181 desktopFile.writeEntry("Type", "Link");
00182 desktopFile.writeEntry("URL", url.prettyURL());
00183 desktopFile.sync();
00184 KDirNotify_stub notifier("*", "*");
00185 notifier.FilesAdded( "remote:/" );
00186 }
00187
00188 if (!name.isEmpty()) {
00189 KConfig recent("krecentconnections", false, false);
00190 recent.setGroup("General");
00191 TQStringList idx = recent.readListEntry("Index");
00192 recent.deleteGroup(name);
00193 if (idx.contains(name)) {
00194 idx.remove(name);
00195 idx.prepend(name);
00196 recent.writeEntry("Index", idx);
00197 recent.setGroup(name);
00198 } else {
00199 TQString last;
00200 if (!idx.isEmpty()) {
00201 last = idx.last();
00202 idx.pop_back();
00203 }
00204 idx.prepend(name);
00205 recent.deleteGroup(last);
00206 recent.writeEntry("Index", idx);
00207 }
00208 recent.setGroup(name);
00209 recent.writeEntry("URL", url.prettyURL());
00210 if (_type == "WebFolder" || _type == "Fish" || _type == "FTP") {
00211 recent.writeEntry("Port", _port->value());
00212 }
00213 recent.writeEntry("Type", _type);
00214 recent.sync();
00215 }
00216
00217 TQDialog::accept();
00218 }
00219
00220
00221 void KNetAttach::updatePort(bool encryption)
00222 {
00223 if (_webfolder->isChecked()) {
00224 if (encryption) {
00225 _port->setValue(443);
00226 } else {
00227 _port->setValue(80);
00228 }
00229 }
00230 }
00231
00232
00233 bool KNetAttach::doConnectionTest(const KURL& url)
00234 {
00235 KIO::UDSEntry entry;
00236 if (KIO::NetAccess::stat(url, entry, this)) {
00237
00238 return true;
00239 }
00240 return false;
00241 }
00242
00243
00244 bool KNetAttach::updateForProtocol(const TQString& protocol)
00245 {
00246 _type = protocol;
00247 if (protocol == "WebFolder") {
00248 _useEncryption->show();
00249 _portText->show();
00250 _port->show();
00251 _userText->show();
00252 _user->show();
00253 } else if (protocol == "Fish") {
00254 _useEncryption->hide();
00255 _portText->show();
00256 _port->show();
00257 _userText->show();
00258 _user->show();
00259 } else if (protocol == "FTP") {
00260 _useEncryption->hide();
00261 _portText->show();
00262 _port->show();
00263 _userText->show();
00264 _user->show();
00265 } else if (protocol == "SMB") {
00266 _useEncryption->hide();
00267 _portText->hide();
00268 _port->hide();
00269 _userText->hide();
00270 _user->hide();
00271 } else {
00272 _type = "";
00273 return false;
00274 }
00275 return true;
00276 }
00277
00278
00279 void KNetAttach::updateFinishButtonText(bool save)
00280 {
00281 if (save) {
00282 finishButton()->setText(i18n("Save && C&onnect"));
00283 } else {
00284 finishButton()->setText(i18n("C&onnect"));
00285 }
00286 }
00287
00288