2015-01-17 12:12:07 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/callback.h>
|
|
|
|
#include <core/idle.h>
|
|
|
|
#include <core/index.h>
|
|
|
|
#include <core/library.h>
|
|
|
|
#include <core/playlist.h>
|
|
|
|
#include <gui/ocarina.h>
|
|
|
|
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static Gtk::Button *c_add;
|
|
|
|
static Gtk::Button *c_update;
|
|
|
|
static Gtk::FileChooserWidget *c_chooser;
|
|
|
|
static Gtk::ProgressBar *c_progress;
|
|
|
|
static Gtk::TreeView *c_treeview;
|
|
|
|
static Glib::RefPtr<Gtk::ListStore> c_list;
|
|
|
|
static Glib::RefPtr<Gtk::CellRendererToggle> c_toggle;
|
|
|
|
|
2015-01-17 12:12:07 -05:00
|
|
|
static class CollectionColumns : public Gtk::TreeModelColumnRecord {
|
|
|
|
public:
|
|
|
|
Gtk::TreeModelColumn<unsigned int> c_id;
|
|
|
|
Gtk::TreeModelColumn<bool> c_enabled;
|
|
|
|
Gtk::TreeModelColumn<unsigned int> c_size;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> c_path;
|
|
|
|
|
|
|
|
CollectionColumns()
|
2015-01-17 13:18:19 -05:00
|
|
|
{ add(c_id); add(c_enabled); add(c_size); add(c_path); }
|
2015-01-17 12:12:07 -05:00
|
|
|
} c_cols;
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static void list_path(Library *lib)
|
|
|
|
{
|
|
|
|
Gtk::TreeModel::Row row;
|
2015-01-17 12:12:07 -05:00
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
if (lib) {
|
|
|
|
row = *(c_list->append());
|
|
|
|
row[c_cols.c_id] = lib->index();
|
|
|
|
row[c_cols.c_enabled] = lib->enabled();
|
|
|
|
row[c_cols.c_size] = lib->size();
|
|
|
|
row[c_cols.c_path] = lib->primary_key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Library *get_library_and_row(const Gtk::TreePath &path,
|
|
|
|
Gtk::TreeModel::Row &row)
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
row = *(c_list->get_iter(path));
|
2015-01-17 12:12:07 -05:00
|
|
|
return tags :: get_library(row[c_cols.c_id]);
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static Library *get_library(const Gtk::TreePath &path)
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
|
|
|
Gtk::TreeModel::Row row;
|
2015-01-17 13:18:19 -05:00
|
|
|
return get_library_and_row(path, row);
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static Library *current_library_and_row(Gtk::TreeModel::Row &row)
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
Gtk::TreePath path;
|
|
|
|
Gtk::TreeViewColumn *col;
|
2015-01-17 12:12:07 -05:00
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
c_treeview->get_cursor(path, col);
|
|
|
|
if (path.empty())
|
|
|
|
return NULL;
|
|
|
|
return get_library_and_row(path, row);
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static Library *current_library()
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
Gtk::TreeModel::Row row;
|
|
|
|
return current_library_and_row(row);
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
|
|
|
|
|
2015-01-17 12:12:07 -05:00
|
|
|
void update_paths()
|
|
|
|
{
|
|
|
|
Library *lib;
|
|
|
|
Gtk::TreeModel::Children::iterator it;
|
|
|
|
|
|
|
|
for (it = c_list->children().begin(); it != c_list->children().end(); it++) {
|
2015-01-17 13:18:19 -05:00
|
|
|
lib = tags :: get_library((*it)[c_cols.c_id]);
|
2015-01-17 12:12:07 -05:00
|
|
|
if (lib)
|
|
|
|
(*it)[c_cols.c_size] = lib->size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static void remove_banned_tracks()
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
IndexEntry *ent = playlist :: get_tracks("Banned");
|
2015-01-17 12:12:07 -05:00
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
if (!ent)
|
|
|
|
return;
|
2015-01-17 12:12:07 -05:00
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
for (it = ent->begin(); it != ent->end(); it++)
|
|
|
|
library :: get_queue()->del(tags :: get_track(*it));
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
|
|
|
|
|
2015-01-17 12:12:07 -05:00
|
|
|
static bool on_idle()
|
|
|
|
{
|
|
|
|
bool ret = idle :: run_task();
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
c_progress->show();
|
|
|
|
c_progress->set_fraction(idle :: get_progress());
|
|
|
|
} else
|
|
|
|
c_progress->hide();
|
|
|
|
|
|
|
|
update_paths();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static void on_add()
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
|
|
|
list_path(library :: add(c_chooser->get_filename()));
|
|
|
|
lib :: idle(on_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_update()
|
|
|
|
{
|
|
|
|
library :: update_all();
|
|
|
|
lib :: idle(on_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col)
|
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
library :: update(get_library(path));
|
2015-01-17 12:12:07 -05:00
|
|
|
lib :: idle(on_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_cursor_changed()
|
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
Library *lib = current_library();
|
|
|
|
if (lib && (c_chooser->get_current_folder() != lib->primary_key()))
|
|
|
|
c_chooser->set_current_folder(lib->primary_key());
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool on_key_pressed(GdkEventKey *event)
|
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
Library *lib;
|
|
|
|
Gtk::TreeModel::Row row;
|
2015-01-17 12:12:07 -05:00
|
|
|
|
|
|
|
if (lib :: key_name(event) != "Delete")
|
|
|
|
return false;
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
lib = current_library_and_row(row);
|
|
|
|
library :: remove(lib);
|
|
|
|
c_list->erase(row);
|
2015-01-17 12:12:07 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
static void on_toggled(const Glib::ustring &str)
|
2015-01-17 12:12:07 -05:00
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
Gtk::TreeModel::Row row;
|
|
|
|
Library *lib = get_library_and_row(Gtk::TreePath(str), row);
|
|
|
|
|
|
|
|
library :: set_enabled(lib, !lib->enabled());
|
|
|
|
row[c_cols.c_enabled] = lib->enabled();
|
|
|
|
if (lib->enabled())
|
|
|
|
remove_banned_tracks();
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void manager :: init()
|
|
|
|
{
|
2015-01-17 13:18:19 -05:00
|
|
|
c_add = lib :: get_widget<Gtk::Button>("colmgr_add");
|
|
|
|
c_update = lib :: get_widget<Gtk::Button>("colmgr_update");
|
2015-01-17 12:12:07 -05:00
|
|
|
|
|
|
|
c_chooser = lib :: get_widget<Gtk::FileChooserWidget>("colmgr_chooser");
|
2015-01-17 13:18:19 -05:00
|
|
|
c_progress = lib :: get_widget<Gtk::ProgressBar>("o_idle_progress");
|
|
|
|
c_toggle = lib :: get_object<Gtk::CellRendererToggle>("colmgr_toggle");
|
|
|
|
c_list = lib :: get_object<Gtk::ListStore>("colmgr_list");
|
|
|
|
c_treeview = lib :: get_widget<Gtk::TreeView>("colmgr_treeview");
|
2015-01-17 12:12:07 -05:00
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
c_add->signal_clicked().connect(sigc::ptr_fun(on_add));
|
|
|
|
c_update->signal_clicked().connect(sigc::ptr_fun(on_update));
|
2015-01-17 12:12:07 -05:00
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
c_toggle->signal_toggled().connect(sigc::ptr_fun(on_toggled));
|
|
|
|
c_list->set_sort_column(c_cols.c_path, Gtk::SORT_ASCENDING);
|
2015-01-17 12:12:07 -05:00
|
|
|
c_treeview->signal_row_activated().connect(sigc::ptr_fun(on_row_activated));
|
|
|
|
c_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed));
|
|
|
|
c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_key_pressed));
|
|
|
|
|
2015-01-17 13:18:19 -05:00
|
|
|
for (unsigned int i = 0; i < tags :: library_size(); i++)
|
|
|
|
list_path(tags :: get_library(i));
|
2015-01-17 12:12:07 -05:00
|
|
|
}
|