gui/collection: Remove old collection manager code

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-01 11:52:46 -05:00
parent 8807f06fd6
commit 3c3f11b958
6 changed files with 9 additions and 386 deletions

View File

@ -183,7 +183,6 @@ void gui_collection_init()
gtk_tree_view_get_selection(treeview),
__collection_select, NULL, NULL);
collection_update_all();
gui_collection_idle_enable();
}

View File

@ -1,190 +0,0 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
extern "C" {
#include <core/collection.h>
#include <core/containers/index.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <gui/builder.h>
}
#include <gui/ocarina.h>
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 Gtk::CellRendererToggle *c_toggle;
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()
{ add(c_id); add(c_enabled); add(c_size); add(c_path); }
} c_cols;
static void list_path(struct library *lib)
{
Gtk::TreeModel::Row row;
if (lib) {
row = *(c_list->append());
row[c_cols.c_id] = lib->li_dbe.dbe_index;
row[c_cols.c_enabled] = lib->li_enabled;
row[c_cols.c_size] = lib->li_size;
row[c_cols.c_path] = lib->li_path;
}
}
static struct library *get_library_and_row(const Gtk::TreePath &path,
Gtk::TreeModel::Row &row)
{
row = *(c_list->get_iter(path));
return library_get(row[c_cols.c_id]);
}
static struct library *get_library(const Gtk::TreePath &path)
{
Gtk::TreeModel::Row row;
return get_library_and_row(path, row);
}
static struct library *current_library_and_row(Gtk::TreeModel::Row &row)
{
Gtk::TreePath path;
Gtk::TreeViewColumn *col;
c_treeview->get_cursor(path, col);
if (path.empty())
return NULL;
return get_library_and_row(path, row);
}
static struct library *current_library()
{
Gtk::TreeModel::Row row;
return current_library_and_row(row);
}
void update_paths()
{
struct library *lib;
Gtk::TreeModel::Children::iterator it;
for (it = c_list->children().begin(); it != c_list->children().end(); it++) {
lib = library_get((*it)[c_cols.c_id]);
if (lib)
(*it)[c_cols.c_size] = lib->li_size;
}
}
static bool on_idle()
{
bool ret = idle_run_task();
if (ret) {
c_progress->show();
c_progress->set_fraction(idle_progress());
} else
c_progress->hide();
update_paths();
return ret;
}
static void idle_enable()
{
Glib :: signal_idle().connect(sigc::ptr_fun(on_idle));
}
static void on_add()
{
list_path(collection_add(c_chooser->get_filename().c_str()));
idle_enable();
}
static void on_update()
{
collection_update_all();
idle_enable();
}
static void on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col)
{
collection_update(get_library(path));
idle_enable();
}
static void on_cursor_changed()
{
struct library *lib = current_library();
if (lib && (c_chooser->get_current_folder() != lib->li_path))
c_chooser->set_current_folder(lib->li_path);
}
static bool on_key_pressed(GdkEventKey *event)
{
struct library *lib;
Gtk::TreeModel::Row row;
std::string key = gdk_keyval_name(event->keyval);
if (key != "Delete")
return false;
lib = current_library_and_row(row);
collection_remove(lib);
c_list->erase(row);
return true;
}
static void on_toggled(const Glib::ustring &str)
{
Gtk::TreeModel::Row row;
struct library *lib = get_library_and_row(Gtk::TreePath(str), row);
collection_set_enabled(lib, !lib->li_enabled);
row[c_cols.c_enabled] = lib->li_enabled;
}
void manager :: init()
{
struct db_entry *library, *next;
c_add = Glib :: wrap(GTK_BUTTON(gui_builder_widget("colmgr_add")), false);
c_update = Glib :: wrap(GTK_BUTTON(gui_builder_widget("colmgr_update")), false);
c_chooser = Glib :: wrap(GTK_FILE_CHOOSER_WIDGET(gui_builder_widget("colmgr_chooser")), false);
c_progress = Glib :: wrap(GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress")), false);
c_list = Glib :: wrap(GTK_LIST_STORE(gui_builder_object("colmgr_list")), false);
c_toggle = Glib :: wrap(GTK_CELL_RENDERER_TOGGLE(gui_builder_object("colmgr_toggle")), false);
c_treeview = Glib :: wrap(GTK_TREE_VIEW(gui_builder_widget("colmgr_treeview")), false);
c_add->signal_clicked().connect(sigc::ptr_fun(on_add));
c_update->signal_clicked().connect(sigc::ptr_fun(on_update));
c_toggle->signal_toggled().connect(sigc::ptr_fun(on_toggled));
c_list->set_sort_column(c_cols.c_path, Gtk::SORT_ASCENDING);
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));
db_for_each(library, next, library_db_get())
list_path(LIBRARY(library));
idle_enable();
}

View File

@ -72,7 +72,6 @@ int main(int argc, char **argv)
gui_audio_init();
plist :: init();
manager :: init();
init_tabs();
post_init_tabs();

View File

@ -23,13 +23,6 @@ void on_pq_created(queue *, unsigned int);
void post_init_queue_tabs();
/* manager.cpp */
namespace manager
{
void init();
}
/* playlist.cpp */
namespace plist
{

View File

@ -283,8 +283,8 @@
<property name="icon_name">media-skip-backward</property>
</object>
</child>
<accelerator key="n" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
<accelerator key="AudioPrev" signal="clicked"/>
<accelerator key="n" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
</object>
<packing>
<property name="expand">False</property>
@ -318,8 +318,8 @@
<property name="icon_size">5</property>
</object>
</child>
<accelerator key="space" signal="clicked"/>
<accelerator key="AudioPlay" signal="clicked"/>
<accelerator key="space" signal="clicked"/>
</object>
<packing>
<property name="expand">False</property>
@ -352,8 +352,8 @@
<property name="icon_size">5</property>
</object>
</child>
<accelerator key="space" signal="clicked"/>
<accelerator key="AudioPlay" signal="clicked"/>
<accelerator key="space" signal="clicked"/>
</object>
<packing>
<property name="expand">False</property>
@ -386,8 +386,8 @@
<property name="icon_name">media-playback-stop</property>
</object>
</child>
<accelerator key="AudioPlay" signal="clicked" modifiers="GDK_MOD1_MASK"/>
<accelerator key="space" signal="clicked" modifiers="GDK_MOD1_MASK"/>
<accelerator key="AudioPlay" signal="clicked" modifiers="GDK_MOD1_MASK"/>
</object>
<packing>
<property name="expand">False</property>
@ -420,8 +420,8 @@
<property name="icon_name">media-skip-forward</property>
</object>
</child>
<accelerator key="n" signal="clicked"/>
<accelerator key="AudioNext" signal="clicked"/>
<accelerator key="n" signal="clicked"/>
</object>
<packing>
<property name="expand">False</property>
@ -631,7 +631,7 @@
<signal name="row-activated" handler="__collection_activated" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2">
<signal name="changed" handler="__collection_selection_changed" object="colmgr_chooser" swapped="no"/>
<signal name="changed" handler="__collection_selection_changed" object="o_collection_chooser" swapped="no"/>
</object>
</child>
<child>
@ -706,7 +706,7 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFileChooserWidget" id="colmgr_chooser">
<object class="GtkFileChooserWidget" id="o_collection_chooser">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
@ -723,184 +723,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="colmgr_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscroll_policy">natural</property>
<property name="vscroll_policy">natural</property>
<property name="model">colmgr_list</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="fixed_width">20</property>
<child>
<object class="GtkCellRendererToggle" id="colmgr_toggle"/>
<attributes>
<attribute name="active">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Size</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn32">
<property name="title" translatable="yes">Collection</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="colmgr_add">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Add the selected directory to the collection.</property>
<child>
<object class="GtkBox" id="box11">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkImage" id="image9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">dialog-ok</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Add</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="colmgr_update">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Update all collections.</property>
<child>
<object class="GtkBox" id="box13">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkImage" id="image10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">view-refresh</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Update</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="buttonbox3">
<property name="visible">True</property>
@ -916,7 +738,7 @@
<property name="receives_default">True</property>
<property name="valign">center</property>
<property name="image">image11</property>
<signal name="clicked" handler="__collection_add" object="colmgr_chooser" swapped="no"/>
<signal name="clicked" handler="__collection_add" object="o_collection_chooser" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>

View File

@ -43,7 +43,7 @@ static void test_collection_sidebar()
notebook = GTK_NOTEBOOK(gui_builder_widget("o_notebook"));
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
chooser = GTK_FILE_CHOOSER(gui_builder_widget("colmgr_chooser"));
chooser = GTK_FILE_CHOOSER(gui_builder_widget("o_collection_chooser"));
treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
selection = gtk_tree_view_get_selection(treeview);
model = GTK_TREE_MODEL(gui_builder_object("o_collection_store"));