aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-06-10 12:46:17 +0100
committerConor Curran <conor.curran@canonical.com>2010-06-10 12:46:17 +0100
commitc98d1cd6c1f1bc875eae17d77680c8ce5d6acb5f (patch)
tree300af11448e6524603548570d55560053465d9d3 /src
parent8e51465790989d6b8ed8194a0d9a86fe7b3412d5 (diff)
downloadayatana-indicator-sound-c98d1cd6c1f1bc875eae17d77680c8ce5d6acb5f.tar.gz
ayatana-indicator-sound-c98d1cd6c1f1bc875eae17d77680c8ce5d6acb5f.tar.bz2
ayatana-indicator-sound-c98d1cd6c1f1bc875eae17d77680c8ce5d6acb5f.zip
player controller object underway
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/music-player-bridge.vala19
-rw-r--r--src/player-controller.vala47
3 files changed, 54 insertions, 15 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f7fb1a1..3479cb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -50,7 +50,8 @@ sound-service-server.h: $(srcdir)/sound-service.xml
#####################
music_bridge_VALASOURCES = \
music-player-bridge.vala \
- transport-menu-item.vala
+ transport-menu-item.vala \
+ player-controller.vala
music_bridge_VALAFLAGS = \
--ccode \
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala
index 92f9dc5..89f633b 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -7,11 +7,11 @@ public class MusicPlayerBridge : GLib.Object
private Listener listener;
private Dbusmenu.Menuitem root_menu;
- private HashMap<string, Dbusmenu.Menuitem> registered_clients;
+ private HashMap<string, PlayerController> registered_clients;
public MusicPlayerBridge()
{
- registered_clients = new HashMap<string, Dbusmenu.Menuitem> ();
+ registered_clients = new HashMap<string, PlayerController> ();
listener = Listener.ref_default();
listener.indicator_added.connect(on_indicator_added);
listener.indicator_removed.connect(on_indicator_removed);
@@ -48,15 +48,8 @@ public class MusicPlayerBridge : GLib.Object
if(server_is_not_of_interest(type)) return;
string client_name = type.split(".")[1];
if (root_menu != null && client_name != null){
- Dbusmenu.Menuitem client_item = new Dbusmenu.Menuitem();
- client_item.property_set(MENUITEM_PROP_LABEL, client_name.concat(" is registered"));
- TransportMenuItem transport_item = new TransportMenuItem();
- root_menu.child_append(client_item);
- root_menu.child_append(transport_item);
-
- registered_clients.set(client_name, client_item);
- // hackery -> need to wrap player sections into its own object
- registered_clients.set("transport", transport_item);
+ PlayerController ctrl = new PlayerController(root_menu, client_name, true);
+ registered_clients.set(client_name, ctrl);
debug("client of name %s has successfully registered with us", client_name);
}
}
@@ -67,10 +60,8 @@ public class MusicPlayerBridge : GLib.Object
if(server_is_not_of_interest(type)) return;
string client_name = type.split(".")[1];
if (root_menu != null && client_name != null){
- root_menu.child_delete(registered_clients[client_name]);
- root_menu.child_delete(registered_clients["transport"]);
+ registered_clients[client_name].vanish();
registered_clients.remove(client_name);
- registered_clients.remove("transport");
debug("Successively removed menu_item for client %s from registered_clients", client_name);
}
}
diff --git a/src/player-controller.vala b/src/player-controller.vala
new file mode 100644
index 0000000..9cdf527
--- /dev/null
+++ b/src/player-controller.vala
@@ -0,0 +1,47 @@
+using Dbusmenu;
+using Gee;
+
+public class PlayerController : GLib.Object
+{
+ private Dbusmenu.Menuitem root_menu;
+ private string name;
+ private bool is_active;
+ private ArrayList<Dbusmenu.Menuitem> custom_items;
+
+ public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active)
+ {
+ this.root_menu = root;
+ this.name = format_client_name(client_name);
+ this.is_active = active;
+ this.custom_items = new ArrayList<Dbusmenu.Menuitem>();
+ //Dbusmenu.Menuitem[];
+ self_construct();
+ }
+
+ public void self_construct()
+ {
+ Dbusmenu.Menuitem client_item = new Dbusmenu.Menuitem();
+ this.custom_items.add(client_item);
+ client_item.property_set(MENUITEM_PROP_LABEL, this.name.concat(""));
+ TransportMenuItem transport_item = new TransportMenuItem();
+ this.custom_items.add(transport_item);
+ root_menu.child_append(client_item);
+ root_menu.child_append(transport_item);
+ }
+
+ public void vanish()
+ {
+ foreach(Dbusmenu.Menuitem item in this.custom_items){
+ root_menu.child_delete(item);
+ }
+ }
+
+ public static string format_client_name(string client_name)
+ {
+ debug("PlayerController->format_client_name");
+ //string first_letter = client_name.slice(1);
+ //debug("PlayerController->format_client_name - first_letter: %s", first_letter);
+ return client_name;
+ }
+
+} \ No newline at end of file