From 7b30cd7ebe6ae7b999e08c04496cee594e593d41 Mon Sep 17 00:00:00 2001 From: Lorb Date: Sun, 15 Jul 2012 10:46:35 +0200 Subject: [PATCH] Added the option and functionality of having timers start when they are selectet. Cleaned the code a little. --- src/xfcetimer.c | 80 +++++++++++++++++++++++++++++++++++-------------------- src/xfcetimer.h | 6 ++--- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/xfcetimer.c b/src/xfcetimer.c index 2344a15..0b9e278 100644 --- a/src/xfcetimer.c +++ b/src/xfcetimer.c @@ -18,7 +18,8 @@ */ -#define TIMEOUT_TIME 2000 /* Countdown update period in milliseconds */ +#define UPDATE_INTERVAL 2000 /* Countdown update period in milliseconds */ + #define PBAR_THICKNESS 10 #define BORDER 8 @@ -159,6 +160,7 @@ static gboolean update_function (gpointer data){ g_timer_destroy(pd->timer); pd->timer=NULL; + /* Disable tooltips, reset pbar */ gtk_tooltips_set_tip(pd->tip,GTK_WIDGET(pd->base),"",NULL); gtk_tooltips_disable(pd->tip); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pd->pbar),0); @@ -167,9 +169,6 @@ static gboolean update_function (gpointer data){ pd->timer_on=FALSE; - /* reset pbar */ - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pd->pbar),0); - make_menu(pd); /* This function won't be called again */ @@ -178,29 +177,6 @@ static gboolean update_function (gpointer data){ } /** - * This is the callback function called when a timer - * is selected in the popup menu -**/ - -static void timer_selected (GtkWidget* menuitem, GdkEventButton* event, gpointer data){ - - plugin_data *pd=(plugin_data *)data; - gint row_count; - - row_count=0; - - /* Find the index of the menuitem selected, save it in pd->selected. Not very - elegant, though */ - while (GTK_MENU_ITEM(menuitem)!=g_array_index(pd->menuarray,GtkMenuItem*,row_count) ) - row_count++; - - pd->selected=row_count; - - /*g_fprintf(stderr,"\n Selecten menuitem is %d",row_count);*/ - -} - -/** * This is the callback function called when the * start/stop item is selected in the popup menu **/ @@ -322,6 +298,33 @@ static void start_stop_selected (GtkWidget* menuitem, GdkEventButton* event, gpo } +/** + * This is the callback function called when a timer + * is selected in the popup menu +**/ + +static void timer_selected (GtkWidget* menuitem, GdkEventButton* event, gpointer data){ + + plugin_data *pd=(plugin_data *)data; + gint row_count; + + row_count=0; + + /* Find the index of the menuitem selected, save it in pd->selected. Not very + elegant, though */ + while (GTK_MENU_ITEM(menuitem)!=g_array_index(pd->menuarray,GtkMenuItem*,row_count) ) + row_count++; + + pd->selected=row_count; + + /*g_fprintf(stderr,"\n Selecten menuitem is %d",row_count);*/ + + /* start the timer if the option to do so on selecting is set */ + if(pd->selecting_starts && !pd->timer_on) + start_stop_selected(menuitem,event,data); + +} + static void pause_resume_selected (GtkWidget* menuitem, GdkEventButton* event, gpointer data){ @@ -1147,6 +1150,8 @@ static void load_settings(plugin_data *pd) xfce_rc_set_group(rc,"others"); pd->nowin_if_alarm= xfce_rc_read_bool_entry (rc,"nowin_if_alarm",FALSE); + pd->selecting_starts= xfce_rc_read_bool_entry + (rc,"selecting_starts",FALSE); pd->repeat_alarm= xfce_rc_read_bool_entry (rc,"repeat_alarm",FALSE); pd->repetitions= xfce_rc_read_int_entry @@ -1248,6 +1253,7 @@ static void save_settings(XfcePanelPlugin *plugin, plugin_data *pd){ xfce_rc_set_group(rc,"others"); xfce_rc_write_bool_entry(rc,"nowin_if_alarm",pd->nowin_if_alarm); + xfce_rc_write_bool_entry(rc,"selecting_starts",pd->selecting_starts); xfce_rc_write_bool_entry(rc,"repeat_alarm",pd->repeat_alarm); xfce_rc_write_int_entry(rc,"repetitions",pd->repetitions); xfce_rc_write_int_entry(rc,"repeat_interval",pd->repeat_interval); @@ -1337,9 +1343,9 @@ options_dialog_response (GtkWidget *dlg, int reponse, plugin_data *pd) save_settings(pd->base,pd); } -/********************************/ +/**********************************/ /* nowin_if_alarm toggle callback */ -/********************************/ +/**********************************/ static void toggle_nowin_if_alarm(GtkToggleButton *button, gpointer data){ plugin_data *pd=(plugin_data *)data; @@ -1348,6 +1354,17 @@ static void toggle_nowin_if_alarm(GtkToggleButton *button, gpointer data){ } +/************************************/ +/* selecting_starts toggle callback */ +/************************************/ +static void toggle_selecting_starts(GtkToggleButton *button, gpointer data){ + + plugin_data *pd=(plugin_data *)data; + + pd->selecting_starts = gtk_toggle_button_get_active(button); + +} + /***************************************/ /* toggle_repeat_alarm toggle callback */ /***************************************/ @@ -1519,6 +1536,10 @@ static void plugin_create_options (XfcePanelPlugin *plugin,plugin_data *pd) { g_signal_connect(G_OBJECT(button),"toggled",G_CALLBACK(toggle_nowin_if_alarm),pd); gtk_box_pack_start(GTK_BOX(vbox),button,FALSE,FALSE,WIDGET_SPACING); + button=gtk_check_button_new_with_label(_("Selecting a timer starts it")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),pd->selecting_starts); + g_signal_connect(G_OBJECT(button),"toggled",G_CALLBACK(toggle_selecting_starts),pd); + gtk_box_pack_start(GTK_BOX(vbox),button,FALSE,FALSE,WIDGET_SPACING); button=gtk_check_button_new_with_label(_("Repeat the alarm command:")); @@ -1602,6 +1623,7 @@ create_plugin_control (XfcePanelPlugin *plugin) pd->timeout_command=NULL; pd->timer=NULL; pd->nowin_if_alarm=FALSE; + pd->selecting_starts=FALSE; pd->repeat_alarm=FALSE; pd->is_paused=FALSE; pd->is_countdown=TRUE; diff --git a/src/xfcetimer.h b/src/xfcetimer.h index 041b992..c30836f 100644 --- a/src/xfcetimer.h +++ b/src/xfcetimer.h @@ -18,9 +18,6 @@ */ -#define UPDATE_INTERVAL 2000 /* Countdown update period in - milliseconds */ - typedef struct { GtkWidget *eventbox, /* Main container widget in ctrl->base */ @@ -36,7 +33,7 @@ typedef struct { XfcePanelPlugin *base; /* The plugin widget */ GtkListStore *list; /* The alarms list */ - gint count, /* Nubmer of alarms */ + gint count, /* Number of alarms */ selected, timeout_period_in_sec, /* Active countdown period */ repetitions, /* Number of alarm repeats */ @@ -46,6 +43,7 @@ typedef struct { guint timeout,repeat_timeout; /* The timeout IDs */ gboolean timer_on, /* TRUE if countdown is in progress */ + selecting_starts, /* selecting a timer also starts it */ nowin_if_alarm, /* Show warning window when alarm command is set */ repeat_alarm, /* Repeat alarm */ -- 1.7.10.4