1
/* Copyright (c) 2009 Mark Trompell <mark@foresightlinux.org>
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Library General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include <libxfce4util/libxfce4util.h>
27
#include <libxfce4panel/xfce-panel-plugin.h>
28
#include <libxfce4panel/xfce-hvbox.h>
29
#include <libindicator/indicator-object.h>
31
#include "indicator.h"
33
/* default settings */
34
#define DEFAULT_SETTING1 NULL
35
#define DEFAULT_SETTING2 1
36
#define DEFAULT_SETTING3 FALSE
37
#define ICONS_DIR "/usr/share/libindicator/icons/"
42
indicator_construct (XfcePanelPlugin *plugin);
45
load_module (const gchar * name, GtkWidget * menu);
48
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator);
51
/* register the plugin */
52
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (indicator_construct);
57
indicator_save (XfcePanelPlugin *plugin,
58
IndicatorPlugin *indicator)
63
/* get the config file location */
64
file = xfce_panel_plugin_save_location (plugin, TRUE);
66
if (G_UNLIKELY (file == NULL))
68
DBG ("Failed to open config file");
72
/* open the config file, read/write */
73
rc = xfce_rc_simple_open (file, FALSE);
76
if (G_LIKELY (rc != NULL))
78
/* save the settings */
80
if (indicator->setting1)
81
xfce_rc_write_entry (rc, "setting1", indicator->setting1);
83
xfce_rc_write_int_entry (rc, "setting2", indicator->setting2);
84
xfce_rc_write_bool_entry (rc, "setting3", indicator->setting3);
86
/* close the rc file */
94
indicator_read (IndicatorPlugin *indicator)
100
/* get the plugin config file location */
101
file = xfce_panel_plugin_save_location (indicator->plugin, TRUE);
103
if (G_LIKELY (file != NULL))
105
/* open the config file, readonly */
106
rc = xfce_rc_simple_open (file, TRUE);
111
if (G_LIKELY (rc != NULL))
113
/* read the settings */
114
value = xfce_rc_read_entry (rc, "setting1", DEFAULT_SETTING1);
115
indicator->setting1 = g_strdup (value);
117
indicator->setting2 = xfce_rc_read_int_entry (rc, "setting2", DEFAULT_SETTING2);
118
indicator->setting3 = xfce_rc_read_bool_entry (rc, "setting3", DEFAULT_SETTING3);
123
/* leave the function, everything went well */
128
/* something went wrong, apply default values */
129
DBG ("Applying default settings");
131
indicator->setting1 = g_strdup (DEFAULT_SETTING1);
132
indicator->setting2 = DEFAULT_SETTING2;
133
indicator->setting3 = DEFAULT_SETTING3;
138
static IndicatorPlugin *
139
indicator_new (XfcePanelPlugin *plugin)
141
IndicatorPlugin *indicator;
142
GtkOrientation orientation;
143
gint indicators_loaded = 0;
145
/* allocate memory for the plugin structure */
146
indicator = panel_slice_new0 (IndicatorPlugin);
148
/* pointer to plugin */
149
indicator->plugin = plugin;
151
/* get the current orientation */
152
orientation = xfce_panel_plugin_get_orientation (plugin);
154
/* Init some theme/icon stuff */
155
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
157
/* g_debug("Icons directory: %s", ICONS_DIR); */
158
gtk_rc_parse_string (
159
"style \"indicator-applet-style\"\n"
161
" GtkMenuBar::shadow-type = none\n"
162
" GtkMenuBar::internal-padding = 0\n"
163
" GtkWidget::focus-line-width = 0\n"
164
" GtkWidget::focus-padding = 0\n"
166
"style \"indicator-applet-menubar-style\"\n"
168
" GtkMenuBar::shadow-type = none\n"
169
" GtkMenuBar::internal-padding = 0\n"
170
" GtkWidget::focus-line-width = 0\n"
171
" GtkWidget::focus-padding = 0\n"
172
" GtkMenuItem::horizontal-padding = 0\n"
174
"style \"indicator-applet-menuitem-style\"\n"
176
" GtkWidget::focus-line-width = 0\n"
177
" GtkWidget::focus-padding = 0\n"
178
" GtkMenuItem::horizontal-padding = 0\n"
180
"widget \"*.indicator-applet\" style \"indicator-applet-style\""
181
"widget \"*.indicator-applet-menuitem\" style \"indicator-applet-menuitem-style\""
182
"widget \"*.indicator-applet-menubar\" style \"indicator-applet-menubar-style\"");
183
gtk_widget_set_name(GTK_WIDGET (plugin), "indicator-applet-menubar");
184
/* create some panel widgets */
187
indicator->menu = gtk_menu_bar_new();
188
GTK_WIDGET_SET_FLAGS (indicator->menu, GTK_WIDGET_FLAGS(indicator->menu) | GTK_CAN_FOCUS);
189
gtk_widget_set_name(GTK_WIDGET (indicator->menu), "indicator-applet-menubar");
190
g_signal_connect(indicator->menu, "button-press-event", G_CALLBACK(on_menu_press), NULL);
191
//g_signal_connect_after(indicator->menu, "expose-event", G_CALLBACK(menu_on_expose), menu);
192
gtk_container_set_border_width(GTK_CONTAINER(indicator->menu), 0);
196
if (g_file_test(INDICATOR_DIR, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
197
GDir * dir = g_dir_open(INDICATOR_DIR, 0, NULL);
200
while ((name = g_dir_read_name(dir)) != NULL) {
201
if (load_module(name, indicator->menu))
207
if (indicators_loaded == 0) {
208
/* A label to allow for click through */
209
indicator->item = gtk_label_new(_("No Indicators"));
210
gtk_widget_show(indicator->item);
211
gtk_container_add (GTK_CONTAINER (plugin), indicator->item);
213
gtk_widget_show(indicator->menu);
214
gtk_container_add (GTK_CONTAINER (plugin), indicator->menu);
222
indicator_free (XfcePanelPlugin *plugin,
223
IndicatorPlugin *indicator)
227
/* check if the dialog is still open. if so, destroy it */
228
dialog = g_object_get_data (G_OBJECT (plugin), "dialog");
229
if (G_UNLIKELY (dialog != NULL))
230
gtk_widget_destroy (dialog);
232
/* free the plugin structure */
233
panel_slice_free (IndicatorPlugin, indicator);
239
indicator_orientation_changed (XfcePanelPlugin *plugin,
240
GtkOrientation orientation,
241
IndicatorPlugin *indicator)
243
/* change the orienation of the box */
244
//xfce_hvbox_set_orientation (XFCE_HVBOX (indicator->hvbox), orientation);
250
indicator_size_changed (XfcePanelPlugin *plugin,
252
IndicatorPlugin *indicator)
254
GtkOrientation orientation;
256
/* get the orientation of the plugin */
257
orientation = xfce_panel_plugin_get_orientation (plugin);
259
/* set the widget size */
260
if (orientation == GTK_ORIENTATION_HORIZONTAL)
261
gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
263
gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
265
/* we handled the orientation */
271
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
273
TRACE ("enters on_button_press");
274
if (indicator != NULL && event->button == 1) /* left click only */
276
/* gtk_menu_popup (GTK_MENU(indicator->menu), NULL, NULL, NULL, NULL, 0,
280
TRACE ("leaves on_button_press");
286
indicator_construct (XfcePanelPlugin *plugin)
288
IndicatorPlugin *indicator;
290
/* setup transation domain */
291
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
293
/* create the plugin */
294
indicator = indicator_new (plugin);
296
/* show the panel's right-click menu on this menu */
297
xfce_panel_plugin_add_action_widget (plugin, indicator->menu);
299
/* connect plugin signals */
300
g_signal_connect (G_OBJECT (plugin), "free-data",
301
G_CALLBACK (indicator_free), indicator);
303
g_signal_connect (G_OBJECT (plugin), "size-changed",
304
G_CALLBACK (indicator_size_changed), indicator);
306
g_signal_connect (G_OBJECT (plugin), "orientation-changed",
307
G_CALLBACK (indicator_orientation_changed), indicator);
312
load_module (const gchar * name, GtkWidget * menu)
314
g_debug("Looking at Module: %s", name);
315
g_return_val_if_fail(name != NULL, FALSE);
317
if (!g_str_has_suffix(name,G_MODULE_SUFFIX))
320
g_debug("Loading Module: %s", name);
322
gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
323
IndicatorObject * io = indicator_object_new_from_file(fullpath);
326
GList * entries = indicator_object_get_entries(io);
327
GList * entry = NULL;
329
for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
330
IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
332
GtkWidget * menuitem = gtk_menu_item_new();
333
GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
334
if (entrydata->image != NULL) {
335
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->image), FALSE, FALSE, 0);
337
if (entrydata->label != NULL) {
338
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->label), FALSE, FALSE, 0);
340
gtk_container_add(GTK_CONTAINER(menuitem), hbox);
341
gtk_widget_show(hbox);
343
if (entrydata->menu != NULL) {
344
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entrydata->menu));
347
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
348
gtk_widget_show(menuitem);
351
g_list_free(entries);