Commits

jjacky committed b31f3cd

adds option to pause the automatic checks

Comments (0)

Files changed (1)

 
 static void menu_check_cb (GtkMenuItem *item, gpointer data);
 static void menu_quit_cb (GtkMenuItem *item, gpointer data);
+static gboolean set_status_icon (gint active);
 
 extern kalpm_state_t kalpm_state;
+static gboolean is_paused = FALSE;
 
 gboolean
 show_error_cmdline (gchar *arg[])
 }
 
 static void
+menu_pause_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
+{
+    /* in case e.g. the menu was shown (sensitive) before an auto-check started */
+    if (kalpm_state.is_busy)
+    {
+        return;
+    }
+    is_paused = !is_paused;
+    /* this will turn the icon to paused, or kalu's gray icon */
+    set_status_icon (0);
+    if (is_paused)
+    {
+        /* remove auto-check timeout */
+        if (kalpm_state.timeout > 0)
+        {
+            g_source_remove (kalpm_state.timeout);
+            kalpm_state.timeout = 0;
+        }
+    }
+    else
+    {
+        kalu_check (FALSE);
+    }
+}
+
+static void
 menu_quit_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
 {
     /* in case e.g. the menu was shown (sensitive) before an auto-check started */
     gtk_widget_show (item);
     gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
     
+    item = gtk_image_menu_item_new_from_stock ((!is_paused) ? GTK_STOCK_MEDIA_PAUSE
+                                                            : GTK_STOCK_MEDIA_PLAY, NULL);
+    gtk_menu_item_set_label (GTK_MENU_ITEM (item),
+            (!is_paused) ? "Pause automatic checks" : "Resume automatic checks");
+    gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
+    g_signal_connect (G_OBJECT (item), "activate",
+                      G_CALLBACK (menu_pause_cb), (gpointer) FALSE);
+    gtk_widget_set_tooltip_text (item,
+        (!is_paused) ? "Disable automatic checks until unpaused"
+                     : "Resume automatic checks, starting now (unless within skip period)");
+    gtk_widget_show (item);
+    gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
+    
     item = gtk_separator_menu_item_new ();
     gtk_widget_show (item);
     gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
 GtkStatusIcon *icon = NULL;
 
 static gboolean
-set_status_icon (gboolean active)
+set_status_icon (gint active)
 {
+    gboolean from_switch = FALSE;
+    
+    if (active >= 4)
+    {
+        from_switch = TRUE;
+        active -= 4;
+    }
+    
     if (active)
     {
         gtk_status_icon_set_from_stock (icon, "kalu-logo");
     }
+    else if (from_switch || !is_paused)
+    {
+        gtk_status_icon_set_from_stock (icon, "kalu-logo-gray");
+    }
     else
     {
-        gtk_status_icon_set_from_stock (icon, "kalu-logo-gray");
+        gtk_status_icon_set_from_stock (icon, GTK_STOCK_MEDIA_PAUSE);
     }
     /* do NOT get called back */
     return FALSE;
 void
 set_kalpm_nb (check_t type, gint nb)
 {
+    debug ("set_kalpm_nb type=%d nb=%d", type, nb);
+    
     if (type & CHECK_UPGRADES)
     {
         kalpm_state.nb_upgrades = nb;
 {
     static gboolean active = FALSE;
     active = !active;
-    set_status_icon (active);
+    /* add 4 to indicate this is from switch_status_icon (no paused) */
+    set_status_icon (4 + active);
     /* keep timeout alive */
     return TRUE;
 }
         /* set timeout for next auto-check */
         guint seconds;
         
+        /* remove status icon timeout */
+        if (kalpm_state.timeout_icon > 0)
+        {
+            g_source_remove (kalpm_state.timeout_icon);
+            kalpm_state.timeout_icon = 0;
+            /* ensure icon is right */
+            set_kalpm_nb (0, 0);
+        }
+        
+        /* if paused (likely this was a manual check) we're done; else we set
+         * a timeout for the next auto check */
+        if (is_paused)
+        {
+            return;
+        }
+        
         if (config->has_skip)
         {
             GDateTime *now, *begin, *end, *next;
         }
         kalpm_state.timeout = g_timeout_add_seconds (seconds,
             (GSourceFunc) kalu_auto_check, NULL);
-        
-        /* remove status icon timeout */
-        if (kalpm_state.timeout_icon > 0)
-        {
-            g_source_remove (kalpm_state.timeout_icon);
-            kalpm_state.timeout_icon = 0;
-            /* ensure icon is right */
-            set_kalpm_nb (0, 0);
-        }
     }
 }