Fix for portrait mode support in CSSU
[tor-status] / src / status-area-applet-tor.vala
index 83225b2..285c99c 100644 (file)
@@ -1,6 +1,6 @@
 /* This file is part of status-area-applet-tor.
  *
- * Copyright (C) 2010 Philipp Zabel
+ * Copyright (C) 2010-2011 Philipp Zabel
  *
  * status-area-applet-tor is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as published
@@ -223,7 +223,7 @@ class TorStatusMenuItem : HD.StatusMenuItem {
                                tor_hash_argv[2] = password;
                                string hash;
                                Process.spawn_sync ("/tmp", tor_hash_argv, null, 0, null, out hash);
-                               hash = hash.str ("16:").replace ("\n", "");
+                               hash = hash.str ("\n16:").offset (1).replace ("\n", "");
 
                                if (hash == null) {
                                        Hildon.Banner.show_information (null, null,
@@ -427,7 +427,6 @@ class TorStatusMenuItem : HD.StatusMenuItem {
        private void button_clicked_cb () {
                var dialog = new Gtk.Dialog ();
                var content = (Gtk.VBox) dialog.get_content_area ();
-               content.set_size_request (-1, 3*70);
 
                dialog.set_title (_("Tor: anonymity online"));
 
@@ -463,20 +462,18 @@ class TorStatusMenuItem : HD.StatusMenuItem {
                                return;
                        }
                        if (response_id == Gtk.ResponseType.ACCEPT) {
-                               if (!tor_enabled && check.get_active ()) {
-                                       tor_enabled = true;
+                               if (!tor_enabled && check.get_active ()) try {
+                                       gconf.set_bool (GCONF_KEY_TOR_ENABLED, true);
 
-                                       if (conic_connected) {
-                                               start_tor ();
-                                       } else {
+                                       // Enabled by user interaction, so connect if needed
+                                       if (!conic_connected)
                                                conic.connect (ConIc.ConnectFlags.NONE);
-                                       }
-                               } else if (tor_enabled && !check.get_active ()) {
-                                       tor_enabled = false;
-
-                                       stop_tor ();
-                                       if (conic_connected)
-                                               conic.disconnect ();
+                               } catch (Error e) {
+                                       Hildon.Banner.show_information (null, null, "Failed to enable GConf key");
+                               } else if (tor_enabled && !check.get_active ()) try {
+                                       gconf.set_bool (GCONF_KEY_TOR_ENABLED, false);
+                               } catch (Error e) {
+                                       Hildon.Banner.show_information (null, null, "Failed to disable GConf key");
                                }
                        }
                        dialog.destroy ();
@@ -526,6 +523,28 @@ class TorStatusMenuItem : HD.StatusMenuItem {
        }
 
        /**
+        * Callback for GConf change notification on the tor_enabled key
+        */
+       private void tor_enabled_changed_cb (GConf.Client gc, uint cxnid, GConf.Entry entry) {
+               if (entry.key == GCONF_KEY_TOR_ENABLED) {
+                       bool old_tor_enabled = tor_enabled;
+                       tor_enabled = entry.get_value ().get_bool ();
+                       if (old_tor_enabled == tor_enabled)
+                               return;
+
+                       if (tor_enabled) {
+                               // Start Tor immediately if a connection is already available
+                               if (conic_connected)
+                                       start_tor ();
+                       } else {
+                               stop_tor ();
+                               if (conic_connected)
+                                       conic.disconnect ();
+                       }
+               }
+       }
+
+       /**
         * Callback for the ConIc connection-event signal
         */
        private void conic_connection_event_cb (ConIc.Connection conic, ConIc.ConnectionEvent event) {
@@ -594,6 +613,10 @@ class TorStatusMenuItem : HD.StatusMenuItem {
                gconf = GConf.Client.get_default ();
                try {
                        tor_enabled = gconf.get_bool (GCONF_KEY_TOR_ENABLED);
+
+                       // Request change notifications for the tor_enabled key
+                       gconf.add_dir (GCONF_DIR_TOR, GConf.ClientPreloadType.ONELEVEL);
+                       gconf.notify_add (GCONF_KEY_TOR_ENABLED, tor_enabled_changed_cb);
                } catch (Error e) {
                        critical ("Failed to get GConf setting: %s", e.message);
                }