166
68
user = o->getOption(base + ".user").toString();
167
69
pass = decodePassword(o->getOption(base + ".pass").toString(), PASSWORDKEY);
171
72
QDomElement ProxySettings::toXml(QDomDocument *doc) const
173
74
QDomElement e = doc->createElement("proxySettings");
174
e.appendChild(textTag(*doc, "host", host));
175
e.appendChild(textTag(*doc, "port", QString::number(port)));
176
e.appendChild(textTag(*doc, "url", url));
177
e.appendChild(textTag(*doc, "useAuth", useAuth));
178
e.appendChild(textTag(*doc, "user", user));
179
e.appendChild(textTag(*doc, "pass", pass));
75
e.appendChild(XMLHelper::textTag(*doc, "host", host));
76
e.appendChild(XMLHelper::textTag(*doc, "port", QString::number(port)));
77
e.appendChild(XMLHelper::textTag(*doc, "url", url));
78
e.appendChild(XMLHelper::textTag(*doc, "useAuth", useAuth));
79
e.appendChild(XMLHelper::textTag(*doc, "user", user));
80
e.appendChild(XMLHelper::textTag(*doc, "pass", pass));
183
84
bool ProxySettings::fromXml(const QDomElement &e)
185
host = findSubTag(e, "host").text();
186
port = findSubTag(e, "port").text().toInt();
187
url = findSubTag(e, "url").text();
188
useAuth = (findSubTag(e, "useAuth").text() == "true") ? true: false;
189
user = findSubTag(e, "user").text();
190
pass = findSubTag(e, "pass").text();
86
host = findSubTag(e, "host", 0).text();
87
port = findSubTag(e, "port", 0).text().toInt();
88
url = findSubTag(e, "url", 0).text();
89
useAuth = (findSubTag(e, "useAuth", 0).text() == "true") ? true: false;
90
user = findSubTag(e, "user", 0).text();
91
pass = findSubTag(e, "pass", 0).text();
195
//----------------------------------------------------------------------------
197
//----------------------------------------------------------------------------
198
class ProxyEdit::Private
203
HostPortEdit *hp_host;
206
QLineEdit *le_url, *le_user, *le_pass;
210
ProxyEdit::ProxyEdit(QWidget *parent, const char *name)
211
:Q3GroupBox(1, Qt::Horizontal, tr("Settings"), parent, name)
215
//QVBoxLayout *vb = new QVBoxLayout(this);
216
//QVBox *gb = new QVBox(this);
222
d->hp_host = new HostPortEdit(this);
224
Q3HBox *hb = new Q3HBox(this);
225
d->lb_url = new QLabel(tr("Polling URL:"), hb);
226
d->le_url = new QLineEdit(hb);
228
d->ck_auth = new QCheckBox(tr("Use authentication"), this);
229
connect(d->ck_auth, SIGNAL(toggled(bool)), SLOT(ck_toggled(bool)));
231
d->gr_auth = new Q3Grid(2, Qt::Horizontal, this);
232
d->gr_auth->setSpacing(4);
233
l = new QLabel(tr("Username:"), d->gr_auth);
234
d->le_user = new QLineEdit(d->gr_auth);
235
l = new QLabel(tr("Password:"), d->gr_auth);
236
d->le_pass = new QLineEdit(d->gr_auth);
237
d->le_pass->setEchoMode(QLineEdit::Password);
238
d->gr_auth->setEnabled(false);
240
d->hp_host->setWhatsThis(
241
tr("Enter the hostname and port of your proxy server.") + " " +
242
tr("Consult your network administrator if necessary."));
243
d->le_user->setWhatsThis(
244
tr("Enter your proxy server login (username) "
245
"or leave this field blank if the proxy server does not require it.") + " " +
246
tr("Consult your network administrator if necessary."));
247
d->le_pass->setWhatsThis(
248
tr("Enter your proxy server password "
249
"or leave this field blank if the proxy server does not require it.") + " " +
250
tr("Consult your network administrator if necessary."));
253
ProxyEdit::~ProxyEdit()
258
void ProxyEdit::reset()
260
d->hp_host->setHost("");
261
d->hp_host->setPort(0);
262
d->le_url->setText("");
263
d->ck_auth->setChecked(false);
264
d->le_user->setText("");
265
d->le_pass->setText("");
268
void ProxyEdit::setType(const QString &s)
271
d->lb_url->setEnabled(true);
272
d->le_url->setEnabled(true);
275
d->lb_url->setEnabled(false);
276
d->le_url->setEnabled(false);
280
ProxySettings ProxyEdit::proxySettings() const
283
s.host = d->hp_host->host();
284
s.port = d->hp_host->port();
285
if(d->le_url->isEnabled())
286
s.url = d->le_url->text();
287
s.useAuth = d->ck_auth->isChecked();
288
s.user = d->le_user->text();
289
s.pass = d->le_pass->text();
293
void ProxyEdit::setProxySettings(const ProxySettings &s)
295
d->hp_host->setHost(s.host);
296
d->hp_host->setPort(s.port);
297
d->le_url->setText(s.url);
298
d->ck_auth->setChecked(s.useAuth);
299
d->le_user->setText(s.user);
300
d->le_pass->setText(s.pass);
303
void ProxyEdit::ck_toggled(bool b)
305
d->gr_auth->setEnabled(b);
308
void ProxyEdit::fixTabbing(QWidget *a, QWidget *b)
310
d->hp_host->fixTabbing(a, d->le_url);
311
setTabOrder(d->le_url, d->ck_auth);
312
setTabOrder(d->ck_auth, d->le_user);
313
setTabOrder(d->le_user, d->le_pass);
314
setTabOrder(d->le_pass, b);
318
95
//----------------------------------------------------------------------------
320
97
//----------------------------------------------------------------------------
321
class ProxyDlg::Private
98
class ProxyDlg::Private : public QObject
103
HostRole = Qt::UserRole + 1,
104
PortRole = Qt::UserRole + 2,
105
UrlRole = Qt::UserRole + 3,
106
AuthRole = Qt::UserRole + 4,
107
UserRole = Qt::UserRole + 5,
108
PassRole = Qt::UserRole + 6,
109
IdRole = Qt::UserRole + 7,
110
TypeRole = Qt::UserRole + 8
326
ProxyEdit *pe_settings;
327
114
ProxyItemList list;
116
Private(ProxyDlg* dialog)
122
connect(q->ui_.lbx_proxy, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentItemChanged(QListWidgetItem*, QListWidgetItem*)));
124
connect(q->ui_.pb_new, SIGNAL(clicked()), SLOT(addProxy()));
125
connect(q->ui_.pb_remove, SIGNAL(clicked()), SLOT(removeProxy()));
127
connect(q->ui_.buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(accept()));
128
connect(q->ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), q, SLOT(reject()));
129
q->ui_.buttonBox->button(QDialogButtonBox::Save)->setDefault(true);
131
connect(q->ui_.lbx_proxy->itemDelegate(), SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), SLOT(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
133
connect(q->ui_.le_host, SIGNAL(textEdited(const QString&)), SLOT(updateCurrentItem()));
134
connect(q->ui_.le_port, SIGNAL(textEdited(const QString&)), SLOT(updateCurrentItem()));
135
connect(q->ui_.le_url, SIGNAL(textEdited(const QString&)), SLOT(updateCurrentItem()));
136
connect(q->ui_.le_user, SIGNAL(textEdited(const QString&)), SLOT(updateCurrentItem()));
137
connect(q->ui_.le_pass, SIGNAL(textEdited(const QString&)), SLOT(updateCurrentItem()));
138
connect(q->ui_.gr_auth, SIGNAL(toggled(bool)), SLOT(updateCurrentItem()));
139
connect(q->ui_.cb_type, SIGNAL(activated (int)), SLOT(updateCurrentItem()));
143
void loadProxies(const QString& currentProxy)
145
q->ui_.lbx_proxy->clear();
147
QListWidgetItem* firstItem = 0;
148
QListWidgetItem* currentItem = 0;
149
foreach(ProxyItem i, list) {
150
QListWidgetItem* item = new QListWidgetItem(i.name);
153
item->setData(IdRole, QVariant(i.id));
154
item->setData(TypeRole, QVariant(i.type));
155
item->setData(HostRole, QVariant(i.settings.host));
156
item->setData(PortRole, QVariant(i.settings.port));
157
item->setData(UserRole, QVariant(i.settings.user));
158
item->setData(PassRole, QVariant(i.settings.pass));
159
item->setData(AuthRole, QVariant(i.settings.useAuth));
160
item->setData(UrlRole, QVariant(i.settings.url));
166
if (i.id == currentProxy) {
172
firstItem = currentItem;
176
q->ui_.lbx_proxy->setCurrentItem(firstItem);
177
q->ui_.lbx_proxy->scrollToItem(firstItem);
184
for (int i = 0; i < q->ui_.lbx_proxy->count(); ++i) {
185
QListWidgetItem* item = q->ui_.lbx_proxy->item(i);
188
pi.name = item->data(Qt::DisplayRole).toString();
189
pi.id = item->data(IdRole).toString();
190
pi.type = item->data(TypeRole).toString();
191
pi.settings.host = item->data(HostRole).toString();
192
pi.settings.port = item->data(PortRole).toInt();
193
pi.settings.user = item->data(UserRole).toString();
194
pi.settings.pass = item->data(PassRole).toString();
195
pi.settings.useAuth = item->data(AuthRole).toBool();
196
pi.settings.url = item->data(UrlRole).toString();
204
emit q->applyList(list, q->ui_.lbx_proxy->currentRow());
208
void currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous)
211
q->ui_.pb_remove->setEnabled(current);
213
QList<QWidget*> editors = QList<QWidget*>()
221
foreach(QWidget* w, editors) {
222
w->blockSignals(true);
223
w->setEnabled(current);
225
if (dynamic_cast<QLineEdit*>(w))
226
dynamic_cast<QLineEdit*>(w)->setText(QString());
231
int type = q->ui_.cb_type->findData(current->data(TypeRole).toString());
232
q->ui_.cb_type->setCurrentIndex(type == -1 ? 0 : type);
233
q->ui_.le_host->setText(current->data(HostRole).toString());
234
q->ui_.le_port->setText(current->data(PortRole).toString());
235
q->ui_.le_user->setText(current->data(UserRole).toString());
236
q->ui_.le_pass->setText(current->data(PassRole).toString());
237
q->ui_.le_url->setText(current->data(UrlRole).toString());
238
q->ui_.gr_auth->setChecked(true); // make sure gr_auth disables its children if AuthRole is false
239
q->ui_.gr_auth->setChecked(current->data(AuthRole).toBool());
242
foreach(QWidget* w, editors) {
243
w->blockSignals(false);
249
void updateCurrentItem()
251
QListWidgetItem* item = q->ui_.lbx_proxy->currentItem();
255
QString type = q->ui_.cb_type->itemData(q->ui_.cb_type->currentIndex()).toString();
256
item->setData(TypeRole, type);
257
item->setData(HostRole, q->ui_.le_host->text());
258
item->setData(PortRole, q->ui_.le_port->text());
259
item->setData(UserRole, q->ui_.le_user->text());
260
item->setData(PassRole, q->ui_.le_pass->text());
261
item->setData(UrlRole, q->ui_.le_url->text());
262
item->setData(AuthRole, q->ui_.gr_auth->isChecked());
264
q->ui_.le_url->setEnabled(type == "poll");
267
void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint)
271
if (hint == QAbstractItemDelegate::SubmitModelCache) {
272
q->ui_.cb_type->setFocus();
276
void addItem(QListWidgetItem* item)
279
item->setFlags(item->flags() | Qt::ItemIsEditable);
280
q->ui_.lbx_proxy->addItem(item);
285
QListWidgetItem* item = new QListWidgetItem(tr("Unnamed"));
287
q->ui_.lbx_proxy->reset(); // ensure that open editors won't get in our way
288
q->ui_.lbx_proxy->setCurrentItem(item);
289
q->ui_.lbx_proxy->editItem(item);
294
QListWidgetItem* item = q->ui_.lbx_proxy->takeItem(q->ui_.lbx_proxy->currentRow());
331
ProxyDlg::ProxyDlg(const ProxyItemList &list, const QStringList &methods, const QString &def, QWidget *parent)
299
ProxyDlg::ProxyDlg(const ProxyItemList &list, const QString &def, QWidget *parent)
332
300
: QDialog(parent)
334
304
setAttribute(Qt::WA_DeleteOnClose);
337
setWindowTitle(CAP(caption()));
338
setModal(QApplication::activeModalWidget() ? true: false);
305
d = new Private(this);
342
d->pe_settings = new ProxyEdit(gb_prop);
343
replaceWidget(lb_proxyedit, d->pe_settings);
344
d->pe_settings->fixTabbing(cb_type, pb_close);
348
connect(pb_new, SIGNAL(clicked()), SLOT(proxy_new()));
349
connect(pb_remove, SIGNAL(clicked()), SLOT(proxy_remove()));
350
connect(pb_save, SIGNAL(clicked()), SLOT(doSave()));
351
connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
352
gb_prop->setEnabled(false);
353
pb_remove->setEnabled(false);
354
pb_save->setDefault(true);
356
cb_type->insertStringList(methods);
357
connect(cb_type, SIGNAL(activated(int)), SLOT(cb_activated(int)));
361
for(ProxyItemList::ConstIterator it = d->list.begin(); it != d->list.end(); ++it) {
362
lbx_proxy->insertItem((*it).name);
363
if ((*it).id == def) defIdx= i;
366
if(!list.isEmpty()) {
369
lbx_proxy->setCurrentItem(defIdx);
373
cb_type->setWhatsThis(
308
setWindowTitle(CAP(windowTitle()));
311
ui_.cb_type->addItem("HTTP \"Connect\"", "http");
312
ui_.cb_type->addItem("SOCKS Version 5", "socks");
313
ui_.cb_type->addItem("HTTP Polling", "poll");
315
ui_.le_host->setWhatsThis(
316
tr("Enter the hostname and port of your proxy server.") + " " +
317
tr("Consult your network administrator if necessary."));
318
ui_.le_port->setWhatsThis(ui_.le_host->whatsThis());
319
ui_.le_user->setWhatsThis(
320
tr("Enter your proxy server login (username) "
321
"or leave this field blank if the proxy server does not require it.") + " " +
322
tr("Consult your network administrator if necessary."));
323
ui_.le_pass->setWhatsThis(
324
tr("Enter your proxy server password "
325
"or leave this field blank if the proxy server does not require it.") + " " +
326
tr("Consult your network administrator if necessary."));
327
ui_.cb_type->setWhatsThis(
374
328
tr("If you require a proxy server to connect, select the type of proxy here.") + " " +
375
329
tr("Consult your network administrator if necessary."));
376
// TODO: whatsthis for name
379
334
ProxyDlg::~ProxyDlg()
384
void ProxyDlg::proxy_new()
387
s.id = ""; // id of "" means 'new'
388
s.name = getUniqueName();
391
lbx_proxy->insertItem(s.name);
392
lbx_proxy->setCurrentItem(lbx_proxy->count()-1);
396
void ProxyDlg::proxy_remove()
398
int x = lbx_proxy->currentItem();
400
ProxyItemList::Iterator it = d->list.begin();
401
for(int n = 0; n < x; ++n)
406
lbx_proxy->removeItem(x);
411
void ProxyDlg::cb_activated(int x)
414
d->pe_settings->setType("http");
416
d->pe_settings->setType("socks");
418
d->pe_settings->setType("poll");
421
void ProxyDlg::selectCurrent()
423
int x = lbx_proxy->currentItem();
425
lbx_proxy->setSelected(x, true);
428
QString ProxyDlg::getUniqueName() const
434
str = QString("Proxy %1").arg(++x);
436
for(ProxyItemList::ConstIterator it = d->list.begin(); it != d->list.end(); ++it) {
437
if(str == (*it).name) {
446
void ProxyDlg::saveIntoItem(int x)
448
ProxyItem &s = d->list[x];
449
s.name = le_name->text();
450
int i = cb_type->currentItem();
458
s.settings = d->pe_settings->proxySettings();
461
void ProxyDlg::qlbx_highlighted(int x)
463
// if we are moving off of another item, save its content
465
saveIntoItem(d->last);
468
// display the new item's content
470
le_name->setText("");
471
cb_type->setCurrentItem(0);
472
d->pe_settings->reset();
473
gb_prop->setEnabled(false);
474
pb_remove->setEnabled(false);
477
ProxyItem &s = d->list[x];
478
le_name->setText(s.name);
482
else if(s.type == "socks")
484
else if(s.type == "poll")
486
cb_type->setCurrentItem(i);
487
d->pe_settings->setProxySettings(s.settings);
489
gb_prop->setEnabled(true);
490
pb_remove->setEnabled(true);
494
void ProxyDlg::qle_textChanged(const QString &s)
496
int x = lbx_proxy->currentItem();
499
lbx_proxy->changeItem(s, x);
504
// hookEdit / unhookEdit - disconnect some signals to prevent recursion
505
void ProxyDlg::hookEdit()
507
connect(lbx_proxy, SIGNAL(highlighted(int)), this, SLOT(qlbx_highlighted(int)));
508
connect(le_name, SIGNAL(textChanged(const QString &)), this, SLOT(qle_textChanged(const QString &)));
511
void ProxyDlg::unhookEdit()
513
disconnect(lbx_proxy, SIGNAL(highlighted(int)), this, SLOT(qlbx_highlighted(int)));
514
disconnect(le_name, SIGNAL(textChanged(const QString &)), this, SLOT(qle_textChanged(const QString &)));
517
void ProxyDlg::doSave()
519
int x = lbx_proxy->currentItem();
522
applyList(d->list, x);
527
339
//----------------------------------------------------------------------------
529
341
//----------------------------------------------------------------------------