view ui/proxysettingsdlg.cpp @ 1119:5349e2354c48

(issue54) Merge branch runafterinstall There is now an NSIS Plugin that executes the Software after installation using COM in the shell of the current user. With the way over the shell there is no inheritance / token management required. As it is impossible to drop all privileges of a token granted by UAC and still be able to reelevate the Token again with another RunAs call later this round trip over the Shell was necessary.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 16 Sep 2014 19:48:22 +0200
parents 8a1071fee883
children
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QSettings>
#include <QPushButton>
#include <QUrl>
#include <QDebug>
#include <QIcon>
#include <QPixmap>
#include <QCheckBox>

#include "proxysettingsdlg.h"

ProxySettingsDlg::ProxySettingsDlg(QWidget *parent) :
    QDialog (parent) {
    setWindowIcon(QIcon(":/img/preferences-network_16.png"));
    setWindowTitle(tr("Proxy server settings"));
    QVBoxLayout *mainLayout = new QVBoxLayout();
    QHBoxLayout *iconTextLayout = new QHBoxLayout();
    QHBoxLayout *labelLineLayout = new QHBoxLayout();
    QHBoxLayout *okCancelLayout = new QHBoxLayout();

    QSettings settings;

    QLabel *iconLabel = new QLabel();
    iconLabel->setPixmap(QPixmap(":/img/preferences-network_64.png"));
    iconTextLayout->addWidget(iconLabel);

    QLabel *explanation = new QLabel(tr("Please enter the proxy server to use in the field below.") +
        " " + tr("The URL can follow the scheme:") + "<br/>" + 
        tr("[&lt;username&gt;:&lt;password&gt;@]&lt;hostname&gt;[:&lt;port&gt;]") +
        "<br/></br/>");
    explanation->setTextFormat(Qt::RichText);
    explanation->setWordWrap(true);

    iconTextLayout->addWidget(explanation);
    mainLayout->addLayout(iconTextLayout);

    bool useProxy = settings.value("UseProxy", false).toBool();
    mCheckBox = new QCheckBox(tr("Use Proxy Server"));
    mCheckBox->setTristate(false);
    mCheckBox->setCheckState(useProxy ? Qt::Checked : Qt::Unchecked);

    mainLayout->addWidget(mCheckBox);

    mProxyURL = new QLineEdit(settings.value("ProxyURL").toString());
    QLabel *proxyLabel = new QLabel(tr("Proxy Server:"));
    proxyLabel->setBuddy(mProxyURL);
    mProxyURL->setReadOnly(!useProxy);
    mProxyURL->setEnabled(useProxy);

    labelLineLayout->addWidget(proxyLabel);
    labelLineLayout->addWidget(mProxyURL);

    mSaveButton = new QPushButton (tr("&Save"));
    QPushButton * cancelButton = new QPushButton (tr("&Cancel"));
    okCancelLayout->addStretch(10);
    okCancelLayout->addWidget(mSaveButton);
    okCancelLayout->addWidget(cancelButton);

    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    connect(mSaveButton, SIGNAL(clicked()), this, SLOT(save()));
    connect(mProxyURL, SIGNAL(textChanged(const QString &)),
            this, SLOT(checkCanSave(const QString&)));
    connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkCanEdit(int)));

    mainLayout->addLayout(labelLineLayout);
    mainLayout->addLayout(okCancelLayout);

    setLayout(mainLayout);
}

void ProxySettingsDlg::checkCanSave(const QString &val) {
    mSaveButton->setEnabled(mCheckBox->checkState() == Qt::Unchecked ||
        QUrl(val).isValid());
}

void ProxySettingsDlg::checkCanEdit(int state) {
    mProxyURL->setReadOnly(state != Qt::Checked);
    mProxyURL->setEnabled(state == Qt::Checked);
}

void ProxySettingsDlg::save() {
    QSettings settings;
    settings.setValue("ProxyURL", mProxyURL->text());
    settings.setValue("UseProxy", mCheckBox->checkState() == Qt::Checked);
    settings.sync();
    accept();
}

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