From de6a2cf11673ad8109b986e7cf24f626ad80df22 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sat, 12 Nov 2011 13:29:41 +0000 Subject: [PATCH] cleanup notification support update NEWS added log_debug regenerate build files --- NEWS | 2 +- po/Makefile.in | 2 +- src/cfg.h | 12 +++++++----- src/lib/log.c | 9 +++++++++ src/lib/log.h | 1 + src/main.c | 6 +----- src/ui.h | 5 ----- src/ui_notify.c | 40 ++++++++++++++++++---------------------- 8 files changed, 38 insertions(+), 39 deletions(-) diff --git a/NEWS b/NEWS index b8b23b1..48528a5 100644 --- 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. diff --git a/po/Makefile.in b/po/Makefile.in index f901ffc..8b758af 100644 --- a/po/Makefile.in +++ b/po/Makefile.in @@ -21,7 +21,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp/r +prefix = /usr/local exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/src/cfg.h b/src/cfg.h index b3b7999..8b09a67 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -22,10 +22,12 @@ #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; diff --git a/src/lib/log.c b/src/lib/log.c index 2de7037..6018b54 100644 --- a/src/lib/log.c +++ b/src/lib/log.c @@ -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); +} diff --git a/src/lib/log.h b/src/lib/log.h index cf4fcd3..38efb3e 100644 --- a/src/lib/log.h +++ b/src/lib/log.h @@ -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(); diff --git a/src/main.c b/src/main.c index 0b2d484..19a01e6 100644 --- a/src/main.c +++ b/src/main.c @@ -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(); diff --git a/src/ui.h b/src/ui.h index b32dc80..efefbce 100644 --- 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 }; /* diff --git a/src/ui_notify.c b/src/ui_notify.c index faca4dc..f6419db 100644 --- a/src/ui_notify.c +++ b/src/ui_notify.c @@ -30,34 +30,28 @@ #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"); } } -- 2.7.4