2
Copyright 2010 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/>.
22
using DbusmenuPlaylists;
23
using DbusmenuPlaylist;
27
public class PlaylistsMenuitem : PlayerItem
29
private HashMap<int, Dbusmenu.Menuitem> current_playlists;
30
public Menuitem root_item;
32
public PlaylistsMenuitem ( PlayerController parent )
34
Object ( item_type: MENUITEM_TYPE, owner: parent );
38
this.current_playlists = new HashMap<int, Dbusmenu.Menuitem>();
39
this.root_item = new Menuitem();
40
this.root_item.property_set ( MENUITEM_PROP_LABEL, _("Choose Playlist") );
41
this.root_item.property_set ( MENUITEM_PATH, "" );
44
public new void update (PlaylistDetails[] playlists)
46
foreach ( PlaylistDetails detail in playlists ){
47
// We don't want to list playlists which are for videos)'
48
if (this.already_observed(detail) || this.is_video_related(detail))
51
Dbusmenu.Menuitem menuitem = new Menuitem();
52
menuitem.property_set (MENUITEM_PROP_LABEL,
53
truncate_item_label_if_needs_be (detail.name));
54
menuitem.property_set (MENUITEM_PROP_ICON_NAME, "playlist-symbolic");
56
menuitem.property_set (MENUITEM_PATH, (string)detail.path);
57
menuitem.property_set_bool (MENUITEM_PROP_VISIBLE, true);
58
menuitem.property_set_bool (MENUITEM_PROP_ENABLED, true);
60
menuitem.item_activated.connect(() => {
61
submenu_item_activated (menuitem.id );
64
this.current_playlists.set( menuitem.id, menuitem );
65
this.root_item.child_append( menuitem );
66
debug ("populating valid playlists %s", detail.name);
68
// Finally remove any that might have been deleted
69
foreach (Dbusmenu.Menuitem item in this.current_playlists.values) {
71
foreach (PlaylistDetails detail in playlists){
72
if (detail.path == item.property_get (MENUITEM_PATH)) {
78
if (this.root_item.property_get (MENUITEM_PATH) == item.property_get (MENUITEM_PATH)){
79
this.root_item.property_set (MENUITEM_PROP_LABEL, _("Choose Playlist"));
81
this.root_item.child_delete (item);
86
public void update_individual_playlist (PlaylistDetails new_detail)
88
foreach ( Dbusmenu.Menuitem item in this.current_playlists.values ){
89
if (new_detail.path == item.property_get (MENUITEM_PATH)){
90
item.property_set (MENUITEM_PROP_LABEL,
91
truncate_item_label_if_needs_be (new_detail.name));
94
// If its active make sure the name is updated on the root item.
95
if (this.root_item.property_get (MENUITEM_PATH) == new_detail.path) {
96
this.root_item.property_set (MENUITEM_PROP_LABEL,
97
truncate_item_label_if_needs_be (new_detail.name));
101
private bool already_observed (PlaylistDetails new_detail)
103
foreach ( Dbusmenu.Menuitem item in this.current_playlists.values ){
104
var path = item.property_get (MENUITEM_PATH);
105
if (new_detail.path == path) return true;
110
private bool is_video_related (PlaylistDetails new_detail)
112
var location = (string)new_detail.path;
113
if (location.contains ("/VideoLibrarySource/")) return true;
117
public void active_playlist_update (PlaylistDetails detail)
119
var update = detail.name;
120
if ( update == "" ) update = _("Choose Playlist");
121
this.root_item.property_set (MENUITEM_PROP_LABEL,
122
truncate_item_label_if_needs_be(update));
123
this.root_item.property_set (MENUITEM_PATH, detail.path);
126
private void submenu_item_activated (int menu_item_id)
128
if (!this.current_playlists.has_key(menu_item_id)) {
129
warning( "item %i was activated but we don't have a corresponding playlist",
133
this.owner.mpris_bridge.activate_playlist ( (GLib.ObjectPath)this.current_playlists[menu_item_id].property_get (MENUITEM_PATH) );
136
private string truncate_item_label_if_needs_be(string item_label)
138
var result = item_label;
139
if (item_label.char_count(-1) > 17){
140
result = item_label.slice ((long)0, (long)15);
146
public static HashSet<string> attributes_format()
148
HashSet<string> attrs = new HashSet<string>();
149
attrs.add(MENUITEM_TITLE);
150
attrs.add(MENUITEM_PLAYLISTS);