From b4e2770223733297fd0e5ea4bfec571d85bd0b03 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 26 Aug 2016 10:19:45 -0400 Subject: [PATCH] Remove gui/queue.c This code is obsolete now that the sidebar handles setting the random button when playlists are changed. Implements #76: Remove struct gui_queue Signed-off-by: Anna Schumaker --- gui/ocarina.c | 2 - gui/playlist.c | 29 ++++---- gui/queue.c | 83 --------------------- gui/view.c | 2 +- include/gui/queue.h | 50 ------------- include/gui/queue/label.h | 37 ---------- include/gui/queue/window.h | 26 ------- include/gui/view.h | 1 - tests/gui/.gitignore | 1 - tests/gui/CMakeLists.txt | 1 - tests/gui/playlist.c | 1 - tests/gui/queue.c | 144 ------------------------------------- 12 files changed, 14 insertions(+), 363 deletions(-) delete mode 100644 gui/queue.c delete mode 100644 include/gui/queue.h delete mode 100644 include/gui/queue/label.h delete mode 100644 include/gui/queue/window.h delete mode 100644 tests/gui/queue.c diff --git a/gui/ocarina.c b/gui/ocarina.c index 9555d61e..3716567c 100644 --- a/gui/ocarina.c +++ b/gui/ocarina.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -109,7 +108,6 @@ static void __ocarina_startup(GApplication *application, gpointer data) gui_treeview_init(); gui_sidebar_init(); gui_view_init(); - gui_queue_init(); gui_collection_init(); gui_playlist_init(); gui_audio_init(); diff --git a/gui/playlist.c b/gui/playlist.c index 42a9e73a..41c0fc70 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -6,8 +6,8 @@ #include #include #include +#include #include -#include #include static bool p_filter_enable = true; @@ -24,12 +24,12 @@ void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter) { - struct gui_queue *gq = gui_queue(queue); - bool match = (gui_sidebar_iter_type(iter) == gq->gq_playlist->pl_type); + struct playlist *playlist = queue->q_private; + bool match = (gui_sidebar_iter_type(iter) == playlist->pl_type); gchar *name = gui_sidebar_iter_name(iter); if (match) - match = string_match(name, gq->gq_text); + match = string_match(name, playlist->pl_name); if (match) gui_sidebar_iter_update(iter); g_free(name); @@ -64,10 +64,7 @@ out: static void *__playlist_init(struct queue *queue, void *data) { struct playlist *playlist = (struct playlist *)data; - unsigned int flags = 0; - if (!string_match(playlist->pl_name, "History")) - flags = GQ_CAN_RANDOM; if (p_init_done && playlist->pl_type == PL_ARTIST) { p_filter_enable = false; gui_playlist_add_artist(playlist); @@ -75,42 +72,42 @@ static void *__playlist_init(struct queue *queue, void *data) } if (p_init_done && playlist->pl_type == PL_USER) gui_playlist_add_user(playlist); - return gui_queue_alloc(playlist, queue, playlist->pl_name, flags); + return playlist; } static void __playlist_deinit(struct queue *queue) { - gui_filter_clear_search(gui_queue(queue)->gq_playlist); - gui_queue_free(queue); + gui_filter_clear_search(queue->q_private); } static void __playlist_added(struct queue *queue, unsigned int row) { - gui_model_add(gui_queue(queue)->gq_playlist, row); + gui_model_add(queue->q_private, row); __playlist_update_sizes(queue); } static void __playlist_removed(struct queue *queue, unsigned int row) { - gui_model_remove(gui_queue(queue)->gq_playlist, row); + gui_model_remove(queue->q_private, row); __playlist_update_sizes(queue); } static void __playlist_cleared(struct queue *queue, unsigned int n) { - gui_model_clear(gui_queue(queue)->gq_playlist, n); + gui_model_clear(queue->q_private, n); __playlist_update_sizes(queue); } static void __playlist_updated(struct queue *queue, unsigned int n) { - gui_model_update(gui_queue(queue)->gq_playlist, n); + gui_model_update(queue->q_private, n); } static bool __playlist_erase(struct queue *queue, struct track *track) { - enum playlist_type_t type = gui_queue(queue)->gq_playlist->pl_type; - const gchar *name = gui_queue(queue)->gq_playlist->pl_name; + struct playlist *playlist = queue->q_private; + enum playlist_type_t type = playlist->pl_type; + const gchar *name = playlist->pl_name; switch (type) { case PL_SYSTEM: diff --git a/gui/queue.c b/gui/queue.c deleted file mode 100644 index 53095303..00000000 --- a/gui/queue.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 (c) Anna Schumaker. - */ -#include -#include -#include -#include -#include -#include -#include - -static struct gui_queue *gq_queue = NULL; - -static void __queue_toggle_flag(bool active, GtkWidget *widget, - enum queue_flags flag) -{ - if (gq_queue == NULL) - return; - - if (active) - queue_set_flag(gq_queue->gq_queue, flag); - else - queue_unset_flag(gq_queue->gq_queue, flag); -} - -void __queue_random(GtkToggleButton *button, gpointer data) -{ - __queue_toggle_flag(gtk_toggle_button_get_active(button), - gtk_button_get_image(GTK_BUTTON(button)), - Q_RANDOM); - if (gq_queue && gq_queue->gq_playlist) { - playlist_set_random(gq_queue->gq_playlist->pl_type, - gq_queue->gq_playlist->pl_name, - gtk_toggle_button_get_active(button)); - } -} - -void gui_queue_init(void) -{ -} - -struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue, - const gchar *text, unsigned int flags) -{ - struct gui_queue *gq = g_malloc(sizeof(struct gui_queue)); - - gq->gq_flags = flags; - gq->gq_text = g_strdup(text); - gq->gq_playlist = playlist; - gq->gq_queue = queue; - - return gq; -} - -void gui_queue_free(struct queue *queue) -{ - struct gui_queue *gq = gui_queue(queue); - - queue->q_private = NULL; - - if (gq_queue == gq) - gui_view_set_playlist(NULL); - g_free(gq->gq_text); - g_free(gq); -} - -void gui_queue_show(struct gui_queue *queue) -{ - GtkButton *random = GTK_BUTTON(gui_builder_widget("random_button")); - bool has_random = false; - - gq_queue = queue; - - gtk_widget_set_sensitive(GTK_WIDGET(random), gui_queue_can_random(queue)); - - if (queue) { - has_random = queue_has_flag(queue->gq_queue, Q_RANDOM); - gui_view_set_playlist(queue->gq_playlist); - } else - gui_view_set_playlist(NULL); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random); -} diff --git a/gui/view.c b/gui/view.c index a12889c5..3d97c7a8 100644 --- a/gui/view.c +++ b/gui/view.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/gui/queue.h b/include/gui/queue.h deleted file mode 100644 index fed83956..00000000 --- a/include/gui/queue.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016 (c) Anna Schumaker. - */ -#ifndef OCARINA_GUI_QUEUE_H -#define OCARINA_GUI_QUEUE_H - -#include -#include - -enum gui_queue_flags { - GQ_CAN_RANDOM = (1 << 0), /* Random button can be clicked. */ -}; - -struct gui_queue { - unsigned int gq_flags; - gchar *gq_text; - - struct playlist *gq_playlist; - struct queue *gq_queue; -}; - - -/* Called to initialize the gui_queue code. */ -void gui_queue_init(void); - -/* Called to allocate a new struct gui_queue. */ -struct gui_queue *gui_queue_alloc(struct playlist *, struct queue *, - const gchar *, unsigned int); - -/* Called to free a struct gui_queue. */ -void gui_queue_free(struct queue *); - -/* Called to access a the struct gui_queue attached to a queue. */ -static inline struct gui_queue *gui_queue(struct queue *queue) -{ - return queue ? (struct gui_queue *)queue->q_private : NULL; -} - -/* Called to ask the struct gui_queue if it can change random flag. */ -static inline bool gui_queue_can_random(struct gui_queue *gq) -{ - if (gq) - return (gq->gq_flags & GQ_CAN_RANDOM) == GQ_CAN_RANDOM; - return false; -} - -/* Called to set the correct state of the random and repeat buttons. */ -void gui_queue_show(struct gui_queue *); - -#endif /* OCARINA_GUI_QUEUE_H */ diff --git a/include/gui/queue/label.h b/include/gui/queue/label.h deleted file mode 100644 index 2f17c010..00000000 --- a/include/gui/queue/label.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2015 (c) Anna Schumaker. - */ -#ifndef OCARINA_GUI_QUEUE_LABEL_H -#define OCARINA_GUI_QUEUE_LABEL_H - -#include -#include - - -class QueueLabel : public Gtk::HBox { -protected: - Glib::RefPtr _builder; - queue *_queue; - -public: - QueueLabel(BaseObjectType *, const Glib::RefPtr); - ~QueueLabel(); - virtual void init(queue *); - virtual void set_sensitive(bool) {}; - virtual void set_size() {}; -}; - - - -class TempLabel : public QueueLabel { -public: - Gtk::Label *temp_number; - Gtk::Label *temp_size; - Gtk::Button *temp_close; - - TempLabel(BaseObjectType *, const Glib::RefPtr); - void set_sensitive(bool); - void set_size(); -}; - -#endif /* OCARINA_GUI_QUEUE_LABEL_H */ diff --git a/include/gui/queue/window.h b/include/gui/queue/window.h deleted file mode 100644 index e8c69b3a..00000000 --- a/include/gui/queue/window.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015 (c) Anna Schumaker. - */ -#ifndef OCARINA_GUI_QUEUE_WINDOW_H -#define OCARINA_GUI_QUEUE_WINDOW_H - -extern "C" { -#include -#include -} -#include - -class QueueWindow : public Gtk::ScrolledWindow { -public: - Glib::RefPtr _builder; - - Gtk::TreeView *q_treeview; - - QueueWindow(BaseObjectType *, const Glib::RefPtr); - ~QueueWindow(); - void init(queue *); - - bool on_key_press(GdkEventKey *); -}; - -#endif /* OCARINA_GUI_QUEUE_WINDOW_H */ diff --git a/include/gui/view.h b/include/gui/view.h index e630364a..a3c8f06f 100644 --- a/include/gui/view.h +++ b/include/gui/view.h @@ -4,7 +4,6 @@ #ifndef OCARINA_GUI_VIEW_H #define OCARINA_GUI_VIEW_H #include -#include /* Called to initialize structures needed by the treeview. */ void gui_view_init(); diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index 8255eda7..153be687 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -6,6 +6,5 @@ filter treeview sidebar view -queue playlist audio diff --git a/tests/gui/CMakeLists.txt b/tests/gui/CMakeLists.txt index df9209a4..3ea62242 100644 --- a/tests/gui/CMakeLists.txt +++ b/tests/gui/CMakeLists.txt @@ -12,6 +12,5 @@ gui_unit_test(Filter) gui_unit_test(Treeview) gui_unit_test(Sidebar) gui_unit_test(View) -gui_unit_test(Queue) gui_unit_test(Playlist) gui_unit_test(Audio) diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c index 6ae87c0c..b70591d6 100644 --- a/tests/gui/playlist.c +++ b/tests/gui/playlist.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/gui/queue.c b/tests/gui/queue.c deleted file mode 100644 index 614a1651..00000000 --- a/tests/gui/queue.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2016 (c) Anna Schumaker. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -static void *test_queue_init(struct queue *queue, void *data) -{ - return gui_queue_alloc(data, queue, "Test Queue", GQ_CAN_RANDOM); -} - -void test_queue_add(struct queue *queue, unsigned int n) - { gui_model_add(gui_queue(queue)->gq_playlist, n); } -void test_queue_remove(struct queue *queue, unsigned int n) - { gui_model_remove(gui_queue(queue)->gq_playlist, n); } -void test_queue_clear(struct queue *queue, unsigned int n) - { gui_model_clear(gui_queue(queue)->gq_playlist, n); } -static void test_queue_save(struct queue *queue, unsigned int row) {} -void test_queue_update(struct queue *queue, unsigned int n) - { gui_model_update(gui_queue(queue)->gq_playlist, n); } - -static struct queue_ops test_ops = { - .qop_init = test_queue_init, - .qop_deinit = gui_queue_free, - .qop_cleared = test_queue_clear, - .qop_added = test_queue_add, - .qop_removed = test_queue_remove, - .qop_save = test_queue_save, - .qop_updated = test_queue_update, -}; - -struct core_init_data init_data = { - .playlist_ops = &test_ops, -}; - -static void test_queue() -{ - GtkToggleButton *random; - struct gui_queue *gq; - GtkEntry *search; - struct queue q; - - search = GTK_ENTRY(gui_filter_search()); - random = GTK_TOGGLE_BUTTON(gui_builder_widget("random_button")); - - /* Test initialization */ - queue_init(&q, Q_ENABLED, &test_ops, NULL); - gq = gui_queue(&q); - - g_assert_true(gui_queue_can_random(gq)); - gq->gq_flags = 0; - g_assert_false(gui_queue_can_random(gq)); - - gtk_entry_set_text(search, "Test text"); - - /* Show a queue where random and repeat are disabled */ - gui_queue_show(gq); - g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(random))); - g_assert_false(gtk_toggle_button_get_active(random)); - g_assert_cmpstr(gtk_entry_get_text(search), ==, ""); - - /* Show a queue where random and repeat are enabled */ - gq->gq_flags = GQ_CAN_RANDOM; - q.q_flags = Q_RANDOM | Q_REPEAT | Q_ENABLED; - gui_queue_show(gq); - g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(random))); - g_assert_true(gtk_toggle_button_get_active(random)); - - /* Attempt to show a NULL pointer */ - gui_queue_show(NULL); - g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(random))); - g_assert_false(gtk_toggle_button_get_active(random)); - - queue_deinit(&q); - g_assert_null(gui_queue(&q)); -} - -static void test_tracks() -{ - struct db_entry *dbe, *next; - GtkTreeModel *filter; - struct gui_queue *gq; - GtkEntry *search; - - search = GTK_ENTRY(gui_filter_search()); - - gq = gui_queue(playlist_get_queue(PL_SYSTEM, "Collection")); - - gui_queue_show(gq); - playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); - while (idle_run_task() == true) {} - - filter = GTK_TREE_MODEL(gui_filter_get()); - g_assert_nonnull(gq); - g_assert_nonnull(filter); - g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 13); - - gtk_entry_set_text(search, "zelda"); - g_signal_emit_by_name(search, "search-changed"); - g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 2); - - gtk_entry_set_text(search, ""); - g_signal_emit_by_name(search, "search-changed"); - g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 13); - - db_for_each(dbe, next, track_db_get()) { - if (TRACK(dbe)->tr_track == 4) { - playlist_remove(PL_SYSTEM, "Collection", TRACK(dbe)); - break; - } - } - - g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 12); - gui_queue_show(NULL); -} - -int main(int argc, char **argv) -{ - int ret; - - gtk_init(&argc, NULL); - gui_builder_init("share/ocarina/ocarina.ui"); - core_init(&argc, NULL, &init_data); - gui_model_init(); - gui_filter_init(); - gui_view_init(); - gui_queue_init(); - while (idle_run_task()) {}; - - g_test_init(&argc, &argv, NULL); - g_test_add_func("/Gui/Queue", test_queue); - g_test_add_func("/Gui/Queue/Tracks", test_tracks); - ret = g_test_run(); - - core_deinit(); - gui_builder_deinit(); - return ret; -}