1
0
mirror of git://projects.qi-hardware.com/vido.git synced 2025-01-03 06:20:14 +02:00

refine signal handling

Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
Mirko Lindner 2010-02-20 20:45:41 +01:00
parent 5d30ead071
commit 9a3ad4954d
3 changed files with 69 additions and 36 deletions

View File

@ -32,12 +32,30 @@ log_define("vido.main_window");
main_window::main_window() main_window::main_window()
{ {
signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event)); sigc::connection press_id;
signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event)); 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) bool main_window::actions(int key)
{ {
// log_debug("in actions" << (*this).press_id << " " << (*this).release_id);
static int key_b = 98; static int key_b = 98;
static int key_f = 102; static int key_f = 102;
static int key_h = 104; static int key_h = 104;
@ -45,34 +63,46 @@ bool main_window::actions(int key)
static int key_r = 114; static int key_r = 114;
static int key_s = 115; static int key_s = 115;
static int key_t = 116; static int key_t = 116;
static int key_f1 = 65470;
if (key == key_q)
{ // key commands only available if ctrl pressed
log_debug("quit requested"); if ((ctrl_state == 1) && ((*this).press_id == 1))
quit(); {
} (*this).disconnect_all();
else if(key == key_r) if (key == key_q)
{ {
log_debug("random"); // log_debug("quit requested");
show_random(); quit();
} }
else if(key == key_s) else if(key == key_r)
{ {
log_debug("search"); // log_debug("random");
search_window(this); show_random();
}else if(key == key_t){ }
GoToTop(); else if(key == key_s)
}else if(key == key_h){ {
show_history(); log_debug("search");
}else if(key == key_f){ search_window(this);
history_jump(1); }else if(key == key_t){
}else if(key == key_b){ GoToTop();
history_jump(-1); }else if(key == key_h){
}else{ show_history();
log_debug("key pressed: " << key); }else if(key == key_f){
} history_jump(1);
}else if(key == key_b){
return true; 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 else
{ {
if (ctrl_state == 1) actions(Key->keyval);
{
actions(Key->keyval);
}
} }
// log_debug("Key Presssed is " << Key->keyval);
log_debug("Key Presssed is " << gdk_keyval_name(Key->keyval));
return true; return true;
} }

View File

@ -27,6 +27,10 @@ class main_window : public Gtk::Window
{ {
public: public:
main_window(); main_window();
sigc::connection press_id;
sigc::connection release_id;
void connect_all();
void disconnect_all();
private: private:
bool actions(int); bool actions(int);

View File

@ -32,5 +32,8 @@ extern void search_window(main_window *window);
extern void getArticleFromUrl(const gchar *url, int pos); extern void getArticleFromUrl(const gchar *url, int pos);
extern void getArticleFromTitle(const gchar *url); extern void getArticleFromTitle(const gchar *url);
extern void GoToTop(); extern void GoToTop();
extern bool get_blocked();
extern void set_blocked(bool value);
extern void show_help();
#endif // VIDO_HH #endif // VIDO_HH