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

« back to all changes in this revision

Viewing changes to .pc/02_fix-menu-position.patch/panel-plugin/indicator.c

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2011-10-30 18:50:42 UTC
  • mfrom: (1.1.4) (3.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20111030185042-2n4km6kcz37dpyd5
Tags: 0.4.0-0ubuntu1
* Upload pkg-xfce svn r6172 to precise, no remaining Ubuntu change:
  - debian/patches:
    + 03_attach-button-to-menu-right-at-the-beginning.patch,
      02_fix-menu-position.patch, 01_search-for-indicator-0.4-pc.patch,
      xubuntu_exclude-modules.patch: dropped, included upstream.
* Bugs fixed by this new upstream release:
  - "Scrolling the mousewheel over the sound-indicator doesn't adjust the
    volume". lp: #879928
  - "xfce4-indicator-plugin does not update output". lp: #852017

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
 
/* prototypes */
34
 
static void
35
 
indicator_construct (XfcePanelPlugin *plugin);
36
 
 
37
 
static gboolean
38
 
load_module (const gchar * name, IndicatorPlugin * indicator);
39
 
 
40
 
/* register the plugin */
41
 
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (indicator_construct);
42
 
 
43
 
 
44
 
static IndicatorPlugin *
45
 
indicator_new (XfcePanelPlugin *plugin)
46
 
{
47
 
  IndicatorPlugin   *indicator;
48
 
  GtkOrientation  orientation;
49
 
  gint indicators_loaded = 0;
50
 
 
51
 
  /* allocate memory for the plugin structure */
52
 
  indicator = panel_slice_new0 (IndicatorPlugin);
53
 
 
54
 
  /* pointer to plugin */
55
 
  indicator->plugin = plugin;
56
 
 
57
 
  /* get the current orientation */
58
 
  orientation = xfce_panel_plugin_get_orientation (plugin);
59
 
 
60
 
  /* Init some theme/icon stuff */
61
 
  gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
62
 
                                  INDICATOR_ICONS_DIR);
63
 
  gtk_widget_set_name(GTK_WIDGET (indicator), "indicator-plugin");
64
 
  
65
 
  indicator->buttonbox = gtk_hbox_new(FALSE,0);
66
 
  gtk_widget_set_can_focus(GTK_WIDGET(indicator->buttonbox), TRUE);
67
 
  gtk_rc_parse_string (
68
 
    "style \"indicator-plugin-style\"\n"
69
 
    "{\n"
70
 
    "    GtkButton::internal-border= 0\n"
71
 
    "    GtkWidget::focus-line-width = 0\n"
72
 
    "    GtkWidget::focus-padding = 0\n"
73
 
    "}\n"
74
 
    "widget \"*.indicator-button\" style \"indicator-plugin-style\"");
75
 
 
76
 
  gtk_widget_set_name(GTK_WIDGET (indicator->buttonbox), "indicator-button");
77
 
  gtk_container_set_border_width(GTK_CONTAINER(indicator->buttonbox), 0);
78
 
  
79
 
  /* load 'em */
80
 
  if (g_file_test(INDICATOR_DIR, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
81
 
    GDir * dir = g_dir_open(INDICATOR_DIR, 0, NULL);
82
 
 
83
 
    const gchar * name;
84
 
    while ((name = g_dir_read_name(dir)) != NULL) {
85
 
      if (load_module(name, indicator))
86
 
        indicators_loaded++;
87
 
    }
88
 
    g_dir_close (dir);
89
 
  }
90
 
 
91
 
  if (indicators_loaded == 0) {
92
 
    /* A label to allow for click through */
93
 
    indicator->item = xfce_create_panel_button();
94
 
    gtk_button_set_label(GTK_BUTTON(indicator->item), _("No Indicators"));
95
 
    gtk_container_add (GTK_CONTAINER (plugin), indicator->item);
96
 
    gtk_widget_show(indicator->item);
97
 
  } else {
98
 
    indicator->ebox = gtk_event_box_new();
99
 
    gtk_widget_set_can_focus(GTK_WIDGET(indicator->ebox), TRUE);
100
 
    gtk_container_add (GTK_CONTAINER (indicator->ebox), GTK_WIDGET(indicator->buttonbox));
101
 
    gtk_container_add (GTK_CONTAINER (plugin), GTK_WIDGET(indicator->ebox));
102
 
    gtk_widget_show(GTK_WIDGET(indicator->buttonbox));
103
 
    gtk_widget_show(GTK_WIDGET(indicator->ebox));
104
 
  }
105
 
  return indicator;
106
 
}
107
 
 
108
 
 
109
 
 
110
 
static void
111
 
indicator_free (XfcePanelPlugin *plugin,
112
 
             IndicatorPlugin    *indicator)
113
 
{
114
 
  GtkWidget *dialog;
115
 
 
116
 
  /* check if the dialog is still open. if so, destroy it */
117
 
  dialog = g_object_get_data (G_OBJECT (plugin), "dialog");
118
 
  if (G_UNLIKELY (dialog != NULL))
119
 
    gtk_widget_destroy (dialog);
120
 
 
121
 
  /* free the plugin structure */
122
 
  panel_slice_free (IndicatorPlugin, indicator);
123
 
}
124
 
 
125
 
 
126
 
 
127
 
static void
128
 
indicator_orientation_changed (XfcePanelPlugin *plugin,
129
 
                            GtkOrientation   orientation,
130
 
                            IndicatorPlugin    *indicator)
131
 
{
132
 
  gint sizex=-1, sizey=-1;
133
 
  gtk_orientable_set_orientation (GTK_ORIENTABLE(indicator->buttonbox), orientation);
134
 
  gtk_widget_get_size_request (GTK_WIDGET (plugin), &sizex, &sizey);
135
 
  gtk_widget_set_size_request (GTK_WIDGET (plugin), sizey, sizex);  
136
 
}
137
 
 
138
 
 
139
 
 
140
 
static gboolean
141
 
indicator_size_changed (XfcePanelPlugin *plugin,
142
 
                     gint             size,
143
 
                     IndicatorPlugin    *indicator)
144
 
{
145
 
  GtkOrientation orientation;
146
 
 
147
 
  /* get the orientation of the plugin */
148
 
  orientation = xfce_panel_plugin_get_orientation (plugin);
149
 
 
150
 
  /* set the widget size */
151
 
  if (orientation == GTK_ORIENTATION_HORIZONTAL)
152
 
    gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
153
 
  else
154
 
    gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
155
 
 
156
 
  return TRUE;
157
 
}
158
 
 
159
 
static gboolean
160
 
on_button_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
161
 
{
162
 
  if (indicator != NULL)
163
 
  {
164
 
    if( event->button == 1) /* left click only */
165
 
    {
166
 
      gtk_menu_popup (GTK_MENU(g_object_get_data (G_OBJECT(widget),"menu")), NULL,
167
 
                      NULL, NULL, NULL, 1, event->time);
168
 
      /* no approvement to the above */
169
 
      /*
170
 
      gtk_menu_popup (GTK_MENU(g_object_get_data (G_OBJECT(widget),"menu")), NULL, NULL,
171
 
                      xfce_panel_plugin_position_menu,
172
 
                      indicator->plugin, 1, gtk_get_current_event_time ());
173
 
      */
174
 
      return TRUE;
175
 
    }
176
 
    /* event doesn't make it to the ebox, so I just push it. */
177
 
    gtk_widget_event (indicator->ebox, (GdkEvent*)event);
178
 
  }
179
 
  return FALSE;
180
 
}
181
 
 
182
 
static void
183
 
indicator_construct (XfcePanelPlugin *plugin)
184
 
{
185
 
  IndicatorPlugin *indicator;
186
 
 
187
 
  /* setup transation domain */
188
 
  xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
189
 
 
190
 
  /* create the plugin */
191
 
  indicator = indicator_new (plugin);
192
 
 
193
 
  /* show the panel's right-click menu on this menu */
194
 
  xfce_panel_plugin_add_action_widget (plugin, indicator->ebox);
195
 
  xfce_panel_plugin_add_action_widget (plugin, indicator->item);
196
 
 
197
 
  /* connect plugin signals */
198
 
  g_signal_connect (G_OBJECT (plugin), "free-data",
199
 
                    G_CALLBACK (indicator_free), indicator);
200
 
 
201
 
  g_signal_connect (G_OBJECT (plugin), "size-changed",
202
 
                    G_CALLBACK (indicator_size_changed), indicator);
203
 
 
204
 
  g_signal_connect (G_OBJECT (plugin), "orientation-changed",
205
 
                    G_CALLBACK (indicator_orientation_changed), indicator);
206
 
}
207
 
 
208
 
 
209
 
static gboolean
210
 
entry_scrolled (GtkWidget *menuitem, GdkEventScroll *event, gpointer data)
211
 
{
212
 
  IndicatorObject *io = g_object_get_data (G_OBJECT (menuitem), "indicator-custom-object-data");
213
 
  IndicatorObjectEntry *entry = g_object_get_data (G_OBJECT (menuitem), "indicator-custom-entry-data");
214
 
 
215
 
  g_return_val_if_fail(INDICATOR_IS_OBJECT(io), FALSE);
216
 
 
217
 
  g_signal_emit_by_name (io, "scroll", 1, event->direction);
218
 
  g_signal_emit_by_name (io, "scroll-entry", entry, 1, event->direction);
219
 
 
220
 
  return FALSE;
221
 
}
222
 
 
223
 
 
224
 
static void
225
 
entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
226
 
{
227
 
  GtkWidget * button = gtk_button_new();
228
 
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
229
 
  gtk_button_set_use_underline(GTK_BUTTON (button),TRUE);
230
 
  gtk_widget_set_name(GTK_WIDGET (button), "indicator-button");
231
 
 
232
 
  if (entry->image != NULL)
233
 
    gtk_button_set_image(GTK_BUTTON(button), GTK_WIDGET(entry->image));
234
 
 
235
 
  if (entry->label != NULL)
236
 
    gtk_button_set_label(GTK_BUTTON(button), gtk_label_get_label (entry->label));
237
 
 
238
 
  if (entry->menu != NULL)
239
 
    g_object_set_data(G_OBJECT(button), "menu", entry->menu);
240
 
 
241
 
  g_signal_connect(button, "button-press-event", G_CALLBACK(on_button_press),
242
 
                   user_data);
243
 
  gtk_box_pack_start(GTK_BOX(((IndicatorPlugin *)user_data)->buttonbox), button, TRUE, TRUE, 0);
244
 
  gtk_widget_show(button);
245
 
  g_object_set_data(G_OBJECT(button), "indicator-custom-object-data", io);
246
 
  g_object_set_data(G_OBJECT(button), "indicator-custom-entry-data", entry);
247
 
}
248
 
 
249
 
 
250
 
static void
251
 
entry_removed_cb (GtkWidget * widget, gpointer userdata)
252
 
{
253
 
  gpointer data = g_object_get_data(G_OBJECT(widget), "indicator-custom-entry-data");
254
 
 
255
 
  if (data != userdata)
256
 
    return;
257
 
    
258
 
  gtk_widget_destroy(widget);
259
 
}
260
 
 
261
 
 
262
 
static void
263
 
entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
264
 
{
265
 
  gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
266
 
}
267
 
 
268
 
 
269
 
static gboolean
270
 
load_module (const gchar * name, IndicatorPlugin * indicator)
271
 
{
272
 
        g_debug("Looking at Module: %s", name);
273
 
        g_return_val_if_fail(name != NULL, FALSE);
274
 
 
275
 
    if (!g_str_has_suffix(name,G_MODULE_SUFFIX))
276
 
        return FALSE;
277
 
 
278
 
        g_debug("Loading Module: %s", name);
279
 
 
280
 
        gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
281
 
        IndicatorObject * io = indicator_object_new_from_file(fullpath);
282
 
        g_free(fullpath);
283
 
 
284
 
    g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,
285
 
                     G_CALLBACK(entry_added), indicator);
286
 
    g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED,
287
 
                     G_CALLBACK(entry_removed), indicator->buttonbox);
288
 
 
289
 
        GList * entries = indicator_object_get_entries(io);
290
 
        GList * entry = NULL;
291
 
 
292
 
        for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
293
 
                IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
294
 
                entry_added(io, entrydata, indicator);
295
 
        }
296
 
 
297
 
        g_list_free(entries);
298
 
 
299
 
        return TRUE;
300
 
}