/* * Copyright 2014 (c) Anna Schumaker. */ #include #include #include #include #include #include static Gtk::FileChooserWidget *c_chooser; static Gtk::ProgressBar *c_progress; static Gtk::TreeView *c_treeview; static void cd_chooser(const std::string &dir) { if (c_chooser->get_current_folder() != dir) c_chooser->set_current_folder(dir); } static bool find_cur_path(Gtk::TreePath &path) { Gtk::TreeViewColumn *col; c_treeview->get_cursor(path, col); return !path.empty(); } static bool on_idle() { bool ret = idle :: run_task(); if (ret) { c_progress->show(); c_progress->set_fraction(idle :: get_progress()); } else c_progress->hide(); colmgr :: update_paths(); return ret; } static void on_ok() { colmgr :: add_path(c_chooser->get_filename()); lib :: idle(on_idle); } static void on_update() { library :: update_all(); lib :: idle(on_idle); } static void on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col) { colmgr :: update_path(path); lib :: idle(on_idle); } static void on_cursor_changed() { Gtk::TreePath path; if (find_cur_path(path)) cd_chooser(colmgr :: get_path(path)); } static bool on_key_pressed(GdkEventKey *event) { Gtk::TreePath path; if (lib :: key_name(event) != "Delete") return false; if (find_cur_path(path)) colmgr :: del_path(path); return true; } static void on_toggled(const Glib::ustring &path) { colmgr :: toggle_path_enabled(Gtk::TreePath(path)); } void collection_mgr_init() { Glib::RefPtr toggle; c_treeview = lib :: get_widget("colmgr_treeview"); c_progress = lib :: get_widget("o_idle_progress"); c_chooser = lib :: get_widget("colmgr_chooser"); toggle = lib :: get_object("colmgr_toggle"); connect_button("colmgr_add", on_ok); connect_button("colmgr_update", on_update); c_treeview->signal_row_activated().connect(sigc::ptr_fun(on_row_activated)); c_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed)); c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_key_pressed)); toggle->signal_toggled().connect(sigc::ptr_fun(on_toggled)); colmgr :: init(); }