aboutsummaryrefslogtreecommitdiff
path: root/src/music-player-bridge.vala
blob: 92f9dc51038a5eafcf534163310992fa9a06f4f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Indicate;
using Dbusmenu;
using Gee;

public class MusicPlayerBridge : GLib.Object
{

  private Listener listener;
  private Dbusmenu.Menuitem root_menu;
	private HashMap<string, Dbusmenu.Menuitem> registered_clients;  
	
  public MusicPlayerBridge()
  {
		registered_clients = new HashMap<string, Dbusmenu.Menuitem> ();
    listener = Listener.ref_default();
    listener.indicator_added.connect(on_indicator_added);
    listener.indicator_removed.connect(on_indicator_removed);
    listener.indicator_modified.connect(on_indicator_modified);
    listener.server_added.connect(on_server_added);
    listener.server_removed.connect(on_server_removed);
    listener.server_count_changed.connect(on_server_count_changed);
  }

  public void set_root_menu_item(Dbusmenu.Menuitem menu)
  {
    debug("MusicPlayerBridge -> set_root_menu_item");
		root_menu = menu;
  }

  public void on_indicator_added(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
  {
    debug("MusicPlayerBridge-> on_indicator_added");
  }

  public void on_indicator_removed(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
  {
    debug("MusicPlayerBridge -> on_indicator_removed");
  }

  public void on_indicator_modified(Indicate.ListenerServer object, Indicate.ListenerIndicator p0, string s)
  {
    debug("MusicPlayerBridge -> indicator_modified with vale %s", s );
  }

  public void on_server_added(Indicate.ListenerServer object, string type)
  {
    debug("MusicPlayerBridge -> on_server_added with value %s", type);
		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); 
			debug("client of name %s has successfully registered with us", client_name);
		}
  }

  public void on_server_removed(Indicate.ListenerServer object, string type)
  {
    debug("MusicPlayerBridge -> on_server_removed with value %s", type);
		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.remove(client_name);
			registered_clients.remove("transport");
			debug("Successively removed menu_item for client %s from registered_clients", client_name);
		}
	}
	
	private bool server_is_not_of_interest(string type){
    if (type == null) return true;
    if (type.contains("music") == false) {
      debug("server is of no interest,  it is not an music server");
      return true;
    }
		return false;
	}
		
  public void on_server_count_changed(Indicate.ListenerServer object, uint i)
  {
    debug("MusicPlayerBridge-> on_server_count_changed with value %u", i);
  }

}