Changeset View
Changeset View
Standalone View
Standalone View
knetattach/knetattach.cpp
Show All 27 Lines | |||||
28 | #include <KLocale> | 28 | #include <KLocale> | ||
29 | #include <KGlobalSettings> | 29 | #include <KGlobalSettings> | ||
30 | #include <KConfig> | 30 | #include <KConfig> | ||
31 | #include <KConfigGroup> | 31 | #include <KConfigGroup> | ||
32 | #include <KStandardDirs> | 32 | #include <KStandardDirs> | ||
33 | #include <KDirNotify> | 33 | #include <KDirNotify> | ||
34 | #include <KCharsets> | 34 | #include <KCharsets> | ||
35 | #include <KDebug> | 35 | #include <KDebug> | ||
36 | #include <KUrl> | | |||
37 | #include <KRun> | 36 | #include <KRun> | ||
38 | #include <KToolInvocation> | 37 | #include <KToolInvocation> | ||
39 | #include <KGlobal> | 38 | #include <KGlobal> | ||
40 | #include <QDesktopServices> | 39 | #include <QDesktopServices> | ||
41 | #include <QTextCodec> | 40 | #include <QTextCodec> | ||
42 | 41 | | |||
43 | KNetAttach::KNetAttach( QWidget* parent ) | 42 | KNetAttach::KNetAttach( QWidget* parent ) | ||
44 | : QWizard( parent ), Ui_KNetAttach() | 43 | : QWizard( parent ), Ui_KNetAttach() | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 140 | if (!recent.hasGroup(_recentConnectionName->currentText())) { | |||
153 | return false; | 152 | return false; | ||
154 | } | 153 | } | ||
155 | KConfigGroup group = recent.group(_recentConnectionName->currentText()); | 154 | KConfigGroup group = recent.group(_recentConnectionName->currentText()); | ||
156 | _type = group.readEntry("Type"); | 155 | _type = group.readEntry("Type"); | ||
157 | setInformationText(_type); | 156 | setInformationText(_type); | ||
158 | if (!updateForProtocol(_type)) { | 157 | if (!updateForProtocol(_type)) { | ||
159 | // FIXME: handle error | 158 | // FIXME: handle error | ||
160 | } | 159 | } | ||
161 | KUrl u(group.readEntry("URL")); | 160 | QUrl u(group.readEntry("URL")); | ||
162 | _host->setText(u.host()); | 161 | _host->setText(u.host()); | ||
163 | _user->setText(u.user()); | 162 | _user->setText(u.userName()); | ||
164 | _path->setText(u.path()); | 163 | _path->setText(u.path()); | ||
165 | if (group.hasKey("Port")) { | 164 | if (group.hasKey("Port")) { | ||
166 | _port->setValue(group.readEntry("Port",0)); | 165 | _port->setValue(group.readEntry("Port",0)); | ||
167 | } else { | 166 | } else { | ||
168 | _port->setValue(u.port()); | 167 | _port->setValue(u.port()); | ||
169 | } | 168 | } | ||
170 | _connectionName->setText(_recentConnectionName->currentText()); | 169 | _connectionName->setText(_recentConnectionName->currentText()); | ||
171 | _createIcon->setChecked(false); | 170 | _createIcon->setChecked(false); | ||
172 | } | 171 | } | ||
173 | updateParametersPageStatus(); | 172 | updateParametersPageStatus(); | ||
174 | 173 | | |||
175 | }else{ | 174 | }else{ | ||
176 | button(BackButton)->setEnabled(false); | 175 | button(BackButton)->setEnabled(false); | ||
177 | button(FinishButton)->setEnabled(false); | 176 | button(FinishButton)->setEnabled(false); | ||
178 | KUrl url; | 177 | QUrl url; | ||
179 | if (_type == QLatin1String("WebFolder")) { | 178 | if (_type == QLatin1String("WebFolder")) { | ||
180 | if (_useEncryption->isChecked()) { | 179 | if (_useEncryption->isChecked()) { | ||
181 | url.setProtocol(QStringLiteral("webdavs")); | 180 | url.setScheme(QStringLiteral("webdavs")); | ||
182 | } else { | 181 | } else { | ||
183 | url.setProtocol(QStringLiteral("webdav")); | 182 | url.setScheme(QStringLiteral("webdav")); | ||
184 | } | 183 | } | ||
185 | url.setPort(_port->value()); | 184 | url.setPort(_port->value()); | ||
186 | } else if (_type == QLatin1String("Fish")) { | 185 | } else if (_type == QLatin1String("Fish")) { | ||
187 | KConfig config(QStringLiteral("kio_fishrc")); | 186 | KConfig config(QStringLiteral("kio_fishrc")); | ||
188 | KConfigGroup cg(&config, _host->text().trimmed()); | 187 | KConfigGroup cg(&config, _host->text().trimmed()); | ||
189 | cg.writeEntry("Charset", KCharsets::charsets()->encodingForName(_encoding->currentText())); | 188 | cg.writeEntry("Charset", KCharsets::charsets()->encodingForName(_encoding->currentText())); | ||
190 | url.setProtocol(_protocolText->currentText()); | 189 | url.setScheme(_protocolText->currentText()); | ||
191 | url.setPort(_port->value()); | 190 | url.setPort(_port->value()); | ||
192 | } else if (_type == QLatin1String("FTP")) { | 191 | } else if (_type == QLatin1String("FTP")) { | ||
193 | url.setProtocol(QStringLiteral("ftp")); | 192 | url.setScheme(QStringLiteral("ftp")); | ||
194 | url.setPort(_port->value()); | 193 | url.setPort(_port->value()); | ||
195 | KConfig config(QStringLiteral("kio_ftprc")); | 194 | KConfig config(QStringLiteral("kio_ftprc")); | ||
196 | KConfigGroup cg(&config, _host->text().trimmed()); | 195 | KConfigGroup cg(&config, _host->text().trimmed()); | ||
197 | cg.writeEntry("Charset", KCharsets::charsets()->encodingForName(_encoding->currentText())); | 196 | cg.writeEntry("Charset", KCharsets::charsets()->encodingForName(_encoding->currentText())); | ||
198 | config.sync(); | 197 | config.sync(); | ||
199 | } else if (_type == QLatin1String("SMB")) { | 198 | } else if (_type == QLatin1String("SMB")) { | ||
200 | url.setProtocol(QStringLiteral("smb")); | 199 | url.setScheme(QStringLiteral("smb")); | ||
201 | } else { // recent | 200 | } else { // recent | ||
202 | } | 201 | } | ||
203 | 202 | | |||
204 | url.setHost(_host->text().trimmed()); | 203 | url.setHost(_host->text().trimmed()); | ||
205 | url.setUser(_user->text().trimmed()); | 204 | url.setUserName(_user->text().trimmed()); | ||
206 | QString path = _path->text().trimmed(); | 205 | QString path = _path->text().trimmed(); | ||
207 | #ifndef Q_WS_WIN | 206 | #ifndef Q_WS_WIN | ||
208 | // could a relative path really be made absolute by simply prepending a '/' ? | 207 | // could a relative path really be made absolute by simply prepending a '/' ? | ||
209 | if (!path.startsWith(QLatin1Char('/'))) { | 208 | if (!path.startsWith(QLatin1Char('/'))) { | ||
210 | path = QLatin1Char('/') + path; | 209 | path = QLatin1Char('/') + path; | ||
211 | } | 210 | } | ||
212 | #endif | 211 | #endif | ||
213 | url.setPath(path); | 212 | url.setPath(path); | ||
Show All 15 Lines | 226 | if (_createIcon->isChecked()) { | |||
229 | 228 | | |||
230 | QString path = KGlobal::dirs()->saveLocation("remote_entries"); | 229 | QString path = KGlobal::dirs()->saveLocation("remote_entries"); | ||
231 | path += name + QStringLiteral(".desktop"); | 230 | path += name + QStringLiteral(".desktop"); | ||
232 | KConfig _desktopFile( path, KConfig::SimpleConfig ); | 231 | KConfig _desktopFile( path, KConfig::SimpleConfig ); | ||
233 | KConfigGroup desktopFile(&_desktopFile, "Desktop Entry"); | 232 | KConfigGroup desktopFile(&_desktopFile, "Desktop Entry"); | ||
234 | desktopFile.writeEntry("Icon", "folder-remote"); | 233 | desktopFile.writeEntry("Icon", "folder-remote"); | ||
235 | desktopFile.writeEntry("Name", name); | 234 | desktopFile.writeEntry("Name", name); | ||
236 | desktopFile.writeEntry("Type", "Link"); | 235 | desktopFile.writeEntry("Type", "Link"); | ||
237 | desktopFile.writeEntry("URL", url.prettyUrl()); | 236 | desktopFile.writeEntry("URL", url.toDisplayString()); | ||
238 | desktopFile.writeEntry("Charset", url.fileEncoding()); | 237 | desktopFile.writeEntry("Charset", url.queryItemValue("charset")); | ||
239 | desktopFile.sync(); | 238 | desktopFile.sync(); | ||
240 | org::kde::KDirNotify::emitFilesAdded( QUrl(QStringLiteral("remote:/")) ); | 239 | org::kde::KDirNotify::emitFilesAdded( QUrl(QStringLiteral("remote:/")) ); | ||
241 | } | 240 | } | ||
242 | 241 | | |||
243 | if (!name.isEmpty()) { | 242 | if (!name.isEmpty()) { | ||
244 | KConfig _recent(QStringLiteral("krecentconnections"), KConfig::NoGlobals); | 243 | KConfig _recent(QStringLiteral("krecentconnections"), KConfig::NoGlobals); | ||
245 | KConfigGroup recent(&_recent, "General"); | 244 | KConfigGroup recent(&_recent, "General"); | ||
246 | QStringList idx = recent.readEntry("Index",QStringList()); | 245 | QStringList idx = recent.readEntry("Index",QStringList()); | ||
247 | _recent.deleteGroup(name); // erase anything stale | 246 | _recent.deleteGroup(name); // erase anything stale | ||
248 | if (idx.contains(name)) { | 247 | if (idx.contains(name)) { | ||
249 | idx.removeAll(name); | 248 | idx.removeAll(name); | ||
250 | idx.prepend(name); | 249 | idx.prepend(name); | ||
251 | recent.writeEntry("Index", idx); | 250 | recent.writeEntry("Index", idx); | ||
252 | } else { | 251 | } else { | ||
253 | QString last; | 252 | QString last; | ||
254 | if (!idx.isEmpty()) { | 253 | if (!idx.isEmpty()) { | ||
255 | last = idx.last(); | 254 | last = idx.last(); | ||
256 | idx.pop_back(); | 255 | idx.pop_back(); | ||
257 | } | 256 | } | ||
258 | idx.prepend(name); | 257 | idx.prepend(name); | ||
259 | _recent.deleteGroup(last); | 258 | _recent.deleteGroup(last); | ||
260 | recent.writeEntry("Index", idx); | 259 | recent.writeEntry("Index", idx); | ||
261 | } | 260 | } | ||
262 | recent = KConfigGroup(&_recent,name); | 261 | recent = KConfigGroup(&_recent,name); | ||
263 | recent.writeEntry("URL", url.prettyUrl()); | 262 | recent.writeEntry("URL", url.toDisplayString()); | ||
264 | if (_type == QLatin1String("WebFolder") || _type == QLatin1String("Fish") || _type == QLatin1String("FTP")) { | 263 | if (_type == QLatin1String("WebFolder") || _type == QLatin1String("Fish") || _type == QLatin1String("FTP")) { | ||
265 | recent.writeEntry("Port", _port->value()); | 264 | recent.writeEntry("Port", _port->value()); | ||
266 | } | 265 | } | ||
267 | recent.writeEntry("Type", _type); | 266 | recent.writeEntry("Type", _type); | ||
268 | recent.sync(); | 267 | recent.sync(); | ||
269 | } | 268 | } | ||
270 | } | 269 | } | ||
271 | return true; | 270 | return true; | ||
272 | } | 271 | } | ||
273 | 272 | | |||
274 | 273 | | |||
275 | void KNetAttach::updatePort(bool encryption) | 274 | void KNetAttach::updatePort(bool encryption) | ||
276 | { | 275 | { | ||
277 | if (_webfolder->isChecked()) { | 276 | if (_webfolder->isChecked()) { | ||
278 | if (encryption) { | 277 | if (encryption) { | ||
279 | _port->setValue(443); | 278 | _port->setValue(443); | ||
280 | } else { | 279 | } else { | ||
281 | _port->setValue(80); | 280 | _port->setValue(80); | ||
282 | } | 281 | } | ||
283 | } | 282 | } | ||
284 | } | 283 | } | ||
285 | 284 | | |||
286 | 285 | | |||
287 | bool KNetAttach::doConnectionTest(const KUrl& url) | 286 | bool KNetAttach::doConnectionTest(const QUrl& url) | ||
288 | { | 287 | { | ||
289 | KIO::UDSEntry entry; | 288 | KIO::UDSEntry entry; | ||
290 | if (KIO::NetAccess::stat(url, entry, this)) { | 289 | if (KIO::NetAccess::stat(url, entry, this)) { | ||
291 | // Anything to test here? | 290 | // Anything to test here? | ||
292 | return true; | 291 | return true; | ||
293 | } | 292 | } | ||
294 | return false; | 293 | return false; | ||
295 | } | 294 | } | ||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |