~ubuntu-branches/ubuntu/maverick/xfce4-indicator-plugin/maverick

« back to all changes in this revision

Viewing changes to .pc/02_menu_on_no-indicators.patch/panel-plugin/indicator.c

  • Committer: Bazaar Package Importer
  • Author(s): Evgeni Golov
  • Date: 2010-07-14 09:35:08 UTC
  • Revision ID: james.westby@ubuntu.com-20100714093508-u6bgh24cbmaa3bw8
Tags: 0.0.1-2
* debian/control:
  + Add Provides: indicator-renderer
  + Add Recommends: indicator-messages
* debian/patches/02_menu_on_no-indicators.patch
  + Display a menu even when there are no indicators.        closes: #587167
* debian/patches/03_skip_pofiles_in_patches.patch
  + Split the POTFILES.skip patch out, list all changed files in there.

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
#define ICONS_DIR "/usr/share/libindicator/icons/"
 
38
 
 
39
 
 
40
/* prototypes */
 
41
static void
 
42
indicator_construct (XfcePanelPlugin *plugin);
 
43
 
 
44
static gboolean
 
45
load_module (const gchar * name, GtkWidget * menu);
 
46
 
 
47
static gboolean
 
48
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator);
 
49
 
 
50
 
 
51
/* register the plugin */
 
52
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (indicator_construct);
 
53
 
 
54
 
 
55
#if 0
 
56
void
 
57
indicator_save (XfcePanelPlugin *plugin,
 
58
             IndicatorPlugin    *indicator)
 
59
{
 
60
  XfceRc *rc;
 
61
  gchar  *file;
 
62
 
 
63
  /* get the config file location */
 
64
  file = xfce_panel_plugin_save_location (plugin, TRUE);
 
65
 
 
66
  if (G_UNLIKELY (file == NULL))
 
67
    {
 
68
       DBG ("Failed to open config file");
 
69
       return;
 
70
    }
 
71
 
 
72
  /* open the config file, read/write */
 
73
  rc = xfce_rc_simple_open (file, FALSE);
 
74
  g_free (file);
 
75
 
 
76
  if (G_LIKELY (rc != NULL))
 
77
    {
 
78
      /* save the settings */
 
79
      DBG(".");
 
80
      if (indicator->setting1)
 
81
        xfce_rc_write_entry    (rc, "setting1", indicator->setting1);
 
82
 
 
83
      xfce_rc_write_int_entry  (rc, "setting2", indicator->setting2);
 
84
      xfce_rc_write_bool_entry (rc, "setting3", indicator->setting3);
 
85
 
 
86
      /* close the rc file */
 
87
      xfce_rc_close (rc);
 
88
    }
 
89
}
 
90
 
 
91
 
 
92
 
 
93
static void
 
94
indicator_read (IndicatorPlugin *indicator)
 
95
{
 
96
  XfceRc      *rc;
 
97
  gchar       *file;
 
98
  const gchar *value;
 
99
 
 
100
  /* get the plugin config file location */
 
101
  file = xfce_panel_plugin_save_location (indicator->plugin, TRUE);
 
102
 
 
103
  if (G_LIKELY (file != NULL))
 
104
    {
 
105
      /* open the config file, readonly */
 
106
      rc = xfce_rc_simple_open (file, TRUE);
 
107
 
 
108
      /* cleanup */
 
109
      g_free (file);
 
110
 
 
111
      if (G_LIKELY (rc != NULL))
 
112
        {
 
113
          /* read the settings */
 
114
          value = xfce_rc_read_entry (rc, "setting1", DEFAULT_SETTING1);
 
115
          indicator->setting1 = g_strdup (value);
 
116
 
 
117
          indicator->setting2 = xfce_rc_read_int_entry (rc, "setting2", DEFAULT_SETTING2);
 
118
          indicator->setting3 = xfce_rc_read_bool_entry (rc, "setting3", DEFAULT_SETTING3);
 
119
 
 
120
          /* cleanup */
 
121
          xfce_rc_close (rc);
 
122
 
 
123
          /* leave the function, everything went well */
 
124
          return;
 
125
        }
 
126
    }
 
127
 
 
128
  /* something went wrong, apply default values */
 
129
  DBG ("Applying default settings");
 
130
 
 
131
  indicator->setting1 = g_strdup (DEFAULT_SETTING1);
 
132
  indicator->setting2 = DEFAULT_SETTING2;
 
133
  indicator->setting3 = DEFAULT_SETTING3;
 
134
}
 
135
#endif
 
136
 
 
137
 
 
138
static IndicatorPlugin *
 
139
indicator_new (XfcePanelPlugin *plugin)
 
140
{
 
141
  IndicatorPlugin   *indicator;
 
142
  GtkOrientation  orientation;
 
143
  gint indicators_loaded = 0;
 
144
 
 
145
  /* allocate memory for the plugin structure */
 
146
  indicator = panel_slice_new0 (IndicatorPlugin);
 
147
 
 
148
  /* pointer to plugin */
 
149
  indicator->plugin = plugin;
 
150
 
 
151
  /* get the current orientation */
 
152
  orientation = xfce_panel_plugin_get_orientation (plugin);
 
153
 
 
154
  /* Init some theme/icon stuff */
 
155
  gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
 
156
                                  ICONS_DIR);
 
157
  /* g_debug("Icons directory: %s", ICONS_DIR); */
 
158
  gtk_rc_parse_string (
 
159
    "style \"indicator-applet-style\"\n"
 
160
    "{\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"
 
165
    "}\n"
 
166
    "style \"indicator-applet-menubar-style\"\n"
 
167
    "{\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"
 
173
    "}\n"
 
174
    "style \"indicator-applet-menuitem-style\"\n"
 
175
    "{\n"
 
176
    "    GtkWidget::focus-line-width = 0\n"
 
177
    "    GtkWidget::focus-padding = 0\n"
 
178
    "    GtkMenuItem::horizontal-padding = 0\n"
 
179
    "}\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 */
 
185
  
 
186
  /* Build menu */
 
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);
 
193
 
 
194
  
 
195
  /* load 'em */
 
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);
 
198
 
 
199
    const gchar * name;
 
200
    while ((name = g_dir_read_name(dir)) != NULL) {
 
201
      if (load_module(name, indicator->menu))
 
202
        indicators_loaded++;
 
203
    }
 
204
    g_dir_close (dir);
 
205
  }
 
206
 
 
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);
 
212
  } else {
 
213
    gtk_widget_show(indicator->menu);
 
214
    gtk_container_add (GTK_CONTAINER (plugin), indicator->menu);
 
215
  }
 
216
  return indicator;
 
217
}
 
218
 
 
219
 
 
220
 
 
221
static void
 
222
indicator_free (XfcePanelPlugin *plugin,
 
223
             IndicatorPlugin    *indicator)
 
224
{
 
225
  GtkWidget *dialog;
 
226
 
 
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);
 
231
 
 
232
  /* free the plugin structure */
 
233
  panel_slice_free (IndicatorPlugin, indicator);
 
234
}
 
235
 
 
236
 
 
237
 
 
238
static void
 
239
indicator_orientation_changed (XfcePanelPlugin *plugin,
 
240
                            GtkOrientation   orientation,
 
241
                            IndicatorPlugin    *indicator)
 
242
{
 
243
  /* change the orienation of the box */
 
244
  //xfce_hvbox_set_orientation (XFCE_HVBOX (indicator->hvbox), orientation);
 
245
}
 
246
 
 
247
 
 
248
 
 
249
static gboolean
 
250
indicator_size_changed (XfcePanelPlugin *plugin,
 
251
                     gint             size,
 
252
                     IndicatorPlugin    *indicator)
 
253
{
 
254
  GtkOrientation orientation;
 
255
 
 
256
  /* get the orientation of the plugin */
 
257
  orientation = xfce_panel_plugin_get_orientation (plugin);
 
258
 
 
259
  /* set the widget size */
 
260
  if (orientation == GTK_ORIENTATION_HORIZONTAL)
 
261
    gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
 
262
  else
 
263
    gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
 
264
 
 
265
  /* we handled the orientation */
 
266
  return TRUE;
 
267
}
 
268
 
 
269
 
 
270
static gboolean
 
271
on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
 
272
{
 
273
    TRACE ("enters on_button_press");
 
274
    if (indicator != NULL && event->button == 1) /* left click only */
 
275
    {
 
276
     /*   gtk_menu_popup (GTK_MENU(indicator->menu), NULL, NULL, NULL, NULL, 0,
 
277
                        event->time);*/
 
278
        return TRUE;
 
279
    }
 
280
    TRACE ("leaves on_button_press");
 
281
    return FALSE ;
 
282
}
 
283
 
 
284
 
 
285
static void
 
286
indicator_construct (XfcePanelPlugin *plugin)
 
287
{
 
288
  IndicatorPlugin *indicator;
 
289
 
 
290
  /* setup transation domain */
 
291
  xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
292
 
 
293
  /* create the plugin */
 
294
  indicator = indicator_new (plugin);
 
295
 
 
296
  /* show the panel's right-click menu on this menu */
 
297
  xfce_panel_plugin_add_action_widget (plugin, indicator->menu);
 
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
}