~ubuntu-branches/ubuntu/trusty/indicator-sound-gtk2/trusty-proposed

« back to all changes in this revision

Viewing changes to src/specific-items-manager.vala

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-09-10 00:09:01 UTC
  • Revision ID: package-import@ubuntu.com-20120910000901-q6469svv5d3pmn0y
Tags: upstream-12.10.0.1
ImportĀ upstreamĀ versionĀ 12.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2011 Canonical Ltd.
 
3
 
 
4
Authors:
 
5
    Conor Curran <conor.curran@canonical.com>
 
6
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
*/
 
19
 
 
20
using Dbusmenu;
 
21
using Gee;
 
22
 
 
23
public class SpecificItemsManager : GLib.Object
 
24
{
 
25
  public enum category{
 
26
    TRACK,
 
27
    PLAYER
 
28
  }
 
29
 
 
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;}
 
34
  private int of_type;
 
35
   
 
36
  public SpecificItemsManager (PlayerController controller,
 
37
                               string path,
 
38
                               category which_type)
 
39
        {
 
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);
 
45
        }
 
46
  construct{
 
47
    this.proxy_items = new ArrayList<Dbusmenu.MenuitemProxy>();    
 
48
  }
 
49
  
 
50
  private int figure_out_positioning()
 
51
  {
 
52
    int result = 0 ;
 
53
    if (this.of_type == category.TRACK){
 
54
      result = this.owner.menu_offset + this.owner.WIDGET_QUANTITY + this.proxy_items.size; 
 
55
    }
 
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;
 
61
      result = pos;
 
62
    }
 
63
    debug ("!!!!! Menu pos of type %i is = %i", this.of_type, result);
 
64
    return result;
 
65
  }
 
66
  
 
67
  private void on_root_changed (GLib.Object? newroot)
 
68
  {
 
69
    if (newroot == null){
 
70
      debug ("root disappeared -remove proxyitems");
 
71
      foreach(var p in proxy_items){
 
72
        this.owner.root_menu.child_delete (p);  
 
73
      }      
 
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>();      
 
77
      return;  
 
78
    }
 
79
    
 
80
    Dbusmenu.Menuitem? root = this.client.get_root();
 
81
    root.child_added.connect (on_child_added);
 
82
    root.child_removed.connect (on_child_removed);
 
83
 
 
84
    // Fetch what children are there already.
 
85
    GLib.List<weak void*> children = root.get_children().copy();
 
86
    
 
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);
 
95
    
 
96
    }
 
97
  }
 
98
  
 
99
  private void on_child_added (GLib.Object child, uint position)
 
100
  {
 
101
    debug ("On child added Specific root node");
 
102
  }
 
103
 
 
104
  private void on_child_removed (GLib.Object child)
 
105
  {
 
106
    debug ("On child removed Specific root node");
 
107
  }
 
108
  
 
109
}