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

[tor-commits] [vidalia/alpha] Simplify the torrc dialog with the new handling



commit 5f7f1e3762a8515a2366b82ce40f8f9ed3d16141
Author: Tomás Touceda <chiiph@xxxxxxxxxxxxxx>
Date:   Fri Feb 3 22:28:46 2012 -0300

    Simplify the torrc dialog with the new handling
---
 src/vidalia/config/TorrcDialog.cpp |   92 +++++++-----------------------------
 src/vidalia/config/TorrcDialog.ui  |   43 -----------------
 2 files changed, 17 insertions(+), 118 deletions(-)

diff --git a/src/vidalia/config/TorrcDialog.cpp b/src/vidalia/config/TorrcDialog.cpp
index a1ad569..6f5a678 100644
--- a/src/vidalia/config/TorrcDialog.cpp
+++ b/src/vidalia/config/TorrcDialog.cpp
@@ -87,56 +87,8 @@ TorrcDialog::loadToolBar()
 bool 
 TorrcDialog::parseAndSet(QString *errmsg)
 {
-  if(!errmsg) errmsg = new QString("");
-  if(!tc || !tc->isConnected()) {
-    *errmsg = tr("Error connecting to Tor");
-    return false;
-  }
-
-  QString key, val;
-  QStringList parts, lines;
-  
-  if(ui.rdoAll->isChecked())
-    lines = ui.teditTorrc->toPlainText().split('\n', QString::SkipEmptyParts);
-  else {
-    QString tmp = ui.teditTorrc->toPlainText();
-    QTextCursor tcursor = ui.teditTorrc->textCursor();
-    int start = tcursor.selectionStart();
-    int end = tcursor.selectionEnd();
-    tmp = tmp.mid(start, end - start).trimmed();
-    if(tmp.isEmpty()) {
-      *errmsg = tr("Selection is empty. Please select some text, or check \"Apply all\"");
-      return false;
-    }
-
-    lines = tmp.split('\n', QString::SkipEmptyParts);
-  }
-  /* First pass: parsing */
-  int i = 0;
-  foreach(QString line, lines) {
-    i++;
-    line = line.trimmed();
-    if(line.startsWith("#")) continue; // Skip commentaries
-    parts = line.split(" ", QString::SkipEmptyParts);
-    if(parts.count() < 2) {
-      *errmsg = tr("Error at line %1: \"%2\"").arg(i).arg(line);
-      return false;
-    }
-  }
-  /* Second pass: setting */
-  QHash<QString,QString> settings;
-  foreach(QString line, lines) {
-    line = line.trimmed();
-    parts = line.split(" ", QString::SkipEmptyParts);
-    key = parts[0];
-    parts.removeFirst();
-    val = parts.join(" ");
-    settings.insert(key, val);
-  }
-
-  if(!tc->setConf(settings, errmsg)) return false;
-
-  return true;
+  return Vidalia::torrc()->setRawContents(ui.teditTorrc->toPlainText(), 
+                                          errmsg, Vidalia::torControl());
 }
 
 /** Loads the saved torrc file that Tor's using to the TextEdit widget for
@@ -144,20 +96,18 @@ TorrcDialog::parseAndSet(QString *errmsg)
 void 
 TorrcDialog::loadTorrc()
 {
-  if(tc && tc->isConnected()) {
-    QString text = "";
-    QFile file(tc->getInfo("config-file").toString());
-    if(file.open(QFile::ReadOnly)) {
-      QTextStream in(&file);
-      QString line = "";
-      do {
-        line = in.readLine();
-        text += line + "\n";
-      } while(!line.isNull());
-      ui.teditTorrc->setText(text);
-    } else {
-      QMessageBox::critical(this, tr("Error"), tr("An error ocurred while opening torrc file"));
-    }
+  QString text = "";
+  QFile file(Vidalia::torrc()->getTorrcPath());
+  if(file.open(QFile::ReadOnly)) {
+    QTextStream in(&file);
+    QString line = "";
+    do {
+      line = in.readLine();
+      text += line + "\n";
+    } while(!line.isNull());
+    ui.teditTorrc->setText(text);
+  } else {
+    QMessageBox::critical(this, tr("Error"), tr("An error ocurred while opening torrc file"));
   }
 }
 
@@ -167,17 +117,9 @@ void
 TorrcDialog::saveTorrc()
 {
   QString errmsg = "";
-  if(tc && tc->isConnected()) {
-    if(!parseAndSet(&errmsg)) {
-      QMessageBox::critical(this, tr("Error"), errmsg);
-      return;
-    }
-    if(ui.chkSave->isChecked()) {
-      if(!tc->saveConf(&errmsg)) {
-        QMessageBox::critical(this, tr("Error"), errmsg);
-        return;
-      }
-    }
+  if(!parseAndSet(&errmsg)) {
+    QMessageBox::critical(this, tr("Error"), errmsg);
+    return;
   }
   accept();
 }
diff --git a/src/vidalia/config/TorrcDialog.ui b/src/vidalia/config/TorrcDialog.ui
index 46ac151..5e55d79 100644
--- a/src/vidalia/config/TorrcDialog.ui
+++ b/src/vidalia/config/TorrcDialog.ui
@@ -50,49 +50,6 @@
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" name="hLayout">
-     <item>
-      <widget class="QRadioButton" name="rdoAll">
-       <property name="text">
-        <string>Apply all</string>
-       </property>
-       <property name="checked">
-        <bool>true</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QRadioButton" name="rdoSelection">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="text">
-        <string>Apply selection only</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <widget class="QCheckBox" name="chkSave">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="text">
-      <string>Save settings. If unchecked it will only apply settings to the current Tor instance.</string>
-     </property>
-     <property name="checked">
-      <bool>true</bool>
-     </property>
-    </widget>
-   </item>
-   <item>
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits