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

[vidalia-svn] r2752: Selected country now saved. Improved UI. Changed internal da (vidalia/branches/exit-country/src/vidalia/config)



Author: cviecco
Date: 2008-06-18 13:52:51 -0400 (Wed, 18 Jun 2008)
New Revision: 2752

Modified:
   vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
   vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
   vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui
   vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
   vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp
   vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h
Log:
Selected country now saved. Improved UI. Changed internal
data structs (separate presentation from state).


Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp	2008-06-18 04:44:31 UTC (rev 2751)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp	2008-06-18 17:52:51 UTC (rev 2752)
@@ -79,32 +79,27 @@
   NetworkSettings settings(Vidalia::torControl());
 
   Q_UNUSED(errmsg);
-/*
-  QString languageCode =
-    LanguageSupport::languageCode(ui.cmboLanguage->currentText());
-  
-  _settings->setLanguageCode(languageCode);
-  _settings->setInterfaceStyle(ui.cmboStyle->currentText());
- 
-  ///* Set to new style 
-  Vidalia::setStyle(ui.cmboStyle->currentText());
-*/
+
   _settings->setUseNodePolicy(ui.chkNodePolicy->isChecked());
 
   /*Now save only is settings have been enabled*/
   if((ui.chkNodePolicy->isChecked())){
-  settings.setUseExitNodePolicy(ui.chkExitNodePolicy->isChecked());
     /*Only save if we have enabled saving exit policies!*/
     if(ui.chkExitNodePolicy->isChecked()){
         /*Need to add validation?*/
-        settings.setExitNodeList(ui.lineEditExitNodes->text().split(",", QString::SkipEmptyParts) );    
+       //OK I dont like this:
+        QString current=ui.cmboExitNodesbyCountry->currentText();
+        QStringList countrylist=current.split("(");
+        current=countrylist.at(0);
+
+        _settings->setExitNodeCountry(current);
     }
   }
-  /*if clear connections is set, clear them up!*/
-  if(ui.chkCloseAllActiveCircuits->isChecked()){
-     closeAllCircuits();     
-  }
 
+  //now apply tor settings
+  applyTorSettings();
+
+
   return true;
 }
   
@@ -131,8 +126,8 @@
   ui.chkNodePolicy->setChecked(_settings->getUseNodePolicy()); 
   ui.chkExitNodePolicy->setChecked(settings.getUseExitNodePolicy());
  
- QStringList exit_nodes = settings.getExitNodeList();
-  ui.lineEditExitNodes->setText(exit_nodes.join(","));
+  //QStringList exit_nodes = settings.getExitNodeList();
+  //ui.lineEditExitNodes->setText(exit_nodes.join(","));
 
   //cmboExitNodesbyCountry->ui.cmboStyle("")
   
@@ -172,6 +167,8 @@
 */ 
 
   /*Fill up the internal structure*/
+  //by_country_exit_nodes.clear();
+  by_country_exit_nodes2.clear();
   foreach( RouterStatus router, networkStatus){
      //fprintf(stderr,"*");
 
@@ -189,7 +186,7 @@
      if (!router.isValid())
       continue;
      flags=router.flags();
-     //check for exit and badexit
+     //Must be exit AND not badexit
      if((router.Exit) !=((router.Exit | router.BadExit) & flags) ) 
       continue;
 
@@ -203,21 +200,31 @@
      }
 
      /*Now insert the information into the HAsh/MAp*/
-     if (by_country_exit_nodes.contains(short_country_name)){
-        by_country_exit_nodes.insert(short_country_name, 
-                 QStringList(by_country_exit_nodes.value(short_country_name))<<uniqueRouterName);
+     if (by_country_exit_nodes2.contains(short_country_name)){
+        //by_country_exit_nodes.insert(short_country_name, 
+        //         QStringList(by_country_exit_nodes.value(short_country_name))<<uniqueRouterName);
+        by_country_exit_nodes2.insert(short_country_name,
+                 QList<RouterStatus>(by_country_exit_nodes2.value(short_country_name))<<router);
+
      }
      else{
-        by_country_exit_nodes.insert(short_country_name,QStringList()<<uniqueRouterName);
-
+        //by_country_exit_nodes.insert(short_country_name,QStringList()<<uniqueRouterName);
+        by_country_exit_nodes2.insert(short_country_name,QList<RouterStatus>()<<router);
      }
   }
 
 
   //* now fill the combo boxes!*/  
-  foreach (QString country, by_country_exit_nodes.keys()) {
+  QListWidgetItem *countryListItem;
+  int itemcount=0;
+  int saved_index=0;
+  char saved_country[4];
+  memset(saved_country,0x00,4);  
+  memcpy(saved_country,_settings->getExitNodeCountry().toAscii(),2);  
+
+  foreach (QString country, by_country_exit_nodes2.keys()) {
     /*Get the count of exit nodes for this country*/
-    count=QString("%1").arg(by_country_exit_nodes.value(country).count(),0,10);
+    count=QString("%1").arg(by_country_exit_nodes2.value(country).count(),0,10);
  
     /*now do de icon for the country*/
     QIcon country_flag;
@@ -228,10 +235,42 @@
       country_flag.addFile(":/images/flags/unkown.png");
     }
     /*finally add the country information to the combo box!*/
-    ui.cmboExitNodesbyCountry->addItem(country_flag,country,
-                             country.append("(").append(count).append(")"));
+    QString countryCount(country);
+    countryCount.append("(").append(count).append(")");
+    ui.cmboExitNodesbyCountry->addItem(country_flag,countryCount,
+                             countryCount);
+    if(country.toAscii()==saved_country){
+      saved_index=itemcount; 
+    }
+
+    /*
+    ui.listWidgetExitCountry->addItem(countryCount);
+    countryListItem=ui.listWidgetExitCountry->item(itemcount);
+    countryListItem->setIcon(country_flag);
+    */
+    itemcount++;
   }
+  
+  
+  //and enable multiple selections?
+  //ui.listWidgetExitCountry->setSelectionMode(QAbstractItemView::MultiSelection);
+ 
+  //Now load settings for country
+  ui.cmboExitNodesbyCountry->setCurrentIndex(saved_index);
 
+  //now apply changes if something was saved!
+  //char saved[20];
+  //memset(saved,0x00,20);
+  //memcpy(saved,_settings->getExitNodeCountry().toAscii(),2);
+  fprintf(stderr,"saved_index=%d saved_country=%s\n",saved_index,saved_country);
+  if(0!=saved_index){
+     //apply a save!
+     QString err;
+     //save(err);
+     ui.cmboExitNodesbyCountry->setCurrentIndex(saved_index);
+     copyCountryToText();
+     applyTorSettings();
+  }
 
 }
 
@@ -245,11 +284,24 @@
   
   current=countrylist.at(0);
   //fprintf(stderr,"nqlen=%d",current.length());
-  ui.lineEditExitNodes->setText(by_country_exit_nodes.value(current).join(","));  
+  //ui.lineEditExitNodes->setText(by_country_exit_nodes.value(current).join(","));  
+  //ui.textEditExitNodes->setText(by_country_exit_nodes.value(current).join(","));
 
+  //copy to list listwidget!
+  ui.listWidgetExitNodes->clear();
+  
+  foreach (RouterStatus router, by_country_exit_nodes2.value(current)){
+     QString displayname(router.name());
+     if( router.Named!= (router.flags() & router.Named)){
+          displayname.append(" ($").append(router.id()).append(")");
+     }    
+     ui.listWidgetExitNodes->addItem(displayname);
+  }   
+
+
   //alsoe enable
   ui.chkCloseAllActiveCircuits->setEnabled(true); 
-   ui.chkCloseAllActiveCircuits->setChecked(true);
+  ui.chkCloseAllActiveCircuits->setChecked(true);
 }
 
 
@@ -257,7 +309,7 @@
  void
 NetworkoutPage::onDisconnected(){
   //erase data structure
-  by_country_exit_nodes.clear();
+  by_country_exit_nodes2.clear();
   //remove data from the country combo box?
 
 }
@@ -296,4 +348,45 @@
   
 }
 
+void
+NetworkoutPage::applyTorSettings(){
 
+  NetworkSettings settings(Vidalia::torControl());
+
+ /*Now save only is settings have been enabled*/
+  if((ui.chkNodePolicy->isChecked())){
+    settings.setUseExitNodePolicy(ui.chkExitNodePolicy->isChecked());
+    /*Only save if we have enabled saving exit policies!*/
+    if(ui.chkExitNodePolicy->isChecked()){
+        /*Need to add validation?*/
+        //settings.setExitNodeList(ui.lineEditExitNodes->text().split(",", QString::SkipEmptyParts) );
+        /*iterate over listwidget?*/
+        QStringList exitList;
+        QString current=ui.cmboExitNodesbyCountry->currentText();
+        //fprintf(stderr,"qlen=%d",current.length());
+        QStringList countrylist=current.split("(");
+        current=countrylist.at(0);
+        
+
+        foreach (RouterStatus router, by_country_exit_nodes2.value(current)){
+           //ui.listWidgetExitNodes->addItem(router.name());
+           QString id(router.id());
+           id.prepend("$");
+           int flags=router.flags();
+           if( router.Named== (flags & router.Named)){
+              id=router.name();
+           }
+           exitList<<id;
+        } 
+        settings.setExitNodeList(exitList);     
+    }
+  }
+  /*if clear connections is set, clear them up!*/
+  if(ui.chkCloseAllActiveCircuits->isChecked()){
+     closeAllCircuits();
+  }
+
+
+
+}
+

Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h	2008-06-18 04:44:31 UTC (rev 2751)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h	2008-06-18 17:52:51 UTC (rev 2752)
@@ -60,8 +60,12 @@
 
   
 private:
+  /*closes all circuits*/
   void closeAllCircuits();
 
+  /*Apply tor gui settings*/
+  void applyTorSettings();
+
   /** A VidaliaSettings object used for saving/loading settings */
   VidaliaSettings* _settings;
 
@@ -69,7 +73,8 @@
   Ui::NetworkoutPage ui;
 
   /*struct to hold the country-exit-node-mappings */
-  QMap<QString,QStringList> by_country_exit_nodes;
+  //QMap<QString,QStringList> by_country_exit_nodes;
+  QMap<QString,QList<RouterStatus> > by_country_exit_nodes2;
 
   TorControl* _torControl;
   FileGeoIpResolver* _geoIpResolver;

Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui	2008-06-18 04:44:31 UTC (rev 2751)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui	2008-06-18 17:52:51 UTC (rev 2752)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>519</width>
-    <height>430</height>
+    <width>622</width>
+    <height>450</height>
    </rect>
   </property>
   <property name="contextMenuPolicy" >
@@ -15,42 +15,45 @@
   <widget class="QCheckBox" name="chkNodePolicy" >
    <property name="geometry" >
     <rect>
-     <x>10</x>
-     <y>10</y>
-     <width>405</width>
-     <height>21</height>
+     <x>9</x>
+     <y>9</y>
+     <width>481</width>
+     <height>23</height>
     </rect>
    </property>
    <property name="text" >
     <string>Enable Vidalia Node Policy Management (Will reduce your anonymity)</string>
    </property>
   </widget>
+  <widget class="QCheckBox" name="chkExitNodePolicy" >
+   <property name="geometry" >
+    <rect>
+     <x>9</x>
+     <y>38</y>
+     <width>461</width>
+     <height>23</height>
+    </rect>
+   </property>
+   <property name="text" >
+    <string>Enable Strict Exit Node Management (Will change your exit node configuration)</string>
+   </property>
+  </widget>
   <widget class="QGroupBox" name="grpExitNodeSettings" >
    <property name="geometry" >
     <rect>
      <x>10</x>
      <y>60</y>
-     <width>481</width>
-     <height>171</height>
+     <width>531</width>
+     <height>211</height>
     </rect>
    </property>
    <property name="title" >
     <string>Exit Node Selection Policy</string>
    </property>
-   <widget class="QLineEdit" name="lineEditExitNodes" >
-    <property name="geometry" >
-     <rect>
-      <x>100</x>
-      <y>40</y>
-      <width>361</width>
-      <height>27</height>
-     </rect>
-    </property>
-   </widget>
    <widget class="QLabel" name="label_2" >
     <property name="geometry" >
      <rect>
-      <x>20</x>
+      <x>10</x>
       <y>50</y>
       <width>71</width>
       <height>18</height>
@@ -63,8 +66,8 @@
    <widget class="QComboBox" name="cmboExitNodesbyCountry" >
     <property name="geometry" >
      <rect>
-      <x>140</x>
-      <y>90</y>
+      <x>160</x>
+      <y>120</y>
       <width>171</width>
       <height>29</height>
      </rect>
@@ -73,8 +76,8 @@
    <widget class="QPushButton" name="pButtonApplyCountry" >
     <property name="geometry" >
      <rect>
-      <x>326</x>
-      <y>90</y>
+      <x>360</x>
+      <y>120</y>
       <width>131</width>
       <height>27</height>
      </rect>
@@ -86,8 +89,8 @@
    <widget class="QLabel" name="label_3" >
     <property name="geometry" >
      <rect>
-      <x>80</x>
-      <y>100</y>
+      <x>90</x>
+      <y>130</y>
       <width>54</width>
       <height>18</height>
      </rect>
@@ -100,7 +103,7 @@
     <property name="geometry" >
      <rect>
       <x>80</x>
-      <y>130</y>
+      <y>160</y>
       <width>171</width>
       <height>23</height>
      </rect>
@@ -109,20 +112,17 @@
      <string>Close All Active Circuits</string>
     </property>
    </widget>
+   <widget class="QListWidget" name="listWidgetExitNodes" >
+    <property name="geometry" >
+     <rect>
+      <x>90</x>
+      <y>30</y>
+      <width>431</width>
+      <height>75</height>
+     </rect>
+    </property>
+   </widget>
   </widget>
-  <widget class="QCheckBox" name="chkExitNodePolicy" >
-   <property name="geometry" >
-    <rect>
-     <x>10</x>
-     <y>40</y>
-     <width>481</width>
-     <height>23</height>
-    </rect>
-   </property>
-   <property name="text" >
-    <string>Enable Strict Exit Node Management (Might change your exit node configuration)</string>
-   </property>
-  </widget>
  </widget>
  <resources/>
  <connections/>

Modified: vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp	2008-06-18 04:44:31 UTC (rev 2751)
+++ vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp	2008-06-18 17:52:51 UTC (rev 2752)
@@ -75,6 +75,7 @@
   }else{
     //very bad!, need to find better way...
     conf.insert("StrictExitNodes","0");
+    conf.insert(SETTING_EXIT_NODE_LIST,"");
   }
 
   conf.insert(SETTING_HTTP_PROXY,

Modified: vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp	2008-06-18 04:44:31 UTC (rev 2751)
+++ vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp	2008-06-18 17:52:51 UTC (rev 2752)
@@ -36,6 +36,8 @@
 #define SETTING_PROXY_EXECUTABLE    "ProxyExecutable"
 #define SETTING_PROXY_EXECUTABLE_ARGUMENTS  "ProxyExecutableArguments"
 #define SETTING_USE_NODE_POLICY     "UseNodePolicy"
+#define SETTING_EXIT_NODES_COUNTRY  "ExitNodesCountry"
+#define SETTING_EXCLUDE_NODES_COUNTRY_LIST "ExcludeNodesCountryList"
 
 #if defined(Q_OS_WIN32)
 #define STARTUP_REG_KEY        "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
@@ -70,6 +72,8 @@
   setDefault(SETTING_RUN_PROXY_AT_START, false);
   setDefault(SETTING_PROXY_EXECUTABLE, "");
   setDefault(SETTING_PROXY_EXECUTABLE_ARGUMENTS, QStringList());
+  setDefault(SETTING_EXIT_NODES_COUNTRY,"");
+  setDefault(SETTING_EXCLUDE_NODES_COUNTRY_LIST,"");
 }
 
 /** Gets the currently preferred language code for Vidalia. */
@@ -242,4 +246,20 @@
 }
 
 
+QString
+VidaliaSettings::getExitNodeCountry()
+//getLanguageCode()
+{
+  return value(SETTING_EXIT_NODES_COUNTRY).toString();
+}
 
+void
+VidaliaSettings::
+setExitNodeCountry(QString exitCountry)
+{
+  setValue(SETTING_EXIT_NODES_COUNTRY, exitCountry);
+}
+
+
+
+

Modified: vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h	2008-06-18 04:44:31 UTC (rev 2751)
+++ vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h	2008-06-18 17:52:51 UTC (rev 2752)
@@ -92,6 +92,11 @@
   // determines if vidalia should try to manage Tor's Nodes
   bool getUseNodePolicy();
   void setUseNodePolicy(bool useNodePolicy);
+  
+  //getting the exit node country (last saved that is!)
+  QString getExitNodeCountry();
+  // Saves the preferred exit country
+  void setExitNodeCountry(QString exitCountry);
 
 };