summaryrefslogtreecommitdiffstats
path: root/knetattach/knetattach.ui.h
blob: 7ac898dec8911e0d5ea4a6e47291dc34b7073ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/

void KNetAttach::init()
{
    setIcon(SmallIcon("knetattach"));
    disconnect(finishButton(), TQ_SIGNAL(clicked()), (TQDialog*)this, TQ_SLOT(accept()));
    connect(finishButton(), TQ_SIGNAL(clicked()), this, TQ_SLOT(finished()));
    finishButton()->setText(i18n("Save && C&onnect"));
    //setResizeMode(Fixed); FIXME: make the wizard fixed-geometry
    setFinishEnabled(_folderParameters, false);
    TDEConfig recent("tderecentconnections", true, false);
    recent.setGroup("General");
    TQStringList idx = recent.readListEntry("Index");
    if (idx.isEmpty()) {
	_recent->setEnabled(false);
	if (_recent->isChecked()) {
	    _webfolder->setChecked(true);
	}
    } else {
	_recent->setEnabled(true);
	_recentConnectionName->insertStringList(idx);
    }
}

void KNetAttach::setInformationText( const TQString &type )
{
    TQString text;
    
    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.");
    } else if (type=="Fish"||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.");
    } 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.");
    } 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.");
    }
    
    _informationText->setText(text);
}

void KNetAttach::showPage( TQWidget *page )
{
    if (page == _folderType) {
    } else if (page == _folderParameters) {
	_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 (_sftp->isChecked()) {
        setInformationText("SFTP");
        updateForProtocol("SFTP");
        _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()) {
	    TDEConfig recent("tderecentconnections", true, false);
	    if (!recent.hasGroup(_recentConnectionName->currentText())) {
		recent.setGroup("General");
		TQStringList idx = recent.readListEntry("Index");
		if (idx.isEmpty()) {
		    _recent->setEnabled(false);
		    if (_recent->isChecked()) {
			_webfolder->setChecked(true);
		    }
		} else {
		    _recent->setEnabled(true);
		    _recentConnectionName->insertStringList(idx);
		}
		showPage(_folderType);
		return;
	    }
	    recent.setGroup(_recentConnectionName->currentText());
	    _type = recent.readEntry("Type");
	    setInformationText(_type);
	    if (!updateForProtocol(_type)) {
		// FIXME: handle error
	    }
	    KURL u(recent.readEntry("URL"));
	    _host->setText(u.host());
	    _user->setText(u.user());
	    _path->setText(u.path());
	    if (recent.hasKey("Port")) {
		_port->setValue(recent.readNumEntry("Port"));
	    } else {
		_port->setValue(u.port());
	    }
	    _connectionName->setText(_recentConnectionName->currentText());
	    _createIcon->setChecked(false);
	}
	updateParametersPageStatus();
    }

    TQWizard::showPage(page);
}


void KNetAttach::updateParametersPageStatus()
{
    setFinishEnabled(_folderParameters,
		  !_host->text().stripWhiteSpace().isEmpty() &&
		  !_path->text().stripWhiteSpace().isEmpty() &&
		  !_connectionName->text().stripWhiteSpace().isEmpty());
}

void KNetAttach::finished()
{
    setBackEnabled(_folderParameters,false);
    setFinishEnabled(_folderParameters, false);
    KURL url;
    if (_type == "WebFolder") {
	if (_useEncryption->isChecked()) {
	    url.setProtocol("webdavs");
	} else {
	    url.setProtocol("webdav");
	}
	url.setPort(_port->value());
    } else if (_type == "Fish") {
	url.setProtocol("fish");
	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());
    } else if (_type == "SMB") {
	url.setProtocol("smb");
    } else { // recent
    }

    url.setHost(_host->text().stripWhiteSpace());
    url.setUser(_user->text().stripWhiteSpace());
    TQString path = _path->text().stripWhiteSpace();
    if (!path.startsWith("/")) {
	path = TQString("/") + 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."));
	showPage(_folderParameters);
	setBackEnabled(_folderParameters, true);
	return;
    }

    kapp->invokeBrowser(url.url());

    TQString name = _connectionName->text().stripWhiteSpace();

    if (_createIcon->isChecked()) {
	TDEGlobal::dirs()->addResourceType("remote_entries",
		TDEStandardDirs::kde_default("data") + "remoteview");

	TQString path = TDEGlobal::dirs()->saveLocation("remote_entries");
	path += name + ".desktop";
	KSimpleConfig desktopFile(path, false);
	desktopFile.setGroup("Desktop Entry");
	desktopFile.writeEntry("Icon", "applications-internet");
	desktopFile.writeEntry("Name", name);
	desktopFile.writeEntry("Type", "Link");
	desktopFile.writeEntry("URL", url.prettyURL());
	desktopFile.sync();
	KDirNotify_stub notifier("*", "*");
	notifier.FilesAdded( "remote:/" );
    }

    if (!name.isEmpty()) {
	TDEConfig recent("tderecentconnections", false, false);
	recent.setGroup("General");
	TQStringList idx = recent.readListEntry("Index");
	recent.deleteGroup(name); // erase anything stale
	if (idx.contains(name)) {
	    idx.remove(name);
	    idx.prepend(name);
	    recent.writeEntry("Index", idx);
	    recent.setGroup(name);
	} else {
	    TQString last;
	    if (!idx.isEmpty()) {
		last = idx.last();
		idx.pop_back();
	    }
	    idx.prepend(name);
	    recent.deleteGroup(last);
	    recent.writeEntry("Index", idx);
	}
	recent.setGroup(name);
	recent.writeEntry("URL", url.prettyURL());
	if (_type == "WebFolder" || _type == "Fish" || _type == "SFTP" || _type == "FTP") {
	    recent.writeEntry("Port", _port->value());
	}
	recent.writeEntry("Type", _type);
	recent.sync();
    }

    TQDialog::accept();
}


void KNetAttach::updatePort(bool encryption)
{
    if (_webfolder->isChecked()) {
	if (encryption) {
	    _port->setValue(443);
	} else {
	    _port->setValue(80);
	}
    }
}


bool KNetAttach::doConnectionTest(const KURL& url)
{
    TDEIO::UDSEntry entry;
    if (TDEIO::NetAccess::stat(url, entry, this)) {
	// Anything to test here?
	return true;
    }
    return false;
}


bool KNetAttach::updateForProtocol(const TQString& protocol)
{
    _type = protocol;
    if (protocol == "WebFolder") {
	_useEncryption->show();
	_portText->show();
	_port->show();
	_userText->show();
	_user->show();
    } else if (protocol == "Fish" || protocol == "SFTP") {
	_useEncryption->hide();
	_portText->show();
	_port->show();
	_userText->show();
	_user->show();
    } else if (protocol == "FTP") {
	_useEncryption->hide();
	_portText->show();
	_port->show();
	_userText->show();
	_user->show();
    } else if (protocol == "SMB") {
	_useEncryption->hide();
	_portText->hide();
	_port->hide();
	_userText->hide();
	_user->hide();
    } else {
	_type = "";
	return false;
    }
    return true;
}


void KNetAttach::updateFinishButtonText(bool save)
{
    if (save) {
	finishButton()->setText(i18n("Save && C&onnect"));
    } else {
	finishButton()->setText(i18n("C&onnect"));
    }
}