From 9a3ad4954d701b4c51bd96927e86efd338a56d5e Mon Sep 17 00:00:00 2001 From: Mirko Lindner Date: Sat, 20 Feb 2010 20:45:41 +0100 Subject: [PATCH] refine signal handling Signed-off-by: Mirko Lindner --- src/main_window.cc | 98 +++++++++++++++++++++++++++++----------------- src/main_window.hh | 4 ++ src/vido.hh | 3 ++ 3 files changed, 69 insertions(+), 36 deletions(-) diff --git a/src/main_window.cc b/src/main_window.cc index 3030a66..93e159f 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -32,12 +32,30 @@ log_define("vido.main_window"); main_window::main_window() { - signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event)); - signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event)); + sigc::connection press_id; + sigc::connection release_id; + +} + +void main_window::connect_all() +{ + log_debug("connecting all"); + (*this).press_id = signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event)); + (*this).release_id = signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event)); + log_debug((*this).press_id << " " << (*this).release_id); +} + +void main_window::disconnect_all() +{ + log_debug("disconnecting all"); + (*this).press_id.disconnect(); + (*this).release_id.disconnect(); + log_debug((*this).press_id << " " << (*this).release_id); } bool main_window::actions(int key) { +// log_debug("in actions" << (*this).press_id << " " << (*this).release_id); static int key_b = 98; static int key_f = 102; static int key_h = 104; @@ -45,34 +63,46 @@ bool main_window::actions(int key) static int key_r = 114; static int key_s = 115; static int key_t = 116; - - if (key == key_q) - { - log_debug("quit requested"); - quit(); - } - else if(key == key_r) - { - log_debug("random"); - show_random(); - } - else if(key == key_s) - { - log_debug("search"); - search_window(this); - }else if(key == key_t){ - GoToTop(); - }else if(key == key_h){ - show_history(); - }else if(key == key_f){ - history_jump(1); - }else if(key == key_b){ - history_jump(-1); - }else{ - log_debug("key pressed: " << key); - } - - return true; + static int key_f1 = 65470; + + // key commands only available if ctrl pressed + if ((ctrl_state == 1) && ((*this).press_id == 1)) + { + (*this).disconnect_all(); + if (key == key_q) + { +// log_debug("quit requested"); + quit(); + } + else if(key == key_r) + { +// log_debug("random"); + show_random(); + } + else if(key == key_s) + { + log_debug("search"); + search_window(this); + }else if(key == key_t){ + GoToTop(); + }else if(key == key_h){ + show_history(); + }else if(key == key_f){ + history_jump(1); + }else if(key == key_b){ + history_jump(-1); + }else{ + (*this).connect_all(); +// log_debug("key pressed: " << key); + } + // other commands + }else{ + if(key == key_f1){ + (*this).disconnect_all(); + show_help(); + } + } + return true; } @@ -84,13 +114,9 @@ bool main_window::on_my_key_press_event(GdkEventKey *Key) } else { - if (ctrl_state == 1) - { - actions(Key->keyval); - } + actions(Key->keyval); } - - log_debug("Key Presssed is " << gdk_keyval_name(Key->keyval)); +// log_debug("Key Presssed is " << Key->keyval); return true; } diff --git a/src/main_window.hh b/src/main_window.hh index 3d1ee3e..cc20ae2 100644 --- a/src/main_window.hh +++ b/src/main_window.hh @@ -27,6 +27,10 @@ class main_window : public Gtk::Window { public: main_window(); + sigc::connection press_id; + sigc::connection release_id; + void connect_all(); + void disconnect_all(); private: bool actions(int); diff --git a/src/vido.hh b/src/vido.hh index e58f983..e42529e 100644 --- a/src/vido.hh +++ b/src/vido.hh @@ -32,5 +32,8 @@ extern void search_window(main_window *window); extern void getArticleFromUrl(const gchar *url, int pos); extern void getArticleFromTitle(const gchar *url); extern void GoToTop(); +extern bool get_blocked(); +extern void set_blocked(bool value); +extern void show_help(); #endif // VIDO_HH