~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to bonobo/panel-module/panel-applet-frame-bonobo.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher, Sebastien Bacher, Jeremy Bicha
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.13.10 upstream) (2.2.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110530110449-hinl17kxkcefjw6x
Tags: 1:3.0.2-0ubuntu1
[ Sebastien Bacher ]
* New upstream version
* debian/control.in:
  - the new libgweather version is in oneiric, use it
  - drop the python and python-gconf depends, 
    they were added for gnome-panel-add which is still using gconf and buggy
* debian/gnome-panel-data.install:
  - don't install the apport hook, it's only getting gconf datas which 
    doesn't work since gnome-panel uses gsettings
* debian/patches/90_build_fixes.patch:
  - restore build fix from git not applied in the new serie
* debian/patches/01_panel_submenus.patch:
  - don't take that Debian diff, the .menus use the upstream naming in Ubuntu
* debian/patches/06_no_resize_grip.patch:
  - dropped, the issue is fixed in the new version
* debian/patches/50_fix-potfiles.patch:
  - dropped, the issue is fixed in the new version
* debian/watch:
  - track unstable series as well

Drop those delta, since gnome-panel is not the default Ubuntu session now we
can go back to an experience closer to the upstream one: 
* debian/control.in:
  - drop the indicators recommends, unity-2d is the ubuntu fallback session
    so we can get back to use an upstream config for gnome-panel and reduce
    the delta we carry
* debian/patches/04_default_panel_config.patch:
  - don't modify the upstream layout
* debian/patches/05_no_session_delay.patch:
  - no need to tweak the upstream session to optimize it
* debian/patches/16_compiz_workspace_switcher.patch:
  - go back to the upstream switcher behaviour    
* debian/patches/25_dynamic_fusa_detection.patch:
  - not needed since we use the upstream layout, could be ported if someone
    is wanting to do the work though
* debian/patches/30_disable-initial-animation.patch, debian/rules:
  - drop the --disable-initial-animation, that was some login optimization
    but since it's not the default desktop you should go back to the 
    upstream behaviour

[ Jeremy Bicha ]   
* New upstream version
* Merge from Debian experimental, remaining Ubuntu changes:
* debian/control:
  - Recommends gnome-settings-daemon which has the timezone polkit service
* debian/rules:
  - Update translations template.
* debian/gnome-panel-data.install:
  - Install apport hook
  - Install the "About Ubuntu" menu item.
* debian/patches/01_layout.patch:
  - Disabled, Help & About Ubuntu don't fit as well in Gnome Panel 3
* debian/patches/01_panel_submenus.patch.
  - Dropped
* debian/patches/03_dnd_places_link.patch:
  - Disabled, when using Drag'n'Drop from Places menu, install a link launcher
    (.desktop file) instead of copying the entire directory.
* debian/patches/17_about-ubuntu-translation.patch:
  - List ubuntu-about.desktop for translation.
* debian/patches/40_unset_menuproxy.patch:
  - Make sure gnome-panel and the applets don't pick up menu proxies.
* debian/patches/50_fix-potfiles.patch
  - Fix i18n
* debian/patches/85_disable_shutdown_on_ltsp.patch:
  - Suppress the shutdown option in the panel if LTSP_CLIENT is set.
* debian/patches/71_change_bookmark_submenu_limit_value.patch
  - Dropped, picked up by Debian
* debian/patches/18_lockdown_lock_editor.patch:
* debian/patches/90_git_wnck_show_realize.patch:
* debian/patches/90_fix_linking_DSO_link.patch:
* debian/patches/91_gir_annotations.patch
* debian/patches/92_git_calendar_day.patch
* debian/patches/92_git_fix_applets_in_multiscreen.patch:
  - Dropped, applied upstream
* debian/watch:
  - watch unstable versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 * panel-applet-frame-bonobo.c: panel side container for applets
4
 
 *
5
 
 * Copyright (C) 2001 - 2003 Sun Microsystems, Inc.
6
 
 * Copyright (C) 2010 Vincent Untz <vuntz@gnome.org>
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public License as
10
 
 * published by the Free Software Foundation; either version 2 of the
11
 
 * License, or (at your option) any later version.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful, but
14
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program; if not, write to the Free Software
20
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
 
 * 02111-1307, USA.
22
 
 *
23
 
 * Authors:
24
 
 *      Mark McLoughlin <mark@skynet.ie>
25
 
 */
26
 
 
27
 
#include <config.h>
28
 
 
29
 
#include <string.h>
30
 
 
31
 
#include <libbonoboui.h>
32
 
 
33
 
#include <panel-applet-frame.h>
34
 
#include <panel-applets-manager.h>
35
 
 
36
 
#include "GNOME_Panel.h"
37
 
 
38
 
#include "panel-applet-frame-bonobo.h"
39
 
 
40
 
G_DEFINE_TYPE (PanelAppletFrameBonobo,
41
 
               panel_applet_frame_bonobo,
42
 
               PANEL_TYPE_APPLET_FRAME)
43
 
 
44
 
struct _PanelAppletFrameBonoboPrivate
45
 
{
46
 
        GNOME_Vertigo_PanelAppletShell  applet_shell;
47
 
        CORBA_Object                    control;
48
 
        Bonobo_PropertyBag              property_bag;
49
 
        BonoboUIComponent              *ui_component;
50
 
};
51
 
 
52
 
#define PROPERTY_ORIENT      "panel-applet-orient"
53
 
#define PROPERTY_SIZE        "panel-applet-size"
54
 
#define PROPERTY_BACKGROUND  "panel-applet-background"
55
 
#define PROPERTY_FLAGS       "panel-applet-flags"
56
 
#define PROPERTY_SIZE_HINTS  "panel-applet-size-hints"
57
 
#define PROPERTY_LOCKED_DOWN "panel-applet-locked-down"
58
 
 
59
 
typedef enum {
60
 
       PANEL_SIZE_XX_SMALL = GNOME_Vertigo_PANEL_XX_SMALL,
61
 
       PANEL_SIZE_X_SMALL  = GNOME_Vertigo_PANEL_X_SMALL,
62
 
       PANEL_SIZE_SMALL    = GNOME_Vertigo_PANEL_SMALL,
63
 
       PANEL_SIZE_MEDIUM   = GNOME_Vertigo_PANEL_MEDIUM,
64
 
       PANEL_SIZE_LARGE    = GNOME_Vertigo_PANEL_LARGE,
65
 
       PANEL_SIZE_X_LARGE  = GNOME_Vertigo_PANEL_X_LARGE,
66
 
       PANEL_SIZE_XX_LARGE = GNOME_Vertigo_PANEL_XX_LARGE 
67
 
} PanelSize;
68
 
 
69
 
/* Keep in sync with panel-applet.h. Uggh. */
70
 
typedef enum {
71
 
        APPLET_FLAGS_NONE   = 0,
72
 
        APPLET_EXPAND_MAJOR = 1 << 0,
73
 
        APPLET_EXPAND_MINOR = 1 << 1,
74
 
        APPLET_HAS_HANDLE   = 1 << 2
75
 
} PanelAppletFlags;
76
 
 
77
 
GQuark
78
 
panel_applet_frame_bonobo_error_quark (void)
79
 
{
80
 
        static GQuark ret = 0;
81
 
 
82
 
        if (ret == 0) {
83
 
                ret = g_quark_from_static_string ("panel_applet_frame_bonobo_error");
84
 
        }
85
 
 
86
 
        return ret;
87
 
}
88
 
 
89
 
static guint
90
 
get_panel_applet_orient (PanelOrientation orientation)
91
 
{
92
 
        /* For some reason libpanel-applet and panel use a different logic for
93
 
         * orientation, so we need to convert it. We should fix this. */
94
 
        switch (orientation) {
95
 
        case PANEL_ORIENTATION_TOP:
96
 
                return 1;
97
 
        case PANEL_ORIENTATION_BOTTOM:
98
 
                return 0;
99
 
        case PANEL_ORIENTATION_LEFT:
100
 
                return 3;
101
 
        case PANEL_ORIENTATION_RIGHT:
102
 
                return 2;
103
 
        default:
104
 
                g_assert_not_reached ();
105
 
                break;
106
 
        }
107
 
}
108
 
 
109
 
static void
110
 
panel_applet_frame_bonobo_update_flags (PanelAppletFrame *frame,
111
 
                                        const CORBA_any  *any)
112
 
{
113
 
        int      flags;
114
 
        gboolean major;
115
 
        gboolean minor;
116
 
        gboolean has_handle;
117
 
        
118
 
        flags = BONOBO_ARG_GET_SHORT (any);
119
 
 
120
 
        major = (flags & APPLET_EXPAND_MAJOR) != 0;
121
 
        minor = (flags & APPLET_EXPAND_MINOR) != 0;
122
 
        has_handle = (flags & APPLET_HAS_HANDLE) != 0;
123
 
 
124
 
        _panel_applet_frame_update_flags (frame, major, minor, has_handle);
125
 
}
126
 
 
127
 
static void
128
 
panel_applet_frame_bonobo_update_size_hints (PanelAppletFrame *frame,
129
 
                                             const CORBA_any  *any)
130
 
{
131
 
        CORBA_sequence_CORBA_long *seq;
132
 
 
133
 
        seq = any->_value;
134
 
 
135
 
        _panel_applet_frame_update_size_hints (frame, seq->_buffer, seq->_length);
136
 
}
137
 
 
138
 
static void
139
 
panel_applet_frame_bonobo_init_properties (PanelAppletFrame *frame)
140
 
{
141
 
        PanelAppletFrameBonobo *bonobo_frame = PANEL_APPLET_FRAME_BONOBO (frame);
142
 
        CORBA_any *any;
143
 
 
144
 
        any = bonobo_pbclient_get_value (bonobo_frame->priv->property_bag,
145
 
                                         PROPERTY_FLAGS,
146
 
                                         BONOBO_ARG_SHORT,
147
 
                                         NULL);
148
 
        if (any) {
149
 
                panel_applet_frame_bonobo_update_flags (frame, any);
150
 
                CORBA_free (any);
151
 
        }
152
 
        
153
 
        any = bonobo_pbclient_get_value (bonobo_frame->priv->property_bag,
154
 
                                         PROPERTY_SIZE_HINTS,
155
 
                                         TC_CORBA_sequence_CORBA_long,
156
 
                                         NULL);
157
 
        if (any) {
158
 
                panel_applet_frame_bonobo_update_size_hints (frame, any);
159
 
                CORBA_free (any);
160
 
        }
161
 
}
162
 
 
163
 
static void
164
 
panel_applet_frame_bonobo_sync_menu_state (PanelAppletFrame *frame,
165
 
                                           gboolean          movable,
166
 
                                           gboolean          removable,
167
 
                                           gboolean          lockable,
168
 
                                           gboolean          locked,
169
 
                                           gboolean          locked_down)
170
 
{
171
 
        PanelAppletFrameBonobo *bonobo_frame = PANEL_APPLET_FRAME_BONOBO (frame);
172
 
 
173
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
174
 
                                      "/commands/LockAppletToPanel",
175
 
                                      "state",
176
 
                                      locked ? "1" : "0",
177
 
                                      NULL);
178
 
 
179
 
        /* First sensitivity */
180
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
181
 
                                      "/commands/LockAppletToPanel",
182
 
                                      "sensitive",
183
 
                                      lockable ? "1" : "0",
184
 
                                      NULL);
185
 
 
186
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
187
 
                                      "/commands/RemoveAppletFromPanel",
188
 
                                      "sensitive",
189
 
                                      (locked && !lockable) ? "0" : (removable ? "1" : "0"),
190
 
                                      NULL);
191
 
 
192
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
193
 
                                      "/commands/MoveApplet",
194
 
                                      "sensitive",
195
 
                                      locked ? "0" : (movable ? "1" : "0"),
196
 
                                      NULL);
197
 
 
198
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
199
 
                                      "/commands/LockAppletToPanel",
200
 
                                      "hidden",
201
 
                                      locked_down ? "1" : "0",
202
 
                                      NULL);
203
 
 
204
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
205
 
                                      "/commands/LockSeparator",
206
 
                                      "hidden",
207
 
                                      locked_down ? "1" : "0",
208
 
                                      NULL);
209
 
 
210
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
211
 
                                      "/commands/RemoveAppletFromPanel",
212
 
                                      "hidden",
213
 
                                      locked_down ? "1" : "0",
214
 
                                      NULL);
215
 
 
216
 
        bonobo_ui_component_set_prop (bonobo_frame->priv->ui_component,
217
 
                                      "/commands/MoveApplet",
218
 
                                      "hidden",
219
 
                                      locked_down ? "1" : "0",
220
 
                                      NULL);
221
 
}
222
 
 
223
 
static void
224
 
panel_applet_frame_bonobo_popup_menu (PanelAppletFrame *frame,
225
 
                                      guint             button,
226
 
                                      guint32           timestamp)
227
 
{
228
 
        PanelAppletFrameBonobo *bonobo_frame = PANEL_APPLET_FRAME_BONOBO (frame);
229
 
        CORBA_Environment env;
230
 
 
231
 
        CORBA_exception_init (&env);
232
 
 
233
 
        GNOME_Vertigo_PanelAppletShell_popup_menu (bonobo_frame->priv->applet_shell,
234
 
                                                   button, timestamp, &env);
235
 
        if (BONOBO_EX (&env))
236
 
                g_warning ("Exception from popup_menu '%s'\n", env._id);
237
 
 
238
 
        CORBA_exception_free (&env);
239
 
}
240
 
 
241
 
static void
242
 
panel_applet_frame_bonobo_change_orientation (PanelAppletFrame *frame,
243
 
                                              PanelOrientation  orientation)
244
 
{
245
 
        PanelAppletFrameBonobo *bonobo_frame = PANEL_APPLET_FRAME_BONOBO (frame);
246
 
        CORBA_unsigned_short orient = 0;
247
 
 
248
 
        switch (orientation) {
249
 
        case PANEL_ORIENTATION_TOP:
250
 
                orient = GNOME_Vertigo_PANEL_ORIENT_DOWN;
251
 
                break;
252
 
        case PANEL_ORIENTATION_BOTTOM:
253
 
                orient = GNOME_Vertigo_PANEL_ORIENT_UP;
254
 
                break;
255
 
        case PANEL_ORIENTATION_LEFT:
256
 
                orient = GNOME_Vertigo_PANEL_ORIENT_RIGHT;
257
 
                break;
258
 
        case PANEL_ORIENTATION_RIGHT:
259
 
                orient = GNOME_Vertigo_PANEL_ORIENT_LEFT;
260
 
                break;
261
 
        default:
262
 
                g_assert_not_reached ();
263
 
                break;
264
 
        }
265
 
 
266
 
        bonobo_pbclient_set_short (bonobo_frame->priv->property_bag, 
267
 
                                   PROPERTY_ORIENT,
268
 
                                   orient,
269
 
                                   NULL);
270
 
 
271
 
        gtk_widget_queue_resize (GTK_WIDGET (frame));
272
 
}
273
 
 
274
 
static void
275
 
panel_applet_frame_bonobo_change_size (PanelAppletFrame *frame,
276
 
                                       guint             size)
277
 
{
278
 
        PanelAppletFrameBonobo *bonobo_frame = PANEL_APPLET_FRAME_BONOBO (frame);
279
 
 
280
 
        /* Normalise the size to the constants defined in the IDL. */
281
 
        size = size <= PANEL_SIZE_XX_SMALL ? PANEL_SIZE_XX_SMALL :
282
 
               size <= PANEL_SIZE_X_SMALL  ? PANEL_SIZE_X_SMALL  :
283
 
               size <= PANEL_SIZE_SMALL    ? PANEL_SIZE_SMALL    :
284
 
               size <= PANEL_SIZE_MEDIUM   ? PANEL_SIZE_MEDIUM   :
285
 
               size <= PANEL_SIZE_LARGE    ? PANEL_SIZE_LARGE    :
286
 
               size <= PANEL_SIZE_X_LARGE  ? PANEL_SIZE_X_LARGE  : PANEL_SIZE_XX_LARGE;
287
 
                 
288
 
        bonobo_pbclient_set_short (bonobo_frame->priv->property_bag, 
289
 
                                   PROPERTY_SIZE,
290
 
                                   size,
291
 
                                   NULL);
292
 
}
293
 
 
294
 
static void
295
 
panel_applet_frame_bonobo_change_background (PanelAppletFrame    *frame,
296
 
                                             PanelBackgroundType  type)
297
 
{
298
 
        PanelAppletFrameBonobo *bonobo_frame = PANEL_APPLET_FRAME_BONOBO (frame);
299
 
        char *bg_str;
300
 
 
301
 
        bg_str = _panel_applet_frame_get_background_string (
302
 
                        frame, PANEL_WIDGET (GTK_WIDGET (frame)->parent), type);
303
 
 
304
 
        if (bg_str != NULL) {
305
 
                bonobo_pbclient_set_string (bonobo_frame->priv->property_bag,
306
 
                                            PROPERTY_BACKGROUND,
307
 
                                            bg_str, NULL);
308
 
 
309
 
                g_free (bg_str);
310
 
        }
311
 
}
312
 
 
313
 
static void
314
 
panel_applet_frame_bonobo_applet_broken (ORBitConnection  *cnx,
315
 
                                         PanelAppletFrame *frame)
316
 
{
317
 
        _panel_applet_frame_applet_broken (frame);
318
 
}
319
 
 
320
 
static void
321
 
popup_handle_remove (BonoboUIComponent *uic,
322
 
                     PanelAppletFrame  *frame,
323
 
                     const gchar       *verbname)
324
 
{
325
 
        _panel_applet_frame_applet_remove (frame);
326
 
}
327
 
 
328
 
static void
329
 
popup_handle_move (BonoboUIComponent *uic,
330
 
                   PanelAppletFrame  *frame,
331
 
                   const gchar       *verbname)
332
 
{
333
 
        _panel_applet_frame_applet_move (frame);
334
 
}
335
 
 
336
 
static void
337
 
listener_popup_handle_lock (BonoboUIComponent            *uic,
338
 
                            const char                   *path,
339
 
                            Bonobo_UIComponent_EventType  type,
340
 
                            const char                   *state,
341
 
                            gpointer                      data)
342
 
{
343
 
        PanelAppletFrame *frame;
344
 
        gboolean          locked;
345
 
 
346
 
        g_assert (!strcmp (path, "LockAppletToPanel"));
347
 
 
348
 
        if (type != Bonobo_UIComponent_STATE_CHANGED)
349
 
                return;
350
 
 
351
 
        if (!state)
352
 
                return;
353
 
 
354
 
        frame = (PanelAppletFrame *) data;
355
 
        locked = (strcmp (state, "1") == 0);
356
 
 
357
 
        _panel_applet_frame_applet_lock (frame, locked);
358
 
 
359
 
        panel_applet_frame_sync_menu_state (frame);
360
 
}
361
 
 
362
 
static BonoboUIVerb popup_verbs [] = {
363
 
        BONOBO_UI_UNSAFE_VERB ("RemoveAppletFromPanel", popup_handle_remove),
364
 
        BONOBO_UI_UNSAFE_VERB ("MoveApplet",            popup_handle_move),
365
 
 
366
 
        BONOBO_UI_VERB_END
367
 
};
368
 
 
369
 
 
370
 
static void
371
 
panel_applet_frame_bonobo_finalize (GObject *object)
372
 
{
373
 
        PanelAppletFrameBonobo *frame = PANEL_APPLET_FRAME_BONOBO (object);
374
 
 
375
 
        if (frame->priv->control) {
376
 
                /* do this before unref'ing every bonobo stuff since it looks
377
 
                 * like we can receive some events when unref'ing them */
378
 
                ORBit_small_unlisten_for_broken (frame->priv->control,
379
 
                                                 G_CALLBACK (panel_applet_frame_bonobo_applet_broken));
380
 
                bonobo_object_release_unref (frame->priv->control, NULL);
381
 
                frame->priv->control = CORBA_OBJECT_NIL;
382
 
        }
383
 
 
384
 
        if (frame->priv->property_bag)
385
 
                bonobo_object_release_unref (
386
 
                        frame->priv->property_bag, NULL);
387
 
 
388
 
        if (frame->priv->applet_shell)
389
 
                bonobo_object_release_unref (
390
 
                        frame->priv->applet_shell, NULL);
391
 
 
392
 
        if (frame->priv->ui_component)
393
 
                bonobo_object_unref (
394
 
                        BONOBO_OBJECT (frame->priv->ui_component));
395
 
 
396
 
        G_OBJECT_CLASS (panel_applet_frame_bonobo_parent_class)->finalize (object);
397
 
}
398
 
 
399
 
static void
400
 
panel_applet_frame_bonobo_init (PanelAppletFrameBonobo *frame)
401
 
{
402
 
        GtkWidget *container;
403
 
 
404
 
        frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
405
 
                                                   PANEL_TYPE_APPLET_FRAME_BONOBO,
406
 
                                                   PanelAppletFrameBonoboPrivate);
407
 
 
408
 
        frame->priv->applet_shell = CORBA_OBJECT_NIL;
409
 
        frame->priv->control      = CORBA_OBJECT_NIL;
410
 
        frame->priv->property_bag = CORBA_OBJECT_NIL;
411
 
        frame->priv->ui_component = NULL;
412
 
}
413
 
 
414
 
static void
415
 
panel_applet_frame_bonobo_class_init (PanelAppletFrameBonoboClass *class)
416
 
{
417
 
        GObjectClass *gobject_class = G_OBJECT_CLASS (class);
418
 
        PanelAppletFrameClass *frame_class = PANEL_APPLET_FRAME_CLASS (class);
419
 
 
420
 
        gobject_class->finalize = panel_applet_frame_bonobo_finalize;
421
 
 
422
 
        frame_class->init_properties = panel_applet_frame_bonobo_init_properties;
423
 
        frame_class->sync_menu_state = panel_applet_frame_bonobo_sync_menu_state;
424
 
        frame_class->popup_menu = panel_applet_frame_bonobo_popup_menu;
425
 
        frame_class->change_orientation = panel_applet_frame_bonobo_change_orientation;
426
 
        frame_class->change_size = panel_applet_frame_bonobo_change_size;
427
 
        frame_class->change_background = panel_applet_frame_bonobo_change_background;
428
 
 
429
 
        g_type_class_add_private (class, sizeof (PanelAppletFrameBonoboPrivate));
430
 
}
431
 
 
432
 
static GNOME_Vertigo_PanelAppletShell
433
 
panel_applet_frame_get_applet_shell (Bonobo_Control control)
434
 
{
435
 
        CORBA_Environment              env;
436
 
        GNOME_Vertigo_PanelAppletShell retval;
437
 
 
438
 
        CORBA_exception_init (&env);
439
 
 
440
 
        retval = Bonobo_Unknown_queryInterface (control, 
441
 
                                                "IDL:GNOME/Vertigo/PanelAppletShell:1.0",
442
 
                                                &env);
443
 
        if (BONOBO_EX (&env)) {
444
 
                g_warning ("Unable to obtain AppletShell interface from control\n");
445
 
 
446
 
                retval = CORBA_OBJECT_NIL;
447
 
        }
448
 
 
449
 
        CORBA_exception_free (&env);
450
 
 
451
 
        return retval;
452
 
}
453
 
 
454
 
static G_CONST_RETURN char *
455
 
panel_applet_frame_get_orient_string (PanelAppletFrame           *frame,
456
 
                                      PanelAppletFrameActivating *frame_act)
457
 
{
458
 
        PanelOrientation  orientation;
459
 
        const char       *retval = NULL;
460
 
 
461
 
        orientation = panel_applet_frame_activating_get_orientation (frame_act);
462
 
 
463
 
        switch (orientation) {
464
 
        case PANEL_ORIENTATION_TOP:
465
 
                retval = "down";
466
 
                break;
467
 
        case PANEL_ORIENTATION_BOTTOM:
468
 
                retval = "up";
469
 
                break;
470
 
        case PANEL_ORIENTATION_LEFT:
471
 
                retval = "right";
472
 
                break;
473
 
        case PANEL_ORIENTATION_RIGHT:
474
 
                retval = "left";
475
 
                break;
476
 
        default:
477
 
                g_assert_not_reached ();
478
 
                break;
479
 
        }
480
 
 
481
 
        return retval;
482
 
}
483
 
 
484
 
static G_CONST_RETURN char *
485
 
panel_applet_frame_get_size_string (PanelAppletFrame           *frame,
486
 
                                    PanelAppletFrameActivating *frame_act)
487
 
{
488
 
        const char *retval = NULL;
489
 
        guint32 size;
490
 
 
491
 
        size = panel_applet_frame_activating_get_size (frame_act);
492
 
 
493
 
        if (size <= PANEL_SIZE_XX_SMALL)
494
 
                retval = "xx-small";
495
 
        else if (size <= PANEL_SIZE_X_SMALL)
496
 
                retval = "x-small";
497
 
        else if (size <= PANEL_SIZE_SMALL)
498
 
                retval = "small";
499
 
        else if (size <= PANEL_SIZE_MEDIUM)
500
 
                retval = "medium";
501
 
        else if (size <= PANEL_SIZE_LARGE)
502
 
                retval = "large";
503
 
        else if (size <= PANEL_SIZE_X_LARGE)
504
 
                retval = "x-large";
505
 
        else
506
 
                retval = "xx-large";
507
 
 
508
 
        return retval;
509
 
}
510
 
 
511
 
static char *
512
 
panel_applet_frame_construct_item (PanelAppletFrame           *frame,
513
 
                                   PanelAppletFrameActivating *frame_act)
514
 
{
515
 
        char *retval;
516
 
        char *conf_path = NULL;
517
 
        char *bg_str = NULL;
518
 
        gboolean locked_down;
519
 
 
520
 
        conf_path = panel_applet_frame_activating_get_conf_path (frame_act);
521
 
        //FIXME vuntz
522
 
#if 0
523
 
        bg_str = _panel_applet_frame_get_background_string (
524
 
                                frame, panel, panel->background.type);
525
 
#endif
526
 
 
527
 
        if (bg_str == NULL)
528
 
                bg_str = g_strdup ("");
529
 
 
530
 
        locked_down = panel_applet_frame_activating_get_locked_down (frame_act);
531
 
 
532
 
        retval = g_strdup_printf (
533
 
                        "prefs_key=%s;"
534
 
                        "background=%s;orient=%s;size=%s;locked_down=%s",
535
 
                        conf_path, bg_str,
536
 
                        panel_applet_frame_get_orient_string (frame, frame_act),
537
 
                        panel_applet_frame_get_size_string (frame, frame_act),
538
 
                        locked_down ? "true" : "false");
539
 
 
540
 
        g_free (conf_path);
541
 
        g_free (bg_str);
542
 
 
543
 
        return retval;
544
 
}
545
 
 
546
 
static void
547
 
panel_applet_frame_event_listener (BonoboListener    *listener,
548
 
                                   const char        *event,
549
 
                                   const CORBA_any   *any,
550
 
                                   CORBA_Environment *ev,
551
 
                                   PanelAppletFrame  *frame)
552
 
{
553
 
        if (!strcmp (event, "Bonobo/Property:change:" PROPERTY_FLAGS))
554
 
                panel_applet_frame_bonobo_update_flags (frame, any);
555
 
 
556
 
        else if (!strcmp (event, "Bonobo/Property:change:" PROPERTY_SIZE_HINTS))
557
 
                panel_applet_frame_bonobo_update_size_hints (frame, any);
558
 
}
559
 
 
560
 
static void
561
 
panel_applet_frame_bonobo_activated (CORBA_Object  object,
562
 
                                     const char   *error_reason,
563
 
                                     gpointer      data)
564
 
{
565
 
        PanelAppletFrameActivating *frame_act;
566
 
        PanelAppletFrameBonobo *bonobo_frame;
567
 
        PanelAppletFrame   *frame;
568
 
        GtkWidget          *widget;
569
 
        BonoboControlFrame *control_frame;
570
 
        Bonobo_Control      control;
571
 
        Bonobo_ItemContainer container;
572
 
        CORBA_Environment   corba_ev;
573
 
        AppletInfo         *info;
574
 
        char               *error;
575
 
        char               *item_name;
576
 
        GError             *gerror = NULL;
577
 
 
578
 
        widget = NULL;
579
 
        bonobo_frame = PANEL_APPLET_FRAME_BONOBO (data);
580
 
        frame = PANEL_APPLET_FRAME (data);
581
 
        frame_act = g_object_get_data (G_OBJECT (frame), "panel-applet-frame-activating");
582
 
        g_object_set_data (G_OBJECT (frame), "panel-applet-frame-activating", NULL);
583
 
 
584
 
        /* according to the source of bonobo control == NULL && no
585
 
           exception can happen, so handle it */
586
 
        if (error_reason != NULL || object == CORBA_OBJECT_NIL) {
587
 
                gerror = g_error_new_literal (panel_applet_frame_bonobo_error_quark (), 0, error_reason);
588
 
                goto error_out;
589
 
        }
590
 
 
591
 
        CORBA_exception_init (&corba_ev);
592
 
 
593
 
        item_name = panel_applet_frame_construct_item (frame,
594
 
                                                       frame_act);
595
 
 
596
 
        bonobo_frame->priv->control = CORBA_OBJECT_NIL;
597
 
        container = Bonobo_Unknown_queryInterface (object,
598
 
                                                   "IDL:Bonobo/ItemContainer:1.0",
599
 
                                                   &corba_ev);
600
 
        if (!BONOBO_EX (&corba_ev) && container != CORBA_OBJECT_NIL) {
601
 
                Bonobo_Unknown containee;
602
 
 
603
 
                containee = Bonobo_ItemContainer_getObjectByName (container,
604
 
                                                                  item_name,
605
 
                                                                  TRUE,
606
 
                                                                  &corba_ev);
607
 
                bonobo_object_release_unref (container, NULL);
608
 
 
609
 
                if (!BONOBO_EX (&corba_ev) && containee != CORBA_OBJECT_NIL) {
610
 
                        bonobo_frame->priv->control =
611
 
                                Bonobo_Unknown_queryInterface (containee,
612
 
                                                               "IDL:Bonobo/Control:1.0",
613
 
                                                               &corba_ev);
614
 
 
615
 
                        bonobo_object_release_unref (containee, NULL);
616
 
                }
617
 
        }
618
 
        g_free (item_name);
619
 
 
620
 
        if (bonobo_frame->priv->control == CORBA_OBJECT_NIL) {
621
 
                error = bonobo_exception_get_text (&corba_ev);
622
 
                gerror = g_error_new (panel_applet_frame_bonobo_error_quark (), 0, "failed to get Bonobo/Control interface:\n", error);
623
 
                CORBA_exception_free (&corba_ev);
624
 
                bonobo_object_release_unref (object, NULL);
625
 
                g_free (error);
626
 
                goto error_out;
627
 
        }
628
 
 
629
 
        widget = bonobo_widget_new_control_from_objref (bonobo_frame->priv->control,
630
 
                                                        CORBA_OBJECT_NIL);
631
 
 
632
 
        CORBA_exception_free (&corba_ev);
633
 
        bonobo_object_release_unref (object, NULL);
634
 
 
635
 
        if (!widget) {
636
 
                gerror = g_error_new_literal (panel_applet_frame_bonobo_error_quark (), 0, "no widget created");
637
 
                goto error_out;
638
 
        }
639
 
 
640
 
        control_frame = bonobo_widget_get_control_frame (BONOBO_WIDGET (widget));
641
 
        if (control_frame == NULL) {
642
 
                gerror = g_error_new_literal (panel_applet_frame_bonobo_error_quark (), 0, "cannot get control frame");
643
 
                goto error_out;
644
 
        }
645
 
 
646
 
        bonobo_frame->priv->property_bag = 
647
 
                bonobo_control_frame_get_control_property_bag (control_frame,
648
 
                                                               &corba_ev);
649
 
        if (bonobo_frame->priv->property_bag == NULL || BONOBO_EX (&corba_ev)) {
650
 
                error = bonobo_exception_get_text (&corba_ev);
651
 
                CORBA_exception_free (&corba_ev);
652
 
                gerror = g_error_new (panel_applet_frame_bonobo_error_quark (), 0, "cannot get property bag frame:\n%s", error);
653
 
                g_free (error);
654
 
                goto error_out;
655
 
        }
656
 
 
657
 
        bonobo_event_source_client_add_listener (bonobo_frame->priv->property_bag,
658
 
                                                 (BonoboListenerCallbackFn) panel_applet_frame_event_listener,
659
 
                                                 "Bonobo/Property:change:panel-applet",
660
 
                                                 NULL,
661
 
                                                 frame);
662
 
        
663
 
        bonobo_frame->priv->ui_component =
664
 
                bonobo_control_frame_get_popup_component (control_frame,
665
 
                                                          &corba_ev);
666
 
        if (bonobo_frame->priv->ui_component == NULL || BONOBO_EX (&corba_ev)) {
667
 
                error = bonobo_exception_get_text (&corba_ev);
668
 
                CORBA_exception_free (&corba_ev);
669
 
                gerror = g_error_new (panel_applet_frame_bonobo_error_quark (), 0, "cannot get popup component:\n%s", error);
670
 
                g_free (error);
671
 
                goto error_out;
672
 
        }
673
 
 
674
 
        bonobo_ui_util_set_ui (bonobo_frame->priv->ui_component, DATADIR,
675
 
                               "GNOME_Panel_Popup.xml", "panel", NULL);
676
 
 
677
 
        bonobo_ui_component_add_listener (bonobo_frame->priv->ui_component,
678
 
                                          "LockAppletToPanel",
679
 
                                          listener_popup_handle_lock,
680
 
                                          frame);
681
 
 
682
 
        bonobo_ui_component_add_verb_list_with_data (
683
 
                bonobo_frame->priv->ui_component, popup_verbs, frame);
684
 
 
685
 
        control = bonobo_control_frame_get_control (control_frame);
686
 
        if (!control) {
687
 
                CORBA_exception_free (&corba_ev);
688
 
                gerror = g_error_new_literal (panel_applet_frame_bonobo_error_quark (), 0, "cannot get control");
689
 
                goto error_out;
690
 
        }
691
 
 
692
 
        bonobo_frame->priv->applet_shell = panel_applet_frame_get_applet_shell (control);
693
 
        if (bonobo_frame->priv->applet_shell == CORBA_OBJECT_NIL) {
694
 
                CORBA_exception_free (&corba_ev);
695
 
                gerror = g_error_new_literal (panel_applet_frame_bonobo_error_quark (), 0, "cannot get applet shell");
696
 
                goto error_out;
697
 
        }
698
 
 
699
 
        CORBA_exception_free (&corba_ev);
700
 
 
701
 
        ORBit_small_listen_for_broken (object,
702
 
                                       G_CALLBACK (panel_applet_frame_bonobo_applet_broken),
703
 
                                       frame);
704
 
 
705
 
        gtk_container_add (GTK_CONTAINER (frame), widget);
706
 
 
707
 
        goto out;
708
 
 
709
 
error_out:
710
 
        if (widget)
711
 
                g_object_unref (widget);
712
 
        if (!gerror)
713
 
                gerror = g_error_new_literal (panel_applet_frame_bonobo_error_quark (), 0, "unknown error");
714
 
 
715
 
out:
716
 
        _panel_applet_frame_activated (frame, frame_act, gerror);
717
 
}
718
 
 
719
 
gboolean
720
 
panel_applet_frame_bonobo_load (const gchar                 *iid,
721
 
                                PanelAppletFrameActivating  *frame_act)
722
 
{
723
 
        PanelAppletFrameBonobo *bonobo_frame;
724
 
        PanelAppletFrame       *frame;
725
 
        CORBA_Environment       ev;
726
 
 
727
 
        g_return_val_if_fail (iid != NULL, FALSE);
728
 
        g_return_val_if_fail (frame_act != NULL, FALSE);
729
 
 
730
 
        if (!panel_applets_manager_factory_activate (iid))
731
 
                return FALSE;
732
 
 
733
 
        bonobo_frame = g_object_new (PANEL_TYPE_APPLET_FRAME_BONOBO, NULL);
734
 
        frame = PANEL_APPLET_FRAME (bonobo_frame);
735
 
        _panel_applet_frame_set_iid (frame, iid);
736
 
 
737
 
        g_object_set_data (G_OBJECT (frame), "panel-applet-frame-activating", frame_act);
738
 
 
739
 
        CORBA_exception_init (&ev);
740
 
 
741
 
        bonobo_activation_activate_from_id_async ((gchar *) iid, 0,
742
 
                                                  (BonoboActivationCallback) panel_applet_frame_bonobo_activated,
743
 
                                                  frame, &ev);
744
 
 
745
 
        CORBA_exception_free (&ev);
746
 
 
747
 
        return TRUE;
748
 
}