jjacky avatar jjacky committed fa7c3e4

added Misc in Preferences w/ previous tweaks and new OnDblClick

- added action on dbl-click on systray icon: nothing, check for updates, or system upgrade (default)
- added section "Misc" on Preferences for previous tweaks (SyncDbsInTooltip & SaneSortOrder) as well as new OnDblClick

Comments (0)

Files changed (4)

                         debug ("config: checks_manual: %d", checks);
                     }
                 }
+                else if (strcmp (key, "OnDblClick") == 0)
+                {
+                    if (strcmp (value, "CHECK") == 0)
+                    {
+                        config->on_dbl_click = DO_CHECK;
+                    }
+                    else if (strcmp (value, "SYSUPGRADE") == 0)
+                    {
+                        config->on_dbl_click = DO_SYSUPGRADE;
+                    }
+                    else if (strcmp (value, "NOTHING") == 0)
+                    {
+                        config->on_dbl_click = DO_NOTHING;
+                    }
+                    else
+                    {
+                        set_error ("unknown value for %s: %s", key, value);
+                        success = FALSE;
+                        goto cleanup;
+                    }
+                    debug ("config: on dbl-click: %s", config->on_dbl_click);
+                }
                 else if (strcmp (key, "SaneSortOrder") == 0)
                 {
                     config->sane_sort_order = (*value == '1');
     CHECK_NEWS          = (1 << 4)
 } check_t;
 
+typedef enum {
+    DO_NOTHING = 0,
+    DO_CHECK,
+    DO_SYSUPGRADE
+} on_dbl_click_t;
+
 typedef struct _templates_t {
     char *title;
     char *package;
     char            *cmdline_aur;
     alpm_list_t     *cmdline_post;
     gboolean         sane_sort_order;
+    on_dbl_click_t   on_dbl_click;
     
     templates_t     *tpl_upgrades;
     templates_t     *tpl_watched;
 static void kalu_auto_check (void);
 static void menu_check_cb (GtkMenuItem *item, gpointer data);
 static void menu_quit_cb (GtkMenuItem *item, gpointer data);
-static void menu_updater_cb (GtkMenuItem *item, gpointer data);
 static void icon_popup_cb (GtkStatusIcon *icon, guint button, guint activate_time, gpointer data);
 static void free_config (void);
 
     set_kalpm_busy (FALSE);
 }
 
-static void
+static inline void
 kalu_check (gboolean is_auto)
 {
     /* in case e.g. the menu was shown (sensitive) before an auto-check started */
     watched_manage (is_aur);
 }
 
-static void
-menu_updater_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
+static inline void
+kalu_sysupgrade ()
 {
     /* in case e.g. the menu was shown (sensitive) before an auto-check started */
     if (kalpm_state.is_busy)
         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
         gtk_widget_set_tooltip_text (item, "Perform a system upgrade");
         g_signal_connect (G_OBJECT (item), "activate",
-                          G_CALLBACK (menu_updater_cb), NULL);
+                          G_CALLBACK (kalu_sysupgrade), NULL);
         gtk_widget_show (item);
         gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
     }
     gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, activate_time);
 }
 
+static guint icon_press_timeout = 0;
+
+static gboolean
+icon_press_click (gpointer data _UNUSED_)
+{
+    icon_press_timeout = 0;
+    
+    /* do something... */
+    
+    return FALSE;
+}
+
+static gboolean
+icon_press_cb (GtkStatusIcon *icon _UNUSED_, GdkEventButton *event, gpointer data _UNUSED_)
+{
+    /* left button? */
+    if (event->button == 1)
+    {
+        if (event->type == GDK_2BUTTON_PRESS)
+        {
+            /* we probably had a timeout set for the click, remove it */
+            if (icon_press_timeout > 0)
+            {
+                g_source_remove (icon_press_timeout);
+                icon_press_timeout = 0;
+            }
+            
+            if (config->on_dbl_click == DO_SYSUPGRADE)
+            {
+                kalu_sysupgrade ();
+            }
+            else if (config->on_dbl_click == DO_CHECK)
+            {
+                kalu_check (FALSE);
+            }
+        }
+        else if (event->type == GDK_BUTTON_PRESS)
+        {
+            /* As per GTK manual: on a dbl-click, we get GDK_BUTTON_PRESS twice
+             * and then a GDK_2BUTTON_PRESS. Obviously, we want then to ignore
+             * the two GDK_BUTTON_PRESS.
+             * Also per manual, for a double click to occur, the second button
+             * press must occur within 1/4 of a second of the first; so:
+             * - on GDK_BUTTON_PRESS we set a timeout, in 250ms
+             *  - if it expires/gets triggered, it was a click
+             *  - if another click happens within that time, the timeout will be
+             *    removed (see GDK_2BUTTON_PRESS above) and the clicks ignored
+             * - if a GDK_BUTTON_PRESS occurs while a timeout is set, it's a
+             * second click and ca be ignored, GDK_2BUTTON_PRESS will handle it */
+            if (icon_press_timeout == 0)
+            {
+                icon_press_timeout = g_timeout_add (250, icon_press_click, NULL);
+            }
+        }
+    }
+    
+    return FALSE;
+}
 
 #define addstr(...)     do {                            \
         len = snprintf (s, (size_t) max, __VA_ARGS__);  \
     config->checks_auto   = CHECK_UPGRADES | CHECK_WATCHED | CHECK_AUR
                             | CHECK_WATCHED_AUR | CHECK_NEWS;
     config->action = UPGRADE_ACTION_KALU;
+    config->on_dbl_click = DO_SYSUPGRADE;
     config->sane_sort_order = TRUE;
     
     config->tpl_upgrades = calloc (1, sizeof (templates_t));
                       G_CALLBACK (icon_query_tooltip_cb), NULL);
     g_signal_connect (G_OBJECT (icon), "popup-menu",
                       G_CALLBACK (icon_popup_cb), NULL);
+    g_signal_connect (G_OBJECT (icon), "button-press-event",
+                      G_CALLBACK (icon_press_cb), NULL);
 
     gtk_status_icon_set_visible (icon, TRUE);
     
 static GtkWidget *watched_aur_title_entry   = NULL;
 static GtkWidget *watched_aur_package_entry = NULL;
 static GtkWidget *watched_aur_sep_entry     = NULL;
+/* Misc */
+static GtkWidget *sane_sort_order           = NULL;
+static GtkWidget *syncdbs_in_tooltip        = NULL;
+static GtkWidget *on_dbl_click              = NULL;
 
 /* we keep a copy of templates like so, so that we can use it when refreshing
  * the different templates. that is, values shown when a template is not set
     new_config.tpl_news         = calloc (1, sizeof (templates_t));
     new_config.aur_ignore       = NULL;
     
-    /* those are "tweaks" not featured in GUI */
-    new_config.sane_sort_order = config->sane_sort_order;
-    add_to_conf ("SaneSortOrder = %d\n", new_config.sane_sort_order);
-    
-    new_config.syncdbs_in_tooltip = config->syncdbs_in_tooltip;
-    add_to_conf ("SyncDbsInTooltip = %d\n", new_config.syncdbs_in_tooltip);
-    
     /* General */
     s = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
     if (NULL == s)
         add_to_conf ("\n");
     }
     
+    /* Misc */
+    new_config.sane_sort_order = gtk_toggle_button_get_active (
+        GTK_TOGGLE_BUTTON (sane_sort_order));
+    add_to_conf ("SaneSortOrder = %d\n", new_config.sane_sort_order);
+    
+    new_config.sane_sort_order = gtk_toggle_button_get_active (
+        GTK_TOGGLE_BUTTON (syncdbs_in_tooltip));
+    add_to_conf ("SyncDbsInTooltip = %d\n", new_config.syncdbs_in_tooltip);
+    
+    new_config.on_dbl_click = gtk_combo_box_get_active (GTK_COMBO_BOX (on_dbl_click));
+    if (new_config.on_dbl_click == DO_SYSUPGRADE)
+    {
+        add_to_conf ("OnDblClick = SYSUPGRADE\n");
+    }
+    else if (new_config.on_dbl_click == DO_CHECK)
+    {
+        add_to_conf ("OnDblClick = CHECK\n");
+    }
+    else /* if (new_config.on_dbl_click == DO_NOTHING) */
+    {
+        add_to_conf ("OnDblClick = NOTHING\n");
+    }
+    
     /* ** TEMPLATES ** */
     
     /* Upgrades */
     
     /*******************************************/
     
+    /* [ Misc ] */
+    top = 0;
+    grid = gtk_grid_new ();
+    lbl_page = gtk_label_new ("Misc");
+    
+    sane_sort_order = gtk_check_button_new_with_label ("Use sane sort indicator");
+    gtk_widget_set_tooltip_text (sane_sort_order, "So when sorted descendingly, the arrow points down...\nThis is used for the packages list in kalu's updater");
+    gtk_widget_set_margin_top (sane_sort_order, 10);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sane_sort_order),
+                                  config->sane_sort_order);
+    gtk_grid_attach (GTK_GRID (grid), sane_sort_order, 0, top, 2, 1);
+    gtk_widget_show (sane_sort_order);
+    
+    ++top;
+    syncdbs_in_tooltip = gtk_check_button_new_with_label ("Show if databases can by synchronized in tooltip");
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (syncdbs_in_tooltip),
+                                  config->syncdbs_in_tooltip);
+    gtk_grid_attach (GTK_GRID (grid), syncdbs_in_tooltip, 0, top, 2, 1);
+    gtk_widget_show (syncdbs_in_tooltip);
+    
+    ++top;
+    label = gtk_label_new ("When double clicking the systray icon :");
+    gtk_grid_attach (GTK_GRID (grid), label, 0, top, 1, 1);
+    gtk_widget_show (label);
+    
+    on_dbl_click = gtk_combo_box_text_new ();
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_dbl_click), "0",
+        "Do nothing");
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_dbl_click), "1",
+        "Check for Upgrades...");
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_dbl_click), "2",
+        "System upgrade...");
+    gtk_grid_attach (GTK_GRID (grid), on_dbl_click, 1, top, 1, 1);
+    gtk_widget_show (on_dbl_click);
+    if (config->on_dbl_click == DO_CHECK)
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_dbl_click), 1);
+    }
+    else if (config->on_dbl_click == DO_SYSUPGRADE)
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_dbl_click), 2);
+    }
+    else /* DO_NOTHING */
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_dbl_click), 0);
+    }
+    
+    /* add page */
+    gtk_widget_show (grid);
+    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), grid, lbl_page);
+    
+    /*******************************************/
+    
     /* buttons */
     hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
     gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.