31
31
#include "common.h"
36
35
#include "item_state.h"
38
36
#include "feedlist.h"
39
38
#include "ui/liferea_shell.h"
40
#include "ui/ui_feedlist.h"
39
#include "ui/ui_common.h"
40
#include "ui/feed_list_view.h"
41
41
#include "ui/ui_tray.h"
42
#include "ui/ui_common.h"
44
43
#include "notification/notification.h"
46
45
static gboolean supports_actions = FALSE;
47
46
static gboolean supports_append = FALSE;
49
static void notif_libnotify_callback_open ( NotifyNotification *n, gchar *action, gpointer user_data ) {
49
notif_libnotify_callback_open (NotifyNotification *n, gchar *action, gpointer user_data)
50
53
g_assert(action != NULL);
51
54
g_assert(strcmp(action, "open") == 0);
53
nodePtr node_p = node_from_id(user_data);
56
ui_feedlist_select(node_p);
56
node_p = node_from_id (user_data);
59
feed_list_view_select (node_p);
58
ui_show_error_box(_("This feed does not exist anymore!"));
61
ui_show_error_box (_("This feed does not exist anymore!"));
60
notify_notification_close(n, NULL);
63
notify_notification_close (n, NULL);
62
65
liferea_shell_present ();
95
102
const gchar *labelURL_p;
97
104
gint item_count = 0;
99
g_assert(action != NULL);
100
g_assert(strcmp(action, "show_details") == 0);
101
node_p = node_from_id(user_data);
106
g_assert (action != NULL);
107
g_assert (strcmp(action, "show_details") == 0);
108
node_p = node_from_id (user_data);
104
111
itemSetPtr itemSet = node_get_itemset (node_p);
106
labelText_now_p = g_strdup("");
113
labelText_now_p = g_strdup ("");
108
115
/* Gather the feed's headlines */
109
116
list_p = itemSet->ids;
111
item_p = item_load ( GPOINTER_TO_UINT (list_p->data));
118
item_p = item_load (GPOINTER_TO_UINT (list_p->data));
112
119
if (item_p->popupStatus && !item_p->readStatus) {
113
120
item_p->popupStatus = FALSE;
116
labelHeadline_p = g_strdup (item_get_title(item_p));
123
labelHeadline_p = g_strdup (item_get_title (item_p));
117
124
if (labelHeadline_p == NULL ) {
118
labelHeadline_p = g_strdup_printf (_("This news entry has no headline") );
125
labelHeadline_p = g_strdup_printf (_("This news entry has no headline"));
121
labelURL_p = item_get_base_url(item_p);
122
if (labelURL_p != NULL ) {
123
labelText_p = g_strdup_printf ("%s <a href='%s'>%s</a>\n", labelHeadline_p, labelURL_p, _("Visit") );
128
labelURL_p = item_get_base_url (item_p);
130
labelText_p = g_strdup_printf ("%s <a href='%s'>%s</a>\n", labelHeadline_p, labelURL_p, _("Visit"));
125
labelText_p = g_strdup_printf ("%s\n", labelHeadline_p );
132
labelText_p = g_strdup_printf ("%s\n", labelHeadline_p);
128
135
labelText_prev_p = labelText_now_p;
129
labelText_now_p = g_strconcat( labelText_now_p, labelText_p, NULL);
136
labelText_now_p = g_strconcat(labelText_now_p, labelText_p, NULL);
131
138
g_free(labelHeadline_p);
132
139
g_free(labelText_p);
145
152
ui_show_error_box(_("This feed does not exist anymore!"));
148
notify_notification_close ( n,NULL);
155
notify_notification_close (n, NULL);
151
158
// notify_notification_update ( n, node_get_title(node_p), labelText_now_p, NULL);
152
159
// notify_notification_clear_actions(n);
154
n = notify_notification_new (node_get_title(node_p), labelText_now_p, NULL);
156
notify_notification_set_icon_from_pixbuf (n,node_get_icon(node_p));
161
#if HAVE_LIBNOTIFY == 4
162
n = notify_notification_new (node_get_title (node_p), labelText_now_p, NULL);
164
n = notify_notification_new (node_get_title (node_p), labelText_now_p, NULL, NULL);
166
notify_notification_set_icon_from_pixbuf (n, node_get_icon (node_p));
158
167
notify_notification_set_category (n, "feed");
160
notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER );
168
notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER);
162
170
if (supports_actions) {
163
notify_notification_add_action(n, "open", _("Open feed"),
171
notify_notification_add_action (n, "open", _("Open feed"),
164
172
(NotifyActionCallback)notif_libnotify_callback_open,
165
173
node_p->id, NULL);
166
notify_notification_add_action(n, "mark_read", _("Mark all as read"),
174
notify_notification_add_action (n, "mark_read", _("Mark all as read"),
167
175
(NotifyActionCallback)notif_libnotify_callback_mark_read,
168
176
node_p->id, NULL);
171
conf_get_bool_value(SHOW_TRAY_ICON);
179
#if HAVE_LIBNOTIFY == 1
180
notify_notification_attach_to_status_icon (n, ui_tray_get_status_icon ());
172
182
if (!notify_notification_show (n, NULL)) {
173
fprintf(stderr, "PLUGIN:notif_libnotify.c - failed to update notification via libnotify\n");
183
g_warning ("libnotify.c - failed to update notification via libnotify\n");
176
g_free(labelText_now_p);
186
g_free (labelText_now_p);
180
static gboolean notif_libnotify_init(void) {
191
notif_libnotify_init (void)
184
195
/* Check whether the notification daemon supports actions, per Actions
185
196
in http://www.galago-project.org/specs/notification/0.9/x81.html */
186
197
if (notify_init ("liferea")) {
187
198
caps = notify_get_server_caps ();
189
for (c = caps; c != NULL; c = c->next) {
190
if (g_str_equal ((char*)c->data, "actions")) {
191
supports_actions = TRUE;
194
if (g_str_equal ((char*)c->data, "append")) {
195
supports_append = TRUE;
199
g_list_foreach (caps, (GFunc)g_free, NULL);
200
if (g_list_find_custom (caps, "actions", (GCompareFunc) strcmp))
201
supports_actions = TRUE;
202
if (g_list_find_custom (caps, "append", (GCompareFunc) strcmp))
203
supports_append = TRUE;
205
g_list_foreach (caps, (GFunc)g_free, NULL);
210
static void notif_libnotify_deinit(void) {
216
notif_libnotify_deinit (void)
214
static void notif_libnotify_enable(void) { }
216
static void notif_libnotify_disable(void) { }
219
222
notif_libnotify_node_has_new_items (nodePtr node, gboolean enforced)
221
224
itemSetPtr itemSet;
224
227
NotifyNotification *n;
229
229
gchar *labelSummary_p;
230
230
gint item_count = 0;
232
if (!conf_get_bool_value(SHOW_POPUP_WINDOWS) && !enforced)
232
gboolean show_popup_windows;
234
conf_get_bool_value(SHOW_POPUP_WINDOWS, &show_popup_windows);
236
if (!show_popup_windows && !enforced)
235
239
/* Count updated feed */
250
254
labelSummary_p = g_strdup_printf (ngettext ("<b>%s</b> has <b>%d</b> update", "<b>%s</b> has <b>%d</b> updates", item_count),
251
255
node_get_title (node), item_count);
252
n = notify_notification_new ( _("Feed Update"), labelSummary_p, "liferea");
253
g_free(labelSummary_p);
256
#if HAVE_LIBNOTIFY == 4
257
n = notify_notification_new (_("Feed Update"), labelSummary_p, "liferea");
259
n = notify_notification_new (_("Feed Update"), labelSummary_p, "liferea", NULL);
261
g_free (labelSummary_p);
255
if (supports_append) {
256
notify_notification_set_hint_string(n, "append", "allow");
263
if (supports_append) {
264
notify_notification_set_hint_string(n, "append", "allow");
258
266
notify_notification_set_icon_from_pixbuf (n, node_get_icon (node));
260
269
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
261
270
if (supports_actions) {
262
271
notify_notification_add_action (n, "show_details", _("Show details"),
272
281
notify_notification_set_category (n, "feed");
274
if (ui_tray_get_origin (&x, &y) == TRUE) {
275
ui_tray_size_request (&size);
280
notify_notification_set_hint_int32 (n, "x", x);
281
notify_notification_set_hint_int32 (n, "y", y);
282
#if HAVE_LIBNOTIFY == 1
283
notify_notification_attach_to_status_icon (n, ui_tray_get_status_icon ());
284
285
if (!notify_notification_show (n, NULL))
285
g_warning ("PLUGIN:notif_libnotify.c - failed to send notification via libnotify");
286
g_warning ("notif_libnotify.c - failed to send notification via libnotify");
288
static void notif_libnotify_node_removed(nodePtr node) { }
290
/* notification plugin definition */
292
static struct notificationPlugin npi = {
293
NOTIFICATION_PLUGIN_API_VERSION,
294
NOTIFICATION_TYPE_POPUP,
289
struct notificationPlugin libnotify_plugin = {
297
291
notif_libnotify_init,
298
292
notif_libnotify_deinit,
299
notif_libnotify_enable,
300
notif_libnotify_disable,
301
293
notif_libnotify_node_has_new_items,
302
notif_libnotify_node_removed
305
static struct plugin pi = {
307
"libnotify notification",
308
PLUGIN_TYPE_NOTIFICATION,
309
//"Implementation of a notification using libnotify.",
314
DECLARE_NOTIFICATION_PLUGIN(npi);