~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/notification/libnotify.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#ifdef HAVE_CONFIG_H
22
 
#  include <config.h>
 
22
#include <config.h>
23
23
#endif
24
24
 
25
25
#include <string.h>
31
31
#include "common.h"
32
32
#include "conf.h"
33
33
#include "debug.h"
34
 
#include "node.h"
35
34
#include "item.h"
36
35
#include "item_state.h"
37
 
#include "plugin.h"
38
36
#include "feedlist.h"
 
37
#include "node.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"
43
42
 
44
43
#include "notification/notification.h"
45
44
 
46
45
static gboolean supports_actions = FALSE;
47
46
static gboolean supports_append  = FALSE;
48
47
 
49
 
static void notif_libnotify_callback_open ( NotifyNotification *n, gchar *action, gpointer user_data ) {
 
48
static void
 
49
notif_libnotify_callback_open (NotifyNotification *n, gchar *action, gpointer user_data)
 
50
{
 
51
        nodePtr node_p;
 
52
 
50
53
        g_assert(action != NULL);
51
54
        g_assert(strcmp(action, "open") == 0);
52
55
 
53
 
        nodePtr node_p = node_from_id(user_data);
54
 
        
55
 
        if(node_p)
56
 
                ui_feedlist_select(node_p);
 
56
        node_p = node_from_id (user_data);
 
57
 
 
58
        if (node_p)
 
59
                feed_list_view_select (node_p);
57
60
        else
58
 
                ui_show_error_box(_("This feed does not exist anymore!"));
 
61
                ui_show_error_box (_("This feed does not exist anymore!"));
59
62
 
60
 
        notify_notification_close(n, NULL);
 
63
        notify_notification_close (n, NULL);
61
64
 
62
65
        liferea_shell_present ();
63
66
}
65
68
static void
66
69
notif_libnotify_callback_mark_read (NotifyNotification *n, gchar *action, gpointer user_data)
67
70
{
 
71
        nodePtr node;
 
72
 
68
73
        g_assert (action != NULL);
69
74
        g_assert (strcmp (action, "mark_read") == 0);
70
75
 
71
 
        nodePtr node = node_from_id (user_data);
72
 
        
 
76
        node = node_from_id (user_data);
 
77
 
73
78
        if (node) {
74
79
                feedlist_mark_all_read (node);
75
80
                feedlist_reset_new_item_count ();
77
82
        } else {
78
83
                ui_show_error_box (_("This feed does not exist anymore!"));
79
84
        }
80
 
        
 
85
 
81
86
        notify_notification_close (n, NULL);
82
87
}
83
88
 
84
 
static void notif_libnotify_callback_show_details ( NotifyNotification *n, gchar *action, gpointer user_data ) {
 
89
static void
 
90
notif_libnotify_callback_show_details (NotifyNotification *n, gchar *action, gpointer user_data)
 
91
{
85
92
        nodePtr node_p;
86
93
 
87
94
        GList *list_p;
95
102
        const gchar *labelURL_p;
96
103
 
97
104
        gint item_count = 0;
98
 
        
99
 
        g_assert(action != NULL);
100
 
        g_assert(strcmp(action, "show_details") == 0);
101
 
        node_p = node_from_id(user_data);
102
 
        
103
 
        if(node_p) {
 
105
 
 
106
        g_assert (action != NULL);
 
107
        g_assert (strcmp(action, "show_details") == 0);
 
108
        node_p = node_from_id (user_data);
 
109
 
 
110
        if (node_p) {
104
111
                itemSetPtr itemSet = node_get_itemset (node_p);
105
112
 
106
 
                labelText_now_p = g_strdup("");
 
113
                labelText_now_p = g_strdup ("");
107
114
 
108
115
                /* Gather the feed's headlines */
109
116
                list_p = itemSet->ids;
110
117
                while (list_p) {
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;
114
121
                                item_count += 1;
115
122
 
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"));
119
126
                                }
120
127
 
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);
 
129
                                if (labelURL_p) {
 
130
                                        labelText_p = g_strdup_printf ("%s <a href='%s'>%s</a>\n", labelHeadline_p, labelURL_p, _("Visit"));
124
131
                                } else {
125
 
                                        labelText_p = g_strdup_printf ("%s\n", labelHeadline_p );
 
132
                                        labelText_p = g_strdup_printf ("%s\n", labelHeadline_p);
126
133
                                }
127
134
 
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);
130
137
 
131
138
                                g_free(labelHeadline_p);
132
139
                                g_free(labelText_p);
145
152
                ui_show_error_box(_("This feed does not exist anymore!"));
146
153
        }
147
154
 
148
 
        notify_notification_close ( n,NULL);
149
 
        
150
 
        if(node_p) {
 
155
        notify_notification_close (n, NULL);
 
156
 
 
157
        if (node_p) {
151
158
//              notify_notification_update ( n, node_get_title(node_p), labelText_now_p, NULL);
152
159
//              notify_notification_clear_actions(n);
153
160
 
154
 
                n = notify_notification_new (node_get_title(node_p), labelText_now_p, NULL);
155
 
 
156
 
                notify_notification_set_icon_from_pixbuf (n,node_get_icon(node_p));
157
 
 
 
161
#if HAVE_LIBNOTIFY == 4
 
162
                n = notify_notification_new (node_get_title (node_p), labelText_now_p, NULL);
 
163
#else
 
164
                n = notify_notification_new (node_get_title (node_p), labelText_now_p, NULL, NULL);
 
165
#endif
 
166
                notify_notification_set_icon_from_pixbuf (n, node_get_icon (node_p));
158
167
                notify_notification_set_category (n, "feed");
159
 
 
160
 
                notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER );
 
168
                notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER);
161
169
 
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);
169
177
                }
170
178
 
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 ());
 
181
#endif
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");
174
184
                }
175
185
 
176
 
                g_free(labelText_now_p);
 
186
                g_free (labelText_now_p);
177
187
        }
178
188
}
179
189
 
180
 
static gboolean notif_libnotify_init(void) {
181
 
 
182
 
        GList *caps, *c;
 
190
static gboolean
 
191
notif_libnotify_init (void)
 
192
{
 
193
        GList *caps;
183
194
 
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 ();
188
 
                if (caps != NULL) {
189
 
                        for (c = caps; c != NULL; c = c->next) {
190
 
                                if (g_str_equal ((char*)c->data, "actions")) {
191
 
                                        supports_actions = TRUE;
192
 
                                        continue;
193
 
                                }
194
 
                                if (g_str_equal ((char*)c->data, "append")) {
195
 
                                        supports_append = TRUE;
196
 
                                        continue;
197
 
                                }
198
 
                        }
199
 
                        g_list_foreach (caps, (GFunc)g_free, NULL);
200
 
                        g_list_free (caps);
201
 
                }
 
199
 
 
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;
 
204
 
 
205
                g_list_foreach (caps, (GFunc)g_free, NULL);
 
206
                g_list_free (caps);
202
207
 
203
208
                return TRUE;
204
209
        } else {
207
212
        }
208
213
}
209
214
 
210
 
static void notif_libnotify_deinit(void) {
 
215
static void
 
216
notif_libnotify_deinit (void)
 
217
{
211
218
        notify_uninit();
212
219
}
213
220
 
214
 
static void notif_libnotify_enable(void) { }
215
 
 
216
 
static void notif_libnotify_disable(void) { }
217
 
 
218
221
static void
219
222
notif_libnotify_node_has_new_items (nodePtr node, gboolean enforced)
220
 
{       
 
223
{
221
224
        itemSetPtr      itemSet;
222
225
        GList           *iter;
223
 
        
 
226
 
224
227
        NotifyNotification *n;
225
228
 
226
 
        GtkRequisition  size;
227
 
        gint            x, y;
228
 
 
229
229
        gchar           *labelSummary_p;
230
230
        gint            item_count = 0;
231
231
 
232
 
        if (!conf_get_bool_value(SHOW_POPUP_WINDOWS) && !enforced)
 
232
        gboolean        show_popup_windows;
 
233
 
 
234
        conf_get_bool_value(SHOW_POPUP_WINDOWS, &show_popup_windows);
 
235
 
 
236
        if (!show_popup_windows && !enforced)
233
237
                return;
234
238
 
235
239
        /* Count updated feed */
249
253
 
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");
 
258
#else
 
259
        n = notify_notification_new (_("Feed Update"), labelSummary_p, "liferea", NULL);
 
260
#endif
 
261
        g_free (labelSummary_p);
254
262
 
255
 
        if (supports_append) {
256
 
                notify_notification_set_hint_string(n, "append", "allow");
257
 
        } else {
 
263
        if (supports_append) {
 
264
                notify_notification_set_hint_string(n, "append", "allow");
 
265
        } else {
258
266
                notify_notification_set_icon_from_pixbuf (n, node_get_icon (node));
259
267
        }
 
268
        
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"),
270
279
                                        node->id, NULL);
271
280
        }
272
281
        notify_notification_set_category (n, "feed");
273
 
 
274
 
        if (ui_tray_get_origin (&x, &y) == TRUE) {
275
 
                ui_tray_size_request (&size);
276
 
 
277
 
                x += size.width / 2;
278
 
                y += size.height;
279
 
 
280
 
                notify_notification_set_hint_int32 (n, "x", x);
281
 
                notify_notification_set_hint_int32 (n, "y", y);
282
 
        }
283
 
 
 
282
#if HAVE_LIBNOTIFY == 1
 
283
        notify_notification_attach_to_status_icon (n, ui_tray_get_status_icon ());
 
284
#endif
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");
286
287
}
287
 
        
288
 
static void notif_libnotify_node_removed(nodePtr node) { }
289
 
 
290
 
/* notification plugin definition */
291
 
 
292
 
static struct notificationPlugin npi = {
293
 
        NOTIFICATION_PLUGIN_API_VERSION,
294
 
        NOTIFICATION_TYPE_POPUP,
295
 
        10,
 
288
 
 
289
struct notificationPlugin libnotify_plugin = {
296
290
        "libnotify",
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
303
 
};
304
 
 
305
 
static struct plugin pi = {
306
 
        PLUGIN_API_VERSION,
307
 
        "libnotify notification",
308
 
        PLUGIN_TYPE_NOTIFICATION,
309
 
        //"Implementation of a notification using libnotify.",
310
 
        &npi
311
 
};
312
 
 
313
 
DECLARE_PLUGIN(pi);
314
 
DECLARE_NOTIFICATION_PLUGIN(npi);
 
294
};