aboutsummaryrefslogtreecommitdiff
path: root/src/player-controller.vala
blob: a92d8bf875788639e665b1be5e7148da640e6ac2 (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
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;	

	// TODO: pass in the appropriate position for the menu
	public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active)
	{
		this.root_menu = root;
		this.name = format_client_name(client_name.strip());
		this.is_active = active;
		this.custom_items = new ArrayList<Dbusmenu.Menuitem>();
		self_construct();
	}

	public void vanish()
	{
		foreach(Dbusmenu.Menuitem item in this.custom_items){
			root_menu.child_delete(item);			
		}
	}
	
	private bool self_construct()
	{
		// Separator item
		Dbusmenu.Menuitem separator_item = new Dbusmenu.Menuitem();
		separator_item.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR);			
		this.custom_items.add(separator_item);

		// Title item
		Dbusmenu.Menuitem title_item = new Dbusmenu.Menuitem();
		title_item.property_set(MENUITEM_PROP_LABEL, this.name.concat(""));					
		title_item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia");			
		this.custom_items.add(title_item);

		// Transport item
		TransportMenuItem transport_item = new TransportMenuItem();
		this.custom_items.add(transport_item);

		int offset = 2;
		foreach(Dbusmenu.Menuitem item in this.custom_items){
			root_menu.child_add_position(item, offset + this.custom_items.index_of(item));			
		}
		return true;
	}	
//		if(!root_menu.child_add_position(client_item, 2) ||
//		!root_menu.child_add_position(transport_item, 3)){
//			//TODO raise here!
//			return false;
//		}
//		return true;
	

	private static string format_client_name(string client_name)
	{
		string formatted = client_name;
		if(formatted.len() > 1){
			formatted = client_name.up(1).concat(client_name.slice(1, client_name.len()));
			debug("PlayerController->format_client_name - : %s", formatted);
		}
		
		return formatted;
	}
	
}