cleanup notification support
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 12 Nov 2011 13:29:41 +0000 (13:29 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 12 Nov 2011 13:29:41 +0000 (13:29 +0000)
update NEWS
added log_debug
regenerate build files

NEWS
po/Makefile.in
src/cfg.h
src/lib/log.c
src/lib/log.h
src/main.c
src/ui.h
src/ui_notify.c

diff --git a/NEWS b/NEWS
index b8b23b1..48528a5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,7 +15,7 @@
 ** psensor: fixed compilation with AMD/ATI GPU monitoring support
    (submitted by Lubos Stanek).
 ** psensor: default log level set to LOG_WARN.
-** few code refactoring and cleanup
+** few code refactoring and cleanup.
 ** psensor: added support of status tray icon for DE not supporting
    Ubuntu Application Indicator.
 
index f901ffc..8b758af 100644 (file)
@@ -21,7 +21,7 @@ srcdir = .
 top_srcdir = ..
 
 
-prefix = /tmp/r
+prefix = /usr/local
 exec_prefix = ${prefix}
 datarootdir = ${prefix}/share
 datadir = ${datarootdir}
index b3b7999..8b09a67 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
 
 #include "color.h"
 
-#define SENSORLIST_POSITION_RIGHT 0
-#define SENSORLIST_POSITION_LEFT 1
-#define SENSORLIST_POSITION_TOP 2
-#define SENSORLIST_POSITION_BOTTOM 3
+enum sensorlist_position {
+       SENSORLIST_POSITION_RIGHT,
+       SENSORLIST_POSITION_LEFT,
+       SENSORLIST_POSITION_TOP,
+       SENSORLIST_POSITION_BOTTOM
+};
 
 struct config {
        struct color *graph_bgcolor;
@@ -38,7 +40,7 @@ struct config {
        /*
           Position of the sensors list table
         */
-       int sensorlist_position;
+       enum sensorlist_position sensorlist_position;
 
        int window_decoration_enabled;
        int window_keep_below_enabled;
index 2de7037..6018b54 100644 (file)
@@ -101,3 +101,12 @@ void log_printf(int lvl, const char *fmt, ...)
                fprintf(stdf, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
        }
 }
+
+void log_debug(const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       log_printf(LOG_ERR, fmt, ap);
+       va_end(ap);
+}
index cf4fcd3..38efb3e 100644 (file)
@@ -30,6 +30,7 @@ enum log_level {
 void log_open(const char *path);
 
 void log_printf(int lvl, const char *fmt, ...);
+void log_debug(const char *fmt, ...);
 
 void log_close();
 
index 0b2d484..19a01e6 100644 (file)
@@ -134,7 +134,7 @@ static void log_measures(struct psensor **sensors)
 {
        if (log_level == LOG_DEBUG)
                while (*sensors) {
-                       log_printf(LOG_DEBUG, "%s %.2f",
+                       log_printf(LOG_DEBUG, "Measure: %s %.2f",
                                   (*sensors)->name,
                                   psensor_get_current_value(*sensors));
 
@@ -424,10 +424,6 @@ int main(int argc, char **argv)
 
        gtk_init(NULL, NULL);
 
-#ifdef HAVE_LIBNOTIFY
-       ui.notification_last_time = NULL;
-#endif
-
        ui.sensors_mutex = g_mutex_new();
 
        config_init();
index b32dc80..efefbce 100644 (file)
--- a/src/ui.h
+++ b/src/ui.h
@@ -58,11 +58,6 @@ struct ui_psensor {
        int graph_update_interval;
 
        GMutex *sensors_mutex;
-
-#ifdef HAVE_LIBNOTIFY
-       /* Time of the last notification */
-       struct timeval *notification_last_time;
-#endif
 };
 
 /*
index faca4dc..f6419db 100644 (file)
 #include "ui.h"
 #include "ui_notify.h"
 
+/* Time of the last notification. */
+static struct timeval last_notification_tv;
+
 void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
 {
-       struct timeval *t = malloc(sizeof(struct timeval));
+       struct timeval t;
        char *name;
        NotifyNotification *notif;
 
-       if (gettimeofday(t, NULL) != 0) {
-               fprintf(stderr, _("ERROR: failed gettimeofday\n"));
-               free(t);
+       log_debug("ui_notify() last_notification %d",
+                 last_notification_tv.tv_sec);
 
+       if (gettimeofday(&t, NULL) != 0) {
+               log_printf(LOG_ERR,  _("gettimeofday failed"));
                return;
        }
 
-       if (!ui->notification_last_time) {
-               /* first notification */
-               ui->notification_last_time = t;
-       } else {
-
-               if (t->tv_sec - ui->notification_last_time->tv_sec < 60) {
-                       /* last notification less than 1mn ago */
-                       free(t);
-                       return;
-               } else {
-                       /* last notification more than 1mn ago */
-                       free(ui->notification_last_time);
-                       ui->notification_last_time = t;
-               }
-       }
+       if (!last_notification_tv.tv_sec
+           || t.tv_sec - last_notification_tv.tv_sec >= 60)
+               last_notification_tv = t;
+       else
+               return ;
 
        if (notify_is_initted() == FALSE)
                notify_init("psensor");
@@ -70,18 +64,20 @@ void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
                 * only 3 parameters.
                 */
 #if NOTIFY_CHECK_VERSION(0, 7, 0)
-               notif = notify_notification_new(_("Temperature alert"),
-                                               name,
-                                               NULL);
+               notif = notify_notification_new
+                       (_("Temperature alert"), name, NULL);
 #else
                notif = notify_notification_new(_("Temperature alert"),
                                                name,
                                                NULL,
                                                GTK_WIDGET(ui->main_window));
 #endif
+               log_debug("ui_notify() notif_notification_new %s", name);
 
                notify_notification_show(notif, NULL);
 
                g_object_unref(notif);
+       } else {
+               log_printf(LOG_ERR, "notify not initted");
        }
 }