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

« back to all changes in this revision

Viewing changes to src/notification/notification.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:
24
24
#include "common.h"
25
25
#include "debug.h"
26
26
#include "node.h"
27
 
#include "plugin.h"
28
27
#include "notification/notification.h"
29
28
 
30
 
static GSList *notificationPlugins = NULL;
31
 
 
32
 
typedef notificationPluginPtr (*infoFunc)();
33
 
 
34
 
gboolean
35
 
notification_plugin_register (pluginPtr plugin, GModule *handle)
36
 
{
37
 
        notificationPluginPtr   notificationPlugin = NULL;
38
 
        infoFunc                notification_plugin_get_info;
39
 
 
40
 
        if (g_module_symbol (handle, "notification_plugin_get_info", (void*)&notification_plugin_get_info)) {
41
 
                /* load notification provider plugin info */
42
 
                if (NULL == (notificationPlugin = (*notification_plugin_get_info) ()))
43
 
                        return FALSE;
44
 
        }
45
 
 
46
 
        /* check notification provider plugin version */
47
 
        if (NOTIFICATION_PLUGIN_API_VERSION != notificationPlugin->api_version) {
48
 
                debug3 (DEBUG_PLUGINS, "notification API version mismatch: \"%s\" has version %d should be %d", plugin->name, notificationPlugin->api_version, NOTIFICATION_PLUGIN_API_VERSION);
49
 
                return FALSE;
50
 
        } 
51
 
 
52
 
        /* check if all mandatory symbols are provided */
53
 
        if (!(notificationPlugin->plugin_init &&
54
 
              notificationPlugin->plugin_deinit)) {
55
 
                debug1 (DEBUG_PLUGINS, "mandatory symbols missing: \"%s\"", plugin->name);
56
 
                return FALSE;
57
 
        }
58
 
 
59
 
        /* add plugin to notification plugin instance list */
60
 
        notificationPlugins = g_slist_append (notificationPlugins, plugin);
61
 
 
62
 
        /* assign the symbols so the caller will accept the plugin */
63
 
        plugin->symbols = notificationPlugin;
64
 
        
65
 
        return TRUE;
66
 
}
67
 
 
68
 
static void
69
 
notification_plugin_init_for_type (notificationType type)
70
 
{
71
 
        GSList                  *iter;
72
 
        notificationPluginPtr   selectedPlugin = NULL;
73
 
        
74
 
        /* Check for already loaded plugin of same type and with higher priority */
75
 
        iter = notificationPlugins;
76
 
        while (iter) {
77
 
                notificationPluginPtr tmp = ((pluginPtr)iter->data)->symbols;
78
 
 
79
 
                if (tmp->type == type) {
80
 
                        if (!selectedPlugin || (tmp->priority > selectedPlugin->priority))
81
 
                                selectedPlugin = tmp;
82
 
                }
83
 
                iter = g_slist_next (iter);
84
 
        }
85
 
        
86
 
        /* Allow the plugin to initialize */
87
 
        if (selectedPlugin) {
88
 
                if ((*selectedPlugin->plugin_init) ()) {
89
 
                        debug2 (DEBUG_PLUGINS, "using \"%s\" for notification type %d", selectedPlugin->name, selectedPlugin->type);
90
 
                } else {
91
 
                        debug1 (DEBUG_PLUGINS, "notification plugin \"%s\" did not load succesfully", selectedPlugin->name);
92
 
                }
93
 
        }
94
 
}
95
 
 
96
 
void
97
 
notification_plugin_init (void)
98
 
{
99
 
        notification_plugin_init_for_type (NOTIFICATION_TYPE_POPUP);
100
 
        notification_plugin_init_for_type (NOTIFICATION_TYPE_TRAY);
101
 
}
102
 
 
103
 
void notification_enable(gboolean enabled) {
104
 
        notificationPluginPtr   plugin;
105
 
        GSList                  *iter;
106
 
 
107
 
        iter = notificationPlugins;
108
 
        while(iter) {
109
 
                plugin = ((pluginPtr)iter->data)->symbols;
110
 
                (*plugin->notification_enable)();
111
 
                iter = g_slist_next(iter);
112
 
        }
113
 
}
114
 
 
115
 
void notification_node_has_new_items(nodePtr node, gboolean enforced) { 
116
 
        notificationPluginPtr   plugin;
117
 
        GSList                  *iter;
118
 
        
119
 
        iter = notificationPlugins;
120
 
        while(iter) {
121
 
                plugin = ((pluginPtr)iter->data)->symbols;
122
 
                (*plugin->node_has_new_items)(node, enforced);
123
 
                iter = g_slist_next(iter);
124
 
        }
125
 
}
126
 
 
127
 
void notification_node_removed(nodePtr node) { 
128
 
        notificationPluginPtr   plugin;
129
 
        GSList                  *iter;
130
 
        
131
 
        iter = notificationPlugins;
132
 
        while(iter) {
133
 
                plugin = ((pluginPtr)iter->data)->symbols;
134
 
                (*plugin->node_removed)(node);
135
 
                iter = g_slist_next(iter);
136
 
        }
 
29
notificationPluginPtr notificationPlugin = NULL;
 
30
 
 
31
void
 
32
notification_plugin_register (notificationPluginPtr plugin)
 
33
{
 
34
        g_return_if_fail (!notificationPlugin);
 
35
 
 
36
        /* add plugin to notification plugin */
 
37
        notificationPlugin = plugin;
 
38
 
 
39
        g_return_if_fail ((notificationPlugin->plugin_init)());
 
40
}
 
41
 
 
42
void
 
43
notification_node_has_new_items(nodePtr node, gboolean enforced)
 
44
{
 
45
        (notificationPlugin->node_has_new_items)(node, enforced);
137
46
}