25
25
#include "ui_indicator.h"
27
#ifdef HAVE_LIBINDICATE
27
#ifdef HAVE_MESSAGING_MENU
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"
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
48
40
static struct indicator_priv {
49
IndicateServer *server;
41
MessagingMenuApp *server;
51
42
GPtrArray *indicators;
52
43
} *indicator_priv = NULL;
55
46
The desktop file to initialize the indicator menu with. Resolves to
56
47
a string like "/usr/share/applications/liferea.desktop".
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";
61
52
remove_all_indicators () {
66
57
Called when the main "Liferea" entry in the indicator menu is clicked.
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)
71
62
liferea_shell_present ();
72
63
remove_all_indicators ();
76
Called when the indicator container applet is shown.
79
on_indicator_interest_added (IndicateServer *server, guint interest, gpointer user_data)
81
if (interest != INDICATE_INTEREST_SERVER_SIGNAL)
84
indicator_priv->visible = TRUE;
89
Called when the indicator container applet is hidden.
92
on_indicator_interest_removed (IndicateServer *server, guint interest, gpointer user_data)
94
if (interest != INDICATE_INTEREST_SERVER_SIGNAL)
97
indicator_priv->visible = FALSE;
102
67
Called when the indicator menu entry for a specific feed
103
68
is clicked, meaning Liferea should switch to that feed.
106
on_indicator_clicked (IndicateIndicator *indicator, guint timestamp, gpointer user_data)
71
on_indicator_clicked (MessagingMenuApp *indicator, gchar *source_id, gpointer user_data)
108
73
feed_list_view_select ((nodePtr) user_data);
109
74
liferea_shell_present ();
116
81
if (indicator_priv->server == NULL || indicator == NULL)
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));
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);
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);
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);
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);
99
g_signal_connect (G_OBJECT (indicator_priv->server), "activate-source", G_CALLBACK (on_indicator_server_clicked), NULL);
142
101
ui_indicator_update ();
176
136
if (node->unreadCount == 0)
179
indicator = indicate_indicator_new_with_server (indicator_priv->server);
180
g_signal_connect (indicator, "user-display", G_CALLBACK (on_indicator_clicked), node);
183
pixbuf = gdk_pixbuf_new_from_file (node->iconFile, NULL);
185
/* display favicon */
186
indicate_gtk_indicator_set_property_icon (indicator, "icon", pixbuf);
187
gdk_pixbuf_unref (pixbuf);
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);
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);
142
messaging_menu_app_append_source_with_count(
143
indicator_priv->server,
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);
153
g_object_unref(icon);
154
g_object_unref(file);
199
159
ui_indicator_update ()
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 ())))
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);
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));
218
172
ui_indicator_is_visible ()
220
return indicator_priv && indicator_priv->visible;