Only put up a notification on a new message.
authorRoy Marples <roy@marples.name>
Wed, 6 Aug 2014 02:32:35 +0000 (02:32 +0000)
committerRoy Marples <roy@marples.name>
Wed, 6 Aug 2014 02:32:35 +0000 (02:32 +0000)
src/dhcpcd-gtk/main.c
src/libdhcpcd/dhcpcd.c
src/libdhcpcd/dhcpcd.h

index 56e2959ae31cab260ddd2291dc758728dd986c10..79749978fef6c2089cf7c3d9ae1559d60f8f7c51 100644 (file)
@@ -141,7 +141,7 @@ update_online(DHCPCD_CONNECTION *con, bool showif)
                        if (i->up)
                                ison = true;
                }
-               msg = dhcpcd_if_message(i);
+               msg = dhcpcd_if_message(i, NULL);
                if (msg) {
                        if (showif)
                                g_message("%s", msg);
@@ -407,6 +407,7 @@ dhcpcd_if_cb(DHCPCD_IF *i, _unused void *data)
        DHCPCD_CONNECTION *con;
        char *msg;
        const char *icon;
+       bool new_msg;
 
        /* Update the tooltip with connection information */
        con = dhcpcd_if_connection(i);
@@ -418,16 +419,18 @@ dhcpcd_if_cb(DHCPCD_IF *i, _unused void *data)
            g_strcmp0(i->reason, "STOPPED") == 0)
                return;
 
-       msg = dhcpcd_if_message(i);
+       msg = dhcpcd_if_message(i, &new_msg);
        if (msg) {
                g_message("%s", msg);
-               if (i->up)
-                       icon = "network-transmit-receive";
-               //else
-               //      icon = "network-transmit";
-               if (!i->up)
-                       icon = "network-offline";
-               notify(_("Network event"), msg, icon);
+               if (new_msg) {
+                       if (i->up)
+                               icon = "network-transmit-receive";
+                       //else
+                       //      icon = "network-transmit";
+                       if (!i->up)
+                               icon = "network-offline";
+                       notify(_("Network event"), msg, icon);
+               }
                g_free(msg);
        }
 }
index 601d58b6e546bfd7f25fe63ef6fcddd9ac1189c8..7c79e8c0fd323681ecbdb9ccedd2f0c1a229b75c 100644 (file)
@@ -394,6 +394,7 @@ dhcpcd_new_if(DHCPCD_CONNECTION *con, char *data, size_t len)
                else
                        con->interfaces = i;
                i->next = NULL;
+               i->last_message = NULL;
        } else
                free(i->data);
 
@@ -448,6 +449,7 @@ dhcpcd_new_if(DHCPCD_CONNECTION *con, char *data, size_t len)
         while (con->interfaces) {
                 e = con->interfaces->next;
                free(con->interfaces->data);
+               free(con->interfaces->last_message);
                 free(con->interfaces);
                 con->interfaces = e;
         }
@@ -706,7 +708,7 @@ dhcpcd_if_connection(DHCPCD_IF *i)
 }
 
 char *
-dhcpcd_if_message(const DHCPCD_IF *i)
+dhcpcd_if_message(DHCPCD_IF *i, bool *new_msg)
 {
        const char *ip, *iplen, *pfx;
        char *msg, *p;
@@ -784,6 +786,16 @@ dhcpcd_if_message(const DHCPCD_IF *i)
                p += snprintf(p, len - (size_t)(p - msg), " %s/%s", ip, iplen);
        else if (ip)
                p += snprintf(p, len - (size_t)(p - msg), " %s", ip);
+
+       if (new_msg) {
+               if (i->last_message == NULL || strcmp(i->last_message, msg))
+                       *new_msg = true;
+               else
+                       *new_msg = false;
+       }
+       free(i->last_message);
+       i->last_message = strdup(msg);
+
        return msg;
 }
 
@@ -798,6 +810,7 @@ dhcpcd_free(DHCPCD_CONNECTION *con)
        while (con->interfaces) {
                nif = con->interfaces->next;
                free(con->interfaces->data);
+               free(con->interfaces->last_message);
                free(con->interfaces);
                con->interfaces = nif;
        }
index 639918a5b9b89c1403ea0e1b6343a07c08d8ed9c..b8c13669f3828a2c898a8009046035ffed8ac222 100644 (file)
 
 #include <stdbool.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifndef DHCPCD_SOCKET
 #define DHCPCD_SOCKET          "/var/run/dhcpcd.sock"
 #endif
@@ -80,6 +84,8 @@ typedef struct dhcpcd_if {
        char *data;
        size_t data_len;
 
+       char *last_message;
+
        struct dhcpcd_connection *con;
 } DHCPCD_IF;
 #else
@@ -180,7 +186,7 @@ DHCPCD_CONNECTION * dhcpcd_if_connection(DHCPCD_IF *);
 const char *dhcpcd_get_value(const DHCPCD_IF *, const char *);
 const char *dhcpcd_get_prefix_value(const DHCPCD_IF *, const char *,
     const char *);
-char * dhcpcd_if_message(const DHCPCD_IF *i);
+char * dhcpcd_if_message(DHCPCD_IF *i, bool *new_msg);
 
 ssize_t dhcpcd_command(DHCPCD_CONNECTION *, const char *, char **);
 ssize_t dhcpcd_command_arg(DHCPCD_CONNECTION *, const char *, const char *,
@@ -231,4 +237,8 @@ bool dhcpcd_config_set_static(DHCPCD_OPTION **, const char *, const char *);
 bool dhcpcd_config_write(DHCPCD_CONNECTION *,
     const char *, const char *, const DHCPCD_OPTION *);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif