~ubuntu-branches/ubuntu/oneiric/xfce4-indicator-plugin/oneiric-proposed

« back to all changes in this revision

Viewing changes to .pc/xubuntu_exclude-modules.patch/panel-plugin/indicator.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2011-03-08 21:16:44 UTC
  • Revision ID: james.westby@ubuntu.com-20110308211644-7t9dc0sd4cusdvxh
Tags: 0.2.0-0ubuntu4
* debian/patches:
  - xubuntu_exclude-modules.patch: add a blacklist option. Some modules are
    unneeded/redundant/badly work on Xubuntu (e.g. appmenu), so give the
    possibility to ignore them.
  - series: add this patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Copyright (c) 2009 Mark Trompell <mark@foresightlinux.org>
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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.
 
16
 */
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
#include <config.h>
 
20
#endif
 
21
#ifdef HAVE_STRING_H
 
22
#include <string.h>
 
23
#endif
 
24
 
 
25
#include <gtk/gtk.h>
 
26
#include <libxfce4util/libxfce4util.h>
 
27
#include <libxfce4panel/xfce-panel-plugin.h>
 
28
#include <libxfce4panel/xfce-hvbox.h>
 
29
#include <libindicator/indicator-object.h>
 
30
 
 
31
#include "indicator.h"
 
32
 
 
33
/* default settings */
 
34
#define DEFAULT_SETTING1 NULL
 
35
#define DEFAULT_SETTING2 1
 
36
#define DEFAULT_SETTING3 FALSE
 
37
 
 
38
/* prototypes */
 
39
static void
 
40
indicator_construct (XfcePanelPlugin *plugin);
 
41
 
 
42
static gboolean
 
43
load_module (const gchar * name, GtkWidget * menu);
 
44
 
 
45
static gboolean
 
46
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator);
 
47
 
 
48
 
 
49
/* register the plugin */
 
50
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (indicator_construct);
 
51
 
 
52
 
 
53
#if 0
 
54
void
 
55
indicator_save (XfcePanelPlugin *plugin,
 
56
             IndicatorPlugin    *indicator)
 
57
{
 
58
  XfceRc *rc;
 
59
  gchar  *file;
 
60
 
 
61
  /* get the config file location */
 
62
  file = xfce_panel_plugin_save_location (plugin, TRUE);
 
63
 
 
64
  if (G_UNLIKELY (file == NULL))
 
65
    {
 
66
       DBG ("Failed to open config file");
 
67
       return;
 
68
    }
 
69
 
 
70
  /* open the config file, read/write */
 
71
  rc = xfce_rc_simple_open (file, FALSE);
 
72
  g_free (file);
 
73
 
 
74
  if (G_LIKELY (rc != NULL))
 
75
    {
 
76
      /* save the settings */
 
77
      DBG(".");
 
78
      if (indicator->setting1)
 
79
        xfce_rc_write_entry    (rc, "setting1", indicator->setting1);
 
80
 
 
81
      xfce_rc_write_int_entry  (rc, "setting2", indicator->setting2);
 
82
      xfce_rc_write_bool_entry (rc, "setting3", indicator->setting3);
 
83
 
 
84
      /* close the rc file */
 
85
      xfce_rc_close (rc);
 
86
    }
 
87
}
 
88
 
 
89
 
 
90
 
 
91
static void
 
92
indicator_read (IndicatorPlugin *indicator)
 
93
{
 
94
  XfceRc      *rc;
 
95
  gchar       *file;
 
96
  const gchar *value;
 
97
 
 
98
  /* get the plugin config file location */
 
99
  file = xfce_panel_plugin_save_location (indicator->plugin, TRUE);
 
100
 
 
101
  if (G_LIKELY (file != NULL))
 
102
    {
 
103
      /* open the config file, readonly */
 
104
      rc = xfce_rc_simple_open (file, TRUE);
 
105
 
 
106
      /* cleanup */
 
107
      g_free (file);
 
108
 
 
109
      if (G_LIKELY (rc != NULL))
 
110
        {
 
111
          /* read the settings */
 
112
          value = xfce_rc_read_entry (rc, "setting1", DEFAULT_SETTING1);
 
113
          indicator->setting1 = g_strdup (value);
 
114
 
 
115
          indicator->setting2 = xfce_rc_read_int_entry (rc, "setting2", DEFAULT_SETTING2);
 
116
          indicator->setting3 = xfce_rc_read_bool_entry (rc, "setting3", DEFAULT_SETTING3);
 
117
 
 
118
          /* cleanup */
 
119
          xfce_rc_close (rc);
 
120
 
 
121
          /* leave the function, everything went well */
 
122
          return;
 
123
        }
 
124
    }
 
125
 
 
126
  /* something went wrong, apply default values */
 
127
  DBG ("Applying default settings");
 
128
 
 
129
  indicator->setting1 = g_strdup (DEFAULT_SETTING1);
 
130
  indicator->setting2 = DEFAULT_SETTING2;
 
131
  indicator->setting3 = DEFAULT_SETTING3;
 
132
}
 
133
#endif
 
134
 
 
135
 
 
136
static IndicatorPlugin *
 
137
indicator_new (XfcePanelPlugin *plugin)
 
138
{
 
139
  IndicatorPlugin   *indicator;
 
140
  GtkOrientation  orientation;
 
141
  gint indicators_loaded = 0;
 
142
 
 
143
  /* allocate memory for the plugin structure */
 
144
  indicator = panel_slice_new0 (IndicatorPlugin);
 
145
 
 
146
  /* pointer to plugin */
 
147
  indicator->plugin = plugin;
 
148
 
 
149
  /* get the current orientation */
 
150
  orientation = xfce_panel_plugin_get_orientation (plugin);
 
151
 
 
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"
 
158
    "{\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"
 
163
    "}\n"
 
164
    "style \"indicator-applet-menubar-style\"\n"
 
165
    "{\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"
 
171
    "}\n"
 
172
    "style \"indicator-applet-menuitem-style\"\n"
 
173
    "{\n"
 
174
    "    GtkWidget::focus-line-width = 0\n"
 
175
    "    GtkWidget::focus-padding = 0\n"
 
176
    "    GtkMenuItem::horizontal-padding = 0\n"
 
177
    "}\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 */
 
183
  
 
184
  /* Build menu */
 
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);
 
191
 
 
192
  
 
193
  /* load 'em */
 
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);
 
196
 
 
197
    const gchar * name;
 
198
    while ((name = g_dir_read_name(dir)) != NULL) {
 
199
      if (load_module(name, indicator->menu))
 
200
        indicators_loaded++;
 
201
    }
 
202
    g_dir_close (dir);
 
203
  }
 
204
 
 
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);
 
211
  } else {
 
212
    gtk_widget_show(indicator->menu);
 
213
    gtk_container_add (GTK_CONTAINER (plugin), indicator->menu);
 
214
  }
 
215
  return indicator;
 
216
}
 
217
 
 
218
 
 
219
 
 
220
static void
 
221
indicator_free (XfcePanelPlugin *plugin,
 
222
             IndicatorPlugin    *indicator)
 
223
{
 
224
  GtkWidget *dialog;
 
225
 
 
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);
 
230
 
 
231
  /* free the plugin structure */
 
232
  panel_slice_free (IndicatorPlugin, indicator);
 
233
}
 
234
 
 
235
 
 
236
 
 
237
static void
 
238
indicator_orientation_changed (XfcePanelPlugin *plugin,
 
239
                            GtkOrientation   orientation,
 
240
                            IndicatorPlugin    *indicator)
 
241
{
 
242
  /* change the orienation of the box */
 
243
  //xfce_hvbox_set_orientation (XFCE_HVBOX (indicator->hvbox), orientation);
 
244
}
 
245
 
 
246
 
 
247
 
 
248
static gboolean
 
249
indicator_size_changed (XfcePanelPlugin *plugin,
 
250
                     gint             size,
 
251
                     IndicatorPlugin    *indicator)
 
252
{
 
253
  GtkOrientation orientation;
 
254
 
 
255
  /* get the orientation of the plugin */
 
256
  orientation = xfce_panel_plugin_get_orientation (plugin);
 
257
 
 
258
  /* set the widget size */
 
259
  if (orientation == GTK_ORIENTATION_HORIZONTAL)
 
260
    gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
 
261
  else
 
262
    gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
 
263
 
 
264
  /* we handled the orientation */
 
265
  return TRUE;
 
266
}
 
267
 
 
268
 
 
269
static gboolean
 
270
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
 
271
{
 
272
    TRACE ("enters on_button_press");
 
273
    if (indicator != NULL && event->button == 1) /* left click only */
 
274
    {
 
275
     /*   gtk_menu_popup (GTK_MENU(indicator->menu), NULL, NULL, NULL, NULL, 0,
 
276
                        event->time);*/
 
277
        return TRUE;
 
278
    }
 
279
    TRACE ("leaves on_button_press");
 
280
    return FALSE ;
 
281
}
 
282
 
 
283
 
 
284
static void
 
285
indicator_construct (XfcePanelPlugin *plugin)
 
286
{
 
287
  IndicatorPlugin *indicator;
 
288
 
 
289
  /* setup transation domain */
 
290
  xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
291
 
 
292
  /* create the plugin */
 
293
  indicator = indicator_new (plugin);
 
294
 
 
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);
 
298
 
 
299
  /* connect plugin signals */
 
300
  g_signal_connect (G_OBJECT (plugin), "free-data",
 
301
                    G_CALLBACK (indicator_free), indicator);
 
302
 
 
303
  g_signal_connect (G_OBJECT (plugin), "size-changed",
 
304
                    G_CALLBACK (indicator_size_changed), indicator);
 
305
 
 
306
  g_signal_connect (G_OBJECT (plugin), "orientation-changed",
 
307
                    G_CALLBACK (indicator_orientation_changed), indicator);
 
308
}
 
309
 
 
310
 
 
311
static gboolean
 
312
entry_scrolled (GtkWidget *menuitem, GdkEventScroll *event, gpointer data)
 
313
{
 
314
  IndicatorObject *io = g_object_get_data (G_OBJECT (menuitem), "indicator-custom-object-data");
 
315
  IndicatorObjectEntry *entry = g_object_get_data (G_OBJECT (menuitem), "indicator-custom-entry-data");
 
316
 
 
317
  g_return_val_if_fail(INDICATOR_IS_OBJECT(io), FALSE);
 
318
 
 
319
  g_signal_emit_by_name (io, "scroll", 1, event->direction);
 
320
  g_signal_emit_by_name (io, "scroll-entry", entry, 1, event->direction);
 
321
 
 
322
  return FALSE;
 
323
}
 
324
 
 
325
 
 
326
static void
 
327
entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
 
328
{
 
329
  GtkWidget * menuitem = gtk_menu_item_new();
 
330
  GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
 
331
 
 
332
  g_signal_connect(G_OBJECT(menuitem), "scroll-event", G_CALLBACK(entry_scrolled), entry);
 
333
 
 
334
  if (entry->image != NULL)
 
335
    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
 
336
 
 
337
  if (entry->label != NULL)
 
338
    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
 
339
 
 
340
  gtk_container_add(GTK_CONTAINER(menuitem), hbox);
 
341
  gtk_widget_show(hbox);
 
342
 
 
343
  if (entry->menu != NULL)
 
344
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
 
345
 
 
346
  gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem);
 
347
  gtk_widget_show(menuitem);
 
348
 
 
349
  g_object_set_data(G_OBJECT(menuitem), "indicator-custom-object-data", io);
 
350
  g_object_set_data(G_OBJECT(menuitem), "indicator-custom-entry-data", entry);
 
351
}
 
352
 
 
353
 
 
354
static void
 
355
entry_removed_cb (GtkWidget * widget, gpointer userdata)
 
356
{
 
357
  gpointer data = g_object_get_data(G_OBJECT(widget), "indicator-custom-entry-data");
 
358
 
 
359
  if (data != userdata)
 
360
    return;
 
361
 
 
362
  gtk_widget_destroy(widget);
 
363
}
 
364
 
 
365
 
 
366
static void
 
367
entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
 
368
{
 
369
  gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
 
370
}
 
371
 
 
372
 
 
373
static gboolean
 
374
load_module (const gchar * name, GtkWidget * menu)
 
375
{
 
376
        g_debug("Looking at Module: %s", name);
 
377
        g_return_val_if_fail(name != NULL, FALSE);
 
378
 
 
379
    if (!g_str_has_suffix(name,G_MODULE_SUFFIX))
 
380
        return FALSE;
 
381
 
 
382
        g_debug("Loading Module: %s", name);
 
383
 
 
384
        gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
 
385
        IndicatorObject * io = indicator_object_new_from_file(fullpath);
 
386
        g_free(fullpath);
 
387
 
 
388
    g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,
 
389
                     G_CALLBACK(entry_added), menu);
 
390
    g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED,
 
391
                     G_CALLBACK(entry_removed), menu);
 
392
 
 
393
        GList * entries = indicator_object_get_entries(io);
 
394
        GList * entry = NULL;
 
395
 
 
396
        for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
 
397
                IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
 
398
                entry_added(io, entrydata, menu);
 
399
        }
 
400
 
 
401
        g_list_free(entries);
 
402
 
 
403
        return TRUE;
 
404
}