/* 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
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 ();
}
/**
+ * 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) {
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);
}