From df0d1496de8ce3bff6b893c9c25ffd68aee45e7f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 10 Sep 2014 08:17:12 -0400 Subject: [PATCH] lib: Create a schedule() function This lets me clean up some of the code in controls.cpp Signed-off-by: Anna Schumaker --- gui/controls.cpp | 7 +------ include/lib/lib.h | 1 + lib/lib.cpp | 5 +++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gui/controls.cpp b/gui/controls.cpp index 9c12c463..266a98a1 100644 --- a/gui/controls.cpp +++ b/gui/controls.cpp @@ -43,17 +43,12 @@ static bool on_timeout() return audio_playing(); } -static void enable_timeout() -{ - Glib::signal_timeout().connect(sigc::ptr_fun(on_timeout), 500); -} - static void o_play() { audio :: play(); o_fix_buttons(); - enable_timeout(); + lib :: schedule(on_timeout, 500); } static void o_pause() diff --git a/include/lib/lib.h b/include/lib/lib.h index e9a3e244..64e6321f 100644 --- a/include/lib/lib.h +++ b/include/lib/lib.h @@ -14,6 +14,7 @@ namespace lib const std::string share_file(const std::string &); Glib::RefPtr &get_builder(); const std::string key_name(GdkEventKey *); + void schedule(bool (*)(), unsigned int); template static inline T *get_widget(const std::string &name) diff --git a/lib/lib.cpp b/lib/lib.cpp index 2631acfa..c0a0e06f 100644 --- a/lib/lib.cpp +++ b/lib/lib.cpp @@ -42,3 +42,8 @@ const std::string lib :: key_name(GdkEventKey *event) std::string key = gdk_keyval_name(event->keyval); return key; } + +void lib :: schedule(bool (*func)(), unsigned int milliseconds) +{ + Glib :: signal_timeout().connect(sigc::ptr_fun(func), milliseconds); +}