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

« back to all changes in this revision

Viewing changes to src/transport-menu-item.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 2010 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
using DbusmenuTransport;
 
23
using Transport;
 
24
 
 
25
public class TransportMenuitem : PlayerItem
 
26
 
27
  private Transport.Action cached_action;
 
28
 
 
29
  private bool running {
 
30
    get{
 
31
      return this.owner.current_state == PlayerController.state.CONNECTED;
 
32
    } 
 
33
  }
 
34
 
 
35
  public TransportMenuitem(PlayerController parent)
 
36
  {
 
37
    Object(item_type: MENUITEM_TYPE, owner: parent);
 
38
  }
 
39
  construct{
 
40
    this.property_set_int(MENUITEM_PLAY_STATE, (int)Transport.State.PAUSED);
 
41
    this.property_set (MENUITEM_PROP_LABEL, this.owner.app_info.get_name());
 
42
    this.cached_action = Transport.Action.NO_ACTION;
 
43
  }
 
44
 
 
45
  /**
 
46
  Please remove this timeout when the default player can handle mpris commands
 
47
  immediately once it raises its dbus interface
 
48
  **/
 
49
  public void handle_cached_action()
 
50
  {
 
51
    if (this.cached_action != Transport.Action.NO_ACTION){
 
52
      Timeout.add_seconds (1, send_cached_action);
 
53
    }
 
54
  }
 
55
 
 
56
  private bool send_cached_action()
 
57
  {
 
58
    this.owner.mpris_bridge.transport_update(this.cached_action);
 
59
    this.cached_action = Transport.Action.NO_ACTION;
 
60
    return false;
 
61
  }
 
62
 
 
63
  public void change_play_state (Transport.State update)
 
64
  {
 
65
    int temp = (int)update;
 
66
    this.property_set_int(MENUITEM_PLAY_STATE, temp); 
 
67
  }
 
68
  
 
69
  public override void handle_event(string name,
 
70
                                    Variant input_value,
 
71
                                    uint timestamp)
 
72
  {
 
73
    Variant v = input_value;
 
74
    if ( input_value.is_of_type (VariantType.VARIANT)){
 
75
      v = input_value.get_variant();
 
76
    }
 
77
    
 
78
    int32 input = v.get_int32();
 
79
    
 
80
    if (this.running == true){
 
81
      this.owner.mpris_bridge.transport_update((Transport.Action)input);
 
82
    }
 
83
    else{
 
84
      this.cached_action = (Transport.Action)input;
 
85
      this.owner.instantiate();
 
86
      this.property_set_int (MENUITEM_PLAY_STATE, (int)Transport.State.LAUNCHING);
 
87
    }
 
88
  } 
 
89
 
 
90
  public static HashSet<string> attributes_format()
 
91
  {
 
92
    HashSet<string> attrs = new HashSet<string>();    
 
93
    attrs.add(MENUITEM_PLAY_STATE);
 
94
    return attrs;
 
95
  } 
 
96
 
 
97
}