From 5eeebe78545d14c60e41e90b8d4e1a9bd71946f6 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 12 Sep 2014 08:15:17 -0400 Subject: [PATCH] gui: Move idle function into the collection manager The collection manager is the only thing that uses the idle queue, so let's keep all this code together. Signed-off-by: Anna Schumaker --- gui/collection_mgr.cpp | 23 ++++++++++++++++++++--- gui/gui.cpp | 27 --------------------------- include/gui/ocarina.h | 1 - 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/gui/collection_mgr.cpp b/gui/collection_mgr.cpp index d5a88f64..197a5ae0 100644 --- a/gui/collection_mgr.cpp +++ b/gui/collection_mgr.cpp @@ -2,6 +2,7 @@ * Copyright 2014 (c) Anna Schumaker. */ #include +#include #include #include #include @@ -9,6 +10,7 @@ static Gtk::FileChooserWidget *c_chooser; +static Gtk::ProgressBar *c_progress; static Gtk::TreeView *c_treeview; @@ -25,23 +27,37 @@ static bool find_cur_path(Gtk::TreePath &path) 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()); - enable_idle(); + lib :: idle(on_idle); } static void on_update() { library :: update_all(); - enable_idle(); + lib :: idle(on_idle); } static void on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col) { colmgr :: update_path(path); - enable_idle(); + lib :: idle(on_idle); } static void on_cursor_changed() @@ -73,6 +89,7 @@ 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"); diff --git a/gui/gui.cpp b/gui/gui.cpp index 7a9d798f..ced6dcf8 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -99,32 +98,6 @@ static void on_fav_toggled() -/* - * Idle func - */ -bool on_idle() -{ - Gtk::ProgressBar *prog = lib :: get_widget("o_idle_progress"); - bool ret = idle::run_task(); - - if (ret == false) - prog->hide(); - else { - prog->show(); - prog->set_fraction(idle::get_progress()); - } - - colmgr :: update_paths(); - return ret; -} - -void enable_idle() -{ - lib :: idle(on_idle); -} - - - /* * Ocarina functions */ diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index 0df707a1..38f7a893 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -17,7 +17,6 @@ Gtk::Window *ocarina_init(int *, char ***); /* gui.cpp */ -void enable_idle(); void connect_button(const std::string &, void (*func)()); Gtk::Window *setup_gui();