2
A small wrapper utility to load indicators and put them as menu items
3
into the gnome-panel using it's applet interface.
5
Copyright 2009 Canonical Ltd.
8
Ted Gould <ted@canonical.com>
10
This program is free software: you can redistribute it and/or modify it
11
under the terms of the GNU General Public License version 3, as published
12
by the Free Software Foundation.
14
This program is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranties of
16
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17
PURPOSE. See the GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License along
20
with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include <panel-applet.h>
26
#include "libindicator/indicator-object.h"
28
static gboolean applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data);
31
static void cw_panel_background_changed (PanelApplet *applet,
32
PanelAppletBackgroundType type,
41
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_FastUserSwitchApplet_Factory",
43
"indicator-applet-session", "0",
44
applet_fill_cb, NULL);
50
load_module (const gchar * name, GtkWidget * menu)
52
g_debug("Looking at Module: %s", name);
53
g_return_val_if_fail(name != NULL, FALSE);
55
if (!g_str_has_suffix(name, G_MODULE_SUFFIX)) {
59
g_debug("Loading Module: %s", name);
61
gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
62
IndicatorObject * io = indicator_object_new_from_file(fullpath);
65
GList * entries = indicator_object_get_entries(io);
68
for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
69
IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
71
GtkWidget * menuitem = gtk_menu_item_new();
72
GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
73
if (entrydata->image != NULL) {
74
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->image), FALSE, FALSE, 0);
76
if (entrydata->label != NULL) {
77
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->label), FALSE, FALSE, 0);
79
gtk_container_add(GTK_CONTAINER(menuitem), hbox);
80
gtk_widget_show(hbox);
82
if (entrydata->menu != NULL) {
83
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entrydata->menu));
86
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
87
gtk_widget_show(menuitem);
96
menubar_press (GtkWidget * widget,
97
GdkEventButton *event,
100
if (event->button != 1) {
101
g_signal_stop_emission_by_name(widget, "button-press-event");
108
menubar_on_expose (GtkWidget * widget,
109
GdkEventExpose *event,
112
if (GTK_WIDGET_HAS_FOCUS(menubar))
113
gtk_paint_focus(widget->style, widget->window, GTK_WIDGET_STATE(menubar),
114
NULL, widget, "menubar-applet", 0, 0, -1, -1);
120
about_cb (BonoboUIComponent *ui_container,
124
static const gchar *authors[] = {
125
"Ted Gould <ted@canonical.com>",
129
static gchar *license[] = {
130
N_("This program is free software: you can redistribute it and/or modify it "
131
"under the terms of the GNU General Public License version 3, as published "
132
"by the Free Software Foundation."),
133
N_("This program is distributed in the hope that it will be useful, but "
134
"WITHOUT ANY WARRANTY; without even the implied warranties of "
135
"MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR "
136
"PURPOSE. See the GNU General Public License for more details."),
137
N_("You should have received a copy of the GNU General Public License along "
138
"with this program. If not, see <http://www.gnu.org/licenses/>."),
143
license_i18n = g_strconcat (_(license[0]), "\n\n", _(license[1]), "\n\n", _(license[2]), NULL);
145
gtk_show_about_dialog(NULL,
147
"copyright", "Copyright \xc2\xa9 2009 Canonical, Ltd.",
148
"comments", _("A place to adjust your status, change users or exit your session."),
150
"license", license_i18n,
151
"wrap-license", TRUE,
152
"translator-credits", _("translator-credits"),
153
"logo-icon-name", "indicator-applet",
154
"icon-name", "indicator-applet",
155
"website", "http://launchpad.net/indicator-applet",
156
"website-label", _("Indicator Applet Website"),
160
g_free (license_i18n);
171
applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data)
173
static const BonoboUIVerb menu_verbs[] = {
174
BONOBO_UI_VERB ("IndicatorAppletAbout", about_cb),
177
static const gchar * menu_xml =
178
"<popup name=\"button3\">"
179
"<menuitem name=\"About Item\" verb=\"IndicatorAppletAbout\" _label=\"" N_("_About") "\" pixtype=\"stock\" pixname=\"gtk-about\"/>"
184
gint indicators_loaded = 0;
185
static gboolean first_time = FALSE;
187
/* check if we are running stracciatella session */
188
if (g_strcmp0(g_getenv("GDMSESSION"), "gnome-stracciatella") == 0) {
189
g_debug("Running stracciatella GNOME session, disabling myself");
196
g_set_application_name(_("Indicator Applet Session"));
199
/* Set panel options */
200
gtk_container_set_border_width(GTK_CONTAINER (applet), 0);
201
panel_applet_set_flags(applet, PANEL_APPLET_EXPAND_MINOR);
202
panel_applet_setup_menu(applet, menu_xml, menu_verbs, NULL);
203
atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (applet)),
204
"indicator-applet-session");
206
/* Init some theme/icon stuff */
207
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
208
INDICATOR_ICONS_DIR);
209
/* g_debug("Icons directory: %s", INDICATOR_ICONS_DIR); */
210
gtk_rc_parse_string (
211
"style \"indicator-applet-style\"\n"
213
" GtkMenuBar::shadow-type = none\n"
214
" GtkMenuBar::internal-padding = 0\n"
215
" GtkWidget::focus-line-width = 0\n"
216
" GtkWidget::focus-padding = 0\n"
218
"style \"indicator-applet-menubar-style\"\n"
220
" GtkMenuBar::shadow-type = none\n"
221
" GtkMenuBar::internal-padding = 0\n"
222
" GtkWidget::focus-line-width = 0\n"
223
" GtkWidget::focus-padding = 0\n"
224
" GtkMenuItem::horizontal-padding = 0\n"
226
"style \"indicator-applet-menuitem-style\"\n"
228
" GtkWidget::focus-line-width = 0\n"
229
" GtkWidget::focus-padding = 0\n"
230
" GtkMenuItem::horizontal-padding = 0\n"
232
"widget \"*.fast-user-switch-applet\" style \"indicator-applet-style\""
233
"widget \"*.fast-user-switch-menuitem\" style \"indicator-applet-menuitem-style\""
234
"widget \"*.fast-user-switch-menubar\" style \"indicator-applet-menubar-style\"");
235
//gtk_widget_set_name(GTK_WIDGET (applet), "indicator-applet-menubar");
236
gtk_widget_set_name(GTK_WIDGET (applet), "fast-user-switch-applet");
239
menubar = gtk_menu_bar_new();
240
GTK_WIDGET_SET_FLAGS (menubar, GTK_WIDGET_FLAGS(menubar) | GTK_CAN_FOCUS);
241
gtk_widget_set_name(GTK_WIDGET (menubar), "fast-user-switch-menubar");
242
g_signal_connect(menubar, "button-press-event", G_CALLBACK(menubar_press), NULL);
243
g_signal_connect_after(menubar, "expose-event", G_CALLBACK(menubar_on_expose), menubar);
244
gtk_container_set_border_width(GTK_CONTAINER(menubar), 0);
247
if (g_file_test(INDICATOR_DIR, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
248
GDir * dir = g_dir_open(INDICATOR_DIR, 0, NULL);
251
while ((name = g_dir_read_name(dir)) != NULL) {
252
if (g_strcmp0(name, "libsession.so")) {
255
if (load_module(name, menubar)) {
262
if (indicators_loaded == 0) {
263
/* A label to allow for click through */
264
GtkWidget * item = gtk_label_new(_("No Indicators"));
265
gtk_container_add(GTK_CONTAINER(applet), item);
266
gtk_widget_show(item);
268
gtk_container_add(GTK_CONTAINER(applet), menubar);
269
panel_applet_set_background_widget(applet, menubar);
270
gtk_widget_show(menubar);
273
/* Background of applet */
274
g_signal_connect(applet, "change-background",
275
G_CALLBACK(cw_panel_background_changed), menubar);
277
gtk_widget_show(GTK_WIDGET(applet));
283
cw_panel_background_changed (PanelApplet *applet,
284
PanelAppletBackgroundType type,
289
GtkRcStyle *rc_style;
293
gtk_widget_set_style(GTK_WIDGET (applet), NULL);
294
gtk_widget_set_style(menubar, NULL);
295
rc_style = gtk_rc_style_new ();
296
gtk_widget_modify_style(GTK_WIDGET (applet), rc_style);
297
gtk_widget_modify_style(menubar, rc_style);
298
gtk_rc_style_unref(rc_style);
302
case PANEL_NO_BACKGROUND:
304
case PANEL_COLOR_BACKGROUND:
305
gtk_widget_modify_bg(GTK_WIDGET (applet), GTK_STATE_NORMAL, colour);
306
gtk_widget_modify_bg(menubar, GTK_STATE_NORMAL, colour);
309
case PANEL_PIXMAP_BACKGROUND:
310
style = gtk_style_copy(GTK_WIDGET (applet)->style);
311
if (style->bg_pixmap[GTK_STATE_NORMAL])
312
g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]);
313
style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref (pixmap);
314
gtk_widget_set_style(GTK_WIDGET (applet), style);
315
gtk_widget_set_style(GTK_WIDGET (menubar), style);
316
g_object_unref(style);