aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2013-01-08 16:32:08 +1300
committerRobert Ancell <robert.ancell@canonical.com>2013-01-08 16:32:08 +1300
commit54301406603975e44a4ec1f226d8a8b9796354c6 (patch)
treeeb6b59c5d9d67def32546b37242d8e5ebd878358 /src
parent6895fc9d21b0f9bf4c9a1ce08d1dddf8d01061cc (diff)
downloadayatana-indicator-bluetooth-54301406603975e44a4ec1f226d8a8b9796354c6.tar.gz
ayatana-indicator-bluetooth-54301406603975e44a4ec1f226d8a8b9796354c6.tar.bz2
ayatana-indicator-bluetooth-54301406603975e44a4ec1f226d8a8b9796354c6.zip
Stop feedback loop when switch settings changed from external sources
Diffstat (limited to 'src')
-rw-r--r--src/indicator-bluetooth.vala45
-rw-r--r--src/libido3-0.1.vapi1
2 files changed, 36 insertions, 10 deletions
diff --git a/src/indicator-bluetooth.vala b/src/indicator-bluetooth.vala
index 3881fc7..130f743 100644
--- a/src/indicator-bluetooth.vala
+++ b/src/indicator-bluetooth.vala
@@ -30,16 +30,7 @@ public class BluetoothIndicator : Indicator.Object
private bool new_switch_cb (Dbusmenu.Menuitem newitem, Dbusmenu.Menuitem parent, Dbusmenu.Client client)
{
- var item = new Ido.SwitchMenuItem ();
- item.active = newitem.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) == Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED;
- var label = new Gtk.Label (newitem.property_get (Dbusmenu.MENUITEM_PROP_LABEL));
- label.visible = true;
- item.content_area.add (label);
- newitem.property_changed.connect ((mi, prop, value) =>
- {
- label.label = mi.property_get (Dbusmenu.MENUITEM_PROP_LABEL);
- item.active = mi.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) == Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED;
- });
+ var item = new Switch (newitem);
(client as DbusmenuGtk.Client).newitem_base (newitem, item, parent);
return true;
}
@@ -88,6 +79,40 @@ public class BluetoothIndicator : Indicator.Object
}
}
+public class Switch : Ido.SwitchMenuItem
+{
+ public Dbusmenu.Menuitem menuitem;
+ public new Gtk.Label label;
+ private bool updating_switch = false;
+
+ public Switch (Dbusmenu.Menuitem menuitem)
+ {
+ this.menuitem = menuitem;
+ label = new Gtk.Label ("");
+ label.visible = true;
+ content_area.add (label);
+
+ /* Be the first listener to the activate signal so we can stop it
+ * emitting when we change the state. Without this you get feedback loops */
+ activate.connect (() =>
+ {
+ if (updating_switch)
+ Signal.stop_emission_by_name (this, "activate");
+ });
+
+ menuitem.property_changed.connect ((mi, prop, value) => { update (); });
+ update ();
+ }
+
+ private void update ()
+ {
+ updating_switch = true;
+ label.label = menuitem.property_get (Dbusmenu.MENUITEM_PROP_LABEL);
+ active = menuitem.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) == Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED;
+ updating_switch = false;
+ }
+}
+
[DBus (name = "com.canonical.indicator.bluetooth.service")]
public interface BluetoothService : DBusProxy
{
diff --git a/src/libido3-0.1.vapi b/src/libido3-0.1.vapi
index 1d17cac..e6a8953 100644
--- a/src/libido3-0.1.vapi
+++ b/src/libido3-0.1.vapi
@@ -3,6 +3,7 @@ namespace Ido
[CCode (cheader_filename = "libido/idoswitchmenuitem.h")]
public class SwitchMenuItem : Gtk.CheckMenuItem
{
+ [CCode (has_construct_function = false)]
public SwitchMenuItem ();
public Gtk.Container content_area { get; }
}