comparison ui/proxysettingsdlg.cpp @ 955:0f7aeb12e5e9

(issue41) Add proxsettingsdialog
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 27 Aug 2014 16:31:11 +0200
parents
children c1f32c87716a
comparison
equal deleted inserted replaced
954:eaea1504f282 955:0f7aeb12e5e9
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=2)
5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details.
7 */
8
9 #include <QHBoxLayout>
10 #include <QVBoxLayout>
11 #include <QLabel>
12 #include <QLineEdit>
13 #include <QSettings>
14 #include <QPushButton>
15 #include <QUrl>
16 #include <QDebug>
17 #include <QIcon>
18 #include <QPixmap>
19
20 #include "proxysettingsdlg.h"
21
22 ProxySettingsDlg::ProxySettingsDlg(QWidget *parent) :
23 QDialog (parent) {
24 setWindowIcon(QIcon(":/img/preferences-network_16.png"));
25 setWindowTitle(tr("Proxy server settings"));
26 QVBoxLayout *mainLayout = new QVBoxLayout();
27 QHBoxLayout *iconTextLayout = new QHBoxLayout();
28 QHBoxLayout *labelLineLayout = new QHBoxLayout();
29 QHBoxLayout *okCancelLayout = new QHBoxLayout();
30
31 QSettings settings;
32
33 QLabel *iconLabel = new QLabel();
34 iconLabel->setPixmap(QPixmap(":/img/preferences-network_64.png"));
35 iconTextLayout->addWidget(iconLabel);
36
37 QLabel *explanation = new QLabel(tr("Please enter the proxy server to use in the field below.") +
38 "</br>" + tr("The URL can follow the scheme:") + " " +
39 tr("&lt;username&gt;:&lt;password&gt;@&lt;hostname&gt;:&lt;port&gt;") +
40 "</br></br>");
41 explanation->setTextFormat(Qt::RichText);
42 explanation->setWordWrap(true);
43
44 iconTextLayout->addWidget(explanation);
45 mainLayout->addLayout(iconTextLayout);
46
47 mProxyURL = new QLineEdit(settings.value("ProxyURL").toString());
48 QLabel *proxyLabel = new QLabel(tr("Proxy Server:"));
49 proxyLabel->setBuddy(mProxyURL);
50
51 labelLineLayout->addWidget(proxyLabel);
52 labelLineLayout->addWidget(mProxyURL);
53
54 mSaveButton = new QPushButton (tr("&Save"));
55 QPushButton * cancelButton = new QPushButton (tr("&Cancel"));
56 okCancelLayout->addStretch(10);
57 okCancelLayout->addWidget(mSaveButton);
58 okCancelLayout->addWidget(cancelButton);
59
60 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
61 connect(mSaveButton, SIGNAL(clicked()), this, SLOT(save()));
62 connect(mProxyURL, SIGNAL(textChanged(const QString &)),
63 this, SLOT(checkCanSave(const QString&)));
64
65 mainLayout->addLayout(labelLineLayout);
66 mainLayout->addLayout(okCancelLayout);
67
68 setLayout(mainLayout);
69 }
70
71 void ProxySettingsDlg::checkCanSave(const QString &val) {
72 mSaveButton->setEnabled(val.isEmpty() || QUrl(val).isValid());
73 }
74
75 void ProxySettingsDlg::save() {
76 QSettings settings;
77 settings.setValue("ProxyURL", mProxyURL->text());
78 settings.sync();
79 accept();
80 }

http://wald.intevation.org/projects/trustbridge/