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
40
indicator_construct (XfcePanelPlugin *plugin);
43
load_module (const gchar * name, GtkWidget * menu);
46
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator);
49
/* register the plugin */
50
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (indicator_construct);
55
indicator_save (XfcePanelPlugin *plugin,
56
IndicatorPlugin *indicator)
61
/* get the config file location */
62
file = xfce_panel_plugin_save_location (plugin, TRUE);
64
if (G_UNLIKELY (file == NULL))
66
DBG ("Failed to open config file");
70
/* open the config file, read/write */
71
rc = xfce_rc_simple_open (file, FALSE);
74
if (G_LIKELY (rc != NULL))
76
/* save the settings */
78
if (indicator->setting1)
79
xfce_rc_write_entry (rc, "setting1", indicator->setting1);
81
xfce_rc_write_int_entry (rc, "setting2", indicator->setting2);
82
xfce_rc_write_bool_entry (rc, "setting3", indicator->setting3);
84
/* close the rc file */
92
indicator_read (IndicatorPlugin *indicator)
98
/* get the plugin config file location */
99
file = xfce_panel_plugin_save_location (indicator->plugin, TRUE);
101
if (G_LIKELY (file != NULL))
103
/* open the config file, readonly */
104
rc = xfce_rc_simple_open (file, TRUE);
109
if (G_LIKELY (rc != NULL))
111
/* read the settings */
112
value = xfce_rc_read_entry (rc, "setting1", DEFAULT_SETTING1);
113
indicator->setting1 = g_strdup (value);
115
indicator->setting2 = xfce_rc_read_int_entry (rc, "setting2", DEFAULT_SETTING2);
116
indicator->setting3 = xfce_rc_read_bool_entry (rc, "setting3", DEFAULT_SETTING3);
121
/* leave the function, everything went well */
126
/* something went wrong, apply default values */
127
DBG ("Applying default settings");
129
indicator->setting1 = g_strdup (DEFAULT_SETTING1);
130
indicator->setting2 = DEFAULT_SETTING2;
131
indicator->setting3 = DEFAULT_SETTING3;
136
static IndicatorPlugin *
137
indicator_new (XfcePanelPlugin *plugin)
139
IndicatorPlugin *indicator;
140
GtkOrientation orientation;
141
gint indicators_loaded = 0;
143
/* allocate memory for the plugin structure */
144
indicator = panel_slice_new0 (IndicatorPlugin);
146
/* pointer to plugin */
147
indicator->plugin = plugin;
149
/* get the current orientation */
150
orientation = xfce_panel_plugin_get_orientation (plugin);
152
/* Init some theme/icon stuff */
153
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
154
INDICATOR_ICONS_DIR);
155
/* g_debug("Icons directory: %s", INDICATOR_ICONS_DIR); */
156
gtk_rc_parse_string (
157
"style \"indicator-applet-style\"\n"
159
" GtkMenuBar::shadow-type = none\n"
160
" GtkMenuBar::internal-padding = 0\n"
161
" GtkWidget::focus-line-width = 0\n"
162
" GtkWidget::focus-padding = 0\n"
164
"style \"indicator-applet-menubar-style\"\n"
166
" GtkMenuBar::shadow-type = none\n"
167
" GtkMenuBar::internal-padding = 0\n"
168
" GtkWidget::focus-line-width = 0\n"
169
" GtkWidget::focus-padding = 0\n"
170
" GtkMenuItem::horizontal-padding = 0\n"
172
"style \"indicator-applet-menuitem-style\"\n"
174
" GtkWidget::focus-line-width = 0\n"
175
" GtkWidget::focus-padding = 0\n"
176
" GtkMenuItem::horizontal-padding = 0\n"
178
"widget \"*.indicator-applet\" style \"indicator-applet-style\""
179
"widget \"*.indicator-applet-menuitem\" style \"indicator-applet-menuitem-style\""
180
"widget \"*.indicator-applet-menubar\" style \"indicator-applet-menubar-style\"");
181
gtk_widget_set_name(GTK_WIDGET (plugin), "indicator-applet-menubar");
182
/* create some panel widgets */
185
indicator->menu = gtk_menu_bar_new();
186
GTK_WIDGET_SET_FLAGS (indicator->menu, GTK_WIDGET_FLAGS(indicator->menu) | GTK_CAN_FOCUS);
187
gtk_widget_set_name(GTK_WIDGET (indicator->menu), "indicator-applet-menubar");
188
g_signal_connect(indicator->menu, "button-press-event", G_CALLBACK(on_menu_press), NULL);
189
//g_signal_connect_after(indicator->menu, "expose-event", G_CALLBACK(menu_on_expose), menu);
190
gtk_container_set_border_width(GTK_CONTAINER(indicator->menu), 0);
194
if (g_file_test(INDICATOR_DIR, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
195
GDir * dir = g_dir_open(INDICATOR_DIR, 0, NULL);
198
while ((name = g_dir_read_name(dir)) != NULL) {
199
if (load_module(name, indicator->menu))
205
if (indicators_loaded == 0) {
206
/* A label to allow for click through */
207
indicator->item = xfce_create_panel_button();
208
gtk_button_set_label(indicator->item, _("No Indicators"));
209
gtk_widget_show(indicator->item);
210
gtk_container_add (GTK_CONTAINER (plugin), indicator->item);
212
gtk_widget_show(indicator->menu);
213
gtk_container_add (GTK_CONTAINER (plugin), indicator->menu);
221
indicator_free (XfcePanelPlugin *plugin,
222
IndicatorPlugin *indicator)
226
/* check if the dialog is still open. if so, destroy it */
227
dialog = g_object_get_data (G_OBJECT (plugin), "dialog");
228
if (G_UNLIKELY (dialog != NULL))
229
gtk_widget_destroy (dialog);
231
/* free the plugin structure */
232
panel_slice_free (IndicatorPlugin, indicator);
238
indicator_orientation_changed (XfcePanelPlugin *plugin,
239
GtkOrientation orientation,
240
IndicatorPlugin *indicator)
242
/* change the orienation of the box */
243
//xfce_hvbox_set_orientation (XFCE_HVBOX (indicator->hvbox), orientation);
249
indicator_size_changed (XfcePanelPlugin *plugin,
251
IndicatorPlugin *indicator)
253
GtkOrientation orientation;
255
/* get the orientation of the plugin */
256
orientation = xfce_panel_plugin_get_orientation (plugin);
258
/* set the widget size */
259
if (orientation == GTK_ORIENTATION_HORIZONTAL)
260
gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
262
gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
264
/* we handled the orientation */
270
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
272
TRACE ("enters on_button_press");
273
if (indicator != NULL && event->button == 1) /* left click only */
275
/* gtk_menu_popup (GTK_MENU(indicator->menu), NULL, NULL, NULL, NULL, 0,
279
TRACE ("leaves on_button_press");
285
indicator_construct (XfcePanelPlugin *plugin)
287
IndicatorPlugin *indicator;
289
/* setup transation domain */
290
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
292
/* create the plugin */
293
indicator = indicator_new (plugin);
295
/* show the panel's right-click menu on this menu */
296
xfce_panel_plugin_add_action_widget (plugin, indicator->menu);
297
xfce_panel_plugin_add_action_widget (plugin, indicator->item);
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);