5ff68140b5
I only needed this to make the jump from Ocarina 5.10 -> Ocarina 6.0. It's not needed anymore, now that 6.0 is out. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
140 lines
3.9 KiB
C++
140 lines
3.9 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <callback.h>
|
|
#include <library.h>
|
|
#include <ocarina.h>
|
|
|
|
|
|
static class CollectionColumns : public Gtk::TreeModelColumnRecord {
|
|
public:
|
|
CollectionColumns()
|
|
{ add(c_col_id); add(c_col_enabled); add(c_col_size); add(c_col_path); }
|
|
|
|
Gtk::TreeModelColumn<unsigned int> c_col_id;
|
|
Gtk::TreeModelColumn<bool> c_col_enabled;
|
|
Gtk::TreeModelColumn<unsigned int> c_col_size;
|
|
Gtk::TreeModelColumn<Glib::ustring> c_col_path;
|
|
} collection_cols;
|
|
|
|
static Glib::RefPtr<Gtk::ListStore> get_collection_list()
|
|
{
|
|
return get_object<Gtk::ListStore>("o_collection_dirs");
|
|
}
|
|
|
|
static void on_collection_ok()
|
|
{
|
|
std::string path;
|
|
Gtk::FileChooserWidget *chooser;
|
|
|
|
chooser = get_widget<Gtk::FileChooserWidget>("o_collection_chooser");
|
|
path = chooser->get_filename();
|
|
library::add_path(path);
|
|
enable_idle();
|
|
}
|
|
|
|
static void on_collection_update()
|
|
{
|
|
library :: update_all();
|
|
enable_idle();
|
|
}
|
|
|
|
static void on_collection_row_activated(const Gtk::TreePath &path,
|
|
Gtk::TreeViewColumn *col)
|
|
{
|
|
Gtk::FileChooser *chooser = get_widget<Gtk::FileChooser>("o_collection_chooser");
|
|
Glib::RefPtr<Gtk::ListStore> list = get_collection_list();
|
|
|
|
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
|
Glib::ustring dir = row[collection_cols.c_col_path];
|
|
chooser->set_current_folder(dir);
|
|
}
|
|
|
|
#ifndef CONFIG_TEST
|
|
static
|
|
#endif /* CONFIG_TEST */
|
|
void do_collection_delete()
|
|
{
|
|
Gtk::TreePath path;
|
|
Gtk::TreeViewColumn *col;
|
|
Gtk::TreeView *treeview = get_widget<Gtk::TreeView>("o_collection_treeview");
|
|
|
|
treeview->get_cursor(path, col);
|
|
if (path) {
|
|
Glib::RefPtr<Gtk::ListStore> list = get_collection_list();
|
|
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
|
library :: del_path(row[collection_cols.c_col_id]);
|
|
list->erase(row);
|
|
}
|
|
}
|
|
|
|
static bool on_collection_key_pressed(GdkEventKey *event)
|
|
{
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
if (key == "Delete") {
|
|
do_collection_delete();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
#ifndef CONFIG_TEST
|
|
static
|
|
#endif /* CONFIG_TEST */
|
|
void on_collection_toggled(const Glib::ustring &path)
|
|
{
|
|
Glib::RefPtr<Gtk::ListStore> list = get_collection_list();
|
|
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
|
row[collection_cols.c_col_enabled] = !row[collection_cols.c_col_enabled];
|
|
library :: set_enabled(row[collection_cols.c_col_id],
|
|
row[collection_cols.c_col_enabled]);
|
|
}
|
|
|
|
static void on_library_add(unsigned int id, Library *library)
|
|
{
|
|
Gtk::TreeModel::Row row;
|
|
Glib::RefPtr<Gtk::ListStore> list = get_collection_list();
|
|
|
|
row = *(list->append());
|
|
row[collection_cols.c_col_id] = id;
|
|
row[collection_cols.c_col_enabled] = library->enabled;
|
|
row[collection_cols.c_col_size] = library->count;
|
|
row[collection_cols.c_col_path] = library->root_path;
|
|
}
|
|
|
|
static void on_library_update(unsigned int id, Library *library)
|
|
{
|
|
Gtk::TreeModel::Row row;
|
|
Glib::RefPtr<Gtk::ListStore> list = get_collection_list();
|
|
Gtk::TreeModel::Children children = list->children();
|
|
|
|
for (Gtk::TreeModel::Children::iterator it = children.begin();
|
|
it != children.end(); it++) {
|
|
row = *it;
|
|
if (row[collection_cols.c_col_id] == id)
|
|
row[collection_cols.c_col_size] = library->count;
|
|
}
|
|
}
|
|
|
|
void collection_mgr_init()
|
|
{
|
|
struct Callbacks *cb = get_callbacks();
|
|
|
|
Gtk::TreeView *treeview = get_widget<Gtk::TreeView>("o_collection_treeview");
|
|
Glib::RefPtr<Gtk::ListStore> list = get_collection_list();
|
|
Glib::RefPtr<Gtk::CellRendererToggle> toggle;
|
|
|
|
toggle = get_object<Gtk::CellRendererToggle>("o_collection_toggle");
|
|
|
|
cb->on_library_add = on_library_add;
|
|
cb->on_library_update = on_library_update;
|
|
|
|
connect_button("o_collection_ok", on_collection_ok);
|
|
connect_button("o_collection_update", on_collection_update);
|
|
|
|
list->set_sort_column(collection_cols.c_col_path, Gtk::SORT_ASCENDING);
|
|
treeview->signal_row_activated().connect(sigc::ptr_fun(on_collection_row_activated));
|
|
treeview->signal_key_press_event().connect(sigc::ptr_fun(on_collection_key_pressed));
|
|
toggle->signal_toggled().connect(sigc::ptr_fun(on_collection_toggled));
|
|
}
|