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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
/*
KPF - Public fileserver for KDE
Copyright 2001 Rik Hemsley (rikkus) <rik@kde.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqspinbox.h>
#include <tqdir.h>
#include <tqptrlist.h>
#include <tqlineedit.h>
#include <kapplication.h>
#include <klineedit.h>
#include <kdialog.h>
#include <klocale.h>
#include <kurlrequester.h>
#include <kfiledialog.h>
#include "Defines.h"
#include "ServerWizard.h"
#include "WebServerManager.h"
#include "WebServer.h"
#include "Help.h"
#include <dnssd/servicebrowser.h>
#include <unistd.h>
namespace KPF
{
ServerWizard::ServerWizard(TQWidget * tqparent)
: KWizard(tqparent, "KPF::ServerWizard", true)
{
setCaption(i18n("New Server - %1").tqarg("kpf"));
page1_ = new TQWidget(this);
page2_ = new TQWidget(this);
page3_ = new TQWidget(this);
// page4_ = new TQWidget(this);
page5_ = new TQWidget(this);
TQLabel * l_rootDirectoryHelp =
new TQLabel
(
i18n
(
"<p>"
"Specify the directory which contains the files"
" you wish to share."
"</p>"
"<p>"
"<em>Warning</em>: Do not share any directories that contain"
" sensitive information!"
"</p>"
),
page1_
);
TQLabel * l_listenPortHelp =
new TQLabel
(
i18n
(
"<p>"
"Specify the network `port' on which the server should"
" listen for connections."
"</p>"
),
page2_
);
TQLabel * l_bandwidthLimitHelp =
new TQLabel
(
i18n
(
"<p>"
"Specify the maximum amount of data (in kilobytes) that will be"
" sent out per second."
"</p>"
"<p>"
"This allows you to keep some bandwidth for yourself instead"
" of allowing connections with kpf to hog your connection."
"</p>"
),
page3_
);
/*
TQLabel * l_connectionLimitHelp =
new TQLabel
(
i18n
(
"<p>"
"Specify the maximum number of connections allowed at"
" any one time."
"</p>"
),
page4_
);
*/
bool canPublish = DNSSD::ServiceBrowser::isAvailable() == DNSSD::ServiceBrowser::Working;
TQLabel * l_serverNameHelp =
new TQLabel
(
KPF::HelpText::getServerNameHelp(),
page5_
);
TQLabel * l_root_ =
new TQLabel(i18n("&Root directory:"), page1_);
TQLabel * l_listenPort_ =
new TQLabel(i18n("&Listen port:"), page2_);
TQLabel * l_bandwidthLimit_ =
new TQLabel(i18n("&Bandwidth limit:"), page3_);
// TQLabel * l_connectionLimit_ =
// new TQLabel(i18n("Connection &limit"), page4_);
TQLabel * l_serverName_ =
new TQLabel(i18n("&Server name:"), page5_);
if(!canPublish)
l_serverName_->setEnabled(false);
kur_root_ = new KURLRequester(page1_);
sb_listenPort_ = new TQSpinBox(1, 65535, 1, page2_);
sb_bandwidthLimit_ = new TQSpinBox(1, 999999, 1, page3_);
// sb_connectionLimit_ = new TQSpinBox(1, 9999, 1, page4_);
char hostname[255];
gethostname(hostname, 255-2);
hostname[255-1]=0;
le_serverName_ = new TQLineEdit(hostname, page5_);
if(!canPublish)
le_serverName_->setEnabled(false);
l_root_ ->setBuddy(kur_root_);
l_listenPort_ ->setBuddy(sb_listenPort_);
l_bandwidthLimit_ ->setBuddy(sb_bandwidthLimit_);
l_serverName_ ->setBuddy(le_serverName_);
// l_connectionLimit_ ->setBuddy(sb_connectionLimit_);
sb_listenPort_
->setValue(WebServerManager::instance()->nextFreePort());
sb_bandwidthLimit_ ->setValue(Config::DefaultBandwidthLimit);
sb_bandwidthLimit_ ->setSuffix(i18n(" kB/s"));
// sb_connectionLimit_ ->setValue(Config::DefaultConnectionLimit);
TQVBoxLayout * tqlayout1 =
new TQVBoxLayout(page1_, KDialog::marginHint(), KDialog::spacingHint());
TQVBoxLayout * tqlayout2 =
new TQVBoxLayout(page2_, KDialog::marginHint(), KDialog::spacingHint());
TQVBoxLayout * tqlayout3 =
new TQVBoxLayout(page3_, KDialog::marginHint(), KDialog::spacingHint());
// TQVBoxLayout * tqlayout4 =
// new TQVBoxLayout(page4_, KDialog::marginHint(), KDialog::spacingHint());
TQVBoxLayout * tqlayout5 =
new TQVBoxLayout(page5_, KDialog::marginHint(), KDialog::spacingHint());
tqlayout1->addWidget(l_rootDirectoryHelp);
tqlayout2->addWidget(l_listenPortHelp);
tqlayout3->addWidget(l_bandwidthLimitHelp);
// tqlayout4->addWidget(l_connectionLimitHelp);
tqlayout5->addWidget(l_serverNameHelp);
TQHBoxLayout * tqlayout10 = new TQHBoxLayout(tqlayout1);
tqlayout10->addWidget(l_root_);
tqlayout10->addWidget(kur_root_);
tqlayout1->addStretch(1);
TQHBoxLayout * tqlayout20 = new TQHBoxLayout(tqlayout2);
tqlayout20->addWidget(l_listenPort_);
tqlayout20->addWidget(sb_listenPort_);
tqlayout2->addStretch(1);
TQHBoxLayout * tqlayout30 = new TQHBoxLayout(tqlayout3);
tqlayout30->addWidget(l_bandwidthLimit_);
tqlayout30->addWidget(sb_bandwidthLimit_);
tqlayout3->addStretch(1);
// TQHBoxLayout * tqlayout40 = new TQHBoxLayout(tqlayout4);
// tqlayout40->addWidget(l_connectionLimit_);
// tqlayout40->addWidget(sb_connectionLimit_);
// tqlayout4->addStretch(1);
TQHBoxLayout * tqlayout50 = new TQHBoxLayout(tqlayout5);
tqlayout50->addWidget(l_serverName_);
tqlayout50->addWidget(le_serverName_);
addPage(page1_, i18n("Root Directory"));
addPage(page2_, i18n("Listen Port"));
addPage(page3_, i18n("Bandwidth Limit"));
// addPage(page4_, i18n("Connection Limit"));
addPage(page5_, i18n("Server Name"));
kur_root_->setURL(TQDir::homeDirPath() + "/public_html");
kur_root_->setMode
(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly);
// setFinishEnabled(page4_, true);
setFinishEnabled(page5_, true);
// This slot sets the 'Next' button on page 1 to enabled/disabled
// depending on whether the path is OK.
connect
(
kur_root_,
TQT_SIGNAL(textChanged(const TQString &)),
TQT_SLOT(slotServerRootChanged(const TQString &))
);
// Used for setting the caption on the file dialog.
connect
(
kur_root_,
TQT_SIGNAL(openFileDialog(KURLRequester *)),
TQT_SLOT(slotOpenFileDialog(KURLRequester *))
);
// This slot sets the 'Next' button on page 2 to enabled/disabled
// depending on whether the port is OK.
connect
(
sb_listenPort_,
TQT_SIGNAL(valueChanged(int)),
TQT_SLOT(slotListenPortChanged(int))
);
// Update 'Next' button on page 1.
slotServerRootChanged(kur_root_->url());
// Update 'Next' button on page 2.
slotListenPortChanged(sb_listenPort_->value());
}
ServerWizard::~ServerWizard()
{
}
void
ServerWizard::setLocation(const TQString & location)
{
kur_root_->setURL(location);
}
TQString
ServerWizard::root() const
{
return kur_root_->url();
}
uint
ServerWizard::listenPort() const
{
return sb_listenPort_->value();
}
uint
ServerWizard::bandwidthLimit() const
{
return sb_bandwidthLimit_->value();
}
TQString
ServerWizard::serverName() const
{
return le_serverName_->text();
}
uint
ServerWizard::connectionLimit() const
{
return Config::DefaultConnectionLimit; // sb_connectionLimit_->value();
}
void
ServerWizard::accept()
{
TQWizard::accept();
emit(dying(this));
}
void
ServerWizard::reject()
{
TQWizard::reject();
emit(dying(this));
}
void
ServerWizard::slotListenPortChanged(int newPort)
{
if (newPort <= 1024)
{
setNextEnabled(page2_, false);
return;
}
TQPtrList<WebServer>
serverList(WebServerManager::instance()->serverListLocal());
for (TQPtrListIterator<WebServer> it(serverList); it.current(); ++it)
{
if (it.current()->listenPort() == uint(newPort))
{
setNextEnabled(page2_, false);
return;
}
}
setNextEnabled(page2_, true);
}
void
ServerWizard::slotServerRootChanged(const TQString & _root)
{
TQString root(_root);
kpfDebug << root << endl;
// Duplicate ?
if (WebServerManager::instance()->hasServer(root))
{
kpfDebug << "Already have a server at " << root << endl;
setNextEnabled(page1_, false);
return;
}
if ("/" != root.right(1))
root += "/";
TQFileInfo fi(root);
if (!fi.isDir()) // || (fi.dirPath() == TQDir::homeDirPath()))
{
kpfDebug << root << " isn't a dir" << endl; //, or it's $HOME" << endl;
setNextEnabled(page1_, false);
return;
}
setNextEnabled(page1_, true);
}
void
ServerWizard::slotOpenFileDialog(KURLRequester * urlRequester)
{
KFileDialog * fileDialog = urlRequester->fileDialog();
if (0 == fileDialog)
{
kpfDebug << "URL requester's file dialog is 0" << endl;
return;
}
fileDialog->setCaption(i18n("Choose Directory to Share - %1").tqarg("kpf"));
}
void
ServerWizard::help()
{
kapp->invokeHelp("share-config", "kpf");
}
}
#include "ServerWizard.moc"
// vim:ts=2:sw=2:tw=78:et
|