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

« back to all changes in this revision

Viewing changes to src/ui/ui_indicator.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-03-25 16:55:30 UTC
  • Revision ID: package-import@ubuntu.com-20130325165530-lyrfthmi41q6z0jk
Tags: 1.8.10-0ubuntu2
Port to messaging-menu. (LP: #1040259)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "ui_indicator.h"
26
26
 
27
 
#ifdef HAVE_LIBINDICATE
 
27
#ifdef HAVE_MESSAGING_MENU
28
28
 
29
29
#include <gtk/gtk.h>
30
 
#include <libindicate/server.h>
31
 
#include <libindicate/indicator.h>
32
 
#include <libindicate-gtk/indicator.h>
33
 
#include <libindicate/interests.h>
 
30
#include <messaging-menu.h>
34
31
#include "feedlist.h"
35
32
#include "feed_list_view.h"
36
33
#include "liferea_shell.h"
39
36
 
40
37
/* The maximum number of feeds to display in the indicator menu. */
41
38
#define MAX_INDICATORS      6
42
 
/* Whether Liferea should set the indicator menu to attention
43
 
   status whenever new feed items are downloaded. Since news feeds
44
 
   do not typically require the user's urgent attention, unlike
45
 
   mail and IM messages, this is set to false by default. */
46
 
#define SET_DRAW_ATTENTION  FALSE
47
39
 
48
40
static struct indicator_priv {
49
 
        IndicateServer *server;
50
 
        gboolean visible;
 
41
        MessagingMenuApp *server;
51
42
        GPtrArray *indicators;
52
43
} *indicator_priv = NULL;
53
44
 
55
46
 The desktop file to initialize the indicator menu with. Resolves to
56
47
 a string like "/usr/share/applications/liferea.desktop".
57
48
*/ 
58
 
static const char *DESKTOP_FILE = PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "applications" G_DIR_SEPARATOR_S "liferea.desktop";
 
49
static const char *DESKTOP_FILE = "liferea.desktop";
59
50
 
60
51
static void
61
52
remove_all_indicators () {
66
57
 Called when the main "Liferea" entry in the indicator menu is clicked.
67
58
*/ 
68
59
static void
69
 
on_indicator_server_clicked (IndicateServer *server, gchar *type, gpointer user_data)
 
60
on_indicator_server_clicked (MessagingMenuApp *server, gchar *source_id, gpointer user_data)
70
61
{
71
62
        liferea_shell_present ();
72
63
        remove_all_indicators ();
73
64
}
74
65
 
75
66
/*
76
 
 Called when the indicator container applet is shown.
77
 
*/ 
78
 
static void
79
 
on_indicator_interest_added (IndicateServer *server, guint interest, gpointer user_data)
80
 
{
81
 
        if (interest != INDICATE_INTEREST_SERVER_SIGNAL)
82
 
                return;
83
 
 
84
 
        indicator_priv->visible = TRUE;
85
 
        ui_tray_update ();
86
 
}
87
 
 
88
 
/*
89
 
 Called when the indicator container applet is hidden.
90
 
*/ 
91
 
static void
92
 
on_indicator_interest_removed (IndicateServer *server, guint interest, gpointer user_data)
93
 
{
94
 
        if (interest != INDICATE_INTEREST_SERVER_SIGNAL)
95
 
                return;
96
 
 
97
 
        indicator_priv->visible = FALSE;
98
 
        ui_tray_update ();
99
 
}
100
 
 
101
 
/*
102
67
 Called when the indicator menu entry for a specific feed
103
68
 is clicked, meaning Liferea should switch to that feed.
104
69
*/ 
105
70
static void
106
 
on_indicator_clicked (IndicateIndicator *indicator, guint timestamp, gpointer user_data)
 
71
on_indicator_clicked (MessagingMenuApp *indicator, gchar *source_id, gpointer user_data)
107
72
{
108
73
        feed_list_view_select ((nodePtr) user_data);
109
74
        liferea_shell_present ();
116
81
        if (indicator_priv->server == NULL || indicator == NULL) 
117
82
                return;
118
83
        
119
 
        indicate_server_remove_indicator (indicator_priv->server, INDICATE_INDICATOR(indicator));
120
 
        g_object_unref (G_OBJECT (indicator));
 
84
        messaging_menu_app_remove_source (indicator_priv->server, (char *)(indicator));
121
85
}
122
86
 
123
87
void
127
91
                return;
128
92
        
129
93
        indicator_priv = g_new0 (struct indicator_priv, 1);
130
 
        indicator_priv->visible = FALSE;
131
94
        indicator_priv->indicators = g_ptr_array_new_with_free_func (destroy_indicator);
132
95
        
133
 
        indicator_priv->server = indicate_server_ref_default();
134
 
        indicate_server_set_type (indicator_priv->server, "message.im");
135
 
        indicate_server_set_desktop_file (indicator_priv->server, DESKTOP_FILE);
136
 
        
137
 
        g_signal_connect (G_OBJECT (indicator_priv->server), "server-display", G_CALLBACK (on_indicator_server_clicked), NULL);
138
 
        g_signal_connect (G_OBJECT (indicator_priv->server), "interest-added", G_CALLBACK (on_indicator_interest_added), NULL);
139
 
        g_signal_connect (G_OBJECT (indicator_priv->server), "interest-removed", G_CALLBACK (on_indicator_interest_removed), NULL);
140
 
        
141
 
        indicate_server_show (indicator_priv->server);
 
96
        indicator_priv->server = messaging_menu_app_new (DESKTOP_FILE);
 
97
        messaging_menu_app_register (indicator_priv->server);
 
98
 
 
99
        g_signal_connect (G_OBJECT (indicator_priv->server), "activate-source", G_CALLBACK (on_indicator_server_clicked), NULL);
 
100
        
142
101
        ui_indicator_update ();
143
102
}
144
103
 
159
118
static void
160
119
add_node_indicator (nodePtr node)
161
120
{
162
 
        IndicateIndicator *indicator;
163
 
        GdkPixbuf *pixbuf;
 
121
        GFile *file;
 
122
        GIcon *icon;
164
123
        gchar count[10];
 
124
        gchar *signal;
165
125
        
166
126
        if (indicator_priv->indicators->len >= MAX_INDICATORS)
167
127
                return;
176
136
        if (node->unreadCount == 0)
177
137
                return;
178
138
        
179
 
        indicator = indicate_indicator_new_with_server (indicator_priv->server);
180
 
        g_signal_connect (indicator, "user-display", G_CALLBACK (on_indicator_clicked), node);
181
 
 
182
 
        /* load favicon */
183
 
        pixbuf = gdk_pixbuf_new_from_file (node->iconFile, NULL);
184
 
 
185
 
        /* display favicon */
186
 
        indicate_gtk_indicator_set_property_icon (indicator, "icon", pixbuf);
187
 
        gdk_pixbuf_unref (pixbuf);
188
 
 
189
 
        sprintf (count, "%u", node->unreadCount);
190
 
        indicate_indicator_set_property (indicator, "name", node->title);
191
 
        indicate_indicator_set_property (indicator, "count", count);
192
 
#if SET_DRAW_ATTENTION
193
 
        indicate_indicator_set_property_bool (indicator, "draw-attention", TRUE);
194
 
#endif
195
 
        g_ptr_array_add (indicator_priv->indicators, indicator);
 
139
        file = g_file_new_for_path (node->iconFile);
 
140
        icon = g_file_icon_new (file);
 
141
 
 
142
        messaging_menu_app_append_source_with_count(
 
143
                indicator_priv->server,
 
144
                node->id,
 
145
                icon,
 
146
                node->title,
 
147
                node->unreadCount);
 
148
 
 
149
        signal = g_strdup_printf("activate-source::%s", node->id);
 
150
        g_signal_connect (indicator_priv->server, signal, G_CALLBACK (on_indicator_clicked), node);
 
151
        g_ptr_array_add (indicator_priv->indicators, node->id);
 
152
 
 
153
        g_object_unref(icon);
 
154
        g_object_unref(file);
 
155
        g_free(signal);
196
156
}
197
157
 
198
158
void
199
159
ui_indicator_update ()
200
160
{
201
 
        guint index;
202
 
 
203
161
        /* Do not update indicators if the user is interacting with the main window */
204
162
        if (!indicator_priv || gtk_window_is_active (GTK_WINDOW (liferea_shell_get_window ())))
205
163
                return;
208
166
        remove_all_indicators ();
209
167
        /* ...then walk the tree and add an indicator for each unread feed */
210
168
        feedlist_foreach (add_node_indicator);
211
 
 
212
 
        /* revert order of items */
213
 
        for (index = indicator_priv->indicators->len; index > 0; index--)
214
 
                indicate_indicator_show (g_ptr_array_index (indicator_priv->indicators, index - 1));    
215
169
}
216
170
 
217
171
gboolean
218
172
ui_indicator_is_visible ()
219
173
{
220
 
        return indicator_priv && indicator_priv->visible;
 
174
        return TRUE;
221
175
}
222
176
 
223
177
#else
233
187
void ui_indicator_update () {}
234
188
gboolean ui_indicator_is_visible () { return FALSE; }
235
189
 
236
 
#endif  /* HAVE_LIBINDICATE */
 
190
#endif  /* HAVE_MESSAGING_MENU */