Commits

jjacky committed 01119cc

Preferences: added notification expiration delay (Timeout)

Comments (0)

Files changed (6)

         }
     }
     
-    *cfg = strdup (value);
+    *cfg = strreplace (value, "\\n", "\n");
     debug ("config: %s: %s", option, value);
 }
 
                     
                     debug ("config: interval: %d", config->interval);
                 }
+                else if (strcmp (key, "Timeout") == 0)
+                {
+                    if (strcmp (value, "DEFAULT") == 0)
+                    {
+                        config->timeout = NOTIFY_EXPIRES_DEFAULT;
+                    }
+                    else if (strcmp (value, "NEVER") == 0)
+                    {
+                        config->timeout = NOTIFY_EXPIRES_NEVER;
+                    }
+                    else
+                    {
+                        int timeout = atoi (value);
+                        if (timeout < 4 || timeout > 42)
+                        {
+                            set_error ("Invalid timeout delay: %s", value);
+                            success = FALSE;
+                            goto cleanup;
+                        }
+                        config->timeout = timeout * 1000; /* from seconds to ms */
+                    }
+                    debug ("config: timeout: %d", config->timeout);
+                }
                 else if (strcmp (key, "SkipPeriod") == 0)
                 {
                     int begin_hour, begin_minute, end_hour, end_minute;
-.TH kalu 1 "2012-02-22" 0.0.4.1 "Keeping Arch Linux Up-to-date"
+.TH kalu 1 "2012-02-22" 0.0.5 "Keeping Arch Linux Up-to-date"
 
 .SH NAME
 kalu \- Keeping Arch Linux Up-to-date
 Each field can have none, one or more variables. They are not the same for all
 templates, so they'll be described in each of them below.
 .P
-Note: You can use some markup tags in the body of the notification (i.e. in the
-fields \fBPackage/News item\fR and \fBSeparator\fR but not in \fBTitle\fR), such
-as <b> ... </b> for bold, <i> ... </i> for italic or <u> ... </u> for underline.
+In addition to \\n for a new line, you can use some markup tags, but only in
+the body of the notification (i.e. in the fields \fBPackage/News item\fR and
+\fBSeparator\fR but not in \fBTitle\fR), such as <b> ... </b> for bold,
+<i> ... </i> for italic or <u> ... </u> for underline.
 .P
-Through support is recommended, whether or not those will actually be applied
-on the notifications depends on your notification daemon.
+Note that though support is recommanded, whether or not those will actually be
+applied on the notifications depends on your notification daemon.
 
 .P
 Preferences are presented under the following tabs :
 .RE
 .P
 .RS 4
+\fINotifications expire after (seconds)\fR
+.RS 4
+The delay after which the notification should expire/be automatically closed
+by the daemon. The left-most value will use the default (from the daemon),
+while the right-most value will set notifications to never expires, i.e. they
+will stay opened until either you manually close them, or for notifications
+with an action button until kalu is closed.
+.RE
+.RE
+.P
+.RS 4
 \fICheck for upgrades every (minutes)\fR
 .RS 4
 How often must kalu run its automatic check. Select from the list, or type in
 
 #define _UNUSED_            __attribute__ ((unused)) 
 
-#define KALU_VERSION       "0.0.4.1"
+#define KALU_VERSION       "0.0.5"
 #define KALU_TAG            "Keeping Arch Linux Up-to-date"
 
 #define MAX_PATH            255
 
+#ifndef NOTIFY_EXPIRES_DEFAULT
+#define NOTIFY_EXPIRES_DEFAULT  -1
+#endif
+#ifndef NOTIFY_EXPIRES_NEVER
+#define NOTIFY_EXPIRES_NEVER     0
+#endif
+
 #define KALU_ERROR          g_quark_from_static_string ("kalu error")
 
 #define FREE_PACKAGE_LIST(p)                                                \
     check_t          checks_manual;
     check_t          checks_auto;
     int              interval;
+    int              timeout;
     int              has_skip;
     int              skip_begin_hour;
     int              skip_begin_minute;
     g_object_unref (pixbuf);
     gtk_widget_destroy (w);
     g_object_unref (w);
+    notify_notification_set_timeout (notification, config->timeout);
     if (type & CHECK_UPGRADES)
     {
         if (config->action != UPGRADE_NO_ACTION)
                     g_object_unref (pixbuf);
                     gtk_widget_destroy (w);
                     g_object_unref (w);
+                    notify_notification_set_timeout (notification, config->timeout);
                     if (config->action != UPGRADE_NO_ACTION)
                     {
                         notify_notification_add_action (notification, "do_updates",
     /* (e.g. tpl_sep_watched_verbose defaults to tpl_sep_verbose) */
     config->pacmanconf = strdup ("/etc/pacman.conf");
     config->interval = 3600; /* 1 hour */
+    config->timeout = NOTIFY_EXPIRES_DEFAULT;
     config->checks_manual = CHECK_UPGRADES | CHECK_WATCHED | CHECK_AUR
                             | CHECK_WATCHED_AUR | CHECK_NEWS;
     config->checks_auto   = CHECK_UPGRADES | CHECK_WATCHED | CHECK_AUR
 /* General */
 static GtkWidget *filechooser               = NULL;
 static GtkWidget *combo_interval            = NULL;
+static GtkWidget *timeout_scale             = NULL;
 static GtkWidget *button_skip               = NULL;
 static GtkWidget *spin_begin_hour           = NULL;
 static GtkWidget *spin_begin_minute         = NULL;
     }
 }
 
+static gchar *
+timeout_format_value (GtkScale *scale _UNUSED_, gdouble value, gpointer data _UNUSED_)
+{
+    if (value == 0)
+    {
+        return g_strdup ("Default");
+    }
+    else if (value == 40)
+    {
+        return g_strdup ("Never");
+    }
+    else
+    {
+        return g_strdup_printf ("%d seconds", 3 + (int) value);
+    }
+}
+
 #define refresh_entry_text(entry, tpl, tpl_item)     do {       \
         if (!gtk_widget_get_sensitive (entry))                  \
         {                                                       \
     g_free (s);
     new_config.interval = nb * 60; /* we store seconds, not minutes */
     
+    nb = (gint) gtk_range_get_value (GTK_RANGE (timeout_scale));
+    if (nb == 0)
+    {
+        add_to_conf ("Timeout = DEFAULT\n");
+        nb = NOTIFY_EXPIRES_DEFAULT;
+    }
+    else if (nb == 40)
+    {
+        add_to_conf ("Timeout = NEVER\n");
+        nb = NOTIFY_EXPIRES_NEVER;
+    }
+    else
+    {
+        nb += 3;
+        add_to_conf ("Timeout = %d\n", nb);
+        nb *= 1000; /* we store ms, not seconds */
+    }
+    new_config.timeout = nb;
+    
     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_skip)))
     {
         begin_hour = gtk_spin_button_get_value_as_int (
     gtk_widget_show (filechooser);
     
     ++top;
+    /* Timeout */
+    label = gtk_label_new ("Notifications expire after (seconds) :");
+    gtk_widget_set_tooltip_text (label, "Delay after which the notification should expire/be automatically closed by the daemon.");
+    gtk_grid_attach (GTK_GRID (grid), label, 0, top, 1, 1);
+    gtk_widget_show (label);
+    
+    /* 40 = 42 (MAX) - 4 (MIN) + 2 (DEFAULT + NEVER) */
+    timeout_scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 40, 1);
+    gtk_widget_set_tooltip_text (timeout_scale, "Delay after which the notification should expire/be automatically closed by the daemon.");
+    if (config->timeout == NOTIFY_EXPIRES_DEFAULT)
+    {
+        gtk_range_set_value (GTK_RANGE (timeout_scale), 0);
+    }
+    else if (config->timeout == NOTIFY_EXPIRES_NEVER)
+    {
+        gtk_range_set_value (GTK_RANGE (timeout_scale), 40);
+    }
+    else
+    {
+        gtk_range_set_value (GTK_RANGE (timeout_scale), (config->timeout / 1000) - 3);
+    }
+    gtk_grid_attach (GTK_GRID (grid), timeout_scale, 1, top, 1, 1);
+    gtk_widget_show (timeout_scale);
+    g_signal_connect (G_OBJECT (timeout_scale), "format-value",
+                      G_CALLBACK (timeout_format_value), NULL);
+    
+    ++top;
     /* Interval */
     label = gtk_label_new ("Check for upgrades every (minutes) :");
     gtk_grid_attach (GTK_GRID (grid), label, 0, top, 1, 1);
     g_object_unref (pixbuf);
     gtk_widget_destroy (w);
     g_object_unref (w);
+    notify_notification_set_timeout (notification, config->timeout);
     notify_notification_show (notification, NULL);
     g_object_unref (notification);
 }
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.