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

« back to all changes in this revision

Viewing changes to .pc/25_dynamic_fusa_detection.patch/gnome-panel/panel-applet-frame.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.c: panel side container for applets
4
 
 *
5
 
 * Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
6
 
 * Copyright (C) 2001 - 2003 Sun Microsystems, Inc.
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
 
#include <string.h>
29
 
 
30
 
#include <glib/gi18n.h>
31
 
 
32
 
#include <gconf/gconf.h>
33
 
#include <gdk/gdk.h>
34
 
#include <gdk/gdkx.h>
35
 
 
36
 
#include "panel-applets-manager.h"
37
 
#include "panel-profile.h"
38
 
#include "panel.h"
39
 
#include "applet.h"
40
 
#include "panel-marshal.h"
41
 
#include "panel-background.h"
42
 
#include "panel-lockdown.h"
43
 
#include "panel-stock-icons.h"
44
 
#include "xstuff.h"
45
 
#include "panel-compatibility.h"
46
 
 
47
 
#include "panel-applet-frame.h"
48
 
 
49
 
static void panel_applet_frame_activating_free (PanelAppletFrameActivating *frame_act);
50
 
 
51
 
static void panel_applet_frame_loading_failed  (const char  *iid,
52
 
                                                PanelWidget *panel,
53
 
                                                const char  *id);
54
 
 
55
 
static void panel_applet_frame_load            (const gchar *iid,
56
 
                                                PanelWidget *panel,
57
 
                                                gboolean     locked,
58
 
                                                int          position,
59
 
                                                gboolean     exactpos,
60
 
                                                const char  *id);
61
 
 
62
 
struct _PanelAppletFrameActivating {
63
 
        gboolean     locked;
64
 
        PanelWidget *panel;
65
 
        int          position;
66
 
        gboolean     exactpos;
67
 
        char        *id;
68
 
};
69
 
 
70
 
/* PanelAppletFrame implementation */
71
 
 
72
 
G_DEFINE_TYPE (PanelAppletFrame, panel_applet_frame, GTK_TYPE_EVENT_BOX)
73
 
 
74
 
#define PANEL_APPLET_FRAME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET_FRAME, PanelAppletFramePrivate))
75
 
 
76
 
#define HANDLE_SIZE 10
77
 
#define PANEL_APPLET_PREFS_KEY "/apps/panel/applets/%s/prefs"
78
 
 
79
 
struct _PanelAppletFramePrivate {
80
 
        PanelWidget     *panel;
81
 
        AppletInfo      *applet_info;
82
 
 
83
 
        PanelOrientation orientation;
84
 
 
85
 
        gchar           *iid;
86
 
 
87
 
        GtkAllocation    child_allocation;
88
 
        GdkRectangle     handle_rect;
89
 
 
90
 
        guint            has_handle : 1;
91
 
};
92
 
 
93
 
static void
94
 
panel_applet_frame_paint (GtkWidget    *widget,
95
 
                          GdkRectangle *area)
96
 
{
97
 
        PanelAppletFrame *frame;
98
 
 
99
 
        frame = PANEL_APPLET_FRAME (widget);
100
 
 
101
 
        if (!frame->priv->has_handle)
102
 
                return;
103
 
  
104
 
        if (gtk_widget_is_drawable (widget)) {
105
 
                GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
106
 
 
107
 
                switch (frame->priv->orientation) {
108
 
                case PANEL_ORIENTATION_TOP:
109
 
                case PANEL_ORIENTATION_BOTTOM:
110
 
                        orientation = GTK_ORIENTATION_VERTICAL;
111
 
                        break;
112
 
                case PANEL_ORIENTATION_LEFT:
113
 
                case PANEL_ORIENTATION_RIGHT:
114
 
                        orientation = GTK_ORIENTATION_HORIZONTAL;
115
 
                        break;
116
 
                default:
117
 
                        g_assert_not_reached ();
118
 
                        break;
119
 
                }
120
 
 
121
 
                gtk_paint_handle (
122
 
                        gtk_widget_get_style (widget), gtk_widget_get_window (widget),
123
 
                        gtk_widget_get_state (widget),
124
 
                        GTK_SHADOW_OUT,
125
 
                        area, widget, "handlebox",
126
 
                        frame->priv->handle_rect.x,
127
 
                        frame->priv->handle_rect.y,
128
 
                        frame->priv->handle_rect.width,
129
 
                        frame->priv->handle_rect.height,
130
 
                        orientation);
131
 
        }
132
 
}
133
 
 
134
 
static gboolean
135
 
panel_applet_frame_expose (GtkWidget      *widget,
136
 
                           GdkEventExpose *event)
137
 
{
138
 
        if (gtk_widget_is_drawable (widget)) {
139
 
                GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->expose_event (widget, event);
140
 
 
141
 
                panel_applet_frame_paint (widget, &event->area);
142
 
        }
143
 
 
144
 
        return FALSE;
145
 
}
146
 
 
147
 
static void
148
 
panel_applet_frame_update_background_size (PanelAppletFrame *frame,
149
 
                                           GtkAllocation    *old_allocation,
150
 
                                           GtkAllocation    *new_allocation)
151
 
{
152
 
        PanelBackground *background;
153
 
 
154
 
        if (old_allocation->x      == new_allocation->x &&
155
 
            old_allocation->y      == new_allocation->y &&
156
 
            old_allocation->width  == new_allocation->width &&
157
 
            old_allocation->height == new_allocation->height)
158
 
                return;
159
 
 
160
 
        background = &frame->priv->panel->background;
161
 
 
162
 
        if (background->type == PANEL_BACK_NONE ||
163
 
           (background->type == PANEL_BACK_COLOR && !background->has_alpha))
164
 
                return;
165
 
 
166
 
        panel_applet_frame_change_background (frame, background->type);
167
 
}
168
 
 
169
 
static void
170
 
panel_applet_frame_size_request (GtkWidget      *widget,
171
 
                                 GtkRequisition *requisition)
172
 
{
173
 
        PanelAppletFrame *frame;
174
 
        GtkBin           *bin;
175
 
        GtkWidget        *child;
176
 
        GtkRequisition    child_requisition;
177
 
        guint             border_width;
178
 
 
179
 
        frame = PANEL_APPLET_FRAME (widget);
180
 
        bin = GTK_BIN (widget);
181
 
 
182
 
        if (!frame->priv->has_handle) {
183
 
                GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->size_request (widget, requisition);
184
 
                return;
185
 
        }
186
 
 
187
 
        child = gtk_bin_get_child (bin);
188
 
        if (child && gtk_widget_get_visible (child)) {
189
 
                gtk_widget_size_request (child, &child_requisition);
190
 
 
191
 
                requisition->width  = child_requisition.width;
192
 
                requisition->height = child_requisition.height;
193
 
        }
194
 
 
195
 
        border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
196
 
        requisition->width += border_width;
197
 
        requisition->height += border_width;
198
 
 
199
 
        switch (frame->priv->orientation) {
200
 
        case PANEL_ORIENTATION_TOP:
201
 
        case PANEL_ORIENTATION_BOTTOM:
202
 
                requisition->width += HANDLE_SIZE;
203
 
                break;
204
 
        case PANEL_ORIENTATION_LEFT:
205
 
        case PANEL_ORIENTATION_RIGHT:
206
 
                requisition->height += HANDLE_SIZE;
207
 
                break;
208
 
        default:
209
 
                g_assert_not_reached ();
210
 
                break;
211
 
        }
212
 
}
213
 
 
214
 
static void
215
 
panel_applet_frame_size_allocate (GtkWidget     *widget,
216
 
                                  GtkAllocation *allocation)
217
 
{
218
 
        PanelAppletFrame *frame;
219
 
        GtkBin           *bin;
220
 
        GtkWidget        *child;
221
 
        GdkWindow        *window;
222
 
        GtkAllocation     new_allocation;
223
 
        GtkAllocation     old_allocation;
224
 
        GtkAllocation     widget_allocation;
225
 
 
226
 
        gtk_widget_get_allocation (widget, &widget_allocation);
227
 
 
228
 
        old_allocation.x      = widget_allocation.x;
229
 
        old_allocation.y      = widget_allocation.y;
230
 
        old_allocation.width  = widget_allocation.width;
231
 
        old_allocation.height = widget_allocation.height;
232
 
 
233
 
        frame = PANEL_APPLET_FRAME (widget);
234
 
        bin = GTK_BIN (widget);
235
 
 
236
 
        if (!frame->priv->has_handle) {
237
 
                GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->size_allocate (widget,
238
 
                                                                                   allocation);
239
 
                panel_applet_frame_update_background_size (frame,
240
 
                                                           &old_allocation,
241
 
                                                           allocation);
242
 
                return;
243
 
        }
244
 
 
245
 
        window = gtk_widget_get_window (widget);
246
 
        child = gtk_bin_get_child (bin);
247
 
        gtk_widget_set_allocation (widget, allocation);
248
 
 
249
 
        frame->priv->handle_rect.x = 0;
250
 
        frame->priv->handle_rect.y = 0;
251
 
 
252
 
        switch (frame->priv->orientation) {
253
 
        case PANEL_ORIENTATION_TOP:
254
 
        case PANEL_ORIENTATION_BOTTOM:
255
 
                frame->priv->handle_rect.width  = HANDLE_SIZE;
256
 
                frame->priv->handle_rect.height = allocation->height;
257
 
 
258
 
                if (gtk_widget_get_direction (GTK_WIDGET (frame)) !=
259
 
                    GTK_TEXT_DIR_RTL) {
260
 
                        frame->priv->handle_rect.x = 0;
261
 
                        new_allocation.x = HANDLE_SIZE;
262
 
                } else {
263
 
                        frame->priv->handle_rect.x = allocation->width - HANDLE_SIZE;
264
 
                        new_allocation.x = 0;
265
 
                }
266
 
 
267
 
                new_allocation.y      = 0;
268
 
                new_allocation.width  = allocation->width - HANDLE_SIZE;
269
 
                new_allocation.height = allocation->height;
270
 
                break;
271
 
        case PANEL_ORIENTATION_LEFT:
272
 
        case PANEL_ORIENTATION_RIGHT:
273
 
                frame->priv->handle_rect.width  = allocation->width;
274
 
                frame->priv->handle_rect.height = HANDLE_SIZE;
275
 
 
276
 
                new_allocation.x      = 0;
277
 
                new_allocation.y      = HANDLE_SIZE;
278
 
                new_allocation.width  = allocation->width;
279
 
                new_allocation.height = allocation->height - HANDLE_SIZE;
280
 
                break;
281
 
        default:
282
 
                g_assert_not_reached ();
283
 
                break;
284
 
        }
285
 
 
286
 
        new_allocation.width  = MAX (1, new_allocation.width);
287
 
        new_allocation.height = MAX (1, new_allocation.height);
288
 
 
289
 
        /* If the child allocation changed, that means that the frame is drawn
290
 
         * in a new place, so we must redraw the entire widget.
291
 
         */
292
 
        if (gtk_widget_get_mapped (widget) &&
293
 
            (new_allocation.x != frame->priv->child_allocation.x ||
294
 
             new_allocation.y != frame->priv->child_allocation.y ||
295
 
             new_allocation.width != frame->priv->child_allocation.width ||
296
 
             new_allocation.height != frame->priv->child_allocation.height))
297
 
                gdk_window_invalidate_rect (window, &widget_allocation, FALSE);
298
 
 
299
 
        if (gtk_widget_get_realized (widget)) {
300
 
                guint border_width;
301
 
 
302
 
                border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
303
 
                gdk_window_move_resize (window,
304
 
                        allocation->x + border_width,
305
 
                        allocation->y + border_width,
306
 
                        MAX (allocation->width - border_width * 2, 0),
307
 
                        MAX (allocation->height - border_width * 2, 0));
308
 
        }
309
 
 
310
 
        if (child && gtk_widget_get_visible (child))
311
 
                gtk_widget_size_allocate (child, &new_allocation);
312
 
  
313
 
        frame->priv->child_allocation = new_allocation;
314
 
 
315
 
        panel_applet_frame_update_background_size (frame,
316
 
                                                   &old_allocation,
317
 
                                                   allocation);
318
 
}
319
 
 
320
 
static inline gboolean
321
 
button_event_in_rect (GdkEventButton *event,
322
 
                      GdkRectangle   *rect)
323
 
{
324
 
        if (event->x >= rect->x &&
325
 
            event->x <= (rect->x + rect->width) &&
326
 
            event->y >= rect->y &&
327
 
            event->y <= (rect->y + rect->height))
328
 
                return TRUE;
329
 
 
330
 
        return FALSE;
331
 
}
332
 
 
333
 
static gboolean
334
 
panel_applet_frame_button_changed (GtkWidget      *widget,
335
 
                                   GdkEventButton *event)
336
 
{
337
 
        PanelAppletFrame *frame;
338
 
        gboolean          handled = FALSE;
339
 
 
340
 
        frame = PANEL_APPLET_FRAME (widget);
341
 
 
342
 
        if (!frame->priv->has_handle)
343
 
                return handled;
344
 
 
345
 
        if (event->window != gtk_widget_get_window (widget))
346
 
                return FALSE;
347
 
 
348
 
        switch (event->button) {
349
 
        case 1:
350
 
        case 2:
351
 
                if (button_event_in_rect (event, &frame->priv->handle_rect)) {
352
 
                        if (event->type == GDK_BUTTON_PRESS ||
353
 
                            event->type == GDK_2BUTTON_PRESS) {
354
 
                                panel_widget_applet_drag_start (
355
 
                                        frame->priv->panel, GTK_WIDGET (frame),
356
 
                                        PW_DRAG_OFF_CURSOR, event->time);
357
 
                                handled = TRUE;
358
 
                        } else if (event->type == GDK_BUTTON_RELEASE) {
359
 
                                panel_widget_applet_drag_end (frame->priv->panel);
360
 
                                handled = TRUE;
361
 
                        }
362
 
                }
363
 
                break;
364
 
        case 3:
365
 
                if (event->type == GDK_BUTTON_PRESS ||
366
 
                    event->type == GDK_2BUTTON_PRESS) {
367
 
                        gdk_pointer_ungrab (GDK_CURRENT_TIME);
368
 
 
369
 
                        PANEL_APPLET_FRAME_GET_CLASS (frame)->popup_menu (frame,
370
 
                                                                          event->button,
371
 
                                                                          event->time);
372
 
 
373
 
                        handled = TRUE;
374
 
                } else if (event->type == GDK_BUTTON_RELEASE)
375
 
                        handled = TRUE;
376
 
                break;
377
 
        default:
378
 
                break;
379
 
        }
380
 
 
381
 
        return handled;
382
 
}
383
 
 
384
 
static void
385
 
panel_applet_frame_finalize (GObject *object)
386
 
{
387
 
        PanelAppletFrame *frame = PANEL_APPLET_FRAME (object);
388
 
 
389
 
        panel_applets_manager_factory_deactivate (frame->priv->iid);
390
 
 
391
 
        panel_lockdown_notify_remove (G_CALLBACK (panel_applet_frame_sync_menu_state),
392
 
                                      frame);
393
 
 
394
 
        g_free (frame->priv->iid);
395
 
        frame->priv->iid = NULL;
396
 
 
397
 
        G_OBJECT_CLASS (panel_applet_frame_parent_class)->finalize (object);
398
 
}
399
 
 
400
 
static void
401
 
panel_applet_frame_class_init (PanelAppletFrameClass *klass)
402
 
{
403
 
        GObjectClass   *gobject_class = (GObjectClass *) klass;
404
 
        GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
405
 
 
406
 
        gobject_class->finalize = panel_applet_frame_finalize;
407
 
 
408
 
        widget_class->expose_event         = panel_applet_frame_expose;
409
 
        widget_class->size_request         = panel_applet_frame_size_request;
410
 
        widget_class->size_allocate        = panel_applet_frame_size_allocate;
411
 
        widget_class->button_press_event   = panel_applet_frame_button_changed;
412
 
        widget_class->button_release_event = panel_applet_frame_button_changed;
413
 
 
414
 
        g_type_class_add_private (klass, sizeof (PanelAppletFramePrivate));
415
 
}
416
 
 
417
 
static void
418
 
panel_applet_frame_init (PanelAppletFrame *frame)
419
 
{
420
 
        frame->priv = PANEL_APPLET_FRAME_GET_PRIVATE (frame);
421
 
 
422
 
        frame->priv->panel       = NULL;
423
 
        frame->priv->orientation = PANEL_ORIENTATION_TOP;
424
 
        frame->priv->applet_info = NULL;
425
 
        frame->priv->has_handle  = FALSE;
426
 
}
427
 
 
428
 
static void
429
 
panel_applet_frame_init_properties (PanelAppletFrame *frame)
430
 
{
431
 
        PANEL_APPLET_FRAME_GET_CLASS (frame)->init_properties (frame);
432
 
}
433
 
 
434
 
void
435
 
panel_applet_frame_sync_menu_state (PanelAppletFrame *frame)
436
 
{
437
 
        PanelWidget *panel_widget;
438
 
        gboolean     locked_down;
439
 
        gboolean     locked;
440
 
        gboolean     lockable;
441
 
        gboolean     movable;
442
 
        gboolean     removable;
443
 
 
444
 
        panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame)));
445
 
 
446
 
        movable = panel_applet_can_freely_move (frame->priv->applet_info);
447
 
        removable = panel_profile_id_lists_are_writable ();
448
 
        lockable = panel_applet_lockable (frame->priv->applet_info);
449
 
 
450
 
        locked = panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame));
451
 
        locked_down = panel_lockdown_get_locked_down ();
452
 
 
453
 
        PANEL_APPLET_FRAME_GET_CLASS (frame)->sync_menu_state (frame, movable, removable, lockable, locked, locked_down);
454
 
}
455
 
 
456
 
void
457
 
panel_applet_frame_change_orientation (PanelAppletFrame *frame,
458
 
                                       PanelOrientation  orientation)
459
 
{
460
 
        if (orientation == frame->priv->orientation)
461
 
                return;
462
 
 
463
 
        frame->priv->orientation = orientation;
464
 
        PANEL_APPLET_FRAME_GET_CLASS (frame)->change_orientation (frame, orientation);
465
 
}
466
 
 
467
 
void
468
 
panel_applet_frame_change_size (PanelAppletFrame *frame,
469
 
                                guint             size)
470
 
{
471
 
        PANEL_APPLET_FRAME_GET_CLASS (frame)->change_size (frame, size);
472
 
}
473
 
 
474
 
void
475
 
panel_applet_frame_change_background (PanelAppletFrame    *frame,
476
 
                                      PanelBackgroundType  type)
477
 
{
478
 
        GtkWidget *parent;
479
 
 
480
 
        g_return_if_fail (PANEL_IS_APPLET_FRAME (frame));
481
 
 
482
 
        parent = gtk_widget_get_parent (GTK_WIDGET (frame));
483
 
 
484
 
        g_return_if_fail (PANEL_IS_WIDGET (parent));
485
 
 
486
 
        if (frame->priv->has_handle) {
487
 
                PanelBackground *background;
488
 
 
489
 
                background = &PANEL_WIDGET (parent)->background;
490
 
                panel_background_change_background_on_widget (background,
491
 
                                                              GTK_WIDGET (frame));
492
 
        }
493
 
 
494
 
        PANEL_APPLET_FRAME_GET_CLASS (frame)->change_background (frame, type);
495
 
}
496
 
 
497
 
void
498
 
panel_applet_frame_set_panel (PanelAppletFrame *frame,
499
 
                              PanelWidget      *panel)
500
 
{
501
 
        g_return_if_fail (PANEL_IS_APPLET_FRAME (frame));
502
 
        g_return_if_fail (PANEL_IS_WIDGET (panel));
503
 
 
504
 
        frame->priv->panel = panel;
505
 
}
506
 
 
507
 
void
508
 
_panel_applet_frame_set_iid (PanelAppletFrame *frame,
509
 
                             const gchar      *iid)
510
 
{
511
 
        if (frame->priv->iid)
512
 
                g_free (frame->priv->iid);
513
 
        frame->priv->iid = g_strdup (iid);
514
 
}
515
 
 
516
 
void
517
 
_panel_applet_frame_activated (PanelAppletFrame           *frame,
518
 
                               PanelAppletFrameActivating *frame_act,
519
 
                               GError                     *error)
520
 
{
521
 
        AppletInfo *info;
522
 
 
523
 
        g_assert (frame->priv->iid != NULL);
524
 
 
525
 
        if (error != NULL) {
526
 
                g_warning ("Failed to load applet %s:\n%s",
527
 
                           frame->priv->iid, error->message);
528
 
                g_error_free (error);
529
 
 
530
 
                panel_applet_frame_loading_failed (frame->priv->iid,
531
 
                                                   frame_act->panel,
532
 
                                                   frame_act->id);
533
 
                panel_applet_frame_activating_free (frame_act);
534
 
                gtk_widget_destroy (GTK_WIDGET (frame));
535
 
 
536
 
                return;
537
 
        }
538
 
 
539
 
        frame->priv->panel = frame_act->panel;
540
 
        gtk_widget_show_all (GTK_WIDGET (frame));
541
 
 
542
 
        info = panel_applet_register (GTK_WIDGET (frame), GTK_WIDGET (frame),
543
 
                                      NULL, frame->priv->panel,
544
 
                                      frame_act->locked, frame_act->position,
545
 
                                      frame_act->exactpos, PANEL_OBJECT_APPLET,
546
 
                                      frame_act->id);
547
 
        frame->priv->applet_info = info;
548
 
 
549
 
        panel_widget_set_applet_size_constrained (frame->priv->panel,
550
 
                                                  GTK_WIDGET (frame), TRUE);
551
 
 
552
 
        panel_applet_frame_sync_menu_state (frame);
553
 
        panel_applet_frame_init_properties (frame);
554
 
 
555
 
        panel_lockdown_notify_add (G_CALLBACK (panel_applet_frame_sync_menu_state),
556
 
                                   frame);
557
 
 
558
 
        panel_applet_stop_loading (frame_act->id);
559
 
        panel_applet_frame_activating_free (frame_act);
560
 
}
561
 
 
562
 
void
563
 
_panel_applet_frame_update_flags (PanelAppletFrame *frame,
564
 
                                  gboolean          major,
565
 
                                  gboolean          minor,
566
 
                                  gboolean          has_handle)
567
 
{
568
 
        gboolean old_has_handle;
569
 
 
570
 
        panel_widget_set_applet_expandable (
571
 
                frame->priv->panel, GTK_WIDGET (frame), major, minor);
572
 
 
573
 
        old_has_handle = frame->priv->has_handle;
574
 
        frame->priv->has_handle = has_handle;
575
 
 
576
 
        if (!old_has_handle && frame->priv->has_handle) {
577
 
                /* we've added an handle, so we need to get the background for
578
 
                 * it */
579
 
                PanelBackground *background;
580
 
 
581
 
                background = &frame->priv->panel->background;
582
 
                panel_applet_frame_change_background (frame, background->type);
583
 
        }
584
 
}
585
 
 
586
 
void
587
 
_panel_applet_frame_update_size_hints (PanelAppletFrame *frame,
588
 
                                       gint             *size_hints,
589
 
                                       guint             n_elements)
590
 
{
591
 
        if (frame->priv->has_handle) {
592
 
                gint extra_size = HANDLE_SIZE + 1;
593
 
                gint i;
594
 
 
595
 
                for (i = 0; i < n_elements; i++)
596
 
                        size_hints[i] += extra_size;
597
 
        }
598
 
 
599
 
        /* It takes the ownership of size-hints array */
600
 
        panel_widget_set_applet_size_hints (frame->priv->panel,
601
 
                                            GTK_WIDGET (frame),
602
 
                                            size_hints,
603
 
                                            n_elements);
604
 
}
605
 
 
606
 
char *
607
 
_panel_applet_frame_get_background_string (PanelAppletFrame    *frame,
608
 
                                           PanelWidget         *panel,
609
 
                                           PanelBackgroundType  type)
610
 
{
611
 
        GtkAllocation allocation;
612
 
        int x;
613
 
        int y;
614
 
 
615
 
        gtk_widget_get_allocation (GTK_WIDGET (frame), &allocation);
616
 
 
617
 
        x = allocation.x;
618
 
        y = allocation.y;
619
 
 
620
 
        if (frame->priv->has_handle) {
621
 
                switch (frame->priv->orientation) {
622
 
                case PANEL_ORIENTATION_TOP:
623
 
                case PANEL_ORIENTATION_BOTTOM:
624
 
                        if (gtk_widget_get_direction (GTK_WIDGET (frame)) !=
625
 
                            GTK_TEXT_DIR_RTL)
626
 
                                x += frame->priv->handle_rect.width;
627
 
                        break;
628
 
                case PANEL_ORIENTATION_LEFT:
629
 
                case PANEL_ORIENTATION_RIGHT:
630
 
                        y += frame->priv->handle_rect.height;
631
 
                        break;
632
 
                default:
633
 
                        g_assert_not_reached ();
634
 
                        break;
635
 
                }
636
 
        }
637
 
 
638
 
        return panel_background_make_string (&panel->background, x, y);
639
 
}
640
 
 
641
 
static void
642
 
panel_applet_frame_reload_response (GtkWidget        *dialog,
643
 
                                    int               response,
644
 
                                    PanelAppletFrame *frame)
645
 
{
646
 
        AppletInfo *info;
647
 
 
648
 
        g_return_if_fail (PANEL_IS_APPLET_FRAME (frame));
649
 
 
650
 
        if (!frame->priv->iid || !frame->priv->panel) {
651
 
                g_object_unref (frame);
652
 
                gtk_widget_destroy (dialog);
653
 
                return;
654
 
        }
655
 
 
656
 
        info = frame->priv->applet_info;
657
 
 
658
 
        if (response == GTK_RESPONSE_YES) {
659
 
                PanelWidget *panel;
660
 
                char        *iid;
661
 
                char        *id = NULL;
662
 
                int          position = -1;
663
 
                gboolean     locked = FALSE;
664
 
 
665
 
                panel = frame->priv->panel;
666
 
                iid   = g_strdup (frame->priv->iid);
667
 
 
668
 
                if (info) {
669
 
                        id = g_strdup (info->id);
670
 
                        position  = panel_applet_get_position (info);
671
 
                        locked = panel_widget_get_applet_locked (panel, info->widget);
672
 
                        panel_applet_clean (info);
673
 
                }
674
 
 
675
 
                panel_applet_frame_load (iid, panel, locked,
676
 
                                         position, TRUE, id);
677
 
 
678
 
                g_free (iid);
679
 
                g_free (id);
680
 
 
681
 
        } else if (info) {
682
 
                /* if we can't write to applets list we can't really delete
683
 
                   it, so we'll just ignore this.  FIXME: handle this
684
 
                   more correctly I suppose. */
685
 
                if (panel_profile_id_lists_are_writable ())
686
 
                        panel_profile_delete_object (info);
687
 
        }
688
 
 
689
 
        g_object_unref (frame);
690
 
        gtk_widget_destroy (dialog);
691
 
}
692
 
 
693
 
void
694
 
_panel_applet_frame_applet_broken (PanelAppletFrame *frame)
695
 
{
696
 
        GtkWidget  *dialog;
697
 
        GdkScreen  *screen;
698
 
        const char *applet_name = NULL;
699
 
        char       *dialog_txt;
700
 
 
701
 
        screen = gtk_widget_get_screen (GTK_WIDGET (frame));
702
 
 
703
 
        if (xstuff_is_display_dead ())
704
 
                return;
705
 
 
706
 
        if (frame->priv->iid) {
707
 
                PanelAppletInfo *info;
708
 
 
709
 
                info = (PanelAppletInfo *)panel_applets_manager_get_applet_info (frame->priv->iid);
710
 
                applet_name = panel_applet_info_get_name (info);
711
 
        }
712
 
 
713
 
        if (applet_name)
714
 
                dialog_txt = g_strdup_printf (_("\"%s\" has quit unexpectedly"), applet_name);
715
 
        else
716
 
                dialog_txt = g_strdup (_("Panel object has quit unexpectedly"));
717
 
 
718
 
        dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
719
 
                                         GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
720
 
                                         dialog_txt, applet_name ? applet_name : NULL);
721
 
 
722
 
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
723
 
                                                  _("If you reload a panel object, it will automatically "
724
 
                                                    "be added back to the panel."));
725
 
 
726
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
727
 
 
728
 
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
729
 
                                _("_Don't Reload"), GTK_RESPONSE_NO,
730
 
                                _("_Reload"), GTK_RESPONSE_YES,
731
 
                                NULL);
732
 
 
733
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
734
 
                                         GTK_RESPONSE_YES);
735
 
 
736
 
        gtk_window_set_screen (GTK_WINDOW (dialog), screen);
737
 
 
738
 
        g_signal_connect (dialog, "response",
739
 
                          G_CALLBACK (panel_applet_frame_reload_response),
740
 
                          g_object_ref (frame));
741
 
 
742
 
        panel_widget_register_open_dialog (frame->priv->panel, dialog);
743
 
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);
744
 
        /* FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=165132 */
745
 
        gtk_window_set_title (GTK_WINDOW (dialog), _("Error"));
746
 
 
747
 
        gtk_widget_show (dialog);
748
 
        g_free (dialog_txt);
749
 
}
750
 
 
751
 
void
752
 
_panel_applet_frame_applet_remove (PanelAppletFrame *frame)
753
 
{
754
 
        AppletInfo *info;
755
 
 
756
 
        if (!frame->priv->applet_info)
757
 
                return;
758
 
 
759
 
        info = frame->priv->applet_info;
760
 
        frame->priv->applet_info = NULL;
761
 
 
762
 
        panel_profile_delete_object (info);
763
 
}
764
 
 
765
 
void
766
 
_panel_applet_frame_applet_move (PanelAppletFrame *frame)
767
 
{
768
 
        GtkWidget *widget = GTK_WIDGET (frame);
769
 
        GtkWidget *parent = gtk_widget_get_parent (widget);
770
 
 
771
 
        if (!PANEL_IS_WIDGET (parent))
772
 
                return;
773
 
 
774
 
        panel_widget_applet_drag_start (PANEL_WIDGET (parent),
775
 
                                        widget,
776
 
                                        PW_DRAG_OFF_CENTER,
777
 
                                        GDK_CURRENT_TIME);
778
 
}
779
 
 
780
 
void
781
 
_panel_applet_frame_applet_lock (PanelAppletFrame *frame,
782
 
                                 gboolean          locked)
783
 
{
784
 
        PanelWidget *panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame)));
785
 
 
786
 
        if (panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame)) == locked)
787
 
                return;
788
 
 
789
 
        panel_applet_toggle_locked (frame->priv->applet_info);
790
 
}
791
 
 
792
 
/* Generic methods */
793
 
 
794
 
static GSList *no_reload_applets = NULL;
795
 
 
796
 
enum {
797
 
        LOADING_FAILED_RESPONSE_DONT_DELETE,
798
 
        LOADING_FAILED_RESPONSE_DELETE
799
 
};
800
 
 
801
 
static void
802
 
panel_applet_frame_activating_free (PanelAppletFrameActivating *frame_act)
803
 
{
804
 
        g_free (frame_act->id);
805
 
        g_slice_free (PanelAppletFrameActivating, frame_act);
806
 
}
807
 
 
808
 
PanelOrientation
809
 
panel_applet_frame_activating_get_orientation (PanelAppletFrameActivating *frame_act)
810
 
{
811
 
        return panel_widget_get_applet_orientation (frame_act->panel);
812
 
}
813
 
 
814
 
guint32
815
 
panel_applet_frame_activating_get_size (PanelAppletFrameActivating *frame_act)
816
 
{
817
 
        return frame_act->panel->sz;
818
 
}
819
 
 
820
 
gboolean
821
 
panel_applet_frame_activating_get_locked (PanelAppletFrameActivating *frame_act)
822
 
{
823
 
        return frame_act->locked;
824
 
}
825
 
 
826
 
gboolean
827
 
panel_applet_frame_activating_get_locked_down (PanelAppletFrameActivating *frame_act)
828
 
{
829
 
        return panel_lockdown_get_locked_down ();
830
 
}
831
 
 
832
 
gchar *
833
 
panel_applet_frame_activating_get_conf_path (PanelAppletFrameActivating *frame_act)
834
 
{
835
 
        return g_strdup_printf (PANEL_APPLET_PREFS_KEY, frame_act->id);
836
 
}
837
 
 
838
 
static void
839
 
panel_applet_frame_loading_failed_response (GtkWidget *dialog,
840
 
                                            guint      response,
841
 
                                            char      *id)
842
 
{
843
 
        gtk_widget_destroy (dialog);
844
 
 
845
 
        if (response == LOADING_FAILED_RESPONSE_DELETE &&
846
 
            !panel_lockdown_get_locked_down () &&
847
 
            panel_profile_id_lists_are_writable ()) {
848
 
                GSList *item;
849
 
 
850
 
                item = g_slist_find_custom (no_reload_applets, id,
851
 
                                            (GCompareFunc) strcmp);
852
 
                if (item) {
853
 
                        g_free (item->data);
854
 
                        no_reload_applets = g_slist_delete_link (no_reload_applets,
855
 
                                                                 item);
856
 
                }
857
 
 
858
 
                panel_profile_remove_from_list (PANEL_GCONF_APPLETS, id);
859
 
        }
860
 
 
861
 
        g_free (id);
862
 
}
863
 
 
864
 
static void
865
 
panel_applet_frame_loading_failed (const char  *iid,
866
 
                                   PanelWidget *panel,
867
 
                                   const char  *id)
868
 
{
869
 
        GtkWidget *dialog;
870
 
        char      *problem_txt;
871
 
        gboolean   locked_down;
872
 
 
873
 
        no_reload_applets = g_slist_prepend (no_reload_applets,
874
 
                                             g_strdup (id));
875
 
 
876
 
        locked_down = panel_lockdown_get_locked_down ();
877
 
 
878
 
        problem_txt = g_strdup_printf (_("The panel encountered a problem "
879
 
                                         "while loading \"%s\"."),
880
 
                                       iid);
881
 
 
882
 
        dialog = gtk_message_dialog_new (NULL, 0,
883
 
                                         locked_down ? GTK_MESSAGE_INFO : GTK_MESSAGE_WARNING,
884
 
                                         GTK_BUTTONS_NONE,
885
 
                                         "%s", problem_txt);
886
 
        g_free (problem_txt);
887
 
 
888
 
        if (locked_down) {
889
 
                gtk_dialog_add_buttons (GTK_DIALOG (dialog),
890
 
                                        GTK_STOCK_OK, LOADING_FAILED_RESPONSE_DONT_DELETE,
891
 
                                        NULL);
892
 
        } else {
893
 
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
894
 
                                        _("Do you want to delete the applet "
895
 
                                          "from your configuration?"));
896
 
                gtk_dialog_add_buttons (GTK_DIALOG (dialog),
897
 
                                        PANEL_STOCK_DONT_DELETE, LOADING_FAILED_RESPONSE_DONT_DELETE,
898
 
                                        GTK_STOCK_DELETE, LOADING_FAILED_RESPONSE_DELETE,
899
 
                                        NULL);
900
 
        }
901
 
 
902
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
903
 
                                         LOADING_FAILED_RESPONSE_DONT_DELETE);
904
 
 
905
 
        gtk_window_set_screen (GTK_WINDOW (dialog),
906
 
                               gtk_window_get_screen (GTK_WINDOW (panel->toplevel)));
907
 
 
908
 
        g_signal_connect (dialog, "response",
909
 
                          G_CALLBACK (panel_applet_frame_loading_failed_response),
910
 
                          g_strdup (id));
911
 
 
912
 
        panel_widget_register_open_dialog (panel, dialog);
913
 
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);
914
 
        /* FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=165132 */
915
 
        gtk_window_set_title (GTK_WINDOW (dialog), _("Error"));
916
 
 
917
 
        gtk_widget_show_all (dialog);
918
 
 
919
 
        /* Note: this call will free the memory for id, so the variable should
920
 
         * not get accessed afterwards. */
921
 
        panel_applet_stop_loading (id);
922
 
}
923
 
 
924
 
static void
925
 
panel_applet_frame_load (const gchar *iid,
926
 
                         PanelWidget *panel,
927
 
                         gboolean     locked,
928
 
                         int          position,
929
 
                         gboolean     exactpos,
930
 
                         const char  *id)
931
 
{
932
 
        PanelAppletFrameActivating *frame_act;
933
 
 
934
 
        g_return_if_fail (iid != NULL);
935
 
        g_return_if_fail (panel != NULL);
936
 
        g_return_if_fail (id != NULL);
937
 
 
938
 
        if (g_slist_find_custom (no_reload_applets, id,
939
 
                                 (GCompareFunc) strcmp)) {
940
 
                panel_applet_stop_loading (id);
941
 
                return;
942
 
        }
943
 
 
944
 
        if (panel_lockdown_is_applet_disabled (iid)) {
945
 
                panel_applet_stop_loading (id);
946
 
                return;
947
 
        }
948
 
 
949
 
        frame_act = g_slice_new0 (PanelAppletFrameActivating);
950
 
        frame_act->locked   = locked;
951
 
        frame_act->panel    = panel;
952
 
        frame_act->position = position;
953
 
        frame_act->exactpos = exactpos;
954
 
        frame_act->id       = g_strdup (id);
955
 
 
956
 
        if (!panel_applets_manager_load_applet (iid, frame_act)) {
957
 
                panel_applet_frame_loading_failed (iid, panel, id);
958
 
                panel_applet_frame_activating_free (frame_act);
959
 
        }
960
 
}
961
 
 
962
 
void
963
 
panel_applet_frame_load_from_gconf (PanelWidget *panel_widget,
964
 
                                    gboolean     locked,
965
 
                                    int          position,
966
 
                                    const char  *id)
967
 
{
968
 
        gchar *applet_iid;
969
 
 
970
 
        g_return_if_fail (panel_widget != NULL);
971
 
        g_return_if_fail (id != NULL);
972
 
 
973
 
        applet_iid = panel_compatibility_get_applet_iid (id);
974
 
        if (!applet_iid) {
975
 
                panel_applet_stop_loading (id);
976
 
                return;
977
 
        }
978
 
 
979
 
        panel_applet_frame_load (applet_iid, panel_widget,
980
 
                                 locked, position, TRUE, id);
981
 
 
982
 
        g_free (applet_iid);
983
 
}
984
 
 
985
 
void
986
 
panel_applet_frame_create (PanelToplevel *toplevel,
987
 
                           int            position,
988
 
                           const char    *iid)
989
 
{
990
 
        GConfClient *client;
991
 
        const char  *key;
992
 
        char        *id;
993
 
 
994
 
        g_return_if_fail (iid != NULL);
995
 
 
996
 
        client =  panel_gconf_get_client ();
997
 
 
998
 
        id = panel_profile_prepare_object (PANEL_OBJECT_APPLET, toplevel, position, FALSE);
999
 
 
1000
 
        key = panel_gconf_full_key (PANEL_GCONF_APPLETS, id, "applet_iid");
1001
 
        gconf_client_set_string (client, key, iid, NULL);
1002
 
 
1003
 
        panel_profile_add_to_list (PANEL_GCONF_APPLETS, id);
1004
 
 
1005
 
        g_free (id);
1006
 
}