Archive / / / / / Echo.UI.Widgets.SourcesPane.vala
2008-12-01 17:54:33 UTC
previous next
/* vim: set noexpandtab tabstop=4 shiftwidth=4 nowrap textwidth=100 * * Echo Media Player * Copyright (C) 2008 Shane O'Connell * * [ The original file includes a copyright header in this location describing * the file as being released under the terms of the GNU General Public * License. It has been removed in order to display the file as part of the * archive. ] */ using Echo.Core; using Echo.Database; public class Echo.UI.Widgets.SourcesPane : Gtk.ScrolledWindow { private Gtk.TreeView treeview; private Gtk.ListStore liststore; private enum Column { SOURCE_TYPE = 0, LABEL = 1, ICON = 2, LIBRARY_INDEX = 3 } private enum SourceType { NOW_PLAYING, LIBRARY, PLAYLIST, SEPERATOR } construct { this.liststore = new Gtk.ListStore(4, typeof(int), typeof(string), typeof(Gdk.Pixbuf), typeof(int)); Gtk.TreeIter iter; this.liststore.insert_with_values(out iter, int.MAX, Column.SOURCE_TYPE, SourceType.NOW_PLAYING, Column.LABEL, "Now Playing", Column.ICON, Gtk.IconTheme.get_default().load_icon("applications-multimedia", 24, 0)); this.liststore.insert_with_values(out iter, int.MAX, Column.SOURCE_TYPE, SourceType.SEPERATOR); Gee.List<Library> libraries = Services.database().get_libraries(); for (int i = 0; i < libraries.size; i++) this.liststore.insert_with_values(out iter, int.MAX, Column.SOURCE_TYPE, SourceType.LIBRARY, Column.LIBRARY_INDEX, i, Column.LABEL, libraries.get(i).name, Column.ICON, Gtk.IconTheme.get_default().load_icon(libraries.get(i).icon, 24, 0)); this.liststore.insert_with_values(out iter, int.MAX, Column.SOURCE_TYPE, SourceType.SEPERATOR); this.liststore.insert_with_values(out iter, int.MAX, Column.SOURCE_TYPE, SourceType.PLAYLIST, Column.LABEL, "Playlists", Column.ICON, Gtk.IconTheme.get_default().load_icon("text-x-generic", 24, 0)); var column = new Gtk.TreeViewColumn(); var icon_renderer = new Gtk.CellRendererPixbuf(); column.pack_start(icon_renderer, false); column.add_attribute(icon_renderer, "pixbuf", Column.ICON); var text_renderer = new Gtk.CellRendererText(); column.pack_start(text_renderer, true); column.add_attribute(text_renderer, "text", Column.LABEL); this.treeview = new Gtk.TreeView.with_model(this.liststore); this.treeview.append_column(column); this.treeview.set_headers_visible(false); this.treeview.row_activated += this.row_activated; this.treeview.set_row_separator_func((model, iter) => { Value row_type; model.get_value(iter, Column.SOURCE_TYPE, out row_type); return (row_type.get_int() == SourceType.SEPERATOR); }, null); this.add(this.treeview); this.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); this.set_shadow_type(Gtk.ShadowType.IN); } public signal void now_playing_opened(); public signal void library_opened(Library library); private void row_activated(Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) { Gtk.TreeIter iter; if (this.liststore.get_iter(out iter, path)) { Value row_type; this.liststore.get_value(iter, Column.SOURCE_TYPE, out row_type); switch (row_type.get_int()) { case SourceType.NOW_PLAYING: this.now_playing_opened(); break; case SourceType.LIBRARY: Value library_index; this.liststore.get_value(iter, Column.LIBRARY_INDEX, out library_index); this.library_opened(Services.database().get_libraries().get(library_index.get_int())); break; } } } }