2
This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
3
Copyright 2010 Canonical Ltd.
6
Conor Curran <conor.curran@canonical.com>
8
This program is free software: you can redistribute it and/or modify it
9
under the terms of the GNU General Public License version 3, as published
10
by the Free Software Foundation.
12
This program is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranties of
14
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
PURPOSE. See the GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License along
18
with this program. If not, see <http://www.gnu.org/licenses/>.
24
public class PlayerController : GLib.Object
26
public const int WIDGET_QUANTITY = 4;
28
public static enum widget_order{
43
public int current_state = state.OFFLINE;
45
private Dbusmenu.Menuitem root_menu;
46
public string name { get; set;}
47
public ArrayList<PlayerItem> custom_items;
48
public Mpris2Controller mpris_bridge;
49
public AppInfo? app_info { get; set;}
50
public int menu_offset { get; set;}
52
public PlayerController(Dbusmenu.Menuitem root,
57
this.root_menu = root;
58
this.name = format_client_name(client_name.strip());
59
this.custom_items = new ArrayList<PlayerItem>();
60
this.current_state = initial_state;
61
this.menu_offset = offset;
63
establish_mpris_connection();
67
public void update_state(state new_state)
69
debug("update_state - player controller %s : new state %i", this.name, new_state);
70
this.current_state = new_state;
74
public void activate()
76
this.establish_mpris_connection();
81
The user should be able to start the app from the transport bar when in an offline state
82
There is a need to wait before the application is on DBus before attempting to access its mpris address
83
Hence only when the it has registered with us via libindicate do we attempt to kick off mpris communication
85
public void instantiate()
87
debug("instantiate in player controller for %s", this.name);
89
this.app_info.launch(null, null);
90
this.update_state(state.INSTANTIATING);
92
catch(GLib.Error error){
93
warning("Failed to launch app %s with error message: %s", this.name, error.message);
97
private void establish_mpris_connection()
99
if(this.current_state != state.READY){
100
debug("establish_mpris_connection - Not ready to connect");
103
this.mpris_bridge = new Mpris2Controller(this);
104
this.determine_state();
109
foreach(Dbusmenu.Menuitem item in this.custom_items){
110
root_menu.child_delete(item);
114
public void hibernate()
116
update_state(PlayerController.state.OFFLINE);
117
this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format());
118
this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format());
119
TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem;
120
title.toggle_active_triangle(false);
123
public void update_layout()
125
if(this.current_state != state.CONNECTED){
126
this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE,
128
this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE,
132
this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE,
133
this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format()));
134
this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE,
138
private void construct_widgets()
141
this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR));
144
TitleMenuitem title_menu_item = new TitleMenuitem(this);
145
this.custom_items.add(title_menu_item);
148
MetadataMenuitem metadata_item = new MetadataMenuitem();
149
this.custom_items.add(metadata_item);
152
TransportMenuitem transport_item = new TransportMenuitem(this);
153
this.custom_items.add(transport_item);
155
foreach(PlayerItem item in this.custom_items){
156
root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item));
160
private static string format_client_name(string client_name)
162
string formatted = client_name;
163
if(formatted.len() > 1){
164
formatted = client_name.up(1).concat(client_name.slice(1, client_name.len()));
165
debug("PlayerController->format_client_name - : %s", formatted);
170
// Temporarily we will need to handle to different mpris implemenations
171
// Do it for now - a couple of weeks should see this messy carry on out of
173
public void determine_state()
175
if(this.mpris_bridge.connected() == true){
176
this.update_state(state.CONNECTED);
177
TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem;
178
title.toggle_active_triangle(true);
179
TransportMenuitem transport = this.custom_items[widget_order.TRANSPORT] as TransportMenuitem;
180
transport.change_play_state(TransportMenuitem.state.PAUSED);
183
this.update_state(state.DISCONNECTED);
b'\\ No newline at end of file'