/* * 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; }