From 19c25e46e47cc181fb8a633471a528d78e7d85a6 Mon Sep 17 00:00:00 2001 From: Tapani Mikola Date: Mon, 10 Aug 2009 22:24:30 +0300 Subject: Adding the possibility to set the http proxy manually. --- tools/qmlviewer/main.cpp | 2 + tools/qmlviewer/proxysettings.cpp | 78 +++++++++++++++++ tools/qmlviewer/proxysettings.h | 40 +++++++++ tools/qmlviewer/proxysettings.ui | 176 ++++++++++++++++++++++++++++++++++++++ tools/qmlviewer/qmlviewer.cpp | 48 ++++++++++- tools/qmlviewer/qmlviewer.h | 2 + tools/qmlviewer/qmlviewer.pro | 27 +++--- 7 files changed, 360 insertions(+), 13 deletions(-) create mode 100644 tools/qmlviewer/proxysettings.cpp create mode 100644 tools/qmlviewer/proxysettings.h create mode 100644 tools/qmlviewer/proxysettings.ui diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index e5f5e05..b2593a5 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -60,6 +60,8 @@ int main(int argc, char ** argv) QApplication app(argc, argv); app.setApplicationName("viewer"); + app.setOrganizationName("Nokia"); + app.setOrganizationDomain("nokia.com"); bool frameless = false; QString fileName; diff --git a/tools/qmlviewer/proxysettings.cpp b/tools/qmlviewer/proxysettings.cpp new file mode 100644 index 0000000..f232fd1 --- /dev/null +++ b/tools/qmlviewer/proxysettings.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + + +#include +#include + +#include "proxysettings.h" + +ProxySettings::ProxySettings (QWidget * parent) + : QDialog (parent), Ui::ProxySettings() +{ + setupUi (this); + + proxyServerEdit->setInputMask ("000.000.000.000;_"); + QIntValidator *validator = new QIntValidator (0, 9999, this); + proxyPortEdit->setValidator (validator); + + QSettings settings; + proxyCheckBox->setChecked (settings.value ("http_proxy/use", 0).toBool ()); + proxyServerEdit->insert (settings.value ("http_proxy/hostname", "").toString ()); + proxyPortEdit->insert (settings.value ("http_proxy/port", "80").toString ()); + usernameEdit->insert (settings.value ("http_proxy/username", "").toString ()); + passwordEdit->insert (settings.value ("http_proxy/password", "").toString ()); +} + +ProxySettings::~ProxySettings() +{ +} + +void ProxySettings::accept () +{ + QSettings settings; + + settings.setValue ("http_proxy/use", proxyCheckBox->isChecked ()); + settings.setValue ("http_proxy/hostname", proxyServerEdit->text ()); + settings.setValue ("http_proxy/port", proxyPortEdit->text ()); + settings.setValue ("http_proxy/username", usernameEdit->text ()); + settings.setValue ("http_proxy/password", passwordEdit->text ()); + + QDialog::accept (); +} + +QNetworkProxy ProxySettings::httpProxy () +{ + QSettings settings; + QNetworkProxy proxy; + + bool proxyInUse = settings.value ("http_proxy/use", 0).toBool (); + if (proxyInUse) { + proxy.setType (QNetworkProxy::HttpProxy); + proxy.setHostName (settings.value ("http_proxy/hostname", "").toString ());// "192.168.220.5" + proxy.setPort (settings.value ("http_proxy/port", 80).toInt ()); // 8080 + proxy.setUser (settings.value ("http_proxy/username", "").toString ()); + proxy.setPassword (settings.value ("http_proxy/password", "").toString ()); + //QNetworkProxy::setApplicationProxy (proxy); + } + else { + proxy.setType (QNetworkProxy::NoProxy); + } + return proxy; +} + +bool ProxySettings::httpProxyInUse() +{ + QSettings settings; + return settings.value ("http_proxy/use", 0).toBool (); +} diff --git a/tools/qmlviewer/proxysettings.h b/tools/qmlviewer/proxysettings.h new file mode 100644 index 0000000..1d4d577 --- /dev/null +++ b/tools/qmlviewer/proxysettings.h @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef PROXYSETTINGS_H +#define PROXYSETTINGS_H + +#include +#include +#include "ui_proxysettings.h" + +/** +*/ +class ProxySettings : public QDialog, public Ui::ProxySettings +{ + +Q_OBJECT + +public: + ProxySettings(QWidget * parent = 0); + + ~ProxySettings(); + + static QNetworkProxy httpProxy (); + static bool httpProxyInUse (); + +public slots: + virtual void accept (); +}; + +#endif // PROXYSETTINGS_H diff --git a/tools/qmlviewer/proxysettings.ui b/tools/qmlviewer/proxysettings.ui new file mode 100644 index 0000000..75fad16 --- /dev/null +++ b/tools/qmlviewer/proxysettings.ui @@ -0,0 +1,176 @@ + + + ProxySettings + + + + 0 + 0 + 522 + 280 + + + + Dialog + + + + + 20 + 230 + 491 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 150 + 96 + 363 + 30 + + + + + + + 150 + 138 + 363 + 30 + + + + + + + 150 + 180 + 363 + 30 + + + + QLineEdit::Password + + + + + + 20 + 138 + 126 + 30 + + + + Username: + + + + + + 150 + 54 + 363 + 30 + + + + + + + 20 + 19 + 493 + 23 + + + + Use http proxy + + + + + + 20 + 96 + 126 + 30 + + + + Port: + + + + + + 20 + 180 + 126 + 30 + + + + Password: + + + + + + 20 + 54 + 126 + 30 + + + + Server Address: + + + + + + + buttonBox + accepted() + ProxySettings + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ProxySettings + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index c1b9eb1..a1e4911 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -43,6 +43,7 @@ #include #include #include +#include "proxysettings.h" QT_BEGIN_NAMESPACE @@ -355,6 +356,11 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) if (flatmenu) flatmenu->addSeparator(); + QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings")); + QAction *proxyAction = new QAction(tr("Http &proxy..."), parent); + connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings())); + settingsMenu->addAction(proxyAction); + QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help")); QAction *aboutAction = new QAction(tr("&About Qt..."), parent); connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); @@ -371,6 +377,21 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) } } +void QmlViewer::showProxySettings() +{ + ProxySettings settingsDlg (this); + + connect (&settingsDlg, SIGNAL (accepted()), this, SLOT (proxySettingsChanged ())); + + settingsDlg.exec(); +} + +void QmlViewer::proxySettingsChanged() +{ + setupProxy (); + reload (); +} + void QmlViewer::setScaleSkin() { if (scaleSkin) @@ -899,13 +920,36 @@ void QmlViewer::setupProxy() public: virtual QList queryProxy(const QNetworkProxyQuery &query) { + QString protocolTag = query.protocolTag(); + if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) { + QList ret; + ret << httpProxy; + return ret; + } return QNetworkProxyFactory::systemProxyForQuery(query); } + void setHttpProxy (QNetworkProxy proxy) + { + httpProxy = proxy; + httpProxyInUse = true; + } + void unsetHttpProxy () + { + httpProxyInUse = false; + } + private: + bool httpProxyInUse; + QNetworkProxy httpProxy; }; QNetworkAccessManager * nam = canvas->engine()->networkAccessManager(); - nam->setProxyFactory(new SystemProxyFactory); -} + SystemProxyFactory *proxyFactory = new SystemProxyFactory; + if (ProxySettings::httpProxyInUse()) + proxyFactory->setHttpProxy(ProxySettings::httpProxy()); + else + proxyFactory->unsetHttpProxy(); + nam->setProxyFactory(proxyFactory); + } void QmlViewer::setNetworkCacheSize(int size) { diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 914f77d..5b875d7 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -56,6 +56,8 @@ public slots: void toggleRecordingWithSelection(); void ffmpegFinished(int code); void setSkin(const QString& skinDirectory); + void showProxySettings (); + void proxySettingsChanged (); protected: virtual void keyPressEvent(QKeyEvent *); diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index a8ccd91..8b9a768 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -1,15 +1,20 @@ -TEMPLATE = app -CONFIG += qt uic +TEMPLATE = app +CONFIG += qt \ + uic DESTDIR = ../../bin -QT += declarative script network sql -# Input -HEADERS += qmlviewer.h -SOURCES += main.cpp qmlviewer.cpp - -FORMS = recopts.ui +QT += declarative \ + script \ + network \ + sql +# Input +HEADERS += qmlviewer.h \ + proxysettings.h +SOURCES += main.cpp \ + qmlviewer.cpp \ + proxysettings.cpp +FORMS = recopts.ui \ + proxysettings.ui include($$QT_SOURCE_TREE/tools/shared/deviceskin/deviceskin.pri) - -target.path=$$[QT_INSTALL_BINS] +target.path = $$[QT_INSTALL_BINS] INSTALLS += target - -- cgit v0.12