2
Copyright 2011 Canonical Ltd.
5
Conor Curran <conor.curran@canonical.com>
7
This program is free software: you can redistribute it and/or modify it
8
under the terms of the GNU General Public License version 3, as published
9
by the Free Software Foundation.
11
This program is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranties of
13
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
PURPOSE. See the GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License along
17
with this program. If not, see <http://www.gnu.org/licenses/>.
23
public class SpecificItemsManager : GLib.Object
30
private PlayerController owner {get; set;}
31
private string dbus_path;
32
private Dbusmenu.Client client;
33
public Gee.ArrayList<Dbusmenu.MenuitemProxy> proxy_items {get; construct;}
36
public SpecificItemsManager (PlayerController controller,
40
this.of_type = which_type;
41
this.owner = controller;
42
this.dbus_path = path;
43
this.client = new Dbusmenu.Client (this.owner.dbus_name, this.dbus_path);
44
this.client.root_changed.connect (on_root_changed);
47
this.proxy_items = new ArrayList<Dbusmenu.MenuitemProxy>();
50
private int figure_out_positioning()
53
if (this.of_type == category.TRACK){
54
result = this.owner.menu_offset + this.owner.WIDGET_QUANTITY + this.proxy_items.size;
56
else if (this.of_type == category.PLAYER){
57
int pos = this.owner.menu_offset + this.owner.WIDGET_QUANTITY + this.owner.track_specific_count();
58
//Surely the playlists item is there whether its visible or not ?
59
//TODO test playlists and player specific item positioning.
60
pos += this.owner.use_playlists == true ? 1 : 0;
63
debug ("!!!!! Menu pos of type %i is = %i", this.of_type, result);
67
private void on_root_changed (GLib.Object? newroot)
70
debug ("root disappeared -remove proxyitems");
71
foreach(var p in proxy_items){
72
this.owner.root_menu.child_delete (p);
74
this.proxy_items.clear();
75
debug ("array list size is now %i", this.proxy_items.size);
76
//this.proxy_items = new ArrayList<Dbusmenu.MenuitemProxy>();
80
Dbusmenu.Menuitem? root = this.client.get_root();
81
root.child_added.connect (on_child_added);
82
root.child_removed.connect (on_child_removed);
84
// Fetch what children are there already.
85
GLib.List<weak void*> children = root.get_children().copy();
87
foreach (void* child in children) {
88
int pos = figure_out_positioning();
89
unowned Dbusmenu.Menuitem item = (Dbusmenu.Menuitem)child;
90
Dbusmenu.MenuitemProxy proxy = new Dbusmenu.MenuitemProxy(item);
91
proxy_items.add (proxy);
92
debug ("Proxy item of label = %s added to collection",
93
item.property_get (MENUITEM_PROP_LABEL));
94
this.owner.root_menu.child_add_position (proxy, pos);
99
private void on_child_added (GLib.Object child, uint position)
101
debug ("On child added Specific root node");
104
private void on_child_removed (GLib.Object child)
106
debug ("On child removed Specific root node");