2 * Copyright (C) 2010-2011 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <libnotify/notify.h>
25 /* Macro defined since libnotify 0.5.2 */
26 #ifndef NOTIFY_CHECK_VERSION
27 #define NOTIFY_CHECK_VERSION(x, y, z) 0
31 #include "ui_notify.h"
33 /* Time of the last notification. */
34 static struct timeval last_notification_tv;
36 void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
40 NotifyNotification *notif;
42 log_debug("last_notification %d", last_notification_tv.tv_sec);
44 if (gettimeofday(&t, NULL) != 0) {
45 log_printf(LOG_ERR, _("gettimeofday failed"));
49 if (!last_notification_tv.tv_sec
50 || t.tv_sec - last_notification_tv.tv_sec >= 60)
51 last_notification_tv = t;
55 if (notify_is_initted() == FALSE)
56 notify_init("psensor");
58 if (notify_is_initted() == TRUE) {
59 name = strdup(sensor->name);
62 * Since libnotify 0.7 notify_notification_new has
65 #if NOTIFY_CHECK_VERSION(0, 7, 0)
66 notif = notify_notification_new
67 (_("Temperature alert"), name, NULL);
69 notif = notify_notification_new(_("Temperature alert"),
72 GTK_WIDGET(ui->main_window));
74 log_debug("notif_notification_new %s", sensor->name);
76 notify_notification_show(notif, NULL);
78 g_object_unref(notif);
80 log_printf(LOG_ERR, "notify not initted");