~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): 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:
1
1
/*
2
2
 * @file ui_indicator.c  libindicate support
3
3
 *
4
 
 * Copyright (C) 2010 Maia Kozheva <sikon@ubuntu.com>
 
4
 * Copyright (C) 2010-2011 Maia Kozheva <sikon@ubuntu.com>
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
27
27
#include <libindicate/indicator.h>
28
28
#include <libindicate-gtk/indicator.h>
29
29
#include <libindicate/interests.h>
 
30
#include "feedlist.h"
 
31
#include "feed_list_view.h"
 
32
#include "liferea_shell.h"
30
33
#include "ui_tray.h"
31
 
#include "feedlist.h"
32
34
#include "vfolder.h"
33
35
 
 
36
/* The maximum number of feeds to display in the indicator menu. */
34
37
#define MAX_INDICATORS      6
 
38
/* Whether Liferea should set the indicator menu to attention
 
39
   status whenever new feed items are downloaded. Since news feeds
 
40
   do not typically require the user's urgent attention, unlike
 
41
   mail and IM messages, this is set to false by default. */
35
42
#define SET_DRAW_ATTENTION  FALSE
36
43
 
37
44
static struct indicator_priv {
40
47
        GPtrArray *indicators;
41
48
} *indicator_priv = NULL;
42
49
 
 
50
/*
 
51
 The desktop file to initialize the indicator menu with. Resolves to
 
52
 a string like "/usr/share/applications/liferea.desktop".
 
53
*/ 
43
54
static const char *DESKTOP_FILE = PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "applications" G_DIR_SEPARATOR_S "liferea.desktop";
44
55
 
45
56
static void
47
58
        g_ptr_array_set_size (indicator_priv->indicators, 0);
48
59
}
49
60
 
 
61
/*
 
62
 Called when the main "Liferea" entry in the indicator menu is clicked.
 
63
*/ 
50
64
static void
51
65
on_indicator_server_clicked (IndicateServer *server, gchar *type, gpointer user_data)
52
66
{
54
68
        remove_all_indicators ();
55
69
}
56
70
 
 
71
/*
 
72
 Called when the indicator container applet is shown.
 
73
*/ 
57
74
static void
58
75
on_indicator_interest_added (IndicateServer *server, guint interest, gpointer user_data)
59
76
{
64
81
        ui_tray_update ();
65
82
}
66
83
 
 
84
/*
 
85
 Called when the indicator container applet is hidden.
 
86
*/ 
67
87
static void
68
88
on_indicator_interest_removed (IndicateServer *server, guint interest, gpointer user_data)
69
89
{
74
94
        ui_tray_update ();
75
95
}
76
96
 
 
97
/*
 
98
 Called when the indicator menu entry for a specific feed
 
99
 is clicked, meaning Liferea should switch to that feed.
 
100
*/ 
77
101
static void
78
102
on_indicator_clicked (IndicateIndicator *indicator, guint timestamp, gpointer user_data)
79
103
{
80
 
        ui_feedlist_select ((nodePtr) user_data);
 
104
        feed_list_view_select ((nodePtr) user_data);
81
105
        liferea_shell_present ();
82
106
        remove_all_indicators ();
83
107
}
95
119
void
96
120
ui_indicator_init ()
97
121
{
98
 
        g_assert (!indicator_priv);
 
122
        if (indicator_priv != NULL)
 
123
                return;
 
124
        
99
125
        indicator_priv = g_new0 (struct indicator_priv, 1);
100
126
        indicator_priv->visible = FALSE;
101
127
        indicator_priv->indicators = g_ptr_array_new_with_free_func (destroy_indicator);
115
141
void
116
142
ui_indicator_destroy ()
117
143
{
 
144
        if (indicator_priv == NULL)
 
145
                return;
 
146
        
118
147
        remove_all_indicators ();
119
148
        g_object_unref (indicator_priv->server);
120
149
        indicator_priv->server = NULL;
134
163
                return;
135
164
 
136
165
        if (IS_VFOLDER(node) || g_slist_length (node->children) > 0) {
137
 
                // Not a feed - walk children and do nothing more
 
166
                /* Not a feed - walk children and do nothing more */
138
167
                node_foreach_child (node, add_node_indicator);
139
168
                return;
140
169
        }
141
 
 
142
 
        if (!node->unreadCount)
 
170
        
 
171
        /* Skip feeds with no unread items */
 
172
        if (node->unreadCount == 0)
143
173
                return;
144
174
        
145
175
        indicator = indicate_indicator_new_with_server (indicator_priv->server);
146
176
        g_signal_connect (indicator, "user-display", G_CALLBACK (on_indicator_clicked), node);
147
177
 
148
 
        // load favicon
 
178
        /* load favicon */
149
179
        pixbuf = gdk_pixbuf_new_from_file (node->iconFile, NULL);
150
180
 
151
 
        // display favicon
152
 
        indicate_gtk_indicator_set_property_icon (indicator, "icon", pixbuf);
 
181
        /* display favicon */
 
182
        indicate_indicator_set_property_icon (indicator, "icon", pixbuf);
153
183
        gdk_pixbuf_unref (pixbuf);
154
184
 
155
185
        sprintf (count, "%u", node->unreadCount);
166
196
{
167
197
        guint index;
168
198
 
 
199
        /* Do not update indicators if the user is interacting with the main window */
169
200
        if (!indicator_priv || gtk_window_is_active (GTK_WINDOW (liferea_shell_get_window ())))
170
201
                return;
171
202
 
172
 
        // Remove all previous indicators from the menu
 
203
        /* Remove all previous indicators from the menu */
173
204
        remove_all_indicators ();
174
 
        // ...then walk the tree and add an indicator for each unread feed
 
205
        /* ...then walk the tree and add an indicator for each unread feed */
175
206
        feedlist_foreach (add_node_indicator);
176
207
 
177
 
        // revert order of items
 
208
        /* revert order of items */
178
209
        for (index = indicator_priv->indicators->len; index > 0; index--)
179
210
                indicate_indicator_show (g_ptr_array_index (indicator_priv->indicators, index - 1));    
180
211
}
187
218
 
188
219
#else
189
220
 
 
221
/*
 
222
 If Liferea is compiled without libindicate support, all indicator
 
223
 support functions do nothing. The application behaves as if there
 
224
 is no indicator applet present.
 
225
*/
 
226
 
190
227
void ui_indicator_init () {}
191
228
void ui_indicator_destroy () {}
192
229
void ui_indicator_update () {}