/* 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. ]
*/
#include "SourcesPane.h"
#include "../db/Database.h"
#include <list>
#include <cassert>
using namespace std;
SourcesPane::SourcesPane()
{
m_treestore = Gtk::TreeStore::create(m_tree_columns);
Gtk::TreeIter iter = m_treestore->append();
iter->set_value(m_tree_columns.source_icon,
Gtk::IconTheme::get_default()->load_icon(
"applications-multimedia", 24, Gtk::IconLookupFlags(0)));
iter->set_value(m_tree_columns.source_name, Glib::ustring("Now Playing"));
const std::vector<LibraryRef>& libraries = Database::get_libraries();
for (std::vector<LibraryRef>::const_iterator list_iter = libraries.begin();
list_iter != libraries.end(); list_iter++) {
iter = m_treestore->append();
iter->set_value(m_tree_columns.source_icon,
Gtk::IconTheme::get_default()->load_icon((*list_iter)->get_icon(), 24));
iter->set_value(m_tree_columns.source_name, (*list_iter)->get_name());
}
m_treeview.set_model(m_treestore);
Gtk::TreeViewColumn* column = Gtk::manage(new Gtk::TreeViewColumn());
column->pack_start(m_tree_columns.source_icon, false);
column->pack_start(m_tree_columns.source_name, true);
m_treeview.append_column(*column);
m_treeview.signal_row_activated().connect(
sigc::mem_fun(*this, &SourcesPane::on_row_activated));
m_treeview.set_headers_visible(false);
add(m_treeview);
set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
set_shadow_type(Gtk::SHADOW_IN);
}
void SourcesPane::on_row_activated(const Gtk::TreePath& path, Gtk::TreeViewColumn* column)
{
assert(path[0] >= 0);
assert(path[0] < ((int)Database::get_libraries().size() + 1)); // +1 for Now Playing
if (path[0] == 0)
signal_now_playing_opened().emit();
else
signal_library_opened().emit(Database::get_libraries().at(path[0] - 1));
}