added value of the sensor in the notification body
authorJean-Philippe Orsini <jeanfi@gmail.com>
Thu, 26 Apr 2012 11:00:18 +0000 (11:00 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Thu, 26 Apr 2012 11:00:18 +0000 (11:00 +0000)
NEWS
src/lib/psensor.c
src/lib/psensor.h
src/ui_notify.c

diff --git a/NEWS b/NEWS
index d224bb5..5ada26d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -35,7 +35,8 @@
 ** psensor: added the degree sign before the temperature symbols.
 ** psensor: alarm limit edition using the temperature unit set in the
    global pref.
-** psensor: improved notification (added psensor icon).
+** psensor: improved notification (added psensor icon and value of the
+   sensor).
 
 * v0.6.2.17
 
index b01c81b..f69c6d2 100644 (file)
@@ -236,6 +236,14 @@ psensor_value_to_str(unsigned int type, double value, int use_celcius)
        return str;
 }
 
+char *
+psensor_measure_to_str(const struct measure *m,
+                      unsigned int type,
+                      unsigned int use_celcius)
+{
+       return psensor_value_to_str(type, m->value, use_celcius);
+}
+
 void psensor_set_current_value(struct psensor *sensor, double value)
 {
        struct timeval tv;
index 30c9925..8f110ec 100644 (file)
@@ -160,6 +160,10 @@ char *psensor_value_to_str(unsigned int type,
                           double value,
                           int use_celcius);
 
+char *psensor_measure_to_str(const struct measure *m,
+                            unsigned int type,
+                            unsigned int use_celcius);
+
 struct psensor **get_all_sensors(int use_libatasmart, int values_max_length);
 
 struct psensor **psensor_list_add(struct psensor **sensors,
index 0f48226..73a6cc5 100644 (file)
@@ -27,6 +27,7 @@
 #define NOTIFY_CHECK_VERSION(x, y, z) 0
 #endif
 
+#include "cfg.h"
 #include "ui.h"
 #include "ui_notify.h"
 
@@ -36,8 +37,10 @@ static struct timeval last_notification_tv;
 void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
 {
        struct timeval t;
-       char *body;
+       char *body, *svalue;
+       const char *summary;
        NotifyNotification *notif;
+       unsigned int use_celcius;
 
        log_debug("last_notification %d", last_notification_tv.tv_sec);
 
@@ -56,17 +59,33 @@ void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
                notify_init("psensor");
 
        if (notify_is_initted() == TRUE) {
-               body = strdup(sensor->name);
+               if (ui->config->temperature_unit == CELCIUS)
+                       use_celcius = 1;
+               else
+                       use_celcius = 0;
+
+               svalue = psensor_measure_to_str
+                       (psensor_get_current_measure(sensor),
+                        sensor->type,
+                        use_celcius);
+
+               body = malloc(strlen(sensor->name) + 3 + strlen(svalue) + 1);
+               sprintf(body, "%s : %s", sensor->name, svalue);
+               free(svalue);
+
+               if (is_temp_type(sensor->type))
+                       summary = _("Temperature alert");
+               else
+                       summary = _("N/A");
 
                /*
                 * Since libnotify 0.7 notify_notification_new has
                 * only 3 parameters.
                 */
 #if NOTIFY_CHECK_VERSION(0, 7, 0)
-               notif = notify_notification_new
-                       (_("Temperature alert"), body, PSENSOR_ICON);
+               notif = notify_notification_new(summary, body, PSENSOR_ICON);
 #else
-               notif = notify_notification_new(_("Temperature alert"),
+               notif = notify_notification_new(summary,
                                                body,
                                                PSENSOR_ICON,
                                                GTK_WIDGET(ui->main_window));