diff --git a/gui/collection.cpp b/gui/collection.cpp new file mode 100644 index 00000000..3adfad55 --- /dev/null +++ b/gui/collection.cpp @@ -0,0 +1,98 @@ +/* + * Copyright 2014 (c) Anna Schumaker. + */ +#include +#include + +static Glib::RefPtr model; + + +/* + * Basic helper functions + */ +static inline Playqueue *library_pq() +{ + return deck::get_library_pq(); +} + +static Gtk::ToggleButton *get_random_button() +{ + return get_widget("o_collection_random"); +} + +static void set_queue_size() +{ + Gtk::Label *label = get_widget("o_collection_size"); + label->set_text(itoa(library_pq()->size())); +} + + + +/* + * Gtk signal functions + */ + +static void on_random_toggled() +{ + if (get_random_button()->get_active()) + library_pq()->set_flag(PQ_RANDOM); + else + library_pq()->unset_flag(PQ_RANDOM); +} + + + +/* + * Functions exposed through a TabFuncs structure + */ + +static void collection_init_late() +{ + set_queue_size(); + get_random_button()->set_active(library_pq()->get_flags() & PQ_RANDOM); +} + +static void collection_cleanup() {} + +static bool collection_has_queue(Playqueue *pq) +{ + return pq == library_pq(); +} + +static void collection_track_added(Playqueue *pq, unsigned int row) +{ + model->on_row_inserted(row); + set_queue_size(); +} + +static void collection_track_deleted(Playqueue *pq, unsigned int row) +{ + model->on_row_deleted(row); + set_queue_size(); +} + + +static struct TabFuncs collection_funcs = { + .init_late = collection_init_late, + .cleanup = collection_cleanup, + + .has_queue = collection_has_queue, + .track_added = collection_track_added, + .track_deleted = collection_track_deleted, +}; + + + +/* + * Basic tab setup + */ + +struct TabFuncs *init_collection_tab() +{ + model = Glib::RefPtr(new PlayqueueModel(library_pq())); + get_widget("o_collection_pq_treeview")->set_model(model); + + get_random_button()->signal_toggled().connect(sigc::ptr_fun(on_random_toggled)); + + return &collection_funcs; +} diff --git a/gui/ocarina6.glade b/gui/ocarina6.glade index a1a90b73..499a2c8b 100644 --- a/gui/ocarina6.glade +++ b/gui/ocarina6.glade @@ -163,6 +163,435 @@ left True True + + + True + False + 1 + 1 + vertical + + + True + False + 5 + 5 + 5 + + + True + True + edit-find-symbolic + False + False + + + True + True + 0 + + + + + True + True + True + False + + + True + False + media-playlist-shuffle + + + + + False + True + 1 + + + + + False + True + 2 + 0 + + + + + True + True + 5 + 5 + 5 + in + + + True + True + True + False + True + 9 + + + multiple + + + + + True + fixed + 20 + # + True + + + + 0 + + + + + + + True + fixed + 300 + Title + True + + + + 1 + + + + + + + True + fixed + 60 + Length + True + + + + 2 + + + + + + + True + fixed + 100 + Artist + True + + + + 3 + + + + + + + True + fixed + 100 + Album + True + + + + 4 + + + + + + + True + fixed + 45 + Year + True + + + + 5 + + + + + + + True + fixed + 100 + Genre + True + + + + 6 + + + + + + + True + fixed + 60 + Count + True + + + + 7 + + + + + + + True + fixed + 1 + Played + True + + + + 8 + + + + + + + + + True + True + 1 + + + + + + + True + False + 5 + + + True + False + 0 + media-optical + 1 + + + False + True + 0 + + + + + True + False + vertical + + + True + False + 1 + <big>Collection</big> + True + center + + + False + True + 0 + + + + + True + False + 0 + + + False + True + 1 + + + + + True + True + 1 + + + + + False + + + + + True + False + vertical + + + + + + + + + + + + 1 + + + + + True + False + 5 + + + True + False + 0 + document-open-recent + 1 + + + False + True + 0 + + + + + True + False + vertical + + + True + False + 1 + <big>History</big> + True + center + + + True + True + 0 + + + + + True + False + 0 + center + + + True + True + 1 + + + + + True + True + 1 + + + + + 1 + False + + + + + True + False + vertical + + + + + + + + + + + + 2 + + + + + True + False + 5 + + + True + False + 0 + emblem-documents + 1 + + + False + True + 0 + + + + + True + False + 1 + Playlist +Manager + center + + + True + True + 1 + + + + + 2 + False + + True @@ -408,6 +837,9 @@ + + 3 + @@ -418,6 +850,7 @@ True False + 0 system-file-manager 1 @@ -431,18 +864,20 @@ True False + 1 Collection Manager center - False + True True 1 + 3 False @@ -485,7 +920,7 @@ Manager True - True + False o_progress 1 False @@ -524,7 +959,7 @@ Manager True - True + False True False @@ -543,7 +978,7 @@ Manager - True + False True False @@ -563,7 +998,7 @@ Manager True - True + False True False @@ -583,7 +1018,7 @@ Manager True - True + False True False @@ -603,7 +1038,7 @@ Manager True - True + False True False @@ -634,7 +1069,7 @@ Manager True - True + False True False @@ -654,7 +1089,7 @@ Manager True - True + False True False @@ -686,7 +1121,7 @@ Manager Pause after True - True + False False False 0 @@ -702,6 +1137,7 @@ Manager True True + False adjustment1 True diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 154bf48d..748aaf4e 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -16,6 +17,7 @@ class OcarinaPage; static std::map tab_map; +static std::list tab_types; static unsigned int sort_timeout_count = 0; static class SidebarColumns : public Gtk::TreeModelColumnRecord { @@ -761,12 +763,28 @@ void OcarinaPage::on_focus_search() /* * Do stuff with tabs */ +static TabFuncs *find_tab_funcs(Playqueue *pq) +{ + std::list::iterator tab_it; + for (tab_it = tab_types.begin(); tab_it != tab_types.end(); tab_it++) { + if ((*tab_it)->has_queue(pq)) + return *tab_it; + } + return NULL; +} + static void on_track_added(Playqueue *pq, unsigned int row) { std::map::iterator it; + it = tab_map.find(pq); if (it != tab_map.end()) it->second->on_row_inserted(row); + + struct TabFuncs *tab; + tab = find_tab_funcs(pq); + if (tab) + tab->track_added(pq, row); } static void on_track_deleted(Playqueue *pq, unsigned int row) @@ -775,6 +793,11 @@ static void on_track_deleted(Playqueue *pq, unsigned int row) it = tab_map.find(pq); if (it != tab_map.end()) it->second->on_row_deleted(row); + + struct TabFuncs *tab; + tab = find_tab_funcs(pq); + if (tab) + tab->track_deleted(pq, row); } static void on_track_changed(Playqueue *pq, unsigned int row) @@ -794,7 +817,7 @@ static void on_switch_page(Gtk::Widget *page, int num) get_builder()->get_widget("o_queue_time", label); get_builder()->get_widget("o_notebook", notebook); - if (num >= notebook->get_n_pages() - 1) + if (num >= notebook->get_n_pages() - 4) label->hide(); else { tab->on_runtime_changed(); @@ -856,7 +879,7 @@ void queue_selected(bool random) } } -static void on_new_queue() +/*static void on_new_queue() { queue_selected(false); } @@ -877,7 +900,7 @@ static void init_menu_item(const std::string &name, unsigned int num) Glib::RefPtrmenu = Glib::RefPtr::cast_static(get_builder()->get_object(name)); menu->signal_activate().connect(sigc::bind ( sigc::ptr_fun(on_add_to_queue), num)); -} +}*/ void focus_tab_search() { @@ -906,7 +929,7 @@ void init_tabs() get_callbacks()->on_queue_track_changed = on_track_changed; - Glib::RefPtr new_pq = Glib::RefPtr::cast_static(get_builder()->get_object("o_new_pq")); + /*Glib::RefPtr new_pq = Glib::RefPtr::cast_static(get_builder()->get_object("o_new_pq")); new_pq->signal_activate().connect(sigc::ptr_fun(on_new_queue)); init_menu_item("o_pq_0", 0); @@ -918,7 +941,9 @@ void init_tabs() init_menu_item("o_pq_6", 6); init_menu_item("o_pq_7", 7); init_menu_item("o_pq_8", 8); - init_menu_item("o_pq_9", 9); + init_menu_item("o_pq_9", 9);*/ + + tab_types.push_back(init_collection_tab()); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered)); @@ -930,10 +955,18 @@ void init_tabs2() std::map::iterator it; for (it = tab_map.begin(); it != tab_map.end(); it++) it->second->check_pq_flags(); + + std::list::iterator tab_it; + for (tab_it = tab_types.begin(); tab_it != tab_types.end(); tab_it++) + (*tab_it)->init_late(); } void cleanup_tabs() { while (tab_map.size() > 0) delete tab_map.begin()->second; + + std::list::iterator it; + for (it = tab_types.begin(); it != tab_types.end(); it++) + (*it)->cleanup(); } diff --git a/include/ocarina.h b/include/ocarina.h index d2498b47..f0803d54 100644 --- a/include/ocarina.h +++ b/include/ocarina.h @@ -5,14 +5,20 @@ #define OCARINA_H #include +#include #include +/* collection.cpp */ +struct TabFuncs *init_collection_tab(); + /* collection_mgr.cpp */ void collection_mgr_init(); + /* main.cpp */ Gtk::Window *ocarina_init(int *, char ***); + /* model.cpp */ class PlayqueueModel : public Gtk::TreeModel, public Glib::Object { private: @@ -51,6 +57,7 @@ public: unsigned int path_to_id(const Gtk::TreePath &); }; + /* tabs.cpp */ void queue_selected(bool); void focus_tab_search(); @@ -58,6 +65,7 @@ void init_tabs(); void init_tabs2(); void cleanup_tabs(); + /* wires.cpp */ void enable_idle(); void connect_button(const std::string &, void (*func)()); diff --git a/include/tabs.h b/include/tabs.h new file mode 100644 index 00000000..355aea90 --- /dev/null +++ b/include/tabs.h @@ -0,0 +1,25 @@ +/* + * Copyright 2014 (c) Anna Schumaker. + */ +#ifndef OCARINA_TABS_H +#define OCARINA_TABS_H + +#include + +struct TabFuncs { + void (*init_late)(); + void (*cleanup)(); + + bool (*has_queue)(Playqueue *); + void (*track_added)(Playqueue *, unsigned int); + void (*track_deleted)(Playqueue *, unsigned int); +}; + +static inline std::string itoa(unsigned int i) +{ + std::stringstream ss; + ss << i; + return ss.str(); +} + +#endif /* OCARINA_TABS_H */