Added Socks5 and HTTP-Proxy support to the client.
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 29 Mar 2008 13:00:14 +0000 (13:00 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 29 Mar 2008 13:00:14 +0000 (13:00 +0000)
HTTP-Proxy support is untestet though -> any feedback is welcomed.
I'm unhappy with the design of the dialog though... maybe someone comes up with something prettier

src/client/clientsyncer.cpp
src/qtui/coreconnectdlg.cpp
src/qtui/mainwin.cpp
src/qtui/settingspages/bufferviewsettingspage.cpp
src/qtui/settingspages/bufferviewsettingspage.h
src/qtui/ui/coreaccounteditdlg.ui
version.inc

index dfadf32..9534b6f 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "clientsyncer.h"
 
 
 #include "clientsyncer.h"
 
+#include <QNetworkProxy>
+
 #include "client.h"
 #include "global.h"
 #include "identity.h"
 #include "client.h"
 #include "global.h"
 #include "identity.h"
@@ -119,6 +121,10 @@ void ClientSyncer::connectToCore(const QVariantMap &conn) {
     //emit coreConnectionMsg(tr("Connecting..."));
     Q_ASSERT(!socket);
     QTcpSocket *sock = new QTcpSocket(Client::instance());
     //emit coreConnectionMsg(tr("Connecting..."));
     Q_ASSERT(!socket);
     QTcpSocket *sock = new QTcpSocket(Client::instance());
+    if(conn.contains("useProxy") && conn["useProxy"].toBool()) {
+      QNetworkProxy proxy((QNetworkProxy::ProxyType)conn["proxyType"].toInt(), conn["proxyHost"].toString(), conn["proxyPort"].toUInt(), conn["proxyUser"].toString(), conn["proxyPassword"].toString());
+      sock->setProxy(proxy);
+    }
     socket = sock;
     connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData()));
     connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
     socket = sock;
     connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData()));
     connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
index 3510926..fd4e590 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <QDebug>
 #include <QMessageBox>
 
 #include <QDebug>
 #include <QMessageBox>
+#include <QNetworkProxy>
 
 #include "coreconnectdlg.h"
 
 
 #include "coreconnectdlg.h"
 
@@ -454,11 +455,26 @@ CoreAccountEditDlg::CoreAccountEditDlg(AccountId id, const QVariantMap &acct, co
   existing = _existing;
   account = acct;
   if(id.isValid()) {
   existing = _existing;
   account = acct;
   if(id.isValid()) {
+    // add new settings
+    if(!acct.contains("useProxy")) {
+      account["useProxy"] = false;
+      account["proxyHost"] = "localhost";
+      account["proxyPort"] = 8080;
+      account["proxyType"] = QNetworkProxy::Socks5Proxy;
+      account["proxyUser"] = "";
+      account["proxyPassword"] = "";
+    }
     existing.removeAll(acct["AccountName"].toString());
     ui.host->setText(acct["Host"].toString());
     ui.port->setValue(acct["Port"].toUInt());
     ui.useInternal->setChecked(acct["UseInternal"].toBool());
     ui.accountName->setText(acct["AccountName"].toString());
     existing.removeAll(acct["AccountName"].toString());
     ui.host->setText(acct["Host"].toString());
     ui.port->setValue(acct["Port"].toUInt());
     ui.useInternal->setChecked(acct["UseInternal"].toBool());
     ui.accountName->setText(acct["AccountName"].toString());
+    ui.useProxy->setChecked(account["useProxy"].toBool());
+    ui.proxyHost->setText(account["proxyHost"].toString());
+    ui.proxyPort->setValue(account["proxyPort"].toUInt());
+    ui.proxyType->setCurrentIndex(account["proxyType"].toInt() == QNetworkProxy::Socks5Proxy ? 0 : 1);
+    ui.proxyHost->setText(account["proxyUser"].toString());
+    ui.proxyHost->setText(account["proxyPassword"].toString());
   } else {
     setWindowTitle(tr("Add Core Account"));
   }
   } else {
     setWindowTitle(tr("Add Core Account"));
   }
@@ -469,6 +485,12 @@ QVariantMap CoreAccountEditDlg::accountData() {
   account["Host"] = ui.host->text().trimmed();
   account["Port"] = ui.port->value();
   account["UseInternal"] = ui.useInternal->isChecked();
   account["Host"] = ui.host->text().trimmed();
   account["Port"] = ui.port->value();
   account["UseInternal"] = ui.useInternal->isChecked();
+  account["useProxy"] = ui.useProxy->isChecked();
+  account["proxyHost"] = ui.proxyHost->text().trimmed();
+  account["proxyPort"] = ui.proxyPort->value();
+  account["proxyType"] = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
+  account["proxyUser"] = ui.proxyUser->text().trimmed();
+  account["proxyPassword"] = ui.proxyPassword->text().trimmed();
   return account;
 }
 
   return account;
 }
 
index 846ccc1..870c435 100644 (file)
@@ -195,7 +195,7 @@ void MainWin::setupSettingsDlg() {
   //Category: General
   settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
   settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg));
   //Category: General
   settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
   settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg));
-  // settingsDlg->registerSettingsPage(new BufferViewSettingsPage(settingsDlg));
+  settingsDlg->registerSettingsPage(new BufferViewSettingsPage(settingsDlg));
 }
 
 void MainWin::setupNickWidget() {
 }
 
 void MainWin::setupNickWidget() {
index 861bdb6..3fe64df 100644 (file)
@@ -33,11 +33,33 @@ BufferViewSettingsPage::BufferViewSettingsPage(QWidget *parent)
   connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
 }
 
   connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
 }
 
+BufferViewSettingsPage::~BufferViewSettingsPage() {
+  reset();
+}
+
 void BufferViewSettingsPage::reset() {
 void BufferViewSettingsPage::reset() {
-  // currentId = 0;
   ui.bufferViewList->clear();
   _viewToListPos.clear();
   _listPosToView.clear();
   ui.bufferViewList->clear();
   _viewToListPos.clear();
   _listPosToView.clear();
+
+  QHash<BufferViewConfig *, BufferViewConfig *>::iterator changedConfigIter = _changedBufferViews.begin();
+  QHash<BufferViewConfig *, BufferViewConfig *>::iterator changedConfigIterEnd = _changedBufferViews.end();
+  BufferViewConfig *config;
+  while(changedConfigIter != changedConfigIterEnd) {
+    config = (*changedConfigIter);
+    changedConfigIter = _changedBufferViews.erase(changedConfigIter);
+    config->deleteLater();
+  }
+
+  QList<BufferViewConfig *>::iterator newConfigIter = _newBufferViews.begin();
+  QList<BufferViewConfig *>::iterator newConfigIterEnd = _newBufferViews.end();
+  while(newConfigIter != newConfigIterEnd) {
+    config = *newConfigIter;
+    newConfigIter = _newBufferViews.erase(newConfigIter);
+    config->deleteLater();
+  }
+
+  setChangedState(false);
 }
 
 void BufferViewSettingsPage::load() {
 }
 
 void BufferViewSettingsPage::load() {
@@ -80,7 +102,10 @@ void BufferViewSettingsPage::addBufferView(int bufferViewId) {
 void BufferViewSettingsPage::newBufferView(const QString &bufferViewName) {
   // id's of newly created bufferviews are negative (-1, -2... -n)
   int fakeId = -1 * (_newBufferViews.count() + 1);
 void BufferViewSettingsPage::newBufferView(const QString &bufferViewName) {
   // id's of newly created bufferviews are negative (-1, -2... -n)
   int fakeId = -1 * (_newBufferViews.count() + 1);
-  addBufferView(new BufferViewConfig(fakeId));
+  BufferViewConfig *config = new BufferViewConfig(fakeId);
+  config->setBufferViewName(bufferViewName);
+  _newBufferViews << config;
+  addBufferView(config);
 }
       
 int BufferViewSettingsPage::listPos(BufferViewConfig *config) {
 }
       
 int BufferViewSettingsPage::listPos(BufferViewConfig *config) {
@@ -122,6 +147,7 @@ void BufferViewSettingsPage::on_addBufferView_clicked() {
   BufferViewEditDlg dlg(QString(), existing, this);
   if(dlg.exec() == QDialog::Accepted) {
     newBufferView(dlg.bufferViewName());
   BufferViewEditDlg dlg(QString(), existing, this);
   if(dlg.exec() == QDialog::Accepted) {
     newBufferView(dlg.bufferViewName());
+    changed();
   }
 }
 
   }
 }
 
@@ -142,18 +168,27 @@ void BufferViewSettingsPage::on_renameBufferView_clicked() {
   }
 
   BufferViewEditDlg dlg(config->bufferViewName(), existing, this);
   }
 
   BufferViewEditDlg dlg(config->bufferViewName(), existing, this);
-  if(dlg.exec() != QDialog::Accepted)
-    return;
-  
-  BufferViewConfig *changedConfig;
-  if(!_changedBufferViews.contains(config)) {
-    _changedBufferViews[config] = new BufferViewConfig(-1);
-    _changedBufferViews[config]->fromVariantMap(config->toVariantMap());
+  if(dlg.exec() == QDialog::Accepted) {
+    BufferViewConfig *changedConfig = cloneConfig(config);
+    changedConfig->setBufferViewName(dlg.bufferViewName());
+    changed();
   }
   }
-  
-  changedConfig = _changedBufferViews[config];
-  changedConfig->setBufferViewName(dlg.bufferViewName());
-  changed();
+}
+
+BufferViewConfig *BufferViewSettingsPage::cloneConfig(BufferViewConfig *config) {
+  if(_changedBufferViews.contains(config))
+    return _changedBufferViews[config];
+
+  BufferViewConfig *changedConfig = new BufferViewConfig(-1, this);
+  changedConfig->fromVariantMap(config->toVariantMap());
+  return changedConfig;
+}
+
+BufferViewConfig *BufferViewSettingsPage::configForDisplay(BufferViewConfig *config) {
+  if(_changedBufferViews.contains(config))
+    return _changedBufferViews[config];
+  else
+    return config;
 }
 
 
 }
 
 
index a3f32c1..0c73358 100644 (file)
@@ -32,6 +32,7 @@ class BufferViewSettingsPage : public SettingsPage {
 
 public:
   BufferViewSettingsPage(QWidget *parent = 0);
 
 public:
   BufferViewSettingsPage(QWidget *parent = 0);
+  ~BufferViewSettingsPage();
 
 public slots:
   void save();
 
 public slots:
   void save();
@@ -64,6 +65,8 @@ private:
 
   int listPos(BufferViewConfig *config);
   int bufferViewId(int listPos);
 
   int listPos(BufferViewConfig *config);
   int bufferViewId(int listPos);
+  BufferViewConfig *cloneConfig(BufferViewConfig *config);
+  BufferViewConfig *configForDisplay(BufferViewConfig *config);
 };
 
 
 };
 
 
index 4f056bc..5dda97d 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>395</width>
-    <height>242</height>
+    <width>514</width>
+    <height>534</height>
    </rect>
   </property>
   <property name="windowTitle" >
    </rect>
   </property>
   <property name="windowTitle" >
          </layout>
         </item>
         <item>
          </layout>
         </item>
         <item>
-         <spacer>
-          <property name="orientation" >
-           <enum>Qt::Vertical</enum>
+         <widget class="QGroupBox" name="useProxy" >
+          <property name="title" >
+           <string>Use a proxy:</string>
           </property>
           </property>
-          <property name="sizeHint" >
-           <size>
-            <width>20</width>
-            <height>40</height>
-           </size>
+          <property name="checkable" >
+           <bool>true</bool>
           </property>
           </property>
-         </spacer>
+          <property name="checked" >
+           <bool>false</bool>
+          </property>
+          <layout class="QGridLayout" >
+           <item row="0" column="0" colspan="2" >
+            <widget class="QLabel" name="label_5" >
+             <property name="text" >
+              <string>Proxy Type:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="2" >
+            <widget class="QComboBox" name="proxyType" >
+             <item>
+              <property name="text" >
+               <string>Socks 5</string>
+              </property>
+             </item>
+             <item>
+              <property name="text" >
+               <string>HTTP</string>
+              </property>
+             </item>
+            </widget>
+           </item>
+           <item row="1" column="0" colspan="2" >
+            <widget class="QLabel" name="label_6" >
+             <property name="text" >
+              <string>Proxy Host:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="1" column="2" >
+            <widget class="QLabel" name="label_7" >
+             <property name="text" >
+              <string>Proxy Port:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="2" column="0" colspan="2" >
+            <widget class="QLineEdit" name="proxyHost" >
+             <property name="text" >
+              <string>localhost</string>
+             </property>
+            </widget>
+           </item>
+           <item row="2" column="2" >
+            <widget class="QSpinBox" name="proxyPort" >
+             <property name="maximum" >
+              <number>10000</number>
+             </property>
+             <property name="value" >
+              <number>8080</number>
+             </property>
+            </widget>
+           </item>
+           <item row="3" column="0" >
+            <widget class="QLabel" name="label_8" >
+             <property name="text" >
+              <string>Proxy Username:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="3" column="1" colspan="2" >
+            <widget class="QLineEdit" name="proxyUser" />
+           </item>
+           <item row="4" column="0" >
+            <widget class="QLabel" name="label_9" >
+             <property name="text" >
+              <string>Proxy Password:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="4" column="1" colspan="2" >
+            <widget class="QLineEdit" name="proxyPassword" />
+           </item>
+          </layout>
+         </widget>
         </item>
        </layout>
       </widget>
      </item>
         </item>
        </layout>
       </widget>
      </item>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
      <item>
       <widget class="QDialogButtonBox" name="buttonBox" >
        <property name="orientation" >
      <item>
       <widget class="QDialogButtonBox" name="buttonBox" >
        <property name="orientation" >
    <slot>accept()</slot>
    <hints>
     <hint type="sourcelabel" >
    <slot>accept()</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>263</x>
-     <y>230</y>
+     <x>275</x>
+     <y>521</y>
     </hint>
     <hint type="destinationlabel" >
      <x>157</x>
     </hint>
     <hint type="destinationlabel" >
      <x>157</x>
    <slot>reject()</slot>
    <hints>
     <hint type="sourcelabel" >
    <slot>reject()</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>331</x>
-     <y>230</y>
+     <x>343</x>
+     <y>521</y>
     </hint>
     <hint type="destinationlabel" >
      <x>286</x>
     </hint>
     <hint type="destinationlabel" >
      <x>286</x>
    <slot>setDisabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
    <slot>setDisabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>30</x>
-     <y>79</y>
+     <x>63</x>
+     <y>100</y>
     </hint>
     <hint type="destinationlabel" >
      <x>92</x>
     </hint>
     <hint type="destinationlabel" >
      <x>92</x>
    <slot>setDisabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
    <slot>setDisabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>39</x>
-     <y>78</y>
+     <x>63</x>
+     <y>100</y>
     </hint>
     <hint type="destinationlabel" >
     </hint>
     <hint type="destinationlabel" >
-     <x>331</x>
+     <x>400</x>
      <y>144</y>
     </hint>
    </hints>
      <y>144</y>
     </hint>
    </hints>
    <slot>setFocus()</slot>
    <hints>
     <hint type="sourcelabel" >
    <slot>setFocus()</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>26</x>
-     <y>113</y>
+     <x>59</x>
+     <y>126</y>
     </hint>
     <hint type="destinationlabel" >
      <x>184</x>
     </hint>
     <hint type="destinationlabel" >
      <x>184</x>
index 9668a27..45df457 100644 (file)
@@ -4,8 +4,8 @@
 { using namespace Global;
 
   quasselVersion = "0.2.0-alpha4-pre";
 { using namespace Global;
 
   quasselVersion = "0.2.0-alpha4-pre";
-  quasselDate = "2008-03-27";
-  quasselBuild = 661;
+  quasselDate = "2008-03-29";
+  quasselBuild = 664;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 642;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 642;