/* * Copyright 2014 (c) Anna Schumaker. */ extern "C" { #include #include #include #include #include #include #include } #include #include #include static std::map queue_mapping; /** * * Tab class basics * */ Tab :: Tab(queue *pq) : tab_sorting_count(0), tab_pq(pq), tab_label(NULL) { queue_mapping[tab_pq] = this; tab_builder = Gtk::Builder::create(); tab_builder->add_from_file(gui :: share_file("QueueWindow.ui")); tab_builder->get_widget_derived("QueueWindow", tab_window); tab_window->init(tab_pq); tab_vbox.set_margin_start(1); tab_vbox.set_margin_end(1); tab_vbox.set_homogeneous(false); tab_vbox.show(); } Tab :: ~Tab() {} /** * * QNotifier implementation. * */ void Tab :: on_track_added(unsigned int row) { tab_label->set_size(); } void Tab :: on_track_removed(unsigned int row) { tab_label->set_size(); } /** * * Tab internal helper functions * */ int Tab :: tab_page_num() { Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); return notebook->page_num(tab_vbox); } bool Tab :: tab_is_cur() { Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); return notebook->page_num(tab_vbox) == notebook->get_current_page(); } void Tab :: tab_unmap() { queue_mapping.erase(tab_pq); } /** * * Global functions * */ Tab *find_tab(queue *pq) { std::map::iterator it; it = queue_mapping.find(pq); if (it != queue_mapping.end()) return it->second; return NULL; } static bool on_window_key_pressed(GdkEventKey *event) { Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); std::string key = gdk_keyval_name(event->keyval); if (key.size() >= 3) { if (key.substr(0, 3) == "KP_") key = key.substr(3); } if (key >= "0" && key <= "9") { unsigned int n = atoi(key.c_str()); if (n < tempq_count()) notebook->set_current_page(n); } else if (key == "c") notebook->set_current_page(tempq_count()); else if (key == "h") notebook->set_current_page(tempq_count() + 1); else if (key == "m") notebook->set_current_page(tempq_count() + 3); else if (key == "p") notebook->set_current_page(tempq_count() + 2); else return false; return true; } void init_tabs() { Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false); /* Initialize other tabs */ init_queue_tabs(); /* Setup keyboard shortcuts */ window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed)); } void post_init_tabs() { post_init_queue_tabs(); unsigned int tab = 0; for (tab = 0; tab < tempq_count(); tab++) { if (queue_has_flag(tempq_get(tab), Q_ENABLED)) break; } Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false)->set_current_page(tab); } void cleanup_tabs() { while (queue_mapping.size() > 0) delete queue_mapping.begin()->second; }