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

« back to all changes in this revision

Viewing changes to gnome-panel/applet.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.3.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: james.westby@ubuntu.com-20110530110449-ut1tc5t61rpvf9e3
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#include <glib/gi18n.h>
15
15
#include <gdk/gdkx.h>
16
16
 
 
17
#include <libpanel-util/panel-glib.h>
17
18
#include <libpanel-util/panel-show.h>
18
19
 
19
20
#include "button-widget.h"
20
 
#include "drawer.h"
21
21
#include "launcher.h"
 
22
#include "panel.h"
22
23
#include "panel-addto.h"
23
 
#include "panel-gconf.h"
24
 
#include "panel-config-global.h"
 
24
#include "panel-bindings.h"
25
25
#include "panel-applet-frame.h"
26
26
#include "panel-action-button.h"
27
27
#include "panel-menu-bar.h"
28
28
#include "panel-separator.h"
29
 
#include "panel-compatibility.h"
30
29
#include "panel-toplevel.h"
31
30
#include "panel-util.h"
32
 
#include "panel-profile.h"
33
31
#include "panel-menu-button.h"
34
32
#include "panel-globals.h"
35
33
#include "panel-properties-dialog.h"
 
34
#include "panel-layout.h"
36
35
#include "panel-lockdown.h"
37
 
 
38
 
#define SMALL_ICON_SIZE 20
 
36
#include "panel-schemas.h"
39
37
 
40
38
static GSList *registered_applets = NULL;
41
39
static GSList *queued_position_saves = NULL;
42
40
static guint   queued_position_source = 0;
43
41
 
 
42
static GtkWidget *panel_applet_get_menu (AppletInfo *info);
 
43
static void applet_menu_show       (GtkWidget *w, AppletInfo *info);
 
44
static void applet_menu_deactivate (GtkWidget *w, AppletInfo *info);
44
45
 
45
46
static inline PanelWidget *
46
47
panel_applet_get_panel_widget (AppletInfo *info)
53
54
                              gboolean    dnd_enabled)
54
55
{
55
56
        switch (info->type) {
56
 
        case PANEL_OBJECT_DRAWER:
57
 
                panel_drawer_set_dnd_enabled (info->data, dnd_enabled);
58
 
                break;
59
57
        case PANEL_OBJECT_MENU:
60
58
                panel_menu_button_set_dnd_enabled (PANEL_MENU_BUTTON (info->widget),
61
59
                                                   dnd_enabled);
65
63
                break;
66
64
        case PANEL_OBJECT_APPLET:
67
65
                break;
68
 
        case PANEL_OBJECT_LOGOUT:
69
 
        case PANEL_OBJECT_LOCK:
70
66
        case PANEL_OBJECT_ACTION:
71
67
                panel_action_button_set_dnd_enabled (PANEL_ACTION_BUTTON (info->widget),
72
68
                                                     dnd_enabled);
73
69
                break;
74
70
        case PANEL_OBJECT_MENU_BAR:
75
71
        case PANEL_OBJECT_SEPARATOR:
 
72
        case PANEL_OBJECT_USER_MENU:
76
73
                break;
77
74
        default:
78
75
                g_assert_not_reached ();
81
78
 
82
79
}
83
80
 
84
 
gboolean
85
 
panel_applet_toggle_locked (AppletInfo *info)
86
 
{
87
 
        PanelWidget *panel_widget;
88
 
        gboolean     locked;
89
 
 
90
 
        panel_widget = panel_applet_get_panel_widget (info);
91
 
        
92
 
        locked = panel_widget_toggle_applet_locked (panel_widget, info->widget);
93
 
 
94
 
        panel_applet_save_position (info, info->id, TRUE);
95
 
        panel_applet_set_dnd_enabled (info, !locked);
96
 
 
97
 
        return locked;
98
 
}
99
 
 
100
 
static void
101
 
panel_applet_lock (GtkCheckMenuItem *menuitem,
102
 
                   AppletInfo       *info)
103
 
{
104
 
        gboolean locked;
105
 
 
106
 
        locked = panel_applet_toggle_locked (info);
107
 
 
108
 
        gtk_check_menu_item_set_active (menuitem, locked);
109
 
 
110
 
        if (info->move_item)
111
 
                gtk_widget_set_sensitive (info->move_item, !locked);
112
 
}
113
 
 
114
81
static void
115
82
move_applet_callback (GtkWidget *widget, AppletInfo *info)
116
83
{
128
95
        panel = PANEL_WIDGET (parent);
129
96
 
130
97
        panel_widget_applet_drag_start (panel, info->widget,
131
 
                                        PW_DRAG_OFF_CENTER,
132
98
                                        GDK_CURRENT_TIME);
133
99
}
134
100
 
152
118
}
153
119
 
154
120
static void
155
 
panel_applet_recreate_menu (AppletInfo  *info)
 
121
panel_applet_recreate_menu (AppletInfo *info)
156
122
{
157
 
        GList *l;
158
 
 
159
 
        if (!info->menu)
160
 
                return;
161
 
 
162
 
        for (l = info->user_menu; l; l = l->next) {
163
 
                AppletUserMenu *menu = l->data;
164
 
 
165
 
                menu->menuitem =NULL;
166
 
                menu->submenu =NULL;
 
123
        if (info->menu) {
 
124
                GList *l;
 
125
 
 
126
                for (l = info->user_menu; l; l = l->next) {
 
127
                        AppletUserMenu *menu = l->data;
 
128
 
 
129
                        menu->menuitem = NULL;
 
130
                        menu->submenu = NULL;
 
131
                }
 
132
 
 
133
                if (gtk_widget_get_visible (info->menu))
 
134
                        gtk_menu_shell_deactivate (GTK_MENU_SHELL (info->menu));
 
135
 
 
136
                g_signal_handlers_disconnect_by_func (info->menu,
 
137
                                                      G_CALLBACK (applet_menu_show), info);
 
138
                g_signal_handlers_disconnect_by_func (info->menu,
 
139
                                                      G_CALLBACK (applet_menu_deactivate), info);
 
140
 
 
141
                g_object_unref (info->menu);
 
142
                info->menu = NULL;
167
143
        }
168
144
 
169
 
        g_object_unref (info->menu);
170
 
        info->menu = panel_applet_create_menu (info);
171
 
}
172
 
 
173
 
static void
174
 
panel_applet_locked_change_notify (GConfClient *client,
175
 
                                   guint        cnxn_id,
176
 
                                   GConfEntry  *entry,
177
 
                                   GtkWidget   *applet)
178
 
{
179
 
        GConfValue  *value;
180
 
        gboolean     locked;
181
 
        gboolean     applet_locked;
182
 
        AppletInfo  *info;
183
 
        PanelWidget *panel_widget;
184
 
 
185
 
        g_assert (applet != NULL);
186
 
 
187
 
        info = (AppletInfo  *) g_object_get_data (G_OBJECT (applet),
188
 
                                                  "applet_info");
189
 
        if (info == NULL)
190
 
                return;
191
 
 
192
 
        value = gconf_entry_get_value (entry);
193
 
        if (value == NULL || value->type != GCONF_VALUE_BOOL)
194
 
                return;
195
 
 
196
 
        locked = gconf_value_get_bool (value);
197
 
 
198
 
        panel_widget = panel_applet_get_panel_widget (info);
199
 
        applet_locked = panel_widget_get_applet_locked (panel_widget,
200
 
                                                        info->widget);
201
 
 
202
 
        if ((locked && applet_locked) || !(locked || applet_locked))
203
 
                return;
204
 
 
205
 
        panel_applet_toggle_locked (info);
206
 
 
207
 
        if (info->type == PANEL_OBJECT_APPLET)
208
 
                panel_applet_frame_sync_menu_state (PANEL_APPLET_FRAME (info->widget));
209
 
        else
210
 
                panel_applet_recreate_menu (info);
 
145
        panel_applet_get_menu (info);
211
146
}
212
147
 
213
148
static void
215
150
                        AppletInfo *info)
216
151
{
217
152
 
218
 
        if (info->type == PANEL_OBJECT_DRAWER)
219
 
                drawer_query_deletion (info->data);
220
 
        else
221
 
                panel_profile_delete_object (info);
 
153
        panel_layout_delete_object (info->id);
222
154
}
223
155
 
224
156
static inline GdkScreen *
248
180
                else if (!strcmp (menu->name, "properties"))
249
181
                        launcher_properties (menu->info->data);
250
182
                break;
251
 
        case PANEL_OBJECT_DRAWER: 
252
 
                if (strcmp (menu->name, "add") == 0) {
253
 
                        Drawer *drawer = menu->info->data;
254
 
 
255
 
                        panel_addto_present (GTK_MENU_ITEM (widget),
256
 
                                             panel_toplevel_get_panel_widget (drawer->toplevel));
257
 
                } else if (strcmp (menu->name, "properties") == 0) {
258
 
                        Drawer *drawer = menu->info->data;
259
 
 
260
 
                        panel_properties_dialog_present (drawer->toplevel);
261
 
                } else if (strcmp (menu->name, "help") == 0) {
262
 
                        panel_show_help (screen,
263
 
                                         "user-guide", "gospanel-18", NULL);
264
 
                }
265
 
                break;
266
183
        case PANEL_OBJECT_MENU:
267
184
                panel_menu_button_invoke_menu (
268
185
                        PANEL_MENU_BUTTON (menu->info->widget), menu->name);
269
186
                break;
270
187
        case PANEL_OBJECT_ACTION:
271
 
        case PANEL_OBJECT_LOGOUT:
272
 
        case PANEL_OBJECT_LOCK:
273
188
                panel_action_button_invoke_menu (
274
189
                        PANEL_ACTION_BUTTON (menu->info->widget), menu->name);
275
190
                break;
284
199
                 */
285
200
                break;
286
201
        case PANEL_OBJECT_SEPARATOR:
 
202
        case PANEL_OBJECT_USER_MENU:
287
203
                break;
288
204
        default:
289
205
                g_assert_not_reached ();
471
387
        g_free(n);
472
388
}
473
389
 
474
 
GtkWidget *
475
 
panel_applet_create_menu (AppletInfo *info)
 
390
static GtkWidget *
 
391
panel_applet_create_bare_menu (AppletInfo *info)
476
392
{
477
 
        GtkWidget   *menu;
478
 
        GtkWidget   *menuitem;
479
 
        GList       *l;
480
 
        PanelWidget *panel_widget;
481
 
        gboolean     added_anything = FALSE;
482
 
 
483
 
        panel_widget = panel_applet_get_panel_widget (info);
 
393
        GtkWidget *menu;
484
394
 
485
395
        menu = g_object_ref_sink (gtk_menu_new ());
486
396
 
492
402
        g_signal_connect (menu, "deactivate",
493
403
                          G_CALLBACK (applet_menu_deactivate), info);
494
404
 
 
405
        return menu;
 
406
}
 
407
 
 
408
static void
 
409
panel_applet_menu_lockdown_changed (PanelLockdown *lockdown,
 
410
                                    gpointer       user_data)
 
411
{
 
412
        AppletInfo *info = user_data;
 
413
 
 
414
        panel_applet_recreate_menu (info);
 
415
}
 
416
 
 
417
static GtkWidget *
 
418
panel_applet_get_menu (AppletInfo *info)
 
419
{
 
420
        GtkWidget   *menu;
 
421
        GList       *l;
 
422
        gboolean     added_anything = FALSE;
 
423
 
 
424
        if (info->menu)
 
425
                return info->menu;
 
426
 
 
427
        menu = panel_applet_create_bare_menu (info);
 
428
 
495
429
        for (l = info->user_menu; l; l = l->next) {
496
430
                AppletUserMenu *user_menu = l->data;
497
431
 
504
438
                added_anything = TRUE;
505
439
        }
506
440
 
507
 
        if (!panel_lockdown_get_locked_down ()) {
508
 
                GtkWidget *image;
509
 
                gboolean   locked;
510
 
                gboolean   lockable;
511
 
                gboolean   movable;
512
 
                gboolean   removable;
513
 
 
514
 
                lockable = panel_applet_lockable (info);
515
 
                movable = panel_applet_can_freely_move (info);
516
 
                removable = panel_profile_id_lists_are_writable ();
517
 
 
518
 
                locked = panel_widget_get_applet_locked (panel_widget, info->widget);
519
 
 
520
 
                if (added_anything) {
521
 
                        menuitem = gtk_separator_menu_item_new ();
522
 
                        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
523
 
                        gtk_widget_show (menuitem);
524
 
                }
525
 
 
526
 
                menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Remove From Panel"));
527
 
                image = gtk_image_new_from_stock (GTK_STOCK_REMOVE,
528
 
                                                  GTK_ICON_SIZE_MENU);
529
 
                gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
530
 
                                               image);
531
 
                g_signal_connect (menuitem, "activate",
532
 
                                  G_CALLBACK (applet_remove_callback), info);
533
 
                gtk_widget_show (menuitem);
534
 
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
535
 
                gtk_widget_set_sensitive (menuitem, (!locked || lockable) && removable);
536
 
                
537
 
                menuitem = gtk_menu_item_new_with_mnemonic (_("_Move"));
538
 
                g_signal_connect (menuitem, "activate",
539
 
                                  G_CALLBACK (move_applet_callback), info);
540
 
                gtk_widget_show (menuitem);
541
 
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
542
 
                gtk_widget_set_sensitive (menuitem, !locked && movable);
543
 
 
544
 
                g_assert (info->move_item == NULL);
545
 
 
546
 
                info->move_item = menuitem;
547
 
                g_object_add_weak_pointer (G_OBJECT (menuitem),
548
 
                                           (gpointer *) &info->move_item);
549
 
 
550
 
                menuitem = gtk_separator_menu_item_new ();
551
 
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
552
 
                gtk_widget_show (menuitem);
553
 
 
554
 
                menuitem = gtk_check_menu_item_new_with_mnemonic (_("Loc_k To Panel"));
555
 
                gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem),
556
 
                                                locked);
557
 
                g_signal_connect (menuitem, "toggled",
558
 
                                  G_CALLBACK (panel_applet_lock), info);
559
 
                gtk_widget_show (menuitem);
560
 
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
561
 
                gtk_widget_set_sensitive (menuitem, lockable);
562
 
 
563
 
                added_anything = TRUE;
564
 
        }
565
 
 
566
441
        if ( ! added_anything) {
 
442
                g_signal_handlers_disconnect_by_func (menu,
 
443
                                                      G_CALLBACK (applet_menu_show), info);
 
444
                g_signal_handlers_disconnect_by_func (menu,
 
445
                                                      G_CALLBACK (applet_menu_deactivate), info);
 
446
 
567
447
                g_object_unref (menu);
568
448
                return NULL;
569
449
        }
570
450
 
571
 
        return menu;
572
 
}
 
451
        info->menu = menu;
 
452
 
 
453
        panel_lockdown_on_notify (panel_lockdown_get (),
 
454
                                  NULL,
 
455
                                  G_OBJECT (info->menu),
 
456
                                  panel_applet_menu_lockdown_changed,
 
457
                                  info);
 
458
 
 
459
        return info->menu;
 
460
}
 
461
 
 
462
static void
 
463
panel_applet_edit_menu_lockdown_changed (PanelLockdown *lockdown,
 
464
                                         gpointer       user_data)
 
465
{
 
466
        AppletInfo *info = user_data;
 
467
 
 
468
        if (!panel_lockdown_get_panels_locked_down (lockdown))
 
469
                return;
 
470
 
 
471
        if (info->edit_menu) {
 
472
                if (gtk_widget_get_visible (info->edit_menu))
 
473
                        gtk_menu_shell_deactivate (GTK_MENU_SHELL (info->edit_menu));
 
474
 
 
475
                g_signal_handlers_disconnect_by_func (info->edit_menu,
 
476
                                                      G_CALLBACK (applet_menu_deactivate), info);
 
477
                gtk_widget_destroy (info->edit_menu);
 
478
                info->edit_menu = NULL;
 
479
        }
 
480
}
 
481
 
 
482
static GtkWidget *
 
483
panel_applet_get_edit_menu (AppletInfo *info)
 
484
{
 
485
        GtkWidget   *menu;
 
486
        GtkWidget   *menuitem;
 
487
        PanelWidget *panel_widget;
 
488
        GtkWidget   *image;
 
489
        gboolean     movable;
 
490
        gboolean     removable;
 
491
 
 
492
        if (info->edit_menu)
 
493
                return info->edit_menu;
 
494
 
 
495
        if (panel_lockdown_get_panels_locked_down_s ())
 
496
                return NULL;
 
497
 
 
498
        menu = panel_applet_create_bare_menu (info);
 
499
        panel_widget = panel_applet_get_panel_widget (info);
 
500
 
 
501
        movable = panel_applet_can_freely_move (info);
 
502
        removable = panel_layout_is_writable ();
 
503
 
 
504
        menuitem = gtk_menu_item_new_with_mnemonic (_("_Move"));
 
505
        g_signal_connect (menuitem, "activate",
 
506
                          G_CALLBACK (move_applet_callback), info);
 
507
        gtk_widget_show (menuitem);
 
508
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
 
509
        gtk_widget_set_sensitive (menuitem, movable);
 
510
 
 
511
        menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Remove From Panel"));
 
512
        image = gtk_image_new_from_stock (GTK_STOCK_REMOVE,
 
513
                                          GTK_ICON_SIZE_MENU);
 
514
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
 
515
                                       image);
 
516
        g_signal_connect (menuitem, "activate",
 
517
                          G_CALLBACK (applet_remove_callback), info);
 
518
        gtk_widget_show (menuitem);
 
519
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
 
520
        gtk_widget_set_sensitive (menuitem, removable);
 
521
 
 
522
        info->edit_menu = menu;
 
523
 
 
524
        panel_lockdown_on_notify (panel_lockdown_get (),
 
525
                                  "panels-locked-down",
 
526
                                  G_OBJECT (info->edit_menu),
 
527
                                  panel_applet_edit_menu_lockdown_changed,
 
528
                                  info);
 
529
 
 
530
        return info->edit_menu;
 
531
}
 
532
 
573
533
 
574
534
void
575
535
panel_applet_menu_set_recurse (GtkMenu     *menu,
616
576
 
617
577
        screen = gtk_widget_get_screen (applet);
618
578
 
619
 
        gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
 
579
        gtk_widget_get_preferred_size (GTK_WIDGET (menu), &requisition, NULL);
620
580
 
621
581
        gdk_window_get_origin (gtk_widget_get_window (applet), &menu_x, &menu_y);
622
582
        gtk_widget_get_pointer (applet, &pointer_x, &pointer_y);
667
627
 
668
628
static void
669
629
applet_show_menu (AppletInfo     *info,
 
630
                  GtkWidget      *menu,
 
631
                  gboolean        custom_position,
670
632
                  GdkEventButton *event)
671
633
{
672
634
        PanelWidget *panel_widget;
673
635
 
674
636
        g_return_if_fail (info != NULL);
675
637
 
 
638
        if (menu == NULL)
 
639
                return;
 
640
 
676
641
        panel_widget = panel_applet_get_panel_widget (info);
677
642
 
678
 
        if (info->menu == NULL)
679
 
                info->menu = panel_applet_create_menu (info);
680
 
 
681
 
        if (info->menu == NULL)
682
 
                return;
683
 
 
684
 
        panel_applet_menu_set_recurse (GTK_MENU (info->menu),
 
643
        panel_applet_menu_set_recurse (GTK_MENU (menu),
685
644
                                       "menu_panel",
686
645
                                       panel_widget);
687
646
 
688
 
        gtk_menu_set_screen (GTK_MENU (info->menu),
 
647
        gtk_menu_set_screen (GTK_MENU (menu),
689
648
                             gtk_window_get_screen (GTK_WINDOW (panel_widget->toplevel)));
690
649
 
691
 
        if (!gtk_widget_get_realized (info->menu))
692
 
                gtk_widget_show (info->menu);
 
650
        if (!gtk_widget_get_realized (menu))
 
651
                gtk_widget_show (menu);
693
652
 
694
 
        gtk_menu_popup (GTK_MENU (info->menu),
695
 
                        NULL,
696
 
                        NULL,
697
 
                        (GtkMenuPositionFunc) panel_applet_position_menu,
 
653
        gtk_menu_popup (GTK_MENU (menu),
 
654
                        NULL,
 
655
                        NULL,
 
656
                        custom_position ?
 
657
                                (GtkMenuPositionFunc) panel_applet_position_menu : NULL,
698
658
                        info->widget,
699
659
                        event->button,
700
660
                        event->time);
701
661
}
702
662
 
703
663
static gboolean
704
 
applet_do_popup_menu (GtkWidget      *widget,
705
 
                      GdkEventButton *event,
706
 
                      AppletInfo     *info)
 
664
applet_must_skip_menu (AppletInfo *info)
707
665
{
708
666
        if (panel_applet_is_in_drag ())
709
 
                return FALSE;
 
667
                return TRUE;
710
668
 
711
669
        if (info->type == PANEL_OBJECT_APPLET)
712
 
                return FALSE;
713
 
 
714
 
        applet_show_menu (info, event);
715
 
 
716
 
        return TRUE;
717
 
}
718
 
 
719
 
static gboolean
720
 
applet_popup_menu (GtkWidget      *widget,
721
 
                   AppletInfo     *info)
722
 
{
723
 
        GdkEventButton event;
724
 
 
725
 
        event.button = 3;
726
 
        event.time = GDK_CURRENT_TIME;
727
 
 
728
 
        return applet_do_popup_menu (widget, &event, info);
 
670
                return TRUE;
 
671
 
 
672
        return FALSE;
729
673
}
730
674
 
731
675
static gboolean
733
677
                     GdkEventButton *event,
734
678
                     AppletInfo     *info)
735
679
{
736
 
        if (event->button == 3)
737
 
                return applet_do_popup_menu (widget, event, info);
738
 
 
739
 
        return FALSE;
 
680
        guint modifiers;
 
681
 
 
682
        if (event->button != 3)
 
683
                return FALSE;
 
684
 
 
685
        if (applet_must_skip_menu (info))
 
686
                return FALSE;
 
687
 
 
688
        modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
 
689
 
 
690
        if (modifiers == panel_bindings_get_mouse_button_modifier_keymask ())
 
691
                applet_show_menu (info, panel_applet_get_edit_menu (info), FALSE, event);
 
692
        else
 
693
                applet_show_menu (info, panel_applet_get_menu (info), TRUE, event);
 
694
 
 
695
        return TRUE;
 
696
}
 
697
 
 
698
static gboolean
 
699
applet_key_press (GtkWidget   *widget,
 
700
                  GdkEventKey *event,
 
701
                  AppletInfo  *info)
 
702
{
 
703
        GdkEventButton eventbutton;
 
704
        gboolean is_popup = FALSE;
 
705
        gboolean is_edit_popup = FALSE;
 
706
 
 
707
        if (applet_must_skip_menu (info))
 
708
                return FALSE;
 
709
 
 
710
        eventbutton.button = 3;
 
711
        eventbutton.time = event->time;
 
712
 
 
713
        /* We're not connecting to the popup-menu signal since we want to be
 
714
         * able to deal with two cases:
 
715
         *  - exact keybinding of popup-menu => we open the context menu
 
716
         *  - keybinding of popup-menu + modifier from metacity => we open menu
 
717
         *    to "edit"
 
718
         */
 
719
        panel_util_key_event_is_popup (event, &is_popup, &is_edit_popup);
 
720
 
 
721
        if (is_edit_popup)
 
722
                applet_show_menu (info, panel_applet_get_edit_menu (info), FALSE, &eventbutton);
 
723
        else if (is_popup)
 
724
                applet_show_menu (info, panel_applet_get_menu (info), TRUE, &eventbutton);
 
725
 
 
726
        return (is_popup || is_edit_popup);
740
727
}
741
728
 
742
729
static void
754
741
        queued_position_saves =
755
742
                g_slist_remove (queued_position_saves, info);
756
743
 
757
 
        if (info->type == PANEL_OBJECT_DRAWER) {
758
 
                Drawer *drawer = info->data;
759
 
 
760
 
                if (drawer->toplevel) {
761
 
                        PanelWidget *panel_widget;
762
 
 
763
 
                        panel_widget = panel_toplevel_get_panel_widget (
764
 
                                                        drawer->toplevel);
765
 
                        panel_widget->master_widget = NULL;
766
 
 
767
 
                        gtk_widget_destroy (GTK_WIDGET (drawer->toplevel));
768
 
                        drawer->toplevel = NULL;
769
 
                }
770
 
        }
771
 
 
772
 
        if (info->type != PANEL_OBJECT_APPLET)
773
 
                panel_lockdown_notify_remove (G_CALLBACK (panel_applet_recreate_menu),
774
 
                                              info);
775
 
 
776
 
        if (info->menu)
 
744
        if (info->menu) {
 
745
                if (gtk_widget_get_visible (info->menu))
 
746
                        gtk_menu_shell_deactivate (GTK_MENU_SHELL (info->menu));
 
747
 
 
748
                g_signal_handlers_disconnect_by_func (info->menu,
 
749
                                                      G_CALLBACK (applet_menu_show), info);
 
750
                g_signal_handlers_disconnect_by_func (info->menu,
 
751
                                                      G_CALLBACK (applet_menu_deactivate), info);
777
752
                g_object_unref (info->menu);
 
753
        }
778
754
        info->menu = NULL;
779
755
 
 
756
        if (info->edit_menu) {
 
757
                if (gtk_widget_get_visible (info->edit_menu))
 
758
                        gtk_menu_shell_deactivate (GTK_MENU_SHELL (info->edit_menu));
 
759
 
 
760
                g_signal_handlers_disconnect_by_func (info->edit_menu,
 
761
                                                      G_CALLBACK (applet_menu_show), info);
 
762
                g_signal_handlers_disconnect_by_func (info->edit_menu,
 
763
                                                      G_CALLBACK (applet_menu_deactivate), info);
 
764
                g_object_unref (info->edit_menu);
 
765
        }
 
766
        info->edit_menu = NULL;
 
767
 
780
768
        if (info->data_destroy)
781
769
                info->data_destroy (info->data);
782
770
        info->data = NULL;
794
782
        g_list_free (info->user_menu);
795
783
        info->user_menu = NULL;
796
784
 
 
785
        if (info->settings)
 
786
                g_object_unref (info->settings);
 
787
        info->settings = NULL;
 
788
 
797
789
        g_free (info->id);
798
790
        info->id = NULL;
799
791
 
800
792
        g_free (info);
801
793
}
802
794
 
803
 
typedef struct {
804
 
        char            *id;
805
 
        PanelObjectType  type;
806
 
        char            *toplevel_id;
807
 
        int              position;
808
 
        guint            right_stick : 1;
809
 
        guint            locked : 1;
810
 
} PanelAppletToLoad;
811
 
 
812
 
/* Each time those lists get both empty,
813
 
 * panel_applet_queue_initial_unhide_toplevels() should be called */
814
 
static GSList  *panel_applets_to_load = NULL;
815
 
static GSList  *panel_applets_loading = NULL;
816
 
/* We have a timeout to always unhide toplevels after a delay, in case of some
817
 
 * blocking applet */
818
 
#define         UNHIDE_TOPLEVELS_TIMEOUT_SECONDS 5
819
 
static guint    panel_applet_unhide_toplevels_timeout = 0;
820
 
 
821
 
static gboolean panel_applet_have_load_idle = FALSE;
822
 
 
823
 
static void
824
 
free_applet_to_load (PanelAppletToLoad *applet)
825
 
{
826
 
        g_free (applet->id);
827
 
        applet->id = NULL;
828
 
 
829
 
        g_free (applet->toplevel_id);
830
 
        applet->toplevel_id = NULL;
831
 
 
832
 
        g_free (applet);
833
 
}
834
 
 
835
 
gboolean
836
 
panel_applet_on_load_queue (const char *id)
837
 
{
838
 
        GSList *li;
839
 
        for (li = panel_applets_to_load; li != NULL; li = li->next) {
840
 
                PanelAppletToLoad *applet = li->data;
841
 
                if (strcmp (applet->id, id) == 0)
842
 
                        return TRUE;
843
 
        }
844
 
        for (li = panel_applets_loading; li != NULL; li = li->next) {
845
 
                PanelAppletToLoad *applet = li->data;
846
 
                if (strcmp (applet->id, id) == 0)
847
 
                        return TRUE;
848
 
        }
849
 
        return FALSE;
850
 
}
851
 
 
852
 
/* This doesn't do anything if the initial unhide already happened */
853
 
static gboolean
854
 
panel_applet_queue_initial_unhide_toplevels (gpointer user_data)
855
 
{
856
 
        GSList *l;
857
 
 
858
 
        if (panel_applet_unhide_toplevels_timeout != 0) {
859
 
                g_source_remove (panel_applet_unhide_toplevels_timeout);
860
 
                panel_applet_unhide_toplevels_timeout = 0;
861
 
        }
862
 
 
863
 
        for (l = panel_toplevel_list_toplevels (); l != NULL; l = l->next)
864
 
                panel_toplevel_queue_initial_unhide ((PanelToplevel *) l->data);
865
 
 
866
 
        return FALSE;
867
 
}
868
 
 
869
 
void
870
 
panel_applet_stop_loading (const char *id)
871
 
{
872
 
        PanelAppletToLoad *applet;
873
 
        GSList *l;
874
 
 
875
 
        for (l = panel_applets_loading; l; l = l->next) {
876
 
                applet = l->data;
877
 
 
878
 
                if (strcmp (applet->id, id) == 0)
879
 
                        break;
880
 
        }
881
 
 
882
 
        /* this can happen if we reload an applet after it crashed,
883
 
         * for example */
884
 
        if (l != NULL) {
885
 
                panel_applets_loading = g_slist_delete_link (panel_applets_loading, l);
886
 
                free_applet_to_load (applet);
887
 
        }
888
 
 
889
 
        if (panel_applets_loading == NULL && panel_applets_to_load == NULL)
890
 
                panel_applet_queue_initial_unhide_toplevels (NULL);
891
 
}
892
 
 
893
 
static gboolean
894
 
panel_applet_load_idle_handler (gpointer dummy)
895
 
{
896
 
        PanelObjectType    applet_type;
897
 
        PanelAppletToLoad *applet = NULL;
898
 
        PanelToplevel     *toplevel = NULL;
899
 
        PanelWidget       *panel_widget;
900
 
        GSList            *l;
901
 
 
902
 
        if (!panel_applets_to_load) {
903
 
                panel_applet_have_load_idle = FALSE;
904
 
                return FALSE;
905
 
        }
906
 
 
907
 
        for (l = panel_applets_to_load; l; l = l->next) {
908
 
                applet = l->data;
909
 
 
910
 
                toplevel = panel_profile_get_toplevel_by_id (applet->toplevel_id);
911
 
                if (toplevel)
912
 
                        break;
913
 
        }
914
 
 
915
 
        if (!l) {
916
 
                /* All the remaining applets don't have a panel */
917
 
                for (l = panel_applets_to_load; l; l = l->next)
918
 
                        free_applet_to_load (l->data);
919
 
                g_slist_free (panel_applets_to_load);
920
 
                panel_applets_to_load = NULL;
921
 
                panel_applet_have_load_idle = FALSE;
922
 
 
923
 
                if (panel_applets_loading == NULL) {
924
 
                        /* unhide any potential initially hidden toplevel */
925
 
                        panel_applet_queue_initial_unhide_toplevels (NULL);
926
 
                }
927
 
 
928
 
                return FALSE;
929
 
        }
930
 
 
931
 
        panel_applets_to_load = g_slist_delete_link (panel_applets_to_load, l);
932
 
        panel_applets_loading = g_slist_append (panel_applets_loading, applet);
933
 
 
934
 
        panel_widget = panel_toplevel_get_panel_widget (toplevel);
935
 
 
936
 
        if (applet->right_stick) {
937
 
                if (!panel_widget->packed)
938
 
                        applet->position = panel_widget->size - applet->position;
939
 
                else
940
 
                        applet->position = -1;
941
 
        }
942
 
 
943
 
        /* We load applets asynchronously, so we specifically don't call
944
 
         * panel_applet_stop_loading() for this type. However, in case of
945
 
         * failure during the load, we might call panel_applet_stop_loading()
946
 
         * synchronously, which will make us lose the content of the applet
947
 
         * variable. So we save the type to be sure we always ignore the
948
 
         * applets. */
949
 
        applet_type = applet->type;
950
 
 
951
 
        switch (applet_type) {
952
 
        case PANEL_OBJECT_APPLET:
953
 
                panel_applet_frame_load_from_gconf (
954
 
                                        panel_widget,
955
 
                                        applet->locked,
956
 
                                        applet->position,
957
 
                                        applet->id);
958
 
                break;
959
 
        case PANEL_OBJECT_DRAWER:
960
 
                drawer_load_from_gconf (panel_widget,
961
 
                                        applet->locked,
962
 
                                        applet->position,
963
 
                                        applet->id);
964
 
                break;
965
 
        case PANEL_OBJECT_MENU:
966
 
                panel_menu_button_load_from_gconf (panel_widget,
967
 
                                                   applet->locked,
968
 
                                                   applet->position,
969
 
                                                   TRUE,
970
 
                                                   applet->id);
971
 
                break;
972
 
        case PANEL_OBJECT_LAUNCHER:
973
 
                launcher_load_from_gconf (panel_widget,
974
 
                                          applet->locked,
975
 
                                          applet->position,
976
 
                                          applet->id);
977
 
                break;
978
 
        case PANEL_OBJECT_LOGOUT:
979
 
        case PANEL_OBJECT_LOCK:
980
 
                panel_action_button_load_compatible (
981
 
                                applet->type,
982
 
                                panel_widget,
983
 
                                applet->locked,
984
 
                                applet->position,
985
 
                                TRUE,
986
 
                                applet->id);
987
 
                break;
988
 
        case PANEL_OBJECT_ACTION:
989
 
                panel_action_button_load_from_gconf (
990
 
                                panel_widget,
991
 
                                applet->locked,
992
 
                                applet->position,
993
 
                                TRUE,
994
 
                                applet->id);
995
 
                break;
996
 
        case PANEL_OBJECT_MENU_BAR:
997
 
                panel_menu_bar_load_from_gconf (
998
 
                                panel_widget,
999
 
                                applet->locked,
1000
 
                                applet->position,
1001
 
                                TRUE,
1002
 
                                applet->id);
1003
 
                break;
1004
 
        case PANEL_OBJECT_SEPARATOR:
1005
 
                panel_separator_load_from_gconf (panel_widget,
1006
 
                                                 applet->locked,
1007
 
                                                 applet->position,
1008
 
                                                 applet->id);
1009
 
                break;
1010
 
        default:
1011
 
                g_assert_not_reached ();
1012
 
                break;
1013
 
        }
1014
 
 
1015
 
        /* Only the real applets will do a late stop_loading */
1016
 
        if (applet_type != PANEL_OBJECT_APPLET)
1017
 
                panel_applet_stop_loading (applet->id);
1018
 
 
1019
 
        return TRUE;
1020
 
}
1021
 
 
1022
 
void
1023
 
panel_applet_queue_applet_to_load (const char      *id,
1024
 
                                   PanelObjectType  type,
1025
 
                                   const char      *toplevel_id,
1026
 
                                   int              position,
1027
 
                                   gboolean         right_stick,
1028
 
                                   gboolean         locked)
1029
 
{
1030
 
        PanelAppletToLoad *applet;
1031
 
 
1032
 
        if (!toplevel_id) {
1033
 
                g_warning ("No toplevel on which to load object '%s'\n", id);
1034
 
                return;
1035
 
        }
1036
 
 
1037
 
        applet = g_new0 (PanelAppletToLoad, 1);
1038
 
 
1039
 
        applet->id          = g_strdup (id);
1040
 
        applet->type        = type;
1041
 
        applet->toplevel_id = g_strdup (toplevel_id);
1042
 
        applet->position    = position;
1043
 
        applet->right_stick = right_stick != FALSE;
1044
 
        applet->locked      = locked != FALSE;
1045
 
 
1046
 
        panel_applets_to_load = g_slist_prepend (panel_applets_to_load, applet);
1047
 
}
1048
 
 
1049
 
static int
1050
 
panel_applet_compare (const PanelAppletToLoad *a,
1051
 
                      const PanelAppletToLoad *b)
1052
 
{
1053
 
        int c;
1054
 
 
1055
 
        if ((c = strcmp (a->toplevel_id, b->toplevel_id)))
1056
 
                return c;
1057
 
        else if (a->right_stick != b->right_stick)
1058
 
                return b->right_stick ? -1 : 1;
1059
 
        else
1060
 
                return a->position - b->position;
1061
 
}
1062
 
 
1063
 
void
1064
 
panel_applet_load_queued_applets (gboolean initial_load)
1065
 
{
1066
 
        if (!panel_applets_to_load) {
1067
 
                panel_applet_queue_initial_unhide_toplevels (NULL);
1068
 
                return;
1069
 
        }
1070
 
 
1071
 
        if (panel_applets_to_load && panel_applet_unhide_toplevels_timeout == 0) {
1072
 
                /* Install a timeout to make sure we don't block the
1073
 
                 * unhiding because of an applet that doesn't load */
1074
 
                panel_applet_unhide_toplevels_timeout =
1075
 
                        g_timeout_add_seconds (UNHIDE_TOPLEVELS_TIMEOUT_SECONDS,
1076
 
                                               panel_applet_queue_initial_unhide_toplevels,
1077
 
                                               NULL);
1078
 
        }
1079
 
 
1080
 
        panel_applets_to_load = g_slist_sort (panel_applets_to_load,
1081
 
                                              (GCompareFunc) panel_applet_compare);
1082
 
 
1083
 
        if ( ! panel_applet_have_load_idle) {
1084
 
                /* on panel startup, we don't care about redraws of the
1085
 
                 * toplevels since they are hidden, so we give a higher
1086
 
                 * priority to loading of applets */
1087
 
                if (initial_load)
1088
 
                        g_idle_add_full (G_PRIORITY_HIGH_IDLE,
1089
 
                                         panel_applet_load_idle_handler,
1090
 
                                         NULL, NULL);
1091
 
                else
1092
 
                        g_idle_add (panel_applet_load_idle_handler, NULL);
1093
 
 
1094
 
                panel_applet_have_load_idle = TRUE;
1095
 
        }
1096
 
}
1097
 
 
1098
795
static G_CONST_RETURN char *
1099
796
panel_applet_get_toplevel_id (AppletInfo *applet)
1100
797
{
1107
804
        if (!panel_widget)
1108
805
                return NULL;
1109
806
 
1110
 
        return panel_profile_get_toplevel_id (panel_widget->toplevel);
 
807
        return panel_toplevel_get_id (panel_widget->toplevel);
1111
808
}
1112
809
 
1113
810
static gboolean
1134
831
                            const char *id,
1135
832
                            gboolean    immediate)
1136
833
{
1137
 
        PanelGConfKeyType  key_type;
1138
 
        GConfClient       *client;
1139
 
        PanelWidget       *panel_widget;
1140
 
        const char        *key;
1141
 
        const char        *toplevel_id;
1142
 
        char              *old_toplevel_id;
1143
 
        gboolean           right_stick;
1144
 
        gboolean           locked;
1145
 
        int                position;
 
834
        PanelWidget *panel_widget;
 
835
        const char  *toplevel_id;
 
836
        AppletData  *applet_data;
1146
837
 
1147
838
        g_return_if_fail (applet_info != NULL);
 
839
        g_return_if_fail (G_IS_OBJECT (applet_info->widget));
1148
840
 
1149
841
        if (!immediate) {
1150
842
                if (!queued_position_source)
1163
855
        if (!(toplevel_id = panel_applet_get_toplevel_id (applet_info)))
1164
856
                return;
1165
857
 
1166
 
        client  = panel_gconf_get_client ();
1167
 
 
1168
 
        key_type = applet_info->type == PANEL_OBJECT_APPLET ? PANEL_GCONF_APPLETS : PANEL_GCONF_OBJECTS;
1169
 
        
1170
858
        panel_widget = panel_applet_get_panel_widget (applet_info);
1171
859
 
1172
 
        /* FIXME: Instead of getting keys, comparing and setting, there
1173
 
           should be a dirty flag */
1174
 
 
1175
 
        key = panel_gconf_full_key (key_type, id, "toplevel_id");
1176
 
        old_toplevel_id = gconf_client_get_string (client, key, NULL);
1177
 
        if (old_toplevel_id == NULL || strcmp (old_toplevel_id, toplevel_id) != 0)
1178
 
                gconf_client_set_string (client, key, toplevel_id, NULL);
1179
 
        g_free (old_toplevel_id);
1180
 
 
1181
 
        /* Note: changing some properties of the panel that may not be locked down
1182
 
           (e.g. background) can change the state of the "panel_right_stick" and
1183
 
           "position" properties of an applet that may in fact be locked down.
1184
 
           So check if these are writable before attempting to write them */
1185
 
 
1186
 
        right_stick = panel_is_applet_right_stick (applet_info->widget) ? 1 : 0;
1187
 
        key = panel_gconf_full_key (
1188
 
                        key_type, id, "panel_right_stick");
1189
 
        if (gconf_client_key_is_writable (client, key, NULL) &&
1190
 
            (gconf_client_get_bool (client, key, NULL) ? 1 : 0) != right_stick)
1191
 
                gconf_client_set_bool (client, key, right_stick, NULL);
1192
 
 
1193
 
        position = panel_applet_get_position (applet_info);
1194
 
        if (right_stick && !panel_widget->packed)
1195
 
                position = panel_widget->size - position;
1196
 
 
1197
 
        key = panel_gconf_full_key (key_type, id, "position");
1198
 
        if (gconf_client_key_is_writable (client, key, NULL) &&
1199
 
            gconf_client_get_int (client, key, NULL) != position)
1200
 
                gconf_client_set_int (client, key, position, NULL);
1201
 
        
1202
 
        locked = panel_widget_get_applet_locked (panel_widget, applet_info->widget) ? 1 : 0;
1203
 
        key = panel_gconf_full_key (key_type, id, "locked");
1204
 
        if (gconf_client_get_bool (client, key, NULL) ? 1 : 0 != locked)
1205
 
                gconf_client_set_bool (client, key, locked, NULL);
 
860
        applet_data = g_object_get_data (G_OBJECT (applet_info->widget),
 
861
                                         PANEL_APPLET_DATA);
 
862
 
 
863
        g_settings_set_string (applet_info->settings,
 
864
                               PANEL_OBJECT_TOPLEVEL_ID_KEY,
 
865
                               toplevel_id);
 
866
        g_settings_set_enum (applet_info->settings,
 
867
                             PANEL_OBJECT_PACK_TYPE_KEY,
 
868
                             applet_data->pack_type);
 
869
        g_settings_set_int (applet_info->settings,
 
870
                            PANEL_OBJECT_PACK_INDEX_KEY,
 
871
                            applet_data->pack_index);
1206
872
}
1207
873
 
1208
874
const char *
1275
941
 
1276
942
AppletInfo *
1277
943
panel_applet_register (GtkWidget       *applet,
1278
 
                       gpointer         data,
1279
 
                       GDestroyNotify   data_destroy,
1280
944
                       PanelWidget     *panel,
1281
 
                       gboolean         locked,
1282
 
                       gint             pos,
1283
 
                       gboolean         exactpos,
1284
945
                       PanelObjectType  type,
1285
 
                       const char      *id)
 
946
                       const char      *id,
 
947
                       GSettings       *settings,
 
948
                       gpointer         data,
 
949
                       GDestroyNotify   data_destroy)
1286
950
{
1287
 
        AppletInfo *info;
1288
 
        const char *key;
 
951
        AppletInfo          *info;
 
952
        PanelObjectPackType  pack_type;
 
953
        int                  pack_index;
1289
954
        
1290
955
        g_return_val_if_fail (applet != NULL && panel != NULL, NULL);
1291
956
 
1298
963
        info = g_new0 (AppletInfo, 1);
1299
964
        info->type         = type;
1300
965
        info->widget       = applet;
 
966
        info->settings     = g_object_ref (settings);
1301
967
        info->menu         = NULL;
 
968
        info->edit_menu    = NULL;
1302
969
        info->data         = data;
1303
970
        info->data_destroy = data_destroy;
1304
971
        info->user_menu    = NULL;
1305
 
        info->move_item    = NULL;
1306
972
        info->id           = g_strdup (id);
1307
973
 
1308
974
        g_object_set_data (G_OBJECT (applet), "applet_info", info);
1309
975
 
1310
 
        if (type != PANEL_OBJECT_APPLET)
1311
 
                panel_lockdown_notify_add (G_CALLBACK (panel_applet_recreate_menu),
1312
 
                                           info);
1313
 
 
1314
 
        key = panel_gconf_full_key ((type == PANEL_OBJECT_APPLET) ?
1315
 
                                     PANEL_GCONF_APPLETS : PANEL_GCONF_OBJECTS,
1316
 
                                    id, "locked");
1317
 
        panel_gconf_notify_add_while_alive (key,
1318
 
                                            (GConfClientNotifyFunc) panel_applet_locked_change_notify,
1319
 
                                            G_OBJECT (applet));
1320
 
 
1321
 
        if (type == PANEL_OBJECT_DRAWER) {
1322
 
                Drawer *drawer = data;
1323
 
                PanelWidget *assoc_panel;
1324
 
 
1325
 
                assoc_panel = panel_toplevel_get_panel_widget (drawer->toplevel);
1326
 
 
1327
 
                g_object_set_data (G_OBJECT (applet),
1328
 
                                   PANEL_APPLET_ASSOC_PANEL_KEY, assoc_panel);
1329
 
                assoc_panel->master_widget = applet;
1330
 
                g_object_add_weak_pointer (
1331
 
                        G_OBJECT (applet), (gpointer *) &assoc_panel->master_widget);
1332
 
        }
1333
 
 
1334
 
        g_object_set_data (G_OBJECT (applet),
1335
 
                           PANEL_APPLET_FORBIDDEN_PANELS, NULL);
1336
 
 
1337
976
        registered_applets = g_slist_append (registered_applets, info);
1338
977
 
1339
 
        if (panel_widget_add (panel, applet, locked, pos, exactpos) == -1 &&
1340
 
            panel_widget_add (panel, applet, locked, 0, TRUE) == -1) {
1341
 
                GSList *l;
1342
 
 
1343
 
                for (l = panels; l; l = l->next) {
1344
 
                        panel = PANEL_WIDGET (l->data);
1345
 
 
1346
 
                        if (panel_widget_add (panel, applet, locked, 0, TRUE) != -1)
1347
 
                                break;
1348
 
                }
1349
 
 
1350
 
                if (!l) {
1351
 
                        g_warning (_("Cannot find an empty spot"));
1352
 
                        panel_profile_delete_object (info);
1353
 
                        return NULL;
1354
 
                }
1355
 
        }
 
978
        /* Find where to insert the applet */
 
979
        pack_type = g_settings_get_enum (info->settings, PANEL_OBJECT_PACK_TYPE_KEY);
 
980
        pack_index = g_settings_get_int (info->settings, PANEL_OBJECT_PACK_INDEX_KEY);
 
981
 
 
982
        /* Insert it */
 
983
        panel_widget_add (panel, applet, pack_type, pack_index, TRUE);
1356
984
 
1357
985
        if (BUTTON_IS_WIDGET (applet) ||
1358
986
            gtk_widget_get_has_window (applet)) {
1360
988
                                  G_CALLBACK (applet_button_press),
1361
989
                                  info);
1362
990
 
1363
 
                g_signal_connect (applet, "popup_menu",
1364
 
                                  G_CALLBACK (applet_popup_menu),
 
991
                g_signal_connect (applet, "key_press_event",
 
992
                                  G_CALLBACK (applet_key_press),
1365
993
                                  info);
1366
994
        }
1367
995
 
1369
997
                          G_CALLBACK (panel_applet_destroy),
1370
998
                          info);
1371
999
 
1372
 
        panel_applet_set_dnd_enabled (info, !locked);
 
1000
        panel_applet_set_dnd_enabled (info, TRUE);
1373
1001
 
1374
 
        gtk_widget_show_all (applet);
 
1002
        gtk_widget_show (applet);
1375
1003
 
1376
1004
        orientation_change (info, panel);
1377
1005
        size_change (info, panel);
1385
1013
        return info;
1386
1014
}
1387
1015
 
1388
 
int
1389
 
panel_applet_get_position (AppletInfo *applet)
 
1016
GSettings *
 
1017
panel_applet_get_settings (AppletInfo *applet)
1390
1018
{
1391
 
        AppletData *applet_data;
1392
 
 
1393
 
        g_return_val_if_fail (applet != NULL, 0);
1394
 
        g_return_val_if_fail (G_IS_OBJECT (applet->widget), 0);
1395
 
 
1396
 
        applet_data = g_object_get_data (G_OBJECT (applet->widget), PANEL_APPLET_DATA);
1397
 
 
1398
 
        return applet_data->pos;
 
1019
        g_return_val_if_fail (applet != NULL, NULL);
 
1020
 
 
1021
        return applet->settings;
1399
1022
}
1400
1023
 
1401
1024
gboolean
1402
1025
panel_applet_can_freely_move (AppletInfo *applet)
1403
1026
{
1404
 
        GConfClient       *client;
1405
 
        PanelGConfKeyType  key_type;
1406
 
        const char        *key;
1407
 
 
1408
 
        if (panel_lockdown_get_locked_down ())
1409
 
                return FALSE;
1410
 
 
1411
 
        client  = panel_gconf_get_client ();
1412
 
        
1413
 
        key_type = (applet->type == PANEL_OBJECT_APPLET) ? PANEL_GCONF_APPLETS : PANEL_GCONF_OBJECTS;
1414
 
       
1415
 
        key = panel_gconf_full_key (key_type, applet->id, "position");
1416
 
        if (!gconf_client_key_is_writable (client, key, NULL))
1417
 
                return FALSE;
1418
 
 
1419
 
        key = panel_gconf_full_key (key_type, applet->id, "toplevel_id");
1420
 
        if (!gconf_client_key_is_writable (client, key, NULL))
1421
 
                return FALSE;
1422
 
 
1423
 
        key = panel_gconf_full_key (key_type, applet->id, "panel_right_stick");
1424
 
        if (!gconf_client_key_is_writable (client, key, NULL))
1425
 
                return FALSE;
1426
 
 
1427
 
        return TRUE;
1428
 
}
1429
 
 
1430
 
gboolean
1431
 
panel_applet_lockable (AppletInfo *applet)
1432
 
{
1433
 
        GConfClient        *client;
1434
 
        PanelGConfKeyType   key_type;
1435
 
        const char         *key;
1436
 
 
1437
 
        if (panel_lockdown_get_locked_down ())
1438
 
                return FALSE;
1439
 
        
1440
 
        client  = panel_gconf_get_client ();
1441
 
        
1442
 
        key_type = (applet->type == PANEL_OBJECT_APPLET) ? PANEL_GCONF_APPLETS : PANEL_GCONF_OBJECTS;
1443
 
 
1444
 
        key = panel_gconf_full_key (key_type, applet->id, "locked");
1445
 
 
1446
 
        return gconf_client_key_is_writable (client, key, NULL);
 
1027
        /* if we check for more lockdown than this, then we'll need to update
 
1028
         * callers that use panel_lockdown_on_notify() */
 
1029
        if (panel_lockdown_get_panels_locked_down_s ())
 
1030
                return FALSE;
 
1031
 
 
1032
        return (g_settings_is_writable (applet->settings,
 
1033
                                        PANEL_OBJECT_TOPLEVEL_ID_KEY) &&
 
1034
                g_settings_is_writable (applet->settings,
 
1035
                                        PANEL_OBJECT_PACK_TYPE_KEY) &&
 
1036
                g_settings_is_writable (applet->settings,
 
1037
                                        PANEL_OBJECT_PACK_INDEX_KEY));
1447
1038
}