2
* @file notif_libnotify.c notifications via libnotify
4
* Copyright (c) 2006, Norman Jonas <liferea.sf.net@devport.codepilot.net>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
#include <libnotify/notify.h>
36
#include "item_state.h"
39
#include "ui/liferea_shell.h"
40
#include "ui/ui_feedlist.h"
41
#include "ui/ui_tray.h"
42
#include "ui/ui_common.h"
44
#include "notification/notification.h"
46
static gboolean supports_actions = FALSE;
48
static void notif_libnotify_callback_open ( NotifyNotification *n, gchar *action, gpointer user_data ) {
49
g_assert(action != NULL);
50
g_assert(strcmp(action, "open") == 0);
52
nodePtr node_p = node_from_id(user_data);
55
ui_feedlist_select(node_p);
57
ui_show_error_box(_("This feed does not exist anymore!"));
59
notify_notification_close(n, NULL);
61
liferea_shell_present ();
65
notif_libnotify_callback_mark_read (NotifyNotification *n, gchar *action, gpointer user_data)
67
g_assert (action != NULL);
68
g_assert (strcmp (action, "mark_read") == 0);
70
nodePtr node = node_from_id (user_data);
73
feedlist_mark_all_read (node);
74
feedlist_reset_new_item_count ();
75
item_state_set_all_popup (node->id);
77
ui_show_error_box (_("This feed does not exist anymore!"));
80
notify_notification_close (n, NULL);
83
static void notif_libnotify_callback_show_details ( NotifyNotification *n, gchar *action, gpointer user_data ) {
90
gchar *labelText_now_p = NULL;
91
gchar *labelText_prev_p;
93
gchar *labelHeadline_p;
94
const gchar *labelURL_p;
98
g_assert(action != NULL);
99
g_assert(strcmp(action, "show_details") == 0);
100
node_p = node_from_id(user_data);
103
itemSetPtr itemSet = node_get_itemset (node_p);
105
labelText_now_p = g_strdup("");
107
/* Gather the feed's headlines */
108
list_p = itemSet->ids;
110
item_p = item_load ( GPOINTER_TO_UINT (list_p->data));
111
if (item_p->popupStatus && !item_p->readStatus) {
112
item_p->popupStatus = FALSE;
115
labelHeadline_p = g_strdup (item_get_title(item_p));
116
if (labelHeadline_p == NULL ) {
117
labelHeadline_p = g_strdup_printf (_("This news entry has no headline") );
120
labelURL_p = item_get_base_url(item_p);
121
if (labelURL_p != NULL ) {
122
labelText_p = g_strdup_printf ("%s <a href='%s'>%s</a>\n", labelHeadline_p, labelURL_p, _("Visit") );
124
labelText_p = g_strdup_printf ("%s\n", labelHeadline_p );
127
labelText_prev_p = labelText_now_p;
128
labelText_now_p = g_strconcat( labelText_now_p, labelText_p, NULL);
130
g_free(labelHeadline_p);
132
g_free(labelText_prev_p);
134
item_unload (item_p);
135
list_p = g_list_next (list_p);
137
itemset_free (itemSet);
139
if (item_count == 0) {
140
g_free (labelText_now_p);
144
ui_show_error_box(_("This feed does not exist anymore!"));
147
notify_notification_close ( n,NULL);
150
// notify_notification_update ( n, node_get_title(node_p), labelText_now_p, NULL);
151
// notify_notification_clear_actions(n);
153
n = notify_notification_new (node_get_title(node_p), labelText_now_p, NULL, NULL);
155
notify_notification_set_icon_from_pixbuf (n,node_get_icon(node_p));
157
notify_notification_set_category (n, "feed");
159
notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER );
161
if (supports_actions) {
162
notify_notification_add_action(n, "open", _("Open feed"),
163
(NotifyActionCallback)notif_libnotify_callback_open,
165
notify_notification_add_action(n, "mark_read", _("Mark all as read"),
166
(NotifyActionCallback)notif_libnotify_callback_mark_read,
170
conf_get_bool_value(SHOW_TRAY_ICON);
171
if (!notify_notification_show (n, NULL)) {
172
fprintf(stderr, "PLUGIN:notif_libnotify.c - failed to update notification via libnotify\n");
175
g_free(labelText_now_p);
179
static gboolean notif_libnotify_init(void) {
183
/* Check whether the notification daemon supports actions, per Actions
184
in http://www.galago-project.org/specs/notification/0.9/x81.html */
185
if (notify_init ("liferea")) {
186
caps = notify_get_server_caps ();
188
for (c = caps; c != NULL; c = c->next) {
189
if (g_str_equal ((char*)c->data, "actions")) {
190
supports_actions = TRUE;
194
g_list_foreach (caps, (GFunc)g_free, NULL);
200
debug0 (DEBUG_GUI, "libnotify.c: notify_init returned FALSE");
205
static void notif_libnotify_deinit(void) {
209
static void notif_libnotify_enable(void) { }
211
static void notif_libnotify_disable(void) { }
214
notif_libnotify_node_has_new_items (nodePtr node, gboolean enforced)
219
NotifyNotification *n;
224
gchar *labelSummary_p;
227
if (!conf_get_bool_value(SHOW_POPUP_WINDOWS) && !enforced)
230
/* Count updated feed */
231
itemSet = node_get_itemset (node);
234
itemPtr item = item_load (GPOINTER_TO_UINT (iter->data));
235
if (item->popupStatus && !item->readStatus)
238
iter = g_list_next (iter);
240
itemset_free (itemSet);
245
labelSummary_p = g_strdup_printf (ngettext ("%s has %d new / updated headline\n", "%s has %d new / updated headlines\n", item_count),
246
node_get_title (node), item_count);
247
n = notify_notification_new ( _("Feed Update"), labelSummary_p, NULL, NULL);
248
g_free(labelSummary_p);
250
notify_notification_set_icon_from_pixbuf (n, node_get_icon (node));
251
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
252
if (supports_actions) {
253
notify_notification_add_action (n, "show_details", _("Show details"),
254
(NotifyActionCallback)notif_libnotify_callback_show_details,
256
notify_notification_add_action (n, "open", _("Open feed"),
257
(NotifyActionCallback)notif_libnotify_callback_open,
259
notify_notification_add_action (n, "mark_read", _("Mark all as read"),
260
(NotifyActionCallback)notif_libnotify_callback_mark_read,
263
notify_notification_set_category (n, "feed");
265
if (ui_tray_get_origin (&x, &y) == TRUE) {
266
ui_tray_size_request (&size);
271
notify_notification_set_hint_int32 (n, "x", x);
272
notify_notification_set_hint_int32 (n, "y", y);
275
if (!notify_notification_show (n, NULL))
276
g_warning ("PLUGIN:notif_libnotify.c - failed to send notification via libnotify");
279
static void notif_libnotify_node_removed(nodePtr node) { }
281
/* notification plugin definition */
283
static struct notificationPlugin npi = {
284
NOTIFICATION_PLUGIN_API_VERSION,
285
NOTIFICATION_TYPE_POPUP,
288
notif_libnotify_init,
289
notif_libnotify_deinit,
290
notif_libnotify_enable,
291
notif_libnotify_disable,
292
notif_libnotify_node_has_new_items,
293
notif_libnotify_node_removed
296
static struct plugin pi = {
298
"libnotify notification",
299
PLUGIN_TYPE_NOTIFICATION,
300
//"Implementation of a notification using libnotify.",
305
DECLARE_NOTIFICATION_PLUGIN(npi);