X-Git-Url: http://wpitchoune.net/gitweb/?p=psensor-pkg-debian.git;a=blobdiff_plain;f=src%2Fui_notify.c;h=6361f06648d678160f2bc376ecc025e6e8b50a6a;hp=c92b5fbdfe554d5cae248a672f60fe09748ca6f8;hb=9cb6e128adf4afce6545344b9c2f9619e18ca866;hpb=f055e7507526592d3a74c652f5f053701614c9c0;ds=sidebyside diff --git a/src/ui_notify.c b/src/ui_notify.c index c92b5fb..6361f06 100644 --- a/src/ui_notify.c +++ b/src/ui_notify.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 jeanfi@gmail.com + * Copyright (C) 2010-2014 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -27,6 +27,7 @@ #define NOTIFY_CHECK_VERSION(x, y, z) 0 #endif +#include "cfg.h" #include "ui.h" #include "ui_notify.h" @@ -36,13 +37,15 @@ static struct timeval last_notification_tv; void ui_notify(struct psensor *sensor, struct ui_psensor *ui) { struct timeval t; - char *name; + char *body, *svalue; + const char *summary; NotifyNotification *notif; + unsigned int use_celsius; log_debug("last_notification %d", last_notification_tv.tv_sec); if (gettimeofday(&t, NULL) != 0) { - log_printf(LOG_ERR, _("gettimeofday failed")); + log_err(_("gettimeofday failed.")); return; } @@ -56,27 +59,45 @@ void ui_notify(struct psensor *sensor, struct ui_psensor *ui) notify_init("psensor"); if (notify_is_initted() == TRUE) { - name = strdup(sensor->name); + if (ui->config->temperature_unit == CELSIUS) + use_celsius = 1; + else + use_celsius = 0; + + svalue = psensor_measure_to_str + (psensor_get_current_measure(sensor), + sensor->type, + use_celsius); + + 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 if (is_fan_type(sensor->type)) + summary = _("Fan 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"), name, NULL); + notif = notify_notification_new(summary, body, PSENSOR_ICON); #else - notif = notify_notification_new(_("Temperature alert"), - name, - NULL, + notif = notify_notification_new(summary, + body, + PSENSOR_ICON, GTK_WIDGET(ui->main_window)); #endif - log_debug("notif_notification_new %s", sensor->name); + log_debug("notif_notification_new %s", body); notify_notification_show(notif, NULL); g_object_unref(notif); } else { - log_printf(LOG_ERR, "notify not initted"); + log_err("notify not initialized"); } }