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

« back to all changes in this revision

Viewing changes to .pc/0001-Add-entry_-added-removed-signal-handlers.patch/panel-plugin/indicator.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2011-06-26 01:24:54 UTC
  • mfrom: (3.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110626012454-u3ra9bypujkz4qgk
Tags: 0.2.1-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - debian/patches:
    + 0004-cherry-pick-vertical-panel-fixes.patch: cherry-pick from upstream
      4e55a3d7292bd4f15b1555530f58e559cb99e965
      2c0cc99c948d1b5e1ff5fb11057a6bb549849a2d
      Fixes vertical panel issue with indicators (LP: #787977)
    + 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: refreshed.

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
 
load_module (const gchar * name, GtkWidget * menu)
313
 
{
314
 
        g_debug("Looking at Module: %s", name);
315
 
        g_return_val_if_fail(name != NULL, FALSE);
316
 
 
317
 
    if (!g_str_has_suffix(name,G_MODULE_SUFFIX))
318
 
        return FALSE;
319
 
 
320
 
        g_debug("Loading Module: %s", name);
321
 
 
322
 
        gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
323
 
        IndicatorObject * io = indicator_object_new_from_file(fullpath);
324
 
        g_free(fullpath);
325
 
 
326
 
        GList * entries = indicator_object_get_entries(io);
327
 
        GList * entry = NULL;
328
 
 
329
 
        for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
330
 
                IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
331
 
 
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);
336
 
                }
337
 
                if (entrydata->label != NULL) {
338
 
                        gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->label), FALSE, FALSE, 0);
339
 
                }
340
 
                gtk_container_add(GTK_CONTAINER(menuitem), hbox);
341
 
                gtk_widget_show(hbox);
342
 
 
343
 
                if (entrydata->menu != NULL) {
344
 
                        gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entrydata->menu));
345
 
                }
346
 
 
347
 
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
348
 
                gtk_widget_show(menuitem);
349
 
        }
350
 
 
351
 
        g_list_free(entries);
352
 
 
353
 
        return TRUE;
354
 
}