1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 const string GSBP_LOG_DOMAIN
= "Gmpc.Sidebar.Plugins";
27 public class Gmpc
.Sidebar
.Plugins
29 private static Gtk
.ListStore store
;
31 private static void embed(TreeIter iter
)
34 store
.get(iter
, 3, out plugin
, -1);
45 title
= plugin
.sidebar_get_title();
48 title
= plugin
.get_name();
50 position
= plugin
.sidebar_get_position();
55 label
= new
Label(GLib
.Markup
.printf_escaped("<b>%s</b>",title
));
56 label
.set_use_markup(true);
57 label
.set_alignment(0f
, 0.5f
);
60 store
.set(iter
, 5, label
, -1);
65 sidebar_vbox
= (Grid
)Playlist
.get_widget_by_id("sidebar_plugins_top");
69 sidebar_vbox
= (Grid
)Playlist
.get_widget_by_id("sidebar_plugins_bottom");
76 sidebar_vbox
.add(vbox
);//, false, false, 0);
80 sidebar_vbox
.add(vbox
);//, false, false, 0);
86 store
.set(iter
, 4, vbox
, -1);
88 plugin
.sidebar_pane_construct(vbox
);
92 private static void reorder()
96 // assumption: liststore is sorted descending by position
102 List
<Grid
> list_top
= new List
<Grid
> ();
103 List
<Grid
> list_bottom
= new List
<Grid
> ();
105 store
.get_iter_first(out iter
);
109 store
.get(iter
, 0, out enabled
, 2, out pos
, 4, out vbox
, -1);
110 if ((vbox
== null) || (!enabled
))
115 list_top
.append(vbox
);
119 list_bottom
.append(vbox
);
123 while (store
.iter_next(ref iter
));
125 sidebar_vbox
= (Grid
)Playlist
.get_widget_by_id("sidebar_plugins_top");
128 for (int i
= 0; i
< list_top
.length(); i
++)
131 sidebar_vbox
.reorder_child((Widget
)list_top
.nth_data(i
), i
);
134 sidebar_vbox
= (Grid
)Playlist
.get_widget_by_id("sidebar_plugins_bottom");
136 for (int i
= 0; i
< list_bottom
.length(); i
++)
139 sidebar_vbox
.reorder_child((Widget
)list_bottom
.nth_data(i
), i
);
144 private static void destroy(TreeIter iter
)
148 store
.get(iter
, 3, out plugin
, 4, out vbox
, -1);
150 plugin
.sidebar_pane_destroy(vbox
);
155 private static TreeIter
lookup_iter(SidebarIface plugin
)
158 if(store
.get_iter_first(out iter
))
163 store
.get(iter
, 3, out pl
, -1);
169 while(store
.iter_next(ref iter
));
171 GLib
.error("Plugin not found in list");
174 public static void enable(SidebarIface plugin
)
176 TreeIter iter
= lookup_iter(plugin
);
177 plugin
.set_enabled(true);
178 store
.set(iter
, 0, true, -1);
182 public static void disable(SidebarIface plugin
)
184 TreeIter iter
= lookup_iter(plugin
);
185 plugin
.set_enabled(false);
186 store
.set(iter
, 0, false, -1);
189 public static void update_state(Gmpc
.Plugin
.SidebarState state
)
192 if(store
.get_iter_first(out iter
))
198 store
.get(iter
, 3, out pl
,5, out widget
, -1);
199 pl
.sidebar_set_state(state
);
201 // Hide the sidebar name widget in collapsed mode.
203 if(state
== Gmpc
.Plugin
.SidebarState
.COLLAPSED
) {
210 while(store
.iter_next(ref iter
));
215 public static void init(SidebarIface plugin
)
218 store
= new Gtk
.ListStore(6, typeof(bool), // enabled
219 typeof(string), // name
220 typeof(int), // position
221 typeof(SidebarIface
), // plugin
222 typeof(Grid
), // Widget
223 typeof(Widget
)); // Label
224 log(GSBP_LOG_DOMAIN
, GLib
.LogLevelFlags
.LEVEL_DEBUG
, "Initializing sidebar plugin");
226 store
.append(out iter
);
227 store
.set(iter
, 0, plugin
.get_enabled(),
228 1, plugin
.get_name(),
229 2, plugin
.sidebar_get_position(),
236 store
.set_sort_column_id(2, SortType
.DESCENDING
);
238 if (plugin
.get_enabled())