2 Copyright (C) 2010-2011 jeanfi@gmail.com
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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
24 #include <libnotify/notify.h>
27 #include "ui_notify.h"
29 void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
31 struct timeval *t = malloc(sizeof(struct timeval));
33 NotifyNotification *notif;
35 if (gettimeofday(t, NULL) != 0) {
36 fprintf(stderr, _("ERROR: failed gettimeofday\n"));
42 if (!ui->notification_last_time) {
43 /* first notification */
44 ui->notification_last_time = t;
47 if (t->tv_sec - ui->notification_last_time->tv_sec < 60) {
48 /* last notification less than 1mn ago */
52 /* last notification more than 1mn ago */
53 free(ui->notification_last_time);
54 ui->notification_last_time = t;
58 if (notify_is_initted() == FALSE)
59 notify_init("psensor");
61 if (notify_is_initted() == TRUE) {
62 name = strdup(sensor->name);
64 #ifdef NOTIFY_VERSION_MAJOR
66 since libnotify 0.7 notify_notification_new has
69 libnotify < 0.7 does not define
72 notif = notify_notification_new(_("Temperature alert"),
76 notif = notify_notification_new(_("Temperature alert"),
79 GTK_WIDGET(ui->main_window));
83 notify_notification_show(notif, NULL);
85 g_object_unref(notif);