gui/collection: Remove unused collection code
And the now unused sidebar widget. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
73c70678bb
commit
b3476e15e9
199
gui/collection.c
199
gui/collection.c
|
@ -1,156 +1,19 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/collection.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tempq.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/collection.h>
|
||||
#include <gui/idle.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
enum collection_sidebar_columns {
|
||||
C_SB_IMAGE,
|
||||
C_SB_PATH,
|
||||
C_SB_LIBRARY,
|
||||
};
|
||||
|
||||
static GtkTreeModel *c_model;
|
||||
|
||||
static void __collection_set_header(GtkTreeIter *iter, const gchar *image,
|
||||
const gchar *text)
|
||||
{
|
||||
gtk_tree_store_set(GTK_TREE_STORE(c_model), iter, C_SB_IMAGE, image,
|
||||
C_SB_PATH, text, -1);
|
||||
}
|
||||
|
||||
static void __collection_set_library(GtkTreeIter *iter, struct library *library)
|
||||
{
|
||||
gtk_tree_store_set(GTK_TREE_STORE(c_model), iter,
|
||||
C_SB_IMAGE, "folder",
|
||||
C_SB_PATH, library->li_path,
|
||||
C_SB_LIBRARY, library, -1);
|
||||
}
|
||||
|
||||
static struct library *__collection_get_library(GtkTreeIter *iter)
|
||||
{
|
||||
struct library *library;
|
||||
|
||||
gtk_tree_model_get(c_model, iter, C_SB_LIBRARY, &library, -1);
|
||||
return library;
|
||||
}
|
||||
|
||||
void __collection_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column, gpointer data)
|
||||
{
|
||||
struct library *library = NULL;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_model_get_iter(c_model, &iter, path))
|
||||
library = __collection_get_library(&iter);
|
||||
if (!library)
|
||||
return;
|
||||
|
||||
collection_update(library);
|
||||
gui_idle_enable();
|
||||
}
|
||||
|
||||
void __collection_toggled(GtkCheckMenuItem *check, gpointer data)
|
||||
{
|
||||
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
struct library *library = NULL;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
GList *rows;
|
||||
|
||||
rows = gtk_tree_selection_get_selected_rows(selection, &c_model);
|
||||
if (!rows)
|
||||
return;
|
||||
path = rows->data;
|
||||
if (gtk_tree_model_get_iter(c_model, &iter, path))
|
||||
library = __collection_get_library(&iter);
|
||||
if (!library)
|
||||
return;
|
||||
|
||||
collection_set_enabled(library, gtk_check_menu_item_get_active(check));
|
||||
__collection_set_library(&iter, library);
|
||||
}
|
||||
|
||||
bool __collection_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
struct library *library = NULL;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
GList *rows;
|
||||
|
||||
if (event->keyval != GDK_KEY_Delete)
|
||||
return false;
|
||||
|
||||
rows = gtk_tree_selection_get_selected_rows(selection, &c_model);
|
||||
path = rows->data;
|
||||
|
||||
if (gtk_tree_model_get_iter(c_model, &iter, path))
|
||||
library = __collection_get_library(&iter);
|
||||
if (!library)
|
||||
goto out;
|
||||
|
||||
collection_remove(library);
|
||||
gtk_tree_store_remove(GTK_TREE_STORE(c_model), &iter);
|
||||
out:
|
||||
g_list_free_full(rows, (GDestroyNotify)gtk_tree_path_free);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __collection_buttonpress(GtkWidget *widget, GdkEventButton *event, gpointer data)
|
||||
{
|
||||
GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gui_builder_widget("o_collection_enabled"));
|
||||
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
GtkMenu *menu = GTK_MENU(gui_builder_widget("o_collection_rc"));
|
||||
struct library *library = NULL;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (event->button != 3)
|
||||
return false;
|
||||
|
||||
if (gtk_tree_view_get_path_at_pos(treeview, event->x, event->y,
|
||||
&path, NULL, NULL, NULL))
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
if (gtk_tree_model_get_iter(c_model, &iter, path))
|
||||
library = __collection_get_library(&iter);
|
||||
|
||||
if (library) {
|
||||
gtk_check_menu_item_set_active(check, library->li_enabled);
|
||||
gtk_menu_popup(menu, NULL, NULL, NULL, NULL,
|
||||
event->button, event->time);
|
||||
}
|
||||
|
||||
gtk_tree_path_free(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
void __collection_add(GtkButton *button, GtkFileChooser *chooser)
|
||||
static void __collection_add(GtkFileChooser *chooser)
|
||||
{
|
||||
gchar *filename = gtk_file_chooser_get_filename(chooser);
|
||||
struct library *library;
|
||||
GtkTreeIter iter, last;
|
||||
|
||||
gtk_tree_model_get_iter_first(c_model, &iter);
|
||||
gtk_tree_model_iter_nth_child(c_model, &last, &iter, 0);
|
||||
while (__collection_get_library(&last) != NULL)
|
||||
gtk_tree_model_iter_next(c_model, &last);
|
||||
|
||||
library = collection_add(filename);
|
||||
gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, NULL, &last);
|
||||
__collection_set_library(&iter, library);
|
||||
gui_playlist_add_library(library);
|
||||
if (playlist_new(PL_LIBRARY, filename))
|
||||
gui_playlist_add_library(library_lookup(filename));
|
||||
|
||||
gui_idle_enable();
|
||||
g_free(filename);
|
||||
|
@ -175,73 +38,23 @@ void __collection_choose(GtkButton *button, gpointer data)
|
|||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (res == GTK_RESPONSE_ACCEPT)
|
||||
__collection_add(button, GTK_FILE_CHOOSER(dialog));
|
||||
__collection_add(GTK_FILE_CHOOSER(dialog));
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
g_object_unref(filter);
|
||||
}
|
||||
|
||||
void __collection_selection_changed(GtkTreeSelection *selection,
|
||||
GtkFileChooser *chooser)
|
||||
{
|
||||
GtkStack *stack = GTK_STACK(gui_builder_widget("o_stack"));
|
||||
struct library *library;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_selection_get_selected(selection, &c_model, &iter)) {
|
||||
gtk_stack_set_visible_child_name(stack, "chooser");
|
||||
library = __collection_get_library(&iter);
|
||||
|
||||
gui_sidebar_selected(SB_COLLECTION, NULL);
|
||||
if (library)
|
||||
gtk_file_chooser_set_current_folder(chooser,
|
||||
library->li_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool __gui_collection_init_idle()
|
||||
{
|
||||
struct db_entry *library, *next;
|
||||
GtkTreeIter parent, iter, last;
|
||||
|
||||
gtk_tree_model_get_iter_first(c_model, &parent);
|
||||
while (!gtk_tree_model_iter_has_child(c_model, &parent))
|
||||
gtk_tree_model_iter_next(c_model, &parent);
|
||||
gtk_tree_model_iter_nth_child(c_model, &last, &parent, 0);
|
||||
|
||||
/* Add library paths. */
|
||||
db_for_each(library, next, library_db_get()) {
|
||||
gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, &parent, &last);
|
||||
__collection_set_library(&iter, LIBRARY(library));
|
||||
db_for_each(library, next, library_db_get())
|
||||
gui_playlist_add_library(LIBRARY(library));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void gui_collection_init()
|
||||
{
|
||||
GtkTreeIter parent, iter;
|
||||
GtkTreeView *treeview;
|
||||
|
||||
c_model = GTK_TREE_MODEL(gui_builder_object("o_collection_store"));
|
||||
|
||||
/* Add "Collection" header. */
|
||||
gtk_tree_store_insert(GTK_TREE_STORE(c_model), &parent, NULL, -1);
|
||||
__collection_set_header(&parent, "system-file-manager", "<big>Collection</big>");
|
||||
|
||||
/* Add "Add new Library" entry. */
|
||||
gtk_tree_store_insert(GTK_TREE_STORE(c_model), &iter, &parent, -1);
|
||||
__collection_set_header(&iter, "folder-new",
|
||||
"<span style='italic'><Add new path></span>");
|
||||
|
||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
|
||||
gtk_tree_view_expand_all(treeview);
|
||||
gtk_tree_selection_set_select_function(
|
||||
gtk_tree_view_get_selection(treeview),
|
||||
gui_sidebar_on_select, NULL, NULL);
|
||||
|
||||
idle_schedule(IDLE_SYNC, __gui_collection_init_idle, NULL);
|
||||
gui_idle_enable();
|
||||
}
|
||||
|
|
|
@ -132,8 +132,6 @@ gboolean gui_sidebar_on_select(GtkTreeSelection *selection,
|
|||
void gui_sidebar_selected(enum sidebar_selection_t selected,
|
||||
struct gui_queue *queue)
|
||||
{
|
||||
if (selected != SB_COLLECTION)
|
||||
__sidebar_deselect("o_collection_view");
|
||||
if (selected != SB_PLAYLIST)
|
||||
__sidebar_deselect("o_playlist_view");
|
||||
if (selected != SB_SIDEBAR)
|
||||
|
|
|
@ -21,13 +21,8 @@ void __sidebar_selection_changed() {}
|
|||
#endif /* TEST_NEED_SIDEBAR */
|
||||
|
||||
#ifdef TEST_NEED_COLLECTION
|
||||
void __collection_activated() {}
|
||||
void __collection_add() {}
|
||||
void __collection_buttonpress() {}
|
||||
void __collection_choose() {}
|
||||
void __collection_keypress() {}
|
||||
void __collection_selection_changed() {}
|
||||
void __collection_toggled() {}
|
||||
#endif /* TEST_NEED_COLLECTION */
|
||||
|
||||
#ifdef TEST_NEED_PLAYLIST
|
||||
|
|
|
@ -227,29 +227,6 @@
|
|||
<property name="margin_right">10</property>
|
||||
<property name="icon_name">media-playlist-shuffle</property>
|
||||
</object>
|
||||
<object class="GtkMenu" id="o_collection_rc">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkCheckMenuItem" id="o_collection_enabled">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Library Path Enabled</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="toggled" handler="__collection_toggled" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkTreeStore" id="o_collection_store">
|
||||
<columns>
|
||||
<!-- column-name Image -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name Path -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name Library -->
|
||||
<column type="gpointer"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkImage" id="o_cover">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -956,7 +933,6 @@
|
|||
<object class="GtkTreeView" id="o_playlist_view">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="model">o_playlist_store</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="search_column">1</property>
|
||||
|
@ -992,56 +968,10 @@
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="o_collection_view">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">o_collection_store</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
<signal name="button-press-event" handler="__collection_buttonpress" swapped="no"/>
|
||||
<signal name="key-press-event" handler="__collection_keypress" swapped="no"/>
|
||||
<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="o_collection_chooser" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||
<property name="title" translatable="yes">Image</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="cellrendererpixbuf1">
|
||||
<property name="stock_size">1</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="icon-name">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
|
||||
<property name="title" translatable="yes">Path</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext3"/>
|
||||
<attributes>
|
||||
<attribute name="markup">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -7,5 +7,4 @@ window
|
|||
idle
|
||||
sidebar
|
||||
playlist
|
||||
collection
|
||||
audio
|
||||
|
|
|
@ -33,7 +33,7 @@ res += [ GuiTest("window") ]
|
|||
res += [ GuiTest("idle") ]
|
||||
res += [ GuiTest("sidebar") ]
|
||||
res += [ GuiTest("playlist") ]
|
||||
res += [ GuiTest("collection") ]
|
||||
gui_objs += [ env.Object("../../gui/collection.c") ]
|
||||
gui_objs += [ env.Object("../../gui/artwork.c") ]
|
||||
res += [ GuiTest("audio") ]
|
||||
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#define TEST_NEED_AUDIO
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/collection.h>
|
||||
#include <gui/view.h>
|
||||
#include <tests/gui.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
GMainLoop *main_loop;
|
||||
struct core_init_data init_data;
|
||||
|
||||
static int test_on_idle(gpointer data)
|
||||
{
|
||||
g_main_loop_quit(main_loop);
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static void test_collection_sidebar()
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkProgressBar *progress;
|
||||
GtkFileChooser *chooser;
|
||||
GtkTreeIter iter, child;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *model;
|
||||
GtkTreePath *path;
|
||||
GtkWindow *window;
|
||||
|
||||
struct library *library;
|
||||
int argc = 0;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||
core_init(&argc, NULL, &init_data);
|
||||
gui_view_init();
|
||||
gui_collection_init();
|
||||
while (idle_run_task()) {}
|
||||
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
g_idle_add(test_on_idle, window);
|
||||
|
||||
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
|
||||
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"));
|
||||
test_equal(gtk_tree_model_get_iter_first(model, &iter), true);
|
||||
|
||||
path = gtk_tree_model_get_path(model, &iter);
|
||||
gtk_tree_view_set_cursor(treeview, path, NULL, false);
|
||||
gtk_tree_path_free(path);
|
||||
test_equal(gtk_tree_selection_count_selected_rows(selection), 0);
|
||||
|
||||
gtk_tree_model_iter_nth_child(model, &child, &iter, 0);
|
||||
path = gtk_tree_model_get_path(model, &child);
|
||||
gtk_tree_view_set_cursor(treeview, path, NULL, false);
|
||||
gtk_tree_path_free(path);
|
||||
test_equal(gtk_tree_selection_count_selected_rows(selection), 1);
|
||||
|
||||
gtk_file_chooser_set_filename(chooser, "tests/Music/Hyrule Symphony");
|
||||
g_main_loop_run(main_loop);
|
||||
gtk_button_clicked(GTK_BUTTON(gui_builder_widget("o_collection_add")));
|
||||
|
||||
gtk_tree_model_get_iter_first(model, &iter);
|
||||
test_equal(gtk_tree_model_iter_n_children(model, &iter), 2);
|
||||
gtk_tree_model_iter_nth_child(model, &child, &iter, 0);
|
||||
gtk_tree_model_get(model, &child, 2, &library, -1);
|
||||
test_equal((void *)library, (void *)library_get(0));
|
||||
|
||||
/* Run two idle events to scan the added path. */
|
||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), true);
|
||||
g_main_loop_run(main_loop);
|
||||
test_equal((float)gtk_progress_bar_get_fraction(progress), (float)0.5);
|
||||
while (idle_run_task()) {}
|
||||
g_main_loop_run(main_loop);
|
||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||
|
||||
gtk_tree_store_clear(GTK_TREE_STORE(model));
|
||||
gui_collection_init();
|
||||
while (idle_run_task()) {}
|
||||
gtk_tree_model_get_iter_first(model, &iter);
|
||||
test_equal(gtk_tree_model_iter_n_children(model, &iter), 2);
|
||||
gtk_tree_model_iter_nth_child(model, &child, &iter, 0);
|
||||
gtk_tree_model_get(model, &child, 2, &library, -1);
|
||||
test_equal((void *)library, (void *)library_get(0));
|
||||
|
||||
path = gtk_tree_model_get_path(model, &child);
|
||||
gtk_tree_view_row_activated(treeview, path, NULL);
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
/* Again, run two idle events to update the selected path. */
|
||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), true);
|
||||
g_main_loop_run(main_loop);
|
||||
test_equal((float)gtk_progress_bar_get_fraction(progress), (float)0.5);
|
||||
g_main_loop_run(main_loop);
|
||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||
|
||||
gui_builder_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Collection Sidebar", test_collection_sidebar),
|
||||
);
|
|
@ -4,6 +4,7 @@
|
|||
#define TEST_NEED_AUDIO
|
||||
#define TEST_NEED_COLLECTION
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <tests/gui.h>
|
||||
|
@ -24,6 +25,9 @@ static void test_playlist_sidebar()
|
|||
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||
core_init(&argc, NULL, &init_data);
|
||||
gui_playlist_init();
|
||||
while (idle_run_task()) {}
|
||||
|
||||
test_equal(GTK_IS_TREE_VIEW(GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"))), true);
|
||||
|
||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
|
||||
selection = gtk_tree_view_get_selection(treeview);
|
||||
|
|
Loading…
Reference in New Issue