[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1843: Add an initial UI to the 'Advanced' settings page for choosi (in trunk: . src/gui/config)



Author: edmanm
Date: 2007-08-21 00:33:48 -0400 (Tue, 21 Aug 2007)
New Revision: 1843

Modified:
   trunk/
   trunk/src/gui/config/advancedpage.cpp
   trunk/src/gui/config/advancedpage.h
   trunk/src/gui/config/advancedpage.ui
Log:
 r2004@adrastea:  edmanm | 2007-08-20 23:49:00 -0400
 Add an initial UI to the 'Advanced' settings page for choosing a control port
 authentication method.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /vidalia/local/trunk [r2004] on 54b3572a-7227-0410-958f-53ecd705b71a

Modified: trunk/src/gui/config/advancedpage.cpp
===================================================================
--- trunk/src/gui/config/advancedpage.cpp	2007-08-21 04:33:40 UTC (rev 1842)
+++ trunk/src/gui/config/advancedpage.cpp	2007-08-21 04:33:48 UTC (rev 1843)
@@ -58,6 +58,10 @@
   connect(ui.btnBrowseTorConfig, SIGNAL(clicked()), this, SLOT(browseTorConfig()));
   connect(ui.btnBrowseTorDataDirectory, SIGNAL(clicked()),
           this, SLOT(browseTorDataDirectory()));
+  connect(ui.cmbAuthMethod, SIGNAL(currentIndexChanged(int)),
+          this, SLOT(authMethodChanged(int)));
+  connect(ui.chkRandomPassword, SIGNAL(toggled(bool)),
+          ui.linePassword, SLOT(setDisabled(bool)));
 
   /* Hide platform specific features */
 #if defined(Q_WS_WIN)
@@ -76,12 +80,25 @@
 bool
 AdvancedPage::save(QString &errmsg)
 {
+  /* Validate the control listener address */
   QHostAddress controlAddress(ui.lineControlAddress->text());
   if (controlAddress.isNull()) {
     errmsg = tr("'%1' is not a valid IP address.")
                .arg(ui.lineControlAddress->text());
     return false; 
   }
+  
+  /* Validate the selected authentication options */
+  TorSettings::AuthenticationMethod authMethod = 
+    indexToAuthMethod(ui.cmbAuthMethod->currentIndex());
+  if (authMethod == TorSettings::PasswordAuth &&
+      ui.linePassword->text().isEmpty() &&
+      !ui.chkRandomPassword->isChecked()) {
+    errmsg = tr("You selected 'Password' authentication, but did not "
+                "specify a password.");
+    return false;
+  }
+
   _settings->setControlAddress(controlAddress);
   _settings->setControlPort(ui.lineControlPort->text().toUShort());
   _settings->setTorrc(ui.lineTorConfig->text());
@@ -89,6 +106,12 @@
   _settings->setUser(ui.lineUser->text());
   _settings->setGroup(ui.lineGroup->text());
   
+  _settings->setAuthenticationMethod(authMethod);
+  _settings->setUseRandomPassword(ui.chkRandomPassword->isChecked());
+  if (authMethod == TorSettings::PasswordAuth && 
+      !ui.chkRandomPassword->isChecked())
+    _settings->setControlPassword(ui.linePassword->text());
+
 #if defined(Q_WS_WIN)
   /* Install or uninstall the Tor service as necessary */
   setupService(ui.chkUseService->isChecked());
@@ -107,6 +130,12 @@
   ui.lineTorDataDirectory->setText(_settings->getDataDirectory());
   ui.lineUser->setText(_settings->getUser());
   ui.lineGroup->setText(_settings->getGroup());
+  
+  ui.cmbAuthMethod->setCurrentIndex(
+    authMethodToIndex(_settings->getAuthenticationMethod()));
+  ui.chkRandomPassword->setChecked(_settings->useRandomPassword());
+  if (!ui.chkRandomPassword->isChecked())
+    ui.linePassword->setText(_settings->getControlPassword());
 
 #if defined(Q_WS_WIN)
   TorService s;
@@ -114,6 +143,42 @@
 #endif
 }
 
+/** Called when the user selects a different authentication method from the
+ * combo box. */
+void
+AdvancedPage::authMethodChanged(int index)
+{
+  bool usePassword = (indexToAuthMethod(index) == TorSettings::PasswordAuth);
+  ui.linePassword->setEnabled(usePassword && !ui.chkRandomPassword->isChecked());
+  ui.chkRandomPassword->setEnabled(usePassword);
+}
+
+/** Returns the authentication method for the given <b>index</b>. */
+TorSettings::AuthenticationMethod
+AdvancedPage::indexToAuthMethod(int index)
+{
+  switch (index) {
+    case 0: return TorSettings::NullAuth;
+    case 1: return TorSettings::CookieAuth;
+    case 2: return TorSettings::PasswordAuth;
+    default: break;
+  }
+  return TorSettings::UnknownAuth;
+}
+
+/** Returns the index in the authentication methods combo box for the given
+ * authentication <b>method</b>. */
+int
+AdvancedPage::authMethodToIndex(TorSettings::AuthenticationMethod method)
+{
+  switch (method) {
+    case TorSettings::NullAuth: return 0;
+    case TorSettings::CookieAuth: return 1;
+    default: break;
+  }
+  return 2;
+}
+
 /** Open a QFileDialog to browse for Tor config file. */
 void
 AdvancedPage::browseTorConfig()

Modified: trunk/src/gui/config/advancedpage.h
===================================================================
--- trunk/src/gui/config/advancedpage.h	2007-08-21 04:33:40 UTC (rev 1842)
+++ trunk/src/gui/config/advancedpage.h	2007-08-21 04:33:48 UTC (rev 1843)
@@ -50,6 +50,9 @@
   void load();
 
 private slots:
+  /** Called when the user selects a different authentication method from the
+   * combo box. */
+  void authMethodChanged(int index);
   /** Called when the user clicks "Browse" to choose location of Tor config 
    * file */
   void browseTorConfig();
@@ -58,6 +61,12 @@
   void browseTorDataDirectory();
 
 private:
+  /** Returns the authentication method for the given <b>index</b>. */
+  TorSettings::AuthenticationMethod indexToAuthMethod(int index);
+  /** Returns the index in the authentication methods combo box for the given
+   * authentication <b>method</b>. */
+  int authMethodToIndex(TorSettings::AuthenticationMethod method);
+  
 #if defined(Q_WS_WIN)
   /** Installs or removes the Tor service as necessary */
   void setupService(bool useService);

Modified: trunk/src/gui/config/advancedpage.ui
===================================================================
--- trunk/src/gui/config/advancedpage.ui	2007-08-21 04:33:40 UTC (rev 1842)
+++ trunk/src/gui/config/advancedpage.ui	2007-08-21 04:33:48 UTC (rev 1843)
@@ -509,87 +509,162 @@
        <number>6</number>
       </property>
       <item>
-       <layout class="QHBoxLayout" >
+       <layout class="QGridLayout" >
         <property name="margin" >
          <number>0</number>
         </property>
         <property name="spacing" >
-         <number>6</number>
+         <number>2</number>
         </property>
-        <item>
-         <widget class="QLineEdit" name="lineControlAddress" >
-          <property name="sizePolicy" >
-           <sizepolicy>
-            <hsizetype>1</hsizetype>
-            <vsizetype>0</vsizetype>
-            <horstretch>0</horstretch>
-            <verstretch>0</verstretch>
-           </sizepolicy>
+        <item row="0" column="2" >
+         <widget class="QLabel" name="label_7" >
+          <property name="text" >
+           <string>:</string>
           </property>
-          <property name="maxLength" >
-           <number>15</number>
-          </property>
           <property name="alignment" >
-           <set>Qt::AlignRight</set>
+           <set>Qt::AlignCenter</set>
           </property>
-          <property name="maximumSize" >
-           <size>
-            <width>95</width>
-            <height>16777215</height>
-           </size>
-          </property>
-          <property name="toolTip" >
-           <string>IP address on which Tor is listening for controller connections.</string>
-          </property>
          </widget>
         </item>
-        <item>
-         <widget class="QLabel" name="label" >
+        <item row="1" column="0" >
+         <widget class="QLabel" name="label_6" >
           <property name="text" >
-           <string>:</string>
+           <string>Authentication:</string>
           </property>
+          <property name="alignment" >
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
          </widget>
         </item>
-        <item>
+        <item row="0" column="3" >
          <widget class="QLineEdit" name="lineControlPort" >
-          <property name="sizePolicy" >
-           <sizepolicy>
-            <hsizetype>0</hsizetype>
-            <vsizetype>0</vsizetype>
-            <horstretch>0</horstretch>
-            <verstretch>0</verstretch>
-           </sizepolicy>
-          </property>
           <property name="maximumSize" >
            <size>
             <width>55</width>
             <height>16777215</height>
            </size>
           </property>
-          <property name="contextMenuPolicy" >
-           <enum>Qt::NoContextMenu</enum>
-          </property>
           <property name="toolTip" >
            <string>Port that Vidalia uses to communicate with Tor.</string>
           </property>
+          <property name="maxLength" >
+           <number>5</number>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="0" >
+         <widget class="QLabel" name="label_5" >
           <property name="text" >
-           <string>9051</string>
+           <string>Address:</string>
           </property>
+          <property name="alignment" >
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
          </widget>
         </item>
-        <item>
+        <item row="0" column="4" >
          <spacer>
           <property name="orientation" >
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" >
            <size>
-            <width>221</width>
+            <width>40</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
+        <item row="1" column="1" colspan="3" >
+         <layout class="QHBoxLayout" >
+          <property name="margin" >
+           <number>0</number>
+          </property>
+          <property name="spacing" >
+           <number>6</number>
+          </property>
+          <item>
+           <widget class="QComboBox" name="cmbAuthMethod" >
+            <property name="toolTip" >
+             <string>Authentication method to use when connecting to Tor's control port</string>
+            </property>
+            <property name="sizeAdjustPolicy" >
+             <enum>QComboBox::AdjustToContents</enum>
+            </property>
+            <item>
+             <property name="text" >
+              <string>None</string>
+             </property>
+            </item>
+            <item>
+             <property name="text" >
+              <string>Cookie</string>
+             </property>
+            </item>
+            <item>
+             <property name="text" >
+              <string>Password</string>
+             </property>
+            </item>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item row="0" column="1" >
+         <layout class="QHBoxLayout" >
+          <property name="margin" >
+           <number>0</number>
+          </property>
+          <property name="spacing" >
+           <number>6</number>
+          </property>
+          <item>
+           <widget class="QLineEdit" name="lineControlAddress" >
+            <property name="maximumSize" >
+             <size>
+              <width>75</width>
+              <height>16777215</height>
+             </size>
+            </property>
+            <property name="toolTip" >
+             <string>IP address on which Tor is listening for controller connections.</string>
+            </property>
+            <property name="maxLength" >
+             <number>15</number>
+            </property>
+            <property name="alignment" >
+             <set>Qt::AlignRight</set>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item row="1" column="4" >
+         <widget class="QLineEdit" name="linePassword" >
+          <property name="toolTip" >
+           <string>Password to use when authenticating to Tor</string>
+          </property>
+          <property name="echoMode" >
+           <enum>QLineEdit::Password</enum>
+          </property>
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="5" >
+         <widget class="QCheckBox" name="chkRandomPassword" >
+          <property name="toolTip" >
+           <string>Check this box to use a random password each time Tor is started</string>
+          </property>
+          <property name="text" >
+           <string>Randomly Generate</string>
+          </property>
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
        </layout>
       </item>
      </layout>