summaryrefslogtreecommitdiff
path: root/timerapplet
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2018-08-24 15:28:38 -0400
committerVictor Kareh <[email protected]>2018-08-24 15:28:38 -0400
commitebabac90eea0ad01a4ae8889ea56e74be806755d (patch)
tree08e0002db610863b0b4d85a3d4c563a57a0dd566 /timerapplet
parentf1b205b3afe4ad7801a265bafbd4ff69b34fd167 (diff)
downloadmate-applets-ebabac90eea0ad01a4ae8889ea56e74be806755d.tar.bz2
mate-applets-ebabac90eea0ad01a4ae8889ea56e74be806755d.tar.xz
timerapplet: Allow reseting timer when inactive
Also add click interaction with the panel applet.
Diffstat (limited to 'timerapplet')
-rw-r--r--timerapplet/timerapplet.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/timerapplet/timerapplet.c b/timerapplet/timerapplet.c
index 36da525e..24c7af12 100644
--- a/timerapplet/timerapplet.c
+++ b/timerapplet/timerapplet.c
@@ -72,12 +72,14 @@ static void timer_start_callback (GtkAction *action, TimerApplet *applet);
static void timer_pause_callback (GtkAction *action, TimerApplet *applet);
static void timer_stop_callback (GtkAction *action, TimerApplet *applet);
static void timer_about_callback (GtkAction *action, TimerApplet *applet);
+static void timer_reset_callback (GtkAction *action, TimerApplet *applet);
static void timer_preferences_callback (GtkAction *action, TimerApplet *applet);
static const GtkActionEntry applet_menu_actions [] = {
{ "Start", "media-playback-start", N_("_Start timer"), NULL, NULL, G_CALLBACK (timer_start_callback) },
{ "Pause", "media-playback-pause", N_("P_ause timer"), NULL, NULL, G_CALLBACK (timer_pause_callback) },
{ "Stop", "media-playback-stop", N_("S_top timer"), NULL, NULL, G_CALLBACK (timer_stop_callback) },
+ { "Reset", "edit-undo", N_("R_eset"), NULL, NULL, G_CALLBACK (timer_reset_callback) },
{ "Preferences", "document-properties", N_("_Preferences"), NULL, NULL, G_CALLBACK (timer_preferences_callback) },
{ "About", "help-about", N_("_About"), NULL, NULL, G_CALLBACK (timer_about_callback) }
};
@@ -85,8 +87,9 @@ static const GtkActionEntry applet_menu_actions [] = {
static char *ui = "<menuitem name='Item 1' action='Start' />"
"<menuitem name='Item 2' action='Pause' />"
"<menuitem name='Item 3' action='Stop' />"
- "<menuitem name='Item 4' action='Preferences' />"
- "<menuitem name='Item 5' action='About' />";
+ "<menuitem name='Item 4' action='Reset' />"
+ "<menuitem name='Item 5' action='Preferences' />"
+ "<menuitem name='Item 6' action='About' />";
static void
timer_applet_destroy (MatePanelApplet *applet_widget, TimerApplet *applet)
@@ -121,6 +124,9 @@ timer_callback (TimerApplet *applet)
if (!applet->active)
{
+ applet->pause = FALSE;
+ applet->elapsed = 0;
+
gtk_label_set_text (applet->label, name);
gtk_widget_set_tooltip_text (GTK_WIDGET (applet->label), "");
gtk_widget_hide (GTK_WIDGET (applet->pause_image));
@@ -137,7 +143,10 @@ timer_callback (TimerApplet *applet)
if (remaining <= 0)
{
applet->active = FALSE;
- gtk_label_set_text (applet->label, _("Finished"));
+ applet->timeout_id = 0;
+
+ label = g_strdup_printf ("Finished %s", name);
+ gtk_label_set_text (applet->label, label);
gtk_widget_set_tooltip_text (GTK_WIDGET (applet->label), name);
gtk_widget_hide (GTK_WIDGET (applet->pause_image));
@@ -197,6 +206,7 @@ timer_callback (TimerApplet *applet)
gtk_action_set_sensitive (gtk_action_group_get_action (applet->action_group, "Start"), !applet->active || applet->pause);
gtk_action_set_sensitive (gtk_action_group_get_action (applet->action_group, "Pause"), applet->active && !applet->pause);
gtk_action_set_sensitive (gtk_action_group_get_action (applet->action_group, "Stop"), applet->active);
+ gtk_action_set_sensitive (gtk_action_group_get_action (applet->action_group, "Reset"), !applet->active && !applet->pause && applet->elapsed);
gtk_action_set_sensitive (gtk_action_group_get_action (applet->action_group, "Preferences"), !applet->active && !applet->pause);
g_free (name);
@@ -242,6 +252,16 @@ timer_stop_callback (GtkAction *action, TimerApplet *applet)
timer_callback (applet);
}
+/* reset action */
+static void
+timer_reset_callback (GtkAction *action, TimerApplet *applet)
+{
+ applet->active = FALSE;
+ applet->pause = FALSE;
+ applet->elapsed = 0;
+ timer_callback (applet);
+}
+
/* Show the about dialog */
static void
timer_about_callback (GtkAction *action, TimerApplet *applet)
@@ -359,6 +379,18 @@ timer_preferences_callback (GtkAction *action, TimerApplet *applet)
gtk_widget_show_all (GTK_WIDGET (dialog));
}
+static gboolean
+timer_applet_click (TimerApplet *applet)
+{
+ if (!applet->active && !applet->pause && applet->elapsed)
+ timer_reset_callback (NULL, applet);
+ else if (applet->active && !applet->pause)
+ timer_pause_callback (NULL, applet);
+ else if (!applet->active || applet->pause)
+ timer_start_callback (NULL, applet);
+ return FALSE;
+}
+
static void
timer_settings_changed (GSettings *settings, gchar *key, TimerApplet *applet)
{
@@ -412,6 +444,9 @@ timer_applet_fill (MatePanelApplet* applet_widget)
G_CALLBACK (timer_applet_destroy),
applet);
+ g_signal_connect_swapped(GTK_WIDGET (applet->applet), "button-release-event",
+ G_CALLBACK (timer_applet_click), applet);
+
/* set up context menu */
applet->action_group = gtk_action_group_new ("Timer Applet Actions");
gtk_action_group_set_translation_domain (applet->action_group, GETTEXT_PACKAGE);