4
* Copyright (C) 2003 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22
* Mark McLoughlin <mark@skynet.ie>
27
#include "panel-profile.h"
30
#include <glib/gi18n.h>
32
#include <libpanel-util/panel-list.h>
35
#include "panel-compatibility.h"
36
#include "panel-gconf.h"
38
#include "panel-widget.h"
39
#include "panel-util.h"
40
#include "panel-multiscreen.h"
41
#include "panel-toplevel.h"
42
#include "panel-lockdown.h"
54
PanelOrientation orientation;
56
guint screen_changed : 1;
57
guint monitor_changed : 1;
58
guint size_changed : 1;
60
guint x_right_changed : 1;
61
guint x_centered_changed : 1;
63
guint y_bottom_changed : 1;
64
guint y_centered_changed : 1;
65
guint orientation_changed : 1;
66
} ToplevelLocationChange;
68
typedef const char *(*PanelProfileGetIdFunc) (gpointer object);
69
typedef gboolean (*PanelProfileOnLoadQueue) (const char *id);
70
typedef void (*PanelProfileLoadFunc) (GConfClient *client,
71
const char *profile_dir,
72
PanelGConfKeyType type,
74
typedef void (*PanelProfileDestroyFunc) (const char *id);
76
static GConfEnumStringPair panel_orientation_map [] = {
77
{ PANEL_ORIENTATION_TOP, "top" },
78
{ PANEL_ORIENTATION_BOTTOM, "bottom" },
79
{ PANEL_ORIENTATION_LEFT, "left" },
80
{ PANEL_ORIENTATION_RIGHT, "right" },
84
static GConfEnumStringPair panel_animation_speed_map [] = {
85
{ PANEL_ANIMATION_SLOW, "slow" },
86
{ PANEL_ANIMATION_MEDIUM, "medium" },
87
{ PANEL_ANIMATION_FAST, "fast" },
91
static GConfEnumStringPair panel_background_type_map [] = {
92
{ PANEL_BACK_NONE, "gtk" },
93
{ PANEL_BACK_COLOR, "color" },
94
{ PANEL_BACK_IMAGE, "image" },
98
static GConfEnumStringPair panel_object_type_map [] = {
99
{ PANEL_OBJECT_DRAWER, "drawer-object" },
100
{ PANEL_OBJECT_MENU, "menu-object" },
101
{ PANEL_OBJECT_LAUNCHER, "launcher-object" },
102
{ PANEL_OBJECT_APPLET, "bonobo-applet" },
103
{ PANEL_OBJECT_ACTION, "action-applet" },
104
{ PANEL_OBJECT_MENU_BAR, "menu-bar" },
105
{ PANEL_OBJECT_SEPARATOR, "separator" },
106
/* The following two are for backwards compatibility with 2.0.x */
107
{ PANEL_OBJECT_LOCK, "lock-object" },
108
{ PANEL_OBJECT_LOGOUT, "logout-object" },
112
static GQuark toplevel_id_quark = 0;
113
static GQuark queued_changes_quark = 0;
114
static GQuark commit_timeout_quark = 0;
116
static void panel_profile_object_id_list_update (GConfClient *client,
118
PanelGConfKeyType type);
121
panel_profile_map_orientation_string (const char *str,
122
PanelOrientation *orientation)
126
g_return_val_if_fail (orientation != NULL, FALSE);
131
if (!gconf_string_to_enum (panel_orientation_map, str, &mapped))
134
*orientation = mapped;
140
panel_profile_map_orientation (PanelOrientation orientation)
142
return gconf_enum_to_string (panel_orientation_map, orientation);
146
panel_profile_map_speed_string (const char *str,
147
PanelAnimationSpeed *speed)
151
g_return_val_if_fail (speed != NULL, FALSE);
156
if (!gconf_string_to_enum (panel_animation_speed_map, str, &mapped))
165
panel_profile_map_background_type_string (const char *str,
166
PanelBackgroundType *background_type)
170
g_return_val_if_fail (background_type != NULL, FALSE);
175
if (!gconf_string_to_enum (panel_background_type_map, str, &mapped))
178
*background_type = mapped;
184
panel_profile_map_background_type (PanelBackgroundType background_type)
186
return gconf_enum_to_string (panel_background_type_map, background_type);
190
panel_profile_map_object_type_string (const char *str,
191
PanelObjectType *object_type)
195
g_return_val_if_fail (object_type != NULL, FALSE);
200
if (!gconf_string_to_enum (panel_object_type_map, str, &mapped))
203
*object_type = mapped;
209
panel_profile_set_toplevel_id (PanelToplevel *toplevel,
212
if (!toplevel_id_quark)
213
toplevel_id_quark = g_quark_from_static_string ("panel-toplevel-id");
215
g_object_set_qdata_full (G_OBJECT (toplevel),
222
panel_profile_get_toplevel_id (PanelToplevel *toplevel)
224
if (!toplevel_id_quark)
227
return g_object_get_qdata (G_OBJECT (toplevel), toplevel_id_quark);
231
panel_profile_get_toplevel_by_id (const char *toplevel_id)
233
GSList *toplevels, *l;
235
if (!toplevel_id || !toplevel_id [0])
238
toplevels = panel_toplevel_list_toplevels ();
239
for (l = toplevels; l; l = l->next)
240
if (!strcmp (panel_profile_get_toplevel_id (l->data), toplevel_id))
247
panel_profile_find_new_id (PanelGConfKeyType type)
250
GSList *l, *existing_ids;
257
client = panel_gconf_get_client ();
260
case PANEL_GCONF_TOPLEVELS:
264
case PANEL_GCONF_OBJECTS:
268
case PANEL_GCONF_APPLETS:
274
g_assert_not_reached ();
278
key = panel_gconf_sprintf (PANEL_CONFIG_DIR "/%s", dir);
279
existing_ids = gconf_client_all_dirs (client, key, NULL);
281
for (i = 0; !retval; i++) {
282
retval = g_strdup_printf ("%s_%d", prefix, i);
284
for (l = existing_ids; l; l = l->next)
285
if (!strcmp (panel_gconf_basename (l->data), retval)) {
292
g_assert (retval != NULL);
294
for (l = existing_ids; l; l = l->next)
296
g_slist_free (existing_ids);
302
panel_profile_set_queued_changes (PanelToplevel *toplevel,
303
GConfChangeSet *changes)
305
if (!queued_changes_quark)
306
queued_changes_quark = g_quark_from_static_string ("panel-queued-changes");
308
g_object_set_qdata_full (G_OBJECT (toplevel),
309
queued_changes_quark,
311
(GDestroyNotify) gconf_change_set_unref);
314
static GConfChangeSet *
315
panel_profile_get_queued_changes (GObject *object)
317
if (!queued_changes_quark)
320
return g_object_get_qdata (object, queued_changes_quark);
324
panel_profile_remove_commit_timeout (guint timeout)
326
g_source_remove (timeout);
330
panel_profile_set_commit_timeout (PanelToplevel *toplevel,
333
GDestroyNotify destroy_notify;
335
if (!commit_timeout_quark)
336
commit_timeout_quark = g_quark_from_static_string ("panel-queued-timeout");
339
destroy_notify = (GDestroyNotify) panel_profile_remove_commit_timeout;
341
destroy_notify = NULL;
343
g_object_set_qdata_full (G_OBJECT (toplevel),
344
commit_timeout_quark,
345
GUINT_TO_POINTER (timeout),
350
panel_profile_get_commit_timeout (GObject *object)
352
if (!commit_timeout_quark)
355
return GPOINTER_TO_UINT (g_object_get_qdata (object, commit_timeout_quark));
359
panel_profile_get_toplevel_key (PanelToplevel *toplevel,
364
id = panel_profile_get_toplevel_id (toplevel);
366
return panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, key);
369
#define TOPLEVEL_IS_WRITABLE_FUNC(k, p, s) \
371
panel_profile_is_writable_##p##_##s (PanelToplevel *toplevel) \
373
GConfClient *client; \
375
client = panel_gconf_get_client (); \
376
key = panel_profile_get_toplevel_key (toplevel, k); \
377
return gconf_client_key_is_writable (client, key, NULL); \
381
panel_profile_set_background_type (PanelToplevel *toplevel,
382
PanelBackgroundType background_type)
387
client = panel_gconf_get_client ();
389
key = panel_profile_get_toplevel_key (toplevel, "background/type");
390
gconf_client_set_string (client,
392
panel_profile_map_background_type (background_type),
397
panel_profile_get_background_type (PanelToplevel *toplevel)
399
PanelBackgroundType background_type;
404
client = panel_gconf_get_client ();
406
key = panel_profile_get_toplevel_key (toplevel, "background/type");
407
str = gconf_client_get_string (client, key, NULL);
409
if (!str || !panel_profile_map_background_type_string (str, &background_type))
410
background_type = PANEL_BACK_NONE;
414
return background_type;
417
TOPLEVEL_IS_WRITABLE_FUNC ("background/type", background, type)
420
panel_profile_set_background_color (PanelToplevel *toplevel,
423
panel_profile_set_background_gdk_color (toplevel, &color->gdk);
424
panel_profile_set_background_opacity (toplevel, color->alpha);
428
panel_profile_get_background_color (PanelToplevel *toplevel,
431
panel_profile_get_background_gdk_color (toplevel, &(color->gdk));
432
color->alpha = panel_profile_get_background_opacity (toplevel);
435
TOPLEVEL_IS_WRITABLE_FUNC ("background/color", background, color)
438
panel_profile_set_background_gdk_color (PanelToplevel *toplevel,
445
client = panel_gconf_get_client ();
447
color_str = g_strdup_printf ("#%02x%02x%02x",
448
gdk_color->red / 256,
449
gdk_color->green / 256,
450
gdk_color->blue / 256);
452
key = panel_profile_get_toplevel_key (toplevel, "background/color");
453
gconf_client_set_string (client, key, color_str, NULL);
459
panel_profile_get_background_gdk_color (PanelToplevel *toplevel,
466
client = panel_gconf_get_client ();
468
key = panel_profile_get_toplevel_key (toplevel, "background/color");
469
color_str = gconf_client_get_string (client, key, NULL);
470
if (!color_str || !gdk_color_parse (color_str, gdk_color)) {
472
gdk_color->green = 0;
480
panel_profile_set_background_opacity (PanelToplevel *toplevel,
486
client = panel_gconf_get_client ();
488
key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
489
gconf_client_set_int (client, key, opacity, NULL);
493
panel_profile_get_background_opacity (PanelToplevel *toplevel)
499
client = panel_gconf_get_client ();
501
key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
502
opacity = gconf_client_get_int (client, key, NULL);
507
TOPLEVEL_IS_WRITABLE_FUNC ("background/opacity", background, opacity)
510
panel_profile_set_background_image (PanelToplevel *toplevel,
516
client = panel_gconf_get_client ();
518
key = panel_profile_get_toplevel_key (toplevel, "background/image");
520
if (image && image [0])
521
gconf_client_set_string (client, key, image, NULL);
523
gconf_client_unset (client, key, NULL);
527
panel_profile_get_background_image (PanelToplevel *toplevel)
533
client = panel_gconf_get_client ();
535
key = panel_profile_get_toplevel_key (toplevel, "background/image");
536
retval = gconf_client_get_string (client, key, NULL);
541
TOPLEVEL_IS_WRITABLE_FUNC ("background/image", background, image)
544
panel_profile_set_toplevel_name (PanelToplevel *toplevel,
550
client = panel_gconf_get_client ();
552
key = panel_profile_get_toplevel_key (toplevel, "name");
554
if (name && name [0])
555
gconf_client_set_string (client, key, name, NULL);
557
gconf_client_unset (client, key, NULL);
561
panel_profile_get_toplevel_name (PanelToplevel *toplevel)
567
client = panel_gconf_get_client ();
569
key = panel_profile_get_toplevel_key (toplevel, "name");
570
retval = gconf_client_get_string (client, key, NULL);
575
TOPLEVEL_IS_WRITABLE_FUNC ("name", toplevel, name)
578
panel_profile_set_toplevel_orientation (PanelToplevel *toplevel,
579
PanelOrientation orientation)
584
client = panel_gconf_get_client ();
586
key = panel_profile_get_toplevel_key (toplevel, "orientation");
587
gconf_client_set_string (client,
589
panel_profile_map_orientation (orientation),
594
panel_profile_get_toplevel_orientation (PanelToplevel *toplevel)
596
PanelOrientation orientation;
601
client = panel_gconf_get_client ();
603
key = panel_profile_get_toplevel_key (toplevel, "orientation");
604
str = gconf_client_get_string (client, key, NULL);
606
if (!panel_profile_map_orientation_string (str, &orientation))
607
orientation = panel_toplevel_get_orientation (toplevel);
614
TOPLEVEL_IS_WRITABLE_FUNC ("orientation", toplevel, orientation)
616
#define TOPLEVEL_GET_SET_FUNCS(k, p, t, s, a) \
618
panel_profile_set_##p##_##s (PanelToplevel *toplevel, a s) \
620
GConfClient *client; \
622
client = panel_gconf_get_client (); \
623
key = panel_profile_get_toplevel_key (toplevel, k); \
624
gconf_client_set_##t (client, key, s, NULL); \
627
panel_profile_get_##p##_##s (PanelToplevel *toplevel) \
629
GConfClient *client; \
632
client = panel_gconf_get_client (); \
633
key = panel_profile_get_toplevel_key (toplevel, k); \
634
retval = gconf_client_get_##t (client, key, NULL); \
637
TOPLEVEL_IS_WRITABLE_FUNC(k, p, s)
639
TOPLEVEL_GET_SET_FUNCS ("size", toplevel, int, size, int)
640
TOPLEVEL_GET_SET_FUNCS ("expand", toplevel, bool, expand, gboolean)
641
TOPLEVEL_GET_SET_FUNCS ("auto_hide", toplevel, bool, auto_hide, gboolean)
642
TOPLEVEL_GET_SET_FUNCS ("enable_buttons", toplevel, bool, enable_buttons, gboolean)
643
TOPLEVEL_GET_SET_FUNCS ("enable_arrows", toplevel, bool, enable_arrows, gboolean)
644
TOPLEVEL_GET_SET_FUNCS ("background/fit", background, bool, fit, gboolean)
645
TOPLEVEL_GET_SET_FUNCS ("background/stretch", background, bool, stretch, gboolean)
646
TOPLEVEL_GET_SET_FUNCS ("background/rotate", background, bool, rotate, gboolean)
649
panel_profile_get_attached_object_key (PanelToplevel *toplevel,
652
GtkWidget *attach_widget;
655
attach_widget = panel_toplevel_get_attach_widget (toplevel);
657
id = panel_applet_get_id_by_widget (attach_widget);
662
return panel_gconf_full_key (PANEL_GCONF_OBJECTS, id, key);
666
panel_profile_set_attached_custom_icon (PanelToplevel *toplevel,
667
const char *custom_icon)
672
client = panel_gconf_get_client ();
674
key = panel_profile_get_attached_object_key (toplevel, "use_custom_icon");
676
gconf_client_set_bool (client, key, custom_icon != NULL, NULL);
678
key = panel_profile_get_attached_object_key (toplevel, "custom_icon");
680
gconf_client_set_string (client, key, sure_string (custom_icon), NULL);
684
panel_profile_get_attached_custom_icon (PanelToplevel *toplevel)
689
client = panel_gconf_get_client ();
691
key = panel_profile_get_attached_object_key (toplevel, "use_custom_icon");
692
if (!key || !gconf_client_get_bool (client, key, NULL))
695
key = panel_profile_get_attached_object_key (toplevel, "custom_icon");
697
return key ? gconf_client_get_string (client, key, NULL) : NULL;
701
panel_profile_is_writable_attached_custom_icon (PanelToplevel *toplevel)
706
client = panel_gconf_get_client ();
708
key = panel_profile_get_attached_object_key (toplevel, "use_custom_icon");
712
if (!gconf_client_key_is_writable (client, key, NULL))
715
key = panel_profile_get_attached_object_key (toplevel, "custom_icon");
717
return key ? gconf_client_key_is_writable (client, key, NULL) : TRUE;
721
panel_profile_set_attached_tooltip (PanelToplevel *toplevel,
727
client = panel_gconf_get_client ();
729
key = panel_profile_get_attached_object_key (toplevel, "tooltip");
731
gconf_client_set_string (client, key, tooltip, NULL);
735
panel_profile_get_attached_tooltip (PanelToplevel *toplevel)
740
client = panel_gconf_get_client ();
742
key = panel_profile_get_attached_object_key (toplevel, "tooltip");
744
return key ? gconf_client_get_string (client, key, NULL) : NULL;
748
panel_profile_is_writable_attached_tooltip (PanelToplevel *toplevel)
753
client = panel_gconf_get_client ();
755
key = panel_profile_get_attached_object_key (toplevel, "tooltip");
757
return key ? gconf_client_key_is_writable (client, key, NULL) : TRUE;
760
static PanelBackgroundType
761
get_background_type (GConfClient *client,
762
const char *toplevel_dir)
764
PanelBackgroundType background_type;
765
GError *error = NULL;
769
key = panel_gconf_sprintf ("%s/background/type", toplevel_dir);
770
type_str = gconf_client_get_string (client, key, &error);
772
g_warning (_("Error reading GConf string value '%s': %s"),
773
key, error->message);
774
g_error_free (error);
775
return PANEL_BACK_NONE;
778
if (!type_str || !panel_profile_map_background_type_string (type_str, &background_type))
779
background_type = PANEL_BACK_NONE;
783
return background_type;
787
get_background_color (GConfClient *client,
788
const char *toplevel_dir,
796
key = panel_gconf_sprintf ("%s/background/color", toplevel_dir);
797
color_str = gconf_client_get_string (client, key, &error);
799
g_warning (_("Error reading GConf string value '%s': %s"),
800
key, error->message);
801
g_error_free (error);
802
} else if (!color_str || !gdk_color_parse (color_str, &(color->gdk))) {
804
color->gdk.green = 0;
811
key = panel_gconf_sprintf ("%s/background/opacity", toplevel_dir);
812
color->alpha = gconf_client_get_int (client, key, &error);
814
g_warning (_("Error reading GConf integer value '%s': %s"),
815
key, error->message);
816
g_error_free (error);
817
color->alpha = 65535; /* fallback to fully opaque */
822
get_background_image (GConfClient *client,
823
const char *toplevel_dir,
829
GError *error = NULL;
832
key = panel_gconf_sprintf ("%s/background/image", toplevel_dir);
833
image = gconf_client_get_string (client, key, &error);
835
g_warning (_("Error reading GConf string value '%s': %s"),
836
key, error->message);
837
g_error_free (error);
840
key = panel_gconf_sprintf ("%s/background/fit", toplevel_dir);
841
*fit = gconf_client_get_bool (client, key, NULL);
843
key = panel_gconf_sprintf ("%s/background/stretch", toplevel_dir);
844
*stretch = gconf_client_get_bool (client, key, NULL);
846
key = panel_gconf_sprintf ("%s/background/rotate", toplevel_dir);
847
*rotate = gconf_client_get_bool (client, key, NULL);
853
panel_profile_load_background (PanelToplevel *toplevel,
855
const char *toplevel_dir)
857
PanelWidget *panel_widget;
858
PanelBackground *background;
859
PanelBackgroundType background_type;
866
panel_widget = panel_toplevel_get_panel_widget (toplevel);
867
background = &panel_widget->background;
869
background_type = get_background_type (client, toplevel_dir);
871
get_background_color (client, toplevel_dir, &color);
873
image = get_background_image (client, toplevel_dir, &fit, &stretch, &rotate);
875
panel_background_set (background,
887
panel_profile_commit_toplevel_changes (PanelToplevel *toplevel)
889
GConfChangeSet *queued_changes;
891
queued_changes = panel_profile_get_queued_changes (G_OBJECT (toplevel));
893
gconf_client_commit_change_set (
894
panel_gconf_get_client (),
895
queued_changes, FALSE, NULL);
897
panel_profile_set_queued_changes (toplevel, NULL);
898
panel_profile_set_commit_timeout (toplevel, 0);
904
panel_profile_queue_toplevel_location_change (PanelToplevel *toplevel,
905
ToplevelLocationChange *change)
907
GConfChangeSet *queued_changes;
908
guint commit_timeout;
910
queued_changes = panel_profile_get_queued_changes (G_OBJECT (toplevel));
911
if (!queued_changes) {
912
queued_changes = gconf_change_set_new ();
913
panel_profile_set_queued_changes (toplevel, queued_changes);
916
if (change->screen_changed)
917
gconf_change_set_set_int (
919
panel_profile_get_toplevel_key (toplevel, "screen"),
920
gdk_screen_get_number (change->screen));
922
if (change->monitor_changed)
923
gconf_change_set_set_int (
925
panel_profile_get_toplevel_key (toplevel, "monitor"),
928
if (change->size_changed)
929
gconf_change_set_set_int (
931
panel_profile_get_toplevel_key (toplevel, "size"),
934
if (change->orientation_changed)
935
gconf_change_set_set_string (
937
panel_profile_get_toplevel_key (toplevel, "orientation"),
938
gconf_enum_to_string (panel_orientation_map, change->orientation));
940
if (!panel_toplevel_get_expand (toplevel)) {
941
if (change->x_changed)
942
gconf_change_set_set_int (
944
panel_profile_get_toplevel_key (toplevel, "x"),
947
if (change->x_right_changed)
948
gconf_change_set_set_int (
950
panel_profile_get_toplevel_key (toplevel, "x_right"),
953
if (change->x_centered_changed)
954
gconf_change_set_set_bool (
956
panel_profile_get_toplevel_key (toplevel, "x_centered"),
959
if (change->y_changed)
960
gconf_change_set_set_int (
962
panel_profile_get_toplevel_key (toplevel, "y"),
965
if (change->y_bottom_changed)
966
gconf_change_set_set_int (
968
panel_profile_get_toplevel_key (toplevel, "y_bottom"),
971
if (change->y_centered_changed)
972
gconf_change_set_set_bool (
974
panel_profile_get_toplevel_key (toplevel, "y_centered"),
978
commit_timeout = panel_profile_get_commit_timeout (G_OBJECT (toplevel));
979
if (!commit_timeout) {
982
(GSourceFunc) panel_profile_commit_toplevel_changes,
984
panel_profile_set_commit_timeout (toplevel, commit_timeout);
988
#define TOPLEVEL_LOCATION_CHANGED_HANDLER(c) \
990
panel_profile_toplevel_##c##_changed (PanelToplevel *toplevel) \
992
ToplevelLocationChange change = { NULL }; \
993
change.c##_changed = TRUE; \
994
change.c = panel_toplevel_get_##c (toplevel); \
995
panel_profile_queue_toplevel_location_change (toplevel, &change); \
998
TOPLEVEL_LOCATION_CHANGED_HANDLER(monitor)
999
TOPLEVEL_LOCATION_CHANGED_HANDLER(size)
1000
TOPLEVEL_LOCATION_CHANGED_HANDLER(orientation)
1001
TOPLEVEL_LOCATION_CHANGED_HANDLER(x_centered)
1002
TOPLEVEL_LOCATION_CHANGED_HANDLER(y_centered)
1004
#define TOPLEVEL_POSITION_CHANGED_HANDLER(c) \
1006
panel_profile_toplevel_##c##_changed (PanelToplevel *toplevel) \
1008
ToplevelLocationChange change = { NULL }; \
1009
int x, y, x_right, y_bottom; \
1010
change.c##_changed = TRUE; \
1011
panel_toplevel_get_position (toplevel, \
1015
panel_profile_queue_toplevel_location_change (toplevel, &change); \
1018
TOPLEVEL_POSITION_CHANGED_HANDLER(x)
1019
TOPLEVEL_POSITION_CHANGED_HANDLER(x_right)
1020
TOPLEVEL_POSITION_CHANGED_HANDLER(y)
1021
TOPLEVEL_POSITION_CHANGED_HANDLER(y_bottom)
1024
panel_profile_toplevel_screen_changed (PanelToplevel *toplevel)
1026
ToplevelLocationChange change = { NULL };
1028
change.screen_changed = TRUE;
1029
change.screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
1031
panel_profile_queue_toplevel_location_change (toplevel, &change);
1035
panel_profile_connect_to_toplevel (PanelToplevel *toplevel)
1037
g_signal_connect (toplevel, "notify::screen",
1038
G_CALLBACK (panel_profile_toplevel_screen_changed), NULL);
1039
g_signal_connect (toplevel, "notify::monitor",
1040
G_CALLBACK (panel_profile_toplevel_monitor_changed), NULL);
1041
g_signal_connect (toplevel, "notify::size",
1042
G_CALLBACK (panel_profile_toplevel_size_changed), NULL);
1043
g_signal_connect (toplevel, "notify::x",
1044
G_CALLBACK (panel_profile_toplevel_x_changed), NULL);
1045
g_signal_connect (toplevel, "notify::x-right",
1046
G_CALLBACK (panel_profile_toplevel_x_right_changed), NULL);
1047
g_signal_connect (toplevel, "notify::x-centered",
1048
G_CALLBACK (panel_profile_toplevel_x_centered_changed), NULL);
1049
g_signal_connect (toplevel, "notify::y",
1050
G_CALLBACK (panel_profile_toplevel_y_changed), NULL);
1051
g_signal_connect (toplevel, "notify::y-bottom",
1052
G_CALLBACK (panel_profile_toplevel_y_bottom_changed), NULL);
1053
g_signal_connect (toplevel, "notify::y-centered",
1054
G_CALLBACK (panel_profile_toplevel_y_centered_changed), NULL);
1055
g_signal_connect (toplevel, "notify::orientation",
1056
G_CALLBACK (panel_profile_toplevel_orientation_changed), NULL);
1060
set_name_from_string (PanelToplevel *toplevel,
1066
panel_toplevel_set_name (toplevel, str);
1070
set_orientation_from_string (PanelToplevel *toplevel,
1073
PanelOrientation orientation;
1075
if (!str || !panel_profile_map_orientation_string (str, &orientation))
1078
panel_toplevel_set_orientation (toplevel, orientation);
1082
set_animation_speed_from_string (PanelToplevel *toplevel,
1085
PanelAnimationSpeed animation_speed;
1087
if (!str || !panel_profile_map_speed_string (str, &animation_speed))
1090
panel_toplevel_set_animation_speed (toplevel, animation_speed);
1094
panel_profile_toplevel_change_notify (GConfClient *client,
1097
PanelToplevel *toplevel)
1102
key = panel_gconf_basename (gconf_entry_get_key (entry));
1104
if (!(value = gconf_entry_get_value (entry)))
1107
#define UPDATE_STRING(k, n) \
1108
if (!strcmp (key, k)) { \
1109
if (value->type == GCONF_VALUE_STRING) \
1110
set_##n##_from_string (toplevel, \
1111
gconf_value_get_string (value)); \
1114
#define UPDATE_INT(k, n) \
1115
if (!strcmp (key, k)) { \
1116
if (value->type == GCONF_VALUE_INT) \
1117
panel_toplevel_set_##n (toplevel, \
1118
gconf_value_get_int (value)); \
1121
#define UPDATE_BOOL(k, n) \
1122
if (!strcmp (key, k)) { \
1123
if (value->type == GCONF_VALUE_BOOL) \
1124
panel_toplevel_set_##n (toplevel, \
1125
gconf_value_get_bool (value)); \
1128
#define UPDATE_POS(k, n, n2) \
1129
if (!strcmp (key, k)) { \
1130
if (value->type == GCONF_VALUE_INT) { \
1131
int x, x_right, y, y_bottom; \
1132
panel_toplevel_get_position (toplevel, &x, &x_right, \
1134
panel_toplevel_set_##n ( \
1136
gconf_value_get_int (value), \
1138
panel_toplevel_get_##n##_centered (toplevel)); \
1142
#define UPDATE_POS2(k, n, n2) \
1143
if (!strcmp (key, k)) { \
1144
if (value->type == GCONF_VALUE_INT) { \
1145
int x, x_right, y, y_bottom; \
1146
panel_toplevel_get_position (toplevel, &x, &x_right, \
1148
panel_toplevel_set_##n ( \
1151
gconf_value_get_int (value), \
1152
panel_toplevel_get_##n##_centered (toplevel)); \
1156
#define UPDATE_CENTERED(k, n, n2) \
1157
if (!strcmp (key, k)) { \
1158
if (value->type == GCONF_VALUE_BOOL) { \
1159
int x, x_right, y, y_bottom; \
1160
panel_toplevel_get_position (toplevel, &x, &x_right, \
1162
panel_toplevel_set_##n ( \
1163
toplevel, n, n2, gconf_value_get_bool (value)); \
1167
if (!strcmp (key, "screen")) {
1168
if (value->type == GCONF_VALUE_INT) {
1171
screen = gdk_display_get_screen (
1172
gdk_display_get_default (),
1173
gconf_value_get_int (value));
1175
gtk_window_set_screen (GTK_WINDOW (toplevel), screen);
1177
/* Make sure to set the key back to an actual
1178
* available screen so it will get loaded on
1181
panel_profile_toplevel_screen_changed (toplevel);
1185
else UPDATE_INT ("monitor", monitor)
1186
else UPDATE_STRING ("name", name)
1187
else UPDATE_BOOL ("expand", expand)
1188
else UPDATE_STRING ("orientation", orientation)
1189
else UPDATE_INT ("size", size)
1190
else UPDATE_POS ("x", x, x_right)
1191
else UPDATE_POS ("y", y, y_bottom)
1192
else UPDATE_POS2 ("x_right", x, x_right)
1193
else UPDATE_POS2 ("y_bottom", y, y_bottom)
1194
else UPDATE_CENTERED ("x_centered", x, x_right)
1195
else UPDATE_CENTERED ("y_centered", y, y_bottom)
1196
else UPDATE_BOOL ("auto_hide", auto_hide)
1197
else UPDATE_BOOL ("enable_animations", animate)
1198
else UPDATE_BOOL ("enable_buttons", enable_buttons)
1199
else UPDATE_BOOL ("enable_arrows", enable_arrows)
1200
else UPDATE_INT ("hide_delay", hide_delay)
1201
else UPDATE_INT ("unhide_delay", unhide_delay)
1202
else UPDATE_INT ("auto_hide_size", auto_hide_size)
1203
else UPDATE_STRING ("animation_speed", animation_speed)
1207
panel_profile_background_change_notify (GConfClient *client,
1210
PanelToplevel *toplevel)
1212
PanelWidget *panel_widget;
1213
PanelBackground *background;
1217
key = panel_gconf_basename (gconf_entry_get_key (entry));
1219
if (!(value = gconf_entry_get_value (entry)))
1222
panel_widget = panel_toplevel_get_panel_widget (toplevel);
1223
background = &panel_widget->background;
1225
if (!strcmp (key, "type")) {
1226
if (value->type == GCONF_VALUE_STRING) {
1227
PanelBackgroundType background_type;
1229
if (panel_profile_map_background_type_string (
1230
gconf_value_get_string (value),
1231
&background_type)) {
1232
panel_background_set_type (background, background_type);
1233
panel_toplevel_update_edges (toplevel);
1236
} else if (!strcmp (key, "color")) {
1237
if (value->type == GCONF_VALUE_STRING) {
1241
str = gconf_value_get_string (value);
1243
if (gdk_color_parse (str, &gdk_color))
1244
panel_background_set_gdk_color (background, &gdk_color);
1246
} else if (!strcmp (key, "opacity")) {
1247
if (value->type == GCONF_VALUE_INT)
1248
panel_background_set_opacity (background,
1249
gconf_value_get_int (value));
1250
} else if (!strcmp (key, "image")) {
1251
if (value->type == GCONF_VALUE_STRING)
1252
panel_background_set_image (background,
1253
gconf_value_get_string (value));
1254
} else if (!strcmp (key, "fit")) {
1255
if (value->type == GCONF_VALUE_BOOL)
1256
panel_background_set_fit (background,
1257
gconf_value_get_bool (value));
1258
} else if (!strcmp (key, "stretch")) {
1259
if (value->type == GCONF_VALUE_BOOL)
1260
panel_background_set_stretch (background,
1261
gconf_value_get_bool (value));
1262
} else if (!strcmp (key, "rotate")) {
1263
if (value->type == GCONF_VALUE_BOOL)
1264
panel_background_set_rotate (background,
1265
gconf_value_get_bool (value));
1270
panel_profile_disconnect_toplevel (PanelToplevel *toplevel,
1273
GConfClient *client;
1274
guint notify_id = GPOINTER_TO_UINT (data);
1276
client = panel_gconf_get_client ();
1278
gconf_client_notify_remove (client, notify_id);
1282
panel_profile_toplevel_notify_add (PanelToplevel *toplevel,
1284
GConfClientNotifyFunc func,
1287
GConfClient *client;
1291
client = panel_gconf_get_client ();
1294
tmp = panel_gconf_sprintf (PANEL_CONFIG_DIR "/toplevels/%s",
1295
panel_profile_get_toplevel_id (toplevel));
1297
tmp = panel_gconf_sprintf (PANEL_CONFIG_DIR "/toplevels/%s/%s",
1298
panel_profile_get_toplevel_id (toplevel),
1301
retval = gconf_client_notify_add (client, tmp, func, data, NULL, NULL);
1307
panel_profile_save_id_list (PanelGConfKeyType type,
1311
GConfClient *client;
1313
const char *id_list;
1315
g_assert (!(resave && list != NULL));
1317
client = panel_gconf_get_client ();
1319
id_list = panel_gconf_key_type_to_id_list (type);
1321
key = panel_gconf_general_key (id_list);
1323
list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
1325
/* Make sure the elements in the list appear only once. We only
1326
* do it when we save a list with new elements. */
1327
list = panel_g_slist_make_unique (list,
1328
(GCompareFunc) strcmp,
1332
gconf_client_set_list (client, key, GCONF_VALUE_STRING, list, NULL);
1334
g_slist_foreach (list, (GFunc) g_free, NULL);
1335
g_slist_free (list);
1339
panel_profile_save_other_id_lists (PanelGConfKeyType type)
1341
if (type != PANEL_GCONF_TOPLEVELS)
1342
panel_profile_save_id_list (PANEL_GCONF_TOPLEVELS, NULL, TRUE);
1344
if (type != PANEL_GCONF_OBJECTS)
1345
panel_profile_save_id_list (PANEL_GCONF_OBJECTS, NULL, TRUE);
1347
if (type != PANEL_GCONF_APPLETS)
1348
panel_profile_save_id_list (PANEL_GCONF_APPLETS, NULL, TRUE);
1352
panel_profile_add_to_list (PanelGConfKeyType type,
1355
GConfClient *client;
1358
const char *id_list;
1361
client = panel_gconf_get_client ();
1363
id_list = panel_gconf_key_type_to_id_list (type);
1365
key = panel_gconf_general_key (id_list);
1366
list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
1368
new_id = id ? g_strdup (id) : panel_profile_find_new_id (type);
1370
list = g_slist_append (list, new_id);
1372
panel_profile_save_id_list (type, list, FALSE);
1373
panel_profile_save_other_id_lists (type);
1377
panel_profile_remove_from_list (PanelGConfKeyType type,
1380
GConfClient *client;
1383
const char *id_list;
1385
client = panel_gconf_get_client ();
1387
id_list = panel_gconf_key_type_to_id_list (type);
1389
key = panel_gconf_general_key (id_list);
1390
list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
1392
/* Remove all occurrence of id and not just the first. We're more solid
1393
* this way (see bug #137308 for example). */
1400
if (!strcmp (id, l->data)) {
1402
list = g_slist_delete_link (list, l);
1408
panel_profile_save_id_list (type, list, FALSE);
1409
panel_profile_save_other_id_lists (type);
1413
panel_profile_id_list_is_writable (PanelGConfKeyType type)
1415
GConfClient *client;
1417
const char *id_list;
1419
client = panel_gconf_get_client ();
1421
id_list = panel_gconf_key_type_to_id_list (type);
1423
key = panel_gconf_general_key (id_list);
1424
return gconf_client_key_is_writable (client, key, NULL);
1428
panel_profile_id_lists_are_writable (void)
1431
panel_profile_id_list_is_writable (PANEL_GCONF_TOPLEVELS) &&
1432
panel_profile_id_list_is_writable (PANEL_GCONF_APPLETS) &&
1433
panel_profile_id_list_is_writable (PANEL_GCONF_OBJECTS);
1437
panel_profile_find_empty_spot (GdkScreen *screen,
1438
PanelOrientation *orientation,
1444
gboolean found_a_spot = FALSE;
1447
*orientation = PANEL_ORIENTATION_TOP;
1449
filled_spots = g_new0 (int, panel_multiscreen_monitors (screen));
1451
for (li = panel_toplevel_list_toplevels (); li != NULL; li = li->next) {
1452
PanelToplevel *toplevel = li->data;
1453
GdkScreen *toplevel_screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
1454
int toplevel_monitor = panel_toplevel_get_monitor (toplevel);
1456
if (toplevel_screen != screen ||
1457
panel_toplevel_get_is_attached (toplevel) ||
1458
toplevel_monitor < 0)
1461
filled_spots[toplevel_monitor] |= panel_toplevel_get_orientation (toplevel);
1464
for (i = 0; i < panel_multiscreen_monitors (screen); i++) {
1465
/* These are ordered based on "priority" of the
1466
orientation when picking it */
1467
if ( ! (filled_spots[i] & PANEL_ORIENTATION_TOP)) {
1468
*orientation = PANEL_ORIENTATION_TOP;
1470
found_a_spot = TRUE;
1472
} else if ( ! (filled_spots[i] & PANEL_ORIENTATION_BOTTOM)) {
1473
*orientation = PANEL_ORIENTATION_BOTTOM;
1475
found_a_spot = TRUE;
1477
} else if ( ! (filled_spots[i] & PANEL_ORIENTATION_RIGHT)) {
1478
*orientation = PANEL_ORIENTATION_RIGHT;
1480
found_a_spot = TRUE;
1482
} else if ( ! (filled_spots[i] & PANEL_ORIENTATION_LEFT)) {
1483
*orientation = PANEL_ORIENTATION_LEFT;
1485
found_a_spot = TRUE;
1490
g_free (filled_spots);
1492
return found_a_spot;
1496
panel_profile_create_toplevel (GdkScreen *screen)
1498
GConfClient *client;
1502
PanelOrientation orientation;
1505
g_return_if_fail (screen != NULL);
1507
client = panel_gconf_get_client ();
1509
id = panel_profile_find_new_id (PANEL_GCONF_TOPLEVELS);
1511
dir = g_strdup_printf (PANEL_CONFIG_DIR "/toplevels/%s", id);
1512
panel_gconf_associate_schemas_in_dir (client, dir, PANEL_SCHEMAS_DIR "/toplevels");
1515
key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, "screen");
1516
gconf_client_set_int (client, key, gdk_screen_get_number (screen), NULL);
1518
if (panel_profile_find_empty_spot (screen, &orientation, &monitor)) {
1519
key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, "monitor");
1520
gconf_client_set_int (client, key, monitor, NULL);
1522
key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, "orientation");
1523
gconf_client_set_string (client, key, panel_profile_map_orientation (orientation), NULL);
1526
panel_profile_add_to_list (PANEL_GCONF_TOPLEVELS, id);
1532
panel_profile_delete_toplevel_objects (const char *toplevel_id,
1533
PanelGConfKeyType key_type)
1535
GConfClient *client;
1537
GSList *new_list = NULL,*list, *l;
1539
client = panel_gconf_get_client ();
1541
key = panel_gconf_general_key (panel_gconf_key_type_to_id_list (key_type));
1542
list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
1544
for (l = list; l; l = l->next) {
1546
char *parent_toplevel_id;
1548
key = panel_gconf_full_key (key_type, id, "toplevel_id");
1549
parent_toplevel_id = gconf_client_get_string (client, key, NULL);
1551
if (parent_toplevel_id && !strcmp (toplevel_id, parent_toplevel_id)) {
1553
g_free (parent_toplevel_id);
1557
new_list = g_slist_prepend (new_list, id);
1559
g_free (parent_toplevel_id);
1561
g_slist_free (list);
1563
key = panel_gconf_general_key (panel_gconf_key_type_to_id_list (key_type));
1564
gconf_client_set_list (client, key, GCONF_VALUE_STRING, new_list, NULL);
1566
for (l = new_list; l; l = l->next)
1568
g_slist_free (new_list);
1572
panel_profile_delete_toplevel (PanelToplevel *toplevel)
1574
const char *toplevel_id;
1576
toplevel_id = panel_profile_get_toplevel_id (toplevel);
1578
panel_profile_delete_toplevel_objects (toplevel_id, PANEL_GCONF_OBJECTS);
1579
panel_profile_delete_toplevel_objects (toplevel_id, PANEL_GCONF_APPLETS);
1581
panel_profile_remove_from_list (PANEL_GCONF_TOPLEVELS, toplevel_id);
1585
get_toplevel_screen (GConfClient *client,
1586
const char *toplevel_dir)
1588
GError *error = NULL;
1589
GdkDisplay *display;
1593
key = panel_gconf_sprintf ("%s/screen", toplevel_dir);
1594
screen_n = gconf_client_get_int (client, key, &error);
1596
g_warning (_("Error reading GConf integer value '%s': %s"),
1597
key, error->message);
1598
g_error_free (error);
1599
return gdk_screen_get_default ();
1602
display = gdk_display_get_default ();
1604
if (screen_n < 0 || screen_n >= gdk_display_get_n_screens (display)) {
1606
g_warning (_("Panel '%s' is set to be displayed on screen %d which "
1607
"is not currently available. Not loading this panel."),
1608
toplevel_dir, screen_n);
1613
return gdk_display_get_screen (display, screen_n);
1617
panel_profile_load_toplevel (GConfClient *client,
1618
const char *profile_dir,
1619
PanelGConfKeyType type,
1620
const char *toplevel_id)
1622
PanelToplevel *toplevel;
1629
if (!toplevel_id || !toplevel_id [0])
1632
toplevel_dir = g_strdup_printf ("%s/toplevels/%s", profile_dir, toplevel_id);
1634
if (!gconf_client_dir_exists (client, toplevel_dir, NULL))
1635
panel_gconf_associate_schemas_in_dir (
1636
client, toplevel_dir, PANEL_SCHEMAS_DIR "/toplevels");
1638
gconf_client_add_dir (client,
1640
GCONF_CLIENT_PRELOAD_ONELEVEL,
1643
key = panel_gconf_sprintf ("%s/background", toplevel_dir);
1644
gconf_client_add_dir (client,
1646
GCONF_CLIENT_PRELOAD_ONELEVEL,
1649
if (!(screen = get_toplevel_screen (client, toplevel_dir))) {
1650
gconf_client_remove_dir (client, key, NULL);
1651
gconf_client_remove_dir (client, toplevel_dir, NULL);
1652
g_free (toplevel_dir);
1656
toplevel = g_object_new (PANEL_TYPE_TOPLEVEL,
1660
#define GET_INT(k, fn) \
1664
key = panel_gconf_sprintf ("%s/" k, toplevel_dir); \
1665
val = gconf_client_get_int (client, key, &error); \
1667
panel_toplevel_set_##fn (toplevel, val); \
1669
g_warning (_("Error reading GConf integer value '%s': %s"), \
1670
key, error->message); \
1671
g_error_free (error); \
1675
#define GET_BOOL(k, fn) \
1679
key = panel_gconf_sprintf ("%s/" k, toplevel_dir); \
1680
val = gconf_client_get_bool (client, key, &error); \
1682
panel_toplevel_set_##fn (toplevel, val); \
1684
g_warning (_("Error reading GConf boolean value '%s': %s"), \
1685
key, error->message); \
1686
g_error_free (error); \
1690
#define GET_STRING(k, fn) \
1694
key = panel_gconf_sprintf ("%s/" k, toplevel_dir); \
1695
val = gconf_client_get_string (client, key, &error); \
1696
if (!error && val) { \
1697
set_##fn##_from_string (toplevel, val); \
1699
} else if (error) { \
1700
g_warning (_("Error reading GConf string value '%s': %s"), \
1701
key, error->message); \
1702
g_error_free (error); \
1706
GET_STRING ("name", name);
1707
GET_INT ("monitor", monitor);
1708
GET_BOOL ("expand", expand);
1709
GET_STRING ("orientation", orientation);
1710
GET_INT ("size", size);
1711
GET_BOOL ("auto_hide", auto_hide);
1712
GET_BOOL ("enable_animations", animate);
1713
GET_BOOL ("enable_buttons", enable_buttons);
1714
GET_BOOL ("enable_arrows", enable_arrows);
1715
GET_INT ("hide_delay", hide_delay);
1716
GET_INT ("unhide_delay", unhide_delay);
1717
GET_INT ("auto_hide_size", auto_hide_size);
1718
GET_STRING ("animation_speed", animation_speed);
1720
#define GET_POSITION(a, b, c, fn) \
1722
gboolean centered; \
1725
key = panel_gconf_sprintf ("%s/" c, toplevel_dir); \
1726
centered = gconf_client_get_bool (client, key, &error); \
1728
key = panel_gconf_sprintf ("%s/" a, toplevel_dir); \
1729
position = gconf_client_get_int (client, key, &error); \
1732
GConfValue *value; \
1733
key = panel_gconf_sprintf ("%s/" b, toplevel_dir); \
1734
/* we need to do this since the key was added in 2.19 and \
1735
* the default value returned when the key is not set \
1736
* (for people coming from older versions) is 0, which \
1737
* is not what we want. */ \
1738
value = gconf_client_get_without_default (client, key, &error);\
1739
if (value && value->type == GCONF_VALUE_INT) \
1740
position2 = gconf_value_get_int (value); \
1745
gconf_value_free (value); \
1748
panel_toplevel_set_##fn (toplevel, position, position2, \
1751
g_warning (_("Error reading GConf integer value '%s': %s"), \
1752
key, error->message); \
1753
g_error_free (error); \
1757
GET_POSITION ("x", "x_right", "x_centered", x);
1758
GET_POSITION ("y", "y_bottom", "y_centered", y);
1760
panel_profile_load_background (toplevel, client, toplevel_dir);
1762
panel_profile_set_toplevel_id (toplevel, toplevel_id);
1764
panel_profile_connect_to_toplevel (toplevel);
1766
notify_id = panel_profile_toplevel_notify_add (
1769
(GConfClientNotifyFunc) panel_profile_toplevel_change_notify,
1771
g_signal_connect (toplevel, "destroy",
1772
G_CALLBACK (panel_profile_disconnect_toplevel),
1773
GUINT_TO_POINTER (notify_id));
1775
notify_id = panel_profile_toplevel_notify_add (
1778
(GConfClientNotifyFunc) panel_profile_background_change_notify,
1780
g_signal_connect (toplevel, "destroy",
1781
G_CALLBACK (panel_profile_disconnect_toplevel),
1782
GUINT_TO_POINTER (notify_id));
1784
g_free (toplevel_dir);
1786
panel_setup (toplevel);
1792
panel_profile_load_and_show_toplevel (GConfClient *client,
1793
const char *profile_dir,
1794
PanelGConfKeyType type,
1795
const char *toplevel_id)
1797
PanelToplevel *toplevel;
1798
const char *id_list;
1801
gboolean loading_queued_applets;
1803
toplevel = panel_profile_load_toplevel (client, profile_dir, type, toplevel_id);
1807
gtk_widget_show (GTK_WIDGET (toplevel));
1809
loading_queued_applets = FALSE;
1811
/* reload list of objects to get those that might be on the new
1813
id_list = panel_gconf_key_type_to_id_list (PANEL_GCONF_OBJECTS);
1814
key = panel_gconf_sprintf ("%s/general/%s", profile_dir, id_list);
1815
value = gconf_client_get (client, key, NULL);
1817
panel_profile_object_id_list_update (client, value,
1818
PANEL_GCONF_OBJECTS);
1819
loading_queued_applets = TRUE;
1820
gconf_value_free (value);
1823
id_list = panel_gconf_key_type_to_id_list (PANEL_GCONF_APPLETS);
1824
key = panel_gconf_sprintf ("%s/general/%s", profile_dir, id_list);
1825
value = gconf_client_get (client, key, NULL);
1827
panel_profile_object_id_list_update (client, value,
1828
PANEL_GCONF_APPLETS);
1829
loading_queued_applets = TRUE;
1830
gconf_value_free (value);
1833
if (!loading_queued_applets)
1834
panel_applet_load_queued_applets (FALSE);
1838
panel_profile_load_and_show_toplevel_startup (GConfClient *client,
1839
const char *profile_dir,
1840
PanelGConfKeyType type,
1841
const char *toplevel_id)
1843
PanelToplevel *toplevel;
1845
toplevel = panel_profile_load_toplevel (client, profile_dir, type, toplevel_id);
1847
gtk_widget_show (GTK_WIDGET (toplevel));
1851
panel_profile_destroy_toplevel (const char *id)
1853
PanelToplevel *toplevel;
1855
if (!(toplevel = panel_profile_get_toplevel_by_id (id)))
1858
gtk_widget_destroy (GTK_WIDGET (toplevel));
1862
panel_profile_prepare_object_with_id (PanelObjectType object_type,
1863
const char *toplevel_id,
1865
gboolean right_stick)
1867
PanelGConfKeyType key_type;
1868
GConfClient *client;
1873
key_type = (object_type == PANEL_OBJECT_APPLET) ? PANEL_GCONF_APPLETS : PANEL_GCONF_OBJECTS;
1875
client = panel_gconf_get_client ();
1877
id = panel_profile_find_new_id (key_type);
1879
dir = g_strdup_printf (PANEL_CONFIG_DIR "/%s/%s",
1880
(key_type == PANEL_GCONF_APPLETS) ? "applets" : "objects",
1882
panel_gconf_associate_schemas_in_dir (client, dir, PANEL_SCHEMAS_DIR "/objects");
1884
key = panel_gconf_full_key (key_type, id, "object_type");
1885
gconf_client_set_string (client,
1887
gconf_enum_to_string (panel_object_type_map, object_type),
1890
key = panel_gconf_full_key (key_type, id, "toplevel_id");
1891
gconf_client_set_string (client, key, toplevel_id, NULL);
1893
key = panel_gconf_full_key (key_type, id, "position");
1894
gconf_client_set_int (client, key, position, NULL);
1896
key = panel_gconf_full_key (key_type, id, "panel_right_stick");
1897
gconf_client_set_bool (client, key, right_stick, NULL);
1905
panel_profile_prepare_object (PanelObjectType object_type,
1906
PanelToplevel *toplevel,
1908
gboolean right_stick)
1910
return panel_profile_prepare_object_with_id (object_type,
1911
panel_profile_get_toplevel_id (toplevel),
1917
panel_profile_delete_object (AppletInfo *applet_info)
1919
PanelGConfKeyType type;
1922
type = (applet_info->type) == PANEL_OBJECT_APPLET ? PANEL_GCONF_APPLETS :
1923
PANEL_GCONF_OBJECTS;
1924
id = panel_applet_get_id (applet_info);
1926
panel_profile_remove_from_list (type, id);
1930
panel_profile_load_object (GConfClient *client,
1931
const char *profile_dir,
1932
PanelGConfKeyType type,
1935
PanelObjectType object_type;
1941
gboolean right_stick;
1944
object_dir = g_strdup_printf ("%s/%s/%s",
1946
type == PANEL_GCONF_OBJECTS ? "objects" : "applets",
1949
gconf_client_add_dir (client, object_dir, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
1951
key = panel_gconf_sprintf ("%s/object_type", object_dir);
1952
type_string = gconf_client_get_string (client, key, NULL);
1954
if (!panel_profile_map_object_type_string (type_string, &object_type)) {
1955
g_free (type_string);
1956
gconf_client_remove_dir (client, object_dir, NULL);
1957
g_free (object_dir);
1961
key = panel_gconf_sprintf ("%s/position", object_dir);
1962
position = gconf_client_get_int (client, key, NULL);
1964
key = panel_gconf_sprintf ("%s/toplevel_id", object_dir);
1965
toplevel_id = gconf_client_get_string (client, key, NULL);
1967
key = panel_gconf_sprintf ("%s/panel_right_stick", object_dir);
1968
right_stick = gconf_client_get_bool (client, key, NULL);
1970
key = panel_gconf_sprintf ("%s/locked", object_dir);
1971
locked = gconf_client_get_bool (client, key, NULL);
1973
panel_applet_queue_applet_to_load (id,
1980
g_free (toplevel_id);
1981
g_free (type_string);
1982
g_free (object_dir);
1986
panel_profile_destroy_object (const char *id)
1990
info = panel_applet_get_by_id (id);
1992
panel_applet_clean (info);
1996
panel_profile_delete_dir (GConfClient *client,
1997
PanelGConfKeyType type,
2004
case PANEL_GCONF_TOPLEVELS:
2005
type_str = "toplevels";
2007
case PANEL_GCONF_OBJECTS:
2008
type_str = "objects";
2010
case PANEL_GCONF_APPLETS:
2011
type_str = "applets";
2015
g_assert_not_reached ();
2019
if (type == PANEL_GCONF_TOPLEVELS) {
2020
key = panel_gconf_sprintf (PANEL_CONFIG_DIR "/%s/%s/background",
2022
gconf_client_remove_dir (client, key, NULL);
2025
key = panel_gconf_sprintf (PANEL_CONFIG_DIR "/%s/%s",
2027
gconf_client_remove_dir (client, key, NULL);
2029
gconf_client_recursive_unset (client,
2031
GCONF_UNSET_INCLUDING_SCHEMA_NAMES,
2036
panel_profile_object_exists (GSList *list,
2038
PanelProfileGetIdFunc get_id_func)
2045
for (l = list; l; l = l->next) {
2046
const char *check_id;
2048
check_id = get_id_func (l->data);
2049
g_assert (check_id != NULL);
2051
if (!strcmp (check_id, id))
2059
panel_profile_id_exists (GSList *id_list,
2064
if (!id_list || !id)
2067
for (l = id_list; l; l = l->next) {
2068
const char *check_id = gconf_value_get_string (l->data);
2070
if (!strcmp (id, check_id))
2078
panel_profile_load_added_ids (GConfClient *client,
2079
PanelGConfKeyType type,
2082
PanelProfileGetIdFunc get_id_func,
2083
PanelProfileLoadFunc load_handler,
2084
PanelProfileOnLoadQueue on_load_queue)
2086
GSList *added_ids = NULL;
2089
for (l = id_list; l; l = l->next) {
2090
const char *id = gconf_value_get_string (l->data);
2092
if (!panel_profile_object_exists (list, id, get_id_func) &&
2093
(on_load_queue == NULL || !on_load_queue (id)))
2094
added_ids = g_slist_prepend (added_ids, g_strdup (id));
2097
for (l = added_ids; l; l = l->next) {
2099
id = (char *) l->data;
2102
load_handler (client, PANEL_CONFIG_DIR, type, id);
2108
g_slist_free (added_ids);
2112
panel_profile_delete_removed_ids (GConfClient *client,
2113
PanelGConfKeyType type,
2116
PanelProfileGetIdFunc get_id_func,
2117
PanelProfileDestroyFunc destroy_handler)
2119
GSList *removed_ids = NULL;
2122
for (l = list; l; l = l->next) {
2125
id = get_id_func (l->data);
2127
if (!panel_profile_id_exists (id_list, id))
2128
removed_ids = g_slist_prepend (removed_ids, g_strdup (id));
2131
for (l = removed_ids; l; l = l->next) {
2132
const char *id = l->data;
2134
panel_profile_delete_dir (client, type, id);
2135
destroy_handler (id);
2140
g_slist_free (removed_ids);
2144
panel_profile_toplevel_id_list_notify (GConfClient *client,
2149
GSList *l, *existing_toplevels;
2150
GSList *toplevel_ids;
2152
if (!(value = gconf_entry_get_value (entry)))
2155
if (value->type != GCONF_VALUE_LIST ||
2156
gconf_value_get_list_type (value) != GCONF_VALUE_STRING) {
2157
gconf_value_free (value);
2161
toplevel_ids = g_slist_copy (gconf_value_get_list (value));
2162
toplevel_ids = panel_g_slist_make_unique (toplevel_ids,
2163
panel_gconf_value_strcmp,
2166
existing_toplevels = NULL;
2167
for (l = panel_toplevel_list_toplevels (); l; l = l->next) {
2168
PanelToplevel *toplevel = l->data;
2170
/* Attached toplevels aren't on the id list */
2171
if (panel_toplevel_get_is_attached (toplevel))
2174
existing_toplevels = g_slist_prepend (existing_toplevels, toplevel);
2177
panel_profile_load_added_ids (client,
2178
PANEL_GCONF_TOPLEVELS,
2181
(PanelProfileGetIdFunc) panel_profile_get_toplevel_id,
2182
(PanelProfileLoadFunc) panel_profile_load_and_show_toplevel,
2183
(PanelProfileOnLoadQueue) NULL);
2185
panel_profile_delete_removed_ids (client,
2186
PANEL_GCONF_TOPLEVELS,
2189
(PanelProfileGetIdFunc) panel_profile_get_toplevel_id,
2190
(PanelProfileDestroyFunc) panel_profile_destroy_toplevel);
2192
g_slist_free (existing_toplevels);
2193
g_slist_free (toplevel_ids);
2197
panel_profile_object_id_list_update (GConfClient *client,
2199
PanelGConfKeyType type)
2201
GSList *existing_applets;
2202
GSList *sublist = NULL, *l;
2205
if (value->type != GCONF_VALUE_LIST ||
2206
gconf_value_get_list_type (value) != GCONF_VALUE_STRING) {
2207
gconf_value_free (value);
2211
object_ids = g_slist_copy (gconf_value_get_list (value));
2212
object_ids = panel_g_slist_make_unique (object_ids,
2213
panel_gconf_value_strcmp,
2216
existing_applets = panel_applet_list_applets ();
2218
for (l = existing_applets; l; l = l->next) {
2219
AppletInfo *info = l->data;
2221
if ((type == PANEL_GCONF_APPLETS && info->type == PANEL_OBJECT_APPLET) ||
2222
(type == PANEL_GCONF_OBJECTS && info->type != PANEL_OBJECT_APPLET))
2223
sublist = g_slist_prepend (sublist, info);
2226
panel_profile_load_added_ids (client,
2230
(PanelProfileGetIdFunc) panel_applet_get_id,
2231
(PanelProfileLoadFunc) panel_profile_load_object,
2232
(PanelProfileOnLoadQueue) panel_applet_on_load_queue);
2234
panel_profile_delete_removed_ids (client,
2238
(PanelProfileGetIdFunc) panel_applet_get_id,
2239
(PanelProfileDestroyFunc) panel_profile_destroy_object);
2241
g_slist_free (sublist);
2242
g_slist_free (object_ids);
2244
panel_applet_load_queued_applets (FALSE);
2248
panel_profile_object_id_list_notify (GConfClient *client,
2254
PanelGConfKeyType type = GPOINTER_TO_INT (data);
2256
if (!(value = gconf_entry_get_value (entry)))
2259
panel_profile_object_id_list_update (client, value, type);
2263
panel_profile_load_list (GConfClient *client,
2264
const char *profile_dir,
2265
PanelGConfKeyType type,
2266
PanelProfileLoadFunc load_handler,
2267
GConfClientNotifyFunc notify_handler)
2273
const char *id_list;
2275
id_list = panel_gconf_key_type_to_id_list (type);
2277
key = panel_gconf_sprintf ("%s/general/%s", profile_dir, id_list);
2279
gconf_client_notify_add (client, key, notify_handler,
2280
GINT_TO_POINTER (type),
2283
list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
2284
list = panel_g_slist_make_unique (list,
2285
(GCompareFunc) strcmp,
2288
for (l = list; l; l = l->next) {
2290
id = (char *) l->data;
2293
load_handler (client, profile_dir, type, id);
2298
g_slist_free (list);
2302
panel_profile_copy_defaults_for_screen (GConfClient *client,
2303
const char *profile_dir,
2305
PanelGConfKeyType type)
2307
GSList *default_ids, *l;
2308
GSList *new_ids = NULL;
2310
const char *id_list, *type_str;
2312
id_list = panel_gconf_key_type_to_id_list (type);
2315
case PANEL_GCONF_TOPLEVELS:
2316
type_str = "toplevels";
2318
case PANEL_GCONF_OBJECTS:
2319
type_str = "objects";
2321
case PANEL_GCONF_APPLETS:
2322
type_str = "applets";
2326
g_assert_not_reached ();
2330
key = panel_gconf_sprintf (PANEL_DEFAULTS_DIR "/general/%s", id_list);
2331
default_ids = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
2333
for (l = default_ids; l; l = l->next) {
2334
char *default_id = l->data;
2339
new_id = g_strdup_printf ("%s_screen%d", default_id, screen_n);
2341
src_dir = g_strdup_printf (PANEL_DEFAULTS_DIR "/%s/%s", type_str, default_id);
2342
dest_dir = g_strdup_printf ("%s/%s/%s", profile_dir, type_str, new_id);
2344
panel_gconf_copy_dir (client, src_dir, dest_dir);
2346
new_ids = g_slist_prepend (new_ids, new_id);
2352
g_slist_free (default_ids);
2358
panel_profile_append_new_ids (GConfClient *client,
2359
PanelGConfKeyType type,
2364
const char *id_list;
2366
id_list = panel_gconf_key_type_to_id_list (type);
2368
key = panel_gconf_general_key (id_list);
2369
list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
2371
for (l = new_ids; l; l = l->next)
2372
list = g_slist_append (list, l->data);
2374
g_slist_free (new_ids);
2376
gconf_client_set_list (client, key, GCONF_VALUE_STRING, list, NULL);
2378
for (l = list; l; l = l->next)
2380
g_slist_free (list);
2384
panel_profile_copy_default_objects_for_screen (GConfClient *client,
2385
const char *profile_dir,
2387
PanelGConfKeyType type)
2389
GSList *new_objects, *l, *next;
2391
new_objects = panel_profile_copy_defaults_for_screen (client, profile_dir, screen_n, type);
2393
for (l = new_objects; l; l = next) {
2394
char *object_id = l->data;
2397
char *new_toplevel_id;
2401
key = panel_gconf_full_key (type, object_id, "toplevel_id");
2402
toplevel_id = gconf_client_get_string (client, key, NULL);
2404
new_objects = g_slist_remove_link (new_objects, l);
2410
new_toplevel_id = g_strdup_printf ("%s_screen%d", toplevel_id, screen_n);
2411
gconf_client_set_string (client, key, new_toplevel_id, NULL);
2413
g_free (toplevel_id);
2414
g_free (new_toplevel_id);
2417
panel_profile_append_new_ids (client, type, new_objects);
2421
* We might want to do something more sophisticated like hardcode
2422
* the default panel setup as the fallback panels.
2425
panel_profile_create_fallback_toplevel_list (GConfClient *client,
2426
const char *profile_dir)
2431
id = panel_profile_find_new_id (PANEL_GCONF_TOPLEVELS);
2433
dir = g_strdup_printf ("%s/toplevels/%s", profile_dir, id);
2434
panel_gconf_associate_schemas_in_dir (client, dir, PANEL_SCHEMAS_DIR "/toplevels");
2437
return g_slist_prepend (NULL, id);
2441
panel_profile_load_defaults_on_screen (GConfClient *client,
2442
const char *profile_dir,
2445
GSList *new_toplevels, *l;
2448
screen_n = gdk_screen_get_number (screen);
2450
new_toplevels = panel_profile_copy_defaults_for_screen (
2451
client, profile_dir, screen_n, PANEL_GCONF_TOPLEVELS);
2452
if (!new_toplevels) {
2453
g_warning ("Failed to load default panel configuration. panel-default-setup.entries "
2454
"hasn't been installed using gconftool-2 --load ?\n");
2455
new_toplevels = panel_profile_create_fallback_toplevel_list (client, profile_dir);
2458
for (l = new_toplevels; l; l = l->next) {
2459
char *toplevel_id = l->data;
2462
key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS,
2465
gconf_client_set_int (client, key, screen_n, NULL);
2468
panel_profile_append_new_ids (client, PANEL_GCONF_TOPLEVELS, new_toplevels);
2470
panel_profile_copy_default_objects_for_screen (
2471
client, profile_dir, screen_n, PANEL_GCONF_OBJECTS);
2472
panel_profile_copy_default_objects_for_screen (
2473
client, profile_dir, screen_n, PANEL_GCONF_APPLETS);
2477
panel_profile_ensure_toplevel_per_screen (GConfClient *client,
2478
const char *profile_dir)
2481
GSList *empty_screens = NULL;
2483
GdkDisplay *display;
2486
toplevels = panel_toplevel_list_toplevels ();
2488
display = gdk_display_get_default ();
2490
n_screens = gdk_display_get_n_screens (display);
2491
for (i = 0; i < n_screens; i++) {
2494
screen = gdk_display_get_screen (display, i);
2496
for (l = toplevels; l; l = l->next)
2497
if (gtk_window_get_screen (l->data) == screen)
2501
empty_screens = g_slist_prepend (empty_screens, screen);
2504
for (l = empty_screens; l; l = l->next)
2505
panel_profile_load_defaults_on_screen (client, profile_dir, l->data);
2507
g_slist_free (empty_screens);
2511
panel_profile_load (void)
2513
GConfClient *client;
2515
client = panel_gconf_get_client ();
2517
gconf_client_add_dir (client, PANEL_CONFIG_DIR "/general", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
2519
panel_compatibility_maybe_copy_old_config (client);
2521
panel_compatibility_migrate_panel_id_list (client);
2523
panel_profile_load_list (client,
2525
PANEL_GCONF_TOPLEVELS,
2526
panel_profile_load_and_show_toplevel_startup,
2527
(GConfClientNotifyFunc) panel_profile_toplevel_id_list_notify);
2528
panel_profile_load_list (client,
2530
PANEL_GCONF_OBJECTS,
2531
panel_profile_load_object,
2532
(GConfClientNotifyFunc) panel_profile_object_id_list_notify);
2533
panel_profile_load_list (client,
2535
PANEL_GCONF_APPLETS,
2536
panel_profile_load_object,
2537
(GConfClientNotifyFunc) panel_profile_object_id_list_notify);
2539
panel_profile_ensure_toplevel_per_screen (client, PANEL_CONFIG_DIR);
2541
panel_applet_load_queued_applets (TRUE);
2545
get_program_listing_setting (const char *setting)
2547
GConfClient *client;
2551
client = panel_gconf_get_client ();
2553
key = panel_gconf_general_key (setting);
2554
retval = gconf_client_get_bool (client, key, NULL);
2560
panel_profile_get_show_program_list (void)
2562
return get_program_listing_setting ("show_program_list");
2566
panel_profile_get_enable_program_list (void)
2568
return get_program_listing_setting ("enable_program_list");
2572
panel_profile_get_enable_autocompletion (void)
2574
return get_program_listing_setting ("enable_autocompletion");
2578
panel_profile_set_show_program_list (gboolean show_program_list)
2580
GConfClient *client;
2583
client = panel_gconf_get_client ();
2585
key = panel_gconf_general_key ("show_program_list");
2586
gconf_client_set_bool (client, key, show_program_list, NULL);
2590
panel_profile_is_writable_show_program_list (void)
2592
GConfClient *client;
2595
client = panel_gconf_get_client ();
2597
key = panel_gconf_general_key ("show_program_list");
2598
return gconf_client_key_is_writable (client, key, NULL);
2602
panel_profile_can_be_moved_freely (PanelToplevel *toplevel)
2605
GConfClient *client;
2607
if (panel_lockdown_get_locked_down () ||
2608
!panel_profile_is_writable_toplevel_orientation (toplevel))
2611
client = panel_gconf_get_client ();
2613
key = panel_profile_get_toplevel_key (toplevel, "screen");
2614
if (!gconf_client_key_is_writable (client, key, NULL))
2617
key = panel_profile_get_toplevel_key (toplevel, "monitor");
2618
if (!gconf_client_key_is_writable (client, key, NULL))
2621
/* For expanded panels we don't really have to check
2623
if (panel_toplevel_get_expand (toplevel))
2626
key = panel_profile_get_toplevel_key (toplevel, "x");
2627
if (!gconf_client_key_is_writable (client, key, NULL))
2629
key = panel_profile_get_toplevel_key (toplevel, "x_right");
2630
if (!gconf_client_key_is_writable (client, key, NULL))
2632
key = panel_profile_get_toplevel_key (toplevel, "x_centered");
2633
if (!gconf_client_key_is_writable (client, key, NULL))
2636
key = panel_profile_get_toplevel_key (toplevel, "y");
2637
if (!gconf_client_key_is_writable (client, key, NULL))
2639
key = panel_profile_get_toplevel_key (toplevel, "y_bottom");
2640
if (!gconf_client_key_is_writable (client, key, NULL))
2642
key = panel_profile_get_toplevel_key (toplevel, "y_centered");
2643
if (!gconf_client_key_is_writable (client, key, NULL))