implemented 'proxy settings' dialog
authorpavelpa <pavelpa@localhost>
Fri, 29 Jan 2010 14:16:05 +0000 (14:16 +0000)
committerpavelpa <pavelpa@localhost>
Fri, 29 Jan 2010 14:16:05 +0000 (14:16 +0000)
 - user can secify proxy for network communication

src/app/app.pro
src/app/appsettings.cpp [new file with mode: 0644]
src/app/appsettings.h [new file with mode: 0644]
src/gui/gui.pro
src/gui/importschedulewidget.cpp
src/gui/importschedulewidget.h
src/gui/importschedulewidget.ui
src/gui/mainwindow.cpp
src/gui/proxysettingsdialog.cpp [new file with mode: 0644]
src/gui/proxysettingsdialog.h [new file with mode: 0644]
src/gui/proxysettingsdialog.ui [new file with mode: 0644]

index ab788f7..10ef88b 100644 (file)
@@ -16,7 +16,10 @@ maemo {
     TARGETDEPS += $$DESTDIR/libqalarm.a
 }
 
-SOURCES += main.cpp
+HEADERS += appsettings.h
+
+SOURCES += main.cpp \
+           appsettings.cpp
 
 RESOURCES += ../icons.qrc \
              ../maps.qrc
diff --git a/src/app/appsettings.cpp b/src/app/appsettings.cpp
new file mode 100644 (file)
index 0000000..2d48066
--- /dev/null
@@ -0,0 +1,40 @@
+#include "appsettings.h"
+
+const QString PROXY_ADDRESS_SETTING ("proxyAddress"); 
+const QString PROXY_PORT_SETTING ("proxyPort"); 
+const QString PROXY_ISDIRECT_SETTING ("proxyIsDirectConnection"); 
+
+QSettings AppSettings::mSettings("Ixonos", "FOSDEM");
+
+
+
+QString AppSettings::proxyAddress()
+{
+    return mSettings.value(PROXY_ADDRESS_SETTING).toString();
+}
+
+quint16 AppSettings::proxyPort()
+{
+    return mSettings.value(PROXY_PORT_SETTING).toUInt();
+}
+
+bool AppSettings::isDirectConnection()
+{
+    return mSettings.value(PROXY_ISDIRECT_SETTING).toBool();
+}
+
+void AppSettings::setProxyAddress(const QString &aAddress)
+{
+    mSettings.setValue(PROXY_ADDRESS_SETTING, aAddress);
+}
+
+void AppSettings::setProxyPort(const quint16 aPort)
+{
+    mSettings.setValue(PROXY_PORT_SETTING, aPort);
+}
+
+void AppSettings::setDirectConnection(bool aDirectConnection)
+{
+    mSettings.setValue(PROXY_ISDIRECT_SETTING, aDirectConnection);
+}
+
diff --git a/src/app/appsettings.h b/src/app/appsettings.h
new file mode 100644 (file)
index 0000000..efae165
--- /dev/null
@@ -0,0 +1,25 @@
+
+#ifndef APPSETTINGS_H
+#define APPSETTINGS_H
+
+#include <QString>
+#include <QSettings>
+
+class AppSettings
+{
+    private:
+        AppSettings() {}
+        static QSettings mSettings;
+
+    public:
+        static QString proxyAddress();
+        static quint16 proxyPort();
+        static bool isDirectConnection();
+
+        static void setProxyAddress(const QString &aAddress);
+        static void setProxyPort(const quint16 aPort);
+        static void setDirectConnection(bool aDirectConnection);
+};
+
+#endif /* APPSETTINGS_H */
+
index 5d4cfc7..5ce8c02 100644 (file)
@@ -44,7 +44,8 @@ FORMS += searchhead.ui \
     eventdialog.ui \
     conflictsdialog.ui \
     tabcontainer.ui \
-    mapwindow.ui
+    mapwindow.ui \
+    proxysettingsdialog.ui
 
 HEADERS += roomstabcontainer.h \
     nowtabcontainer.h \
@@ -61,7 +62,8 @@ HEADERS += roomstabcontainer.h \
     eventdialog.h \
     tabwidget.h \
     tabcontainer.h \
-    mapwindow.h
+    mapwindow.h \
+    proxysettingsdialog.h
 
 SOURCES += roomstabcontainer.cpp \
     nowtabcontainer.cpp \
@@ -78,7 +80,8 @@ SOURCES += roomstabcontainer.cpp \
     eventdialog.cpp \
     tabwidget.cpp \
     tabcontainer.cpp \
-    mapwindow.cpp
+    mapwindow.cpp \
+    proxysettingsdialog.cpp
 
 maemo { 
     FORMS += alarmdialog.ui
index 379aa67..32a9c30 100644 (file)
@@ -1,6 +1,7 @@
 #include "importschedulewidget.h"
 
 #include <schedulexmlparser.h>
+#include "proxysettingsdialog.h"
 
 #include <QDir>
 #include <QFile>
@@ -9,9 +10,13 @@
 #include <QNetworkAccessManager>
 #include <QNetworkReply>
 #include <QDebug>
+#include <appsettings.h>
 
 const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
 
+const QString PROXY_USERNAME;
+const QString PROXY_PASSWD;
+
 ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
     : QWidget(aParent)
 {
@@ -28,6 +33,7 @@ ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
     importAction->hide();
     connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
 
+    connect(proxySettings, SIGNAL(clicked()), SLOT(setupProxy()));
     mNetworkAccessManager = new QNetworkAccessManager(this);
     connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
     mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
@@ -80,8 +86,6 @@ void ImportScheduleWidget::browseSchedule()
 
 void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
 {
-    qDebug() << "ImportScheduleWidget::networkQueryFinished()";
-
     if ( aReply->error() != QNetworkReply::NoError )
     {
         qDebug() << "Error occured during download: " << aReply->errorString();
@@ -94,8 +98,6 @@ void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
 
 void ImportScheduleWidget::downloadSchedule()
 {
-    qDebug() << "downloading schedule";
-
     QNetworkRequest request;
     request.setUrl(QUrl(SCHEDULE_URL));
     mNetworkAccessManager->get(request);
@@ -106,14 +108,33 @@ void ImportScheduleWidget::importData(const QByteArray &aData)
     browse->hide();
     online->hide();
     progressBar->show();
+    proxySettings->hide();
 
     int confId = mXmlParser->parseData(aData);
 
     progressBar->hide();
     browse->show();
     online->show();
+    proxySettings->show();
     importScheduleLabel->setText("Import schedule: ");
 
     emit(scheduleImported(confId));
 }
 
+void ImportScheduleWidget::setupProxy()
+{
+    ProxySettingsDialog dialog;
+    dialog.exec();
+
+    qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
+    QNetworkProxy proxy(
+            AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
+            AppSettings::proxyAddress(),
+            AppSettings::proxyPort(),
+            PROXY_USERNAME,
+            PROXY_PASSWD);
+    QNetworkProxy::setApplicationProxy(proxy);
+
+    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
+}
+
index 302dc06..e337b9d 100644 (file)
@@ -20,6 +20,7 @@ class ImportScheduleWidget : public QWidget, Ui::ImportScheduleWidget
         void showParsingProgress(int progress);
         void networkQueryFinished(QNetworkReply *aReply);
         void downloadSchedule();
+        void setupProxy();
     signals:
         void scheduleImported(int confId);
     private:
index c2ee410..a961055 100644 (file)
@@ -5,7 +5,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>634</width>
+    <width>662</width>
     <height>66</height>
    </rect>
   </property>
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QToolButton" name="proxySettings" >
+       <property name="text" >
+        <string>...</string>
+       </property>
+       <property name="autoRaise" >
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
      <item>
       <widget class="QPushButton" name="browse" >
        <property name="sizePolicy" >
index 71440db..15f5071 100644 (file)
 #include "mapwindow.h"
 
 #include <tabcontainer.h>
+#include <appsettings.h>
 
-const QString PROXY_URL("192.168.0.252");
-const quint16 PROXY_PORT = 4040;
 const QString PROXY_USERNAME;
 const QString PROXY_PASSWD;
-const bool DIRECT_CONNECTION = false;
 
 MainWindow::MainWindow(int aEventId, QWidget *aParent)
     : QMainWindow(aParent)
 {
     setupUi(this);
 
-    qDebug() << "Setting-up proxy: " << PROXY_URL << ":" << PROXY_PORT;
-    QNetworkProxy proxy(DIRECT_CONNECTION ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
-            PROXY_URL, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWD);
+    qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
+    QNetworkProxy proxy(
+            AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
+            AppSettings::proxyAddress(),
+            AppSettings::proxyPort(),
+            PROXY_USERNAME,
+            PROXY_PASSWD);
     QNetworkProxy::setApplicationProxy(proxy);
 
     int confId = Conference::activeConference();
diff --git a/src/gui/proxysettingsdialog.cpp b/src/gui/proxysettingsdialog.cpp
new file mode 100644 (file)
index 0000000..54c5c29
--- /dev/null
@@ -0,0 +1,37 @@
+#include "proxysettingsdialog.h"
+
+#include <appsettings.h>
+#include <QDebug>
+
+ProxySettingsDialog::ProxySettingsDialog(QWidget *aParent)
+    : QDialog(aParent)
+{
+    setupUi(this);
+
+    // deserialize dialog data
+    address->setText(AppSettings::proxyAddress());
+    port->setValue(AppSettings::proxyPort());
+    directConnection->setChecked(AppSettings::isDirectConnection());
+
+    connect(okButton, SIGNAL(clicked()), SLOT(saveDialogData()));
+    connect(directConnection, SIGNAL(clicked(bool)), SLOT(connectionTypeChanged(bool)));
+
+    if(directConnection->isChecked())
+        proxyWidget->hide();
+}
+
+void ProxySettingsDialog::connectionTypeChanged(bool aState)
+{
+    aState ? proxyWidget->hide() : proxyWidget->show();
+}
+
+void ProxySettingsDialog::saveDialogData()
+{
+    // serialize dialog data
+    AppSettings::setProxyAddress(address->text());
+    AppSettings::setProxyPort(port->value());
+    AppSettings::setDirectConnection(directConnection->isChecked());
+
+    close();
+}
+
diff --git a/src/gui/proxysettingsdialog.h b/src/gui/proxysettingsdialog.h
new file mode 100644 (file)
index 0000000..59bc57c
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef PROXYSETTINGSDIALOG_H
+#define PROXYSETTINGSDIALOG_H
+
+#include <QDialog>
+#include "ui_proxysettingsdialog.h"
+
+class ProxySettingsDialog : public QDialog, Ui::ProxySettingsDialog
+{
+    Q_OBJECT
+public:
+    ProxySettingsDialog(QWidget *aParent = NULL);
+    ~ProxySettingsDialog() {}
+private slots:
+    void connectionTypeChanged(bool aState);
+    void saveDialogData();
+};
+
+#endif /* PROXYSETTINGSDIALOG_H */  
+
diff --git a/src/gui/proxysettingsdialog.ui b/src/gui/proxysettingsdialog.ui
new file mode 100644 (file)
index 0000000..2b85c58
--- /dev/null
@@ -0,0 +1,106 @@
+<ui version="4.0" >
+ <class>ProxySettingsDialog</class>
+ <widget class="QDialog" name="ProxySettingsDialog" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>469</width>
+    <height>146</height>
+   </rect>
+  </property>
+  <property name="sizePolicy" >
+   <sizepolicy vsizetype="MinimumExpanding" hsizetype="Preferred" >
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle" >
+   <string>Proxy settings</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout" >
+   <item>
+    <widget class="QCheckBox" name="directConnection" >
+     <property name="text" >
+      <string>Direct connection</string>
+     </property>
+     <property name="checked" >
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QWidget" native="1" name="proxyWidget" >
+     <layout class="QHBoxLayout" name="horizontalLayout_3" >
+      <item>
+       <widget class="QLabel" name="label" >
+        <property name="text" >
+         <string>Address: </string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="address" />
+      </item>
+      <item>
+       <widget class="QLabel" name="label_2" >
+        <property name="text" >
+         <string>Port:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QSpinBox" name="port" >
+        <property name="maximum" >
+         <number>9999</number>
+        </property>
+        <property name="value" >
+         <number>8080</number>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer" >
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>20</width>
+       <height>10</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout" >
+     <item>
+      <spacer name="horizontalSpacer" >
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="okButton" >
+       <property name="text" >
+        <string>OK</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>