[gnome-panel] panel: Implement removing objects/toplevels from layout



commit b2dc8aa026aa7ce246ccada119543f1537d31688
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Mar 25 18:25:13 2011 +0100

    panel: Implement removing objects/toplevels from layout
    
    Also, the layout should now detect newly created objects/toplevels, but
    this is untested right now.

 gnome-panel/applet.c              |    5 +-
 gnome-panel/panel-applet-frame.c  |    7 +-
 gnome-panel/panel-compatibility.c |   20 --
 gnome-panel/panel-compatibility.h |    3 -
 gnome-panel/panel-layout.c        |  248 +++++++++++++++++-
 gnome-panel/panel-layout.h        |    3 +
 gnome-panel/panel-menu-button.c   |   11 +-
 gnome-panel/panel-profile.c       |  549 -------------------------------------
 gnome-panel/panel.c               |   11 +-
 9 files changed, 266 insertions(+), 591 deletions(-)
---
diff --git a/gnome-panel/applet.c b/gnome-panel/applet.c
index 6c9818c..b1cf158 100644
--- a/gnome-panel/applet.c
+++ b/gnome-panel/applet.c
@@ -32,6 +32,7 @@
 #include "panel-menu-button.h"
 #include "panel-globals.h"
 #include "panel-properties-dialog.h"
+#include "panel-layout.h"
 #include "panel-lockdown.h"
 #include "panel-schemas.h"
 
@@ -150,7 +151,7 @@ applet_remove_callback (GtkWidget  *widget,
 			AppletInfo *info)
 {
 
-	panel_profile_delete_object (info);
+	panel_layout_delete_object (info->id);
 }
 
 static inline GdkScreen *
@@ -999,7 +1000,7 @@ panel_applet_register (GtkWidget       *applet,
 
 		if (!l) {
 			g_warning (_("Cannot find an empty spot"));
-			panel_profile_delete_object (info);
+			panel_layout_delete_object (info->id);
 			return NULL;
 		}
 	}
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index cb53048..de25e05 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -40,6 +40,7 @@
 #include "applet.h"
 #include "panel-marshal.h"
 #include "panel-background.h"
+#include "panel-layout.h"
 #include "panel-lockdown.h"
 #include "panel-object-loader.h"
 #include "panel-stock-icons.h"
@@ -708,7 +709,7 @@ panel_applet_frame_reload_response (GtkWidget        *dialog,
 		   it, so we'll just ignore this.  FIXME: handle this
 		   more correctly I suppose. */
 		if (panel_profile_id_lists_are_writable ())
-			panel_profile_delete_object (info);
+			panel_layout_delete_object (panel_applet_get_id (info));
 	}
 
 	g_object_unref (frame);
@@ -784,7 +785,7 @@ _panel_applet_frame_applet_remove (PanelAppletFrame *frame)
 	info = frame->priv->applet_info;
 	frame->priv->applet_info = NULL;
 
-	panel_profile_delete_object (info);
+	panel_layout_delete_object (panel_applet_get_id (info));
 }
 
 void
@@ -875,7 +876,7 @@ panel_applet_frame_loading_failed_response (GtkWidget *dialog,
 								 item);
 		}
 
-		panel_profile_remove_from_list (PANEL_GCONF_APPLETS, id);
+		panel_layout_delete_object (id);
 	}
 
 	g_free (id);
diff --git a/gnome-panel/panel-compatibility.c b/gnome-panel/panel-compatibility.c
index cd4f2ad..fd75795 100644
--- a/gnome-panel/panel-compatibility.c
+++ b/gnome-panel/panel-compatibility.c
@@ -31,26 +31,6 @@
 
 #include "panel-compatibility.h"
 
-void
-panel_compatiblity_migrate_settings_menu_button (GConfClient *client,
-						 const char  *id)
-{
-	const char *key;
-
-	panel_profile_remove_from_list (PANEL_GCONF_OBJECTS, id);
-
-	key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, id,
-				    "launcher_location");
-	gconf_client_set_string (client, key,
-				 "gnome-control-center.desktop", NULL);
-
-	key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, id,
-				    "object_type");
-	gconf_client_set_string (client, key, "launcher-object", NULL);
-
-	panel_profile_add_to_list (PANEL_GCONF_OBJECTS, id);
-}
-
 gchar *
 panel_compatibility_get_applet_iid (GSettings   *settings,
 				    const gchar *id)
diff --git a/gnome-panel/panel-compatibility.h b/gnome-panel/panel-compatibility.h
index f18c6a7..ab46234 100644
--- a/gnome-panel/panel-compatibility.h
+++ b/gnome-panel/panel-compatibility.h
@@ -30,9 +30,6 @@
 
 G_BEGIN_DECLS
 
-void panel_compatiblity_migrate_settings_menu_button (GConfClient *client,
-						      const char  *id);
-
 gchar *panel_compatibility_get_applet_iid (GSettings   *settings,
 					   const gchar *id);
 
diff --git a/gnome-panel/panel-layout.c b/gnome-panel/panel-layout.c
index c349d03..0d9ad78 100644
--- a/gnome-panel/panel-layout.c
+++ b/gnome-panel/panel-layout.c
@@ -43,9 +43,15 @@
 
 #include "panel-layout.h"
 
-#define PANEL_LAYOUT_ERROR panel_layout_error_quark ()
 static GSettings *layout_settings = NULL;
 
+#define PANEL_LAYOUT_ERROR panel_layout_error_quark ()
+
+static void panel_layout_load_toplevel    (const char *toplevel_id);
+static void panel_layout_load_object      (const char *object_id);
+static void panel_layout_changed_toplevel (void);
+static void panel_layout_changed_object   (void);
+
 static GQuark
 panel_layout_error_quark (void)
 {
@@ -542,6 +548,239 @@ panel_layout_append_from_file (const char *layout_file,
         panel_layout_append_from_file_real (layout_file, -1, error_fatal);
 }
 
+
+/*******************\
+ * Changing layout *
+\*******************/
+
+
+void
+panel_layout_delete_toplevel (const char *toplevel_id)
+{
+        char  *path;
+        char  *id_copy;
+        char **objects;
+        int    i;
+
+        if (PANEL_GLIB_STR_EMPTY (toplevel_id))
+                return;
+
+        /* The original will be freed if removal succeeds */
+        id_copy = g_strdup (toplevel_id);
+
+        if (!panel_gsettings_remove_all_from_strv (layout_settings,
+                                                   PANEL_LAYOUT_TOPLEVEL_ID_LIST_KEY,
+                                                   id_copy)) {
+                g_free (id_copy);
+                return;
+        }
+
+        path = g_strdup_printf ("%s%s/",
+                                PANEL_LAYOUT_TOPLEVEL_PATH, id_copy);
+        panel_dconf_recursive_reset (path, NULL);
+
+        /* remove all applets that were on this toplevel */
+
+        objects = g_settings_get_strv (layout_settings,
+                                       PANEL_LAYOUT_OBJECT_ID_LIST_KEY);
+
+        for (i = 0; objects[i] != NULL; i++) {
+                GSettings *settings;
+                char       *object_toplevel_id;
+
+                path = g_strdup_printf ("%s%s/",
+                                        PANEL_LAYOUT_OBJECT_PATH, objects[i]);
+
+                settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
+                object_toplevel_id = g_settings_get_string (settings,
+                                                            PANEL_OBJECT_TOPLEVEL_ID_KEY);
+
+                g_object_unref (settings);
+                g_free (path);
+
+                if (g_strcmp0 (id_copy, object_toplevel_id) == 0)
+                        panel_layout_delete_object (objects[i]);
+
+                g_free (object_toplevel_id);
+        }
+
+        g_strfreev (objects);
+
+        g_free (id_copy);
+}
+
+void
+panel_layout_delete_object (const char *object_id)
+{
+        char *path;
+        char *id_copy;
+
+        if (PANEL_GLIB_STR_EMPTY (object_id))
+                return;
+
+        /* The original will be freed if removal succeeds */
+        id_copy = g_strdup (object_id);
+
+        if (!panel_gsettings_remove_all_from_strv (layout_settings,
+                                                   PANEL_LAYOUT_OBJECT_ID_LIST_KEY,
+                                                   id_copy)) {
+                g_free (id_copy);
+                return;
+        }
+
+        path = g_strdup_printf ("%s%s/",
+                                PANEL_LAYOUT_OBJECT_PATH, id_copy);
+        panel_dconf_recursive_reset (path, NULL);
+
+        g_free (id_copy);
+}
+
+static void
+panel_layout_changed_toplevel (void)
+{
+        char       **ids;
+        GSList      *to_remove;
+        gboolean     loading;
+        gboolean     found;
+        const char  *id;
+        GSList      *l;
+        int          i;
+
+        ids = g_settings_get_strv (layout_settings,
+                                   PANEL_LAYOUT_TOPLEVEL_ID_LIST_KEY);
+
+        /* Remove what is not in the layout anymore */
+
+        to_remove = NULL;
+
+        for (l = panel_toplevel_list_toplevels (); l != NULL; l = l->next) {
+                id = panel_toplevel_get_toplevel_id (l->data);
+                found = FALSE;
+
+                for (i = 0; ids[i] != NULL; i++) {
+                        if (g_strcmp0 (ids[i], id) == 0) {
+                                found = TRUE;
+                                break;
+                        }
+                }
+
+                if (!found)
+                        to_remove = g_slist_prepend (to_remove, l->data);
+        }
+
+        for (l = to_remove; l != NULL; l = l->next)
+                gtk_widget_destroy (GTK_WIDGET (l->data));
+
+        g_slist_free (to_remove);
+
+        /* Add what appeared in the layout */
+
+        loading = FALSE;
+
+        for (i = 0; ids[i] != NULL; i++) {
+                found = FALSE;
+
+                for (l = panel_toplevel_list_toplevels (); l != NULL; l = l->next) {
+                        id = panel_toplevel_get_toplevel_id (l->data);
+                        if (g_strcmp0 (ids[i], id) == 0) {
+                                found = TRUE;
+                                break;
+                        }
+                }
+
+                if (!found) {
+                        panel_layout_load_toplevel (ids[i]);
+                        loading = TRUE;
+                }
+        }
+
+        g_strfreev (ids);
+
+        /* Reload list of objects to get those that might be on the new
+         * toplevels */
+        if (loading)
+                panel_layout_changed_object ();
+}
+
+static void
+panel_layout_changed_object (void)
+{
+        char       **ids;
+        GSList      *to_remove;
+        gboolean     loading;
+        gboolean     found;
+        const char  *id;
+        GSList      *l;
+        int          i;
+
+        ids = g_settings_get_strv (layout_settings,
+                                   PANEL_LAYOUT_OBJECT_ID_LIST_KEY);
+
+        /* Remove what is not in the layout anymore */
+
+        to_remove = NULL;
+
+        for (l = panel_applet_list_applets (); l != NULL; l = l->next) {
+                id = panel_applet_get_id (l->data);
+                found = FALSE;
+
+                for (i = 0; ids[i] != NULL; i++) {
+                        if (g_strcmp0 (ids[i], id) == 0) {
+                                found = TRUE;
+                                break;
+                        }
+                }
+
+                if (!found)
+                        to_remove = g_slist_prepend (to_remove, l->data);
+        }
+
+        for (l = to_remove; l != NULL; l = l->next)
+                panel_applet_clean (l->data);
+
+        g_slist_free (to_remove);
+
+        /* Add what appeared in the layout */
+
+        loading = FALSE;
+
+        for (i = 0; ids[i] != NULL; i++) {
+                found = FALSE;
+
+                if (panel_object_loader_is_queued (ids[i]))
+                        continue;
+
+                for (l = panel_applet_list_applets (); l != NULL; l = l->next) {
+                        id = panel_applet_get_id (l->data);
+                        if (g_strcmp0 (ids[i], id) == 0) {
+                                found = TRUE;
+                                break;
+                        }
+                }
+
+                if (!found) {
+                        panel_layout_load_object (ids[i]);
+                        loading = TRUE;
+                }
+        }
+
+        g_strfreev (ids);
+
+        if (loading)
+                panel_object_loader_do_load (FALSE);
+}
+
+static void
+panel_layout_changed (GSettings *settings,
+                      char      *key,
+                      gpointer   user_data)
+{
+        if (g_strcmp0 (key, PANEL_LAYOUT_TOPLEVEL_ID_LIST_KEY) == 0)
+                panel_layout_changed_toplevel ();
+        else if (g_strcmp0 (key, PANEL_LAYOUT_OBJECT_ID_LIST_KEY) == 0)
+                panel_layout_changed_object ();
+}
+
 /******************\
  * Loading layout *
 \******************/
@@ -704,6 +943,13 @@ panel_layout_load (void)
 
         g_strfreev (objects);
 
+        g_signal_connect (layout_settings, "changed",
+                          G_CALLBACK (panel_layout_changed), NULL);
+
+        /* This needs to happen after we've loaded the current toplevels (to
+         * know if we have toplevels on all screens), and after we've connected
+         * to the settings changed notifications (to automatically load created
+         * toplevels) */
         panel_layout_ensure_toplevel_per_screen ();
 
         panel_object_loader_do_load (TRUE);
diff --git a/gnome-panel/panel-layout.h b/gnome-panel/panel-layout.h
index 428a31e..c8b73d6 100644
--- a/gnome-panel/panel-layout.h
+++ b/gnome-panel/panel-layout.h
@@ -34,6 +34,9 @@ void panel_layout_append_from_file (const char *layout_file,
 
 gboolean panel_layout_load (void);
 
+void panel_layout_delete_toplevel (const char *toplevel_id);
+void panel_layout_delete_object   (const char *object_id);
+
 G_END_DECLS
 
 #endif /* __PANEL_LAYOUT_H__ */
diff --git a/gnome-panel/panel-menu-button.c b/gnome-panel/panel-menu-button.c
index b521ca9..dc4b64a 100644
--- a/gnome-panel/panel-menu-button.c
+++ b/gnome-panel/panel-menu-button.c
@@ -36,7 +36,6 @@
 #include <libpanel-util/panel-show.h>
 
 #include "applet.h"
-#include "panel-compatibility.h"
 #include "panel-widget.h"
 #include "panel-util.h"
 #include "panel-profile.h"
@@ -64,7 +63,6 @@ typedef enum {
 	FIRST_MENU,
 	APPLICATIONS_MENU,
 #define DEFAULT_MENU      APPLICATIONS_MENU
-	SETTINGS_MENU,
 	GNOMECC_MENU,
 	LAST_MENU
 } MenuPathRoot;
@@ -77,9 +75,7 @@ typedef struct {
 
 static MenuPathRootItem root_items [] = {
 	{ APPLICATIONS_MENU, "applications", "applications.menu" },
-	{ GNOMECC_MENU,      "gnomecc",      "gnomecc.menu"      },
-	/* compatibility with GNOME < 2.91.0 */
-	{ SETTINGS_MENU,     "settings",     NULL                }
+	{ GNOMECC_MENU,      "gnomecc",      "gnomecc.menu"      }
 };
 
 struct _PanelMenuButtonPrivate {
@@ -876,11 +872,6 @@ panel_menu_button_load (PanelWidget *panel,
 	scheme = g_strndup (menu_path, strcspn (menu_path, ":"));
 	root = panel_menu_scheme_to_path_root (scheme);
 	g_free (scheme);
-	if (root == SETTINGS_MENU) {
-		panel_compatiblity_migrate_settings_menu_button (client, id);
-		g_free (menu_path);
-		return;
-       }
 
 	key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, id, "custom_icon");
 	custom_icon = gconf_client_get_string (client, key, NULL);
diff --git a/gnome-panel/panel-profile.c b/gnome-panel/panel-profile.c
index 70d860f..aa67825 100644
--- a/gnome-panel/panel-profile.c
+++ b/gnome-panel/panel-profile.c
@@ -41,14 +41,6 @@
 #include "panel-toplevel.h"
 #include "panel-lockdown.h"
 
-typedef const char *(*PanelProfileGetIdFunc)   (gpointer           object);
-typedef gboolean    (*PanelProfileOnLoadQueue) (const char        *id);
-typedef void        (*PanelProfileLoadFunc)    (GConfClient       *client,
-						const char        *profile_dir, 
-						PanelGConfKeyType  type,
-						const char        *id);
-typedef void        (*PanelProfileDestroyFunc) (const char        *id);
-
 static GConfEnumStringPair panel_orientation_map [] = {
 	{ PANEL_ORIENTATION_TOP,    "top"    },
 	{ PANEL_ORIENTATION_BOTTOM, "bottom" },
@@ -69,35 +61,12 @@ static GConfEnumStringPair panel_object_type_map [] = {
 	{ 0,                      NULL }
 };
 
-static void panel_profile_object_id_list_update (GConfClient       *client,
-						 GConfValue        *value,
-						 PanelGConfKeyType  type);
-
 const char *
 panel_profile_map_orientation (PanelOrientation orientation)
 {
 	return gconf_enum_to_string (panel_orientation_map, orientation);
 }
 
-gboolean
-panel_profile_map_object_type_string (const char       *str,
-				      PanelObjectType  *object_type)
-{
-	int mapped;
-
-	g_return_val_if_fail (object_type != NULL, FALSE);
-
-	if (!str)
-		return FALSE;
-
-	if (!gconf_string_to_enum (panel_object_type_map, str, &mapped))
-		return FALSE;
-
-	*object_type = mapped;
-
-	return TRUE;
-}
-
 char *
 panel_profile_find_new_id (PanelGConfKeyType type)
 {
@@ -185,19 +154,6 @@ panel_profile_save_id_list (PanelGConfKeyType  type,
 	g_slist_free (list);
 }
 
-static inline void
-panel_profile_save_other_id_lists (PanelGConfKeyType type)
-{
-	if (type != PANEL_GCONF_TOPLEVELS)
-		panel_profile_save_id_list (PANEL_GCONF_TOPLEVELS, NULL, TRUE);
-
-	if (type != PANEL_GCONF_OBJECTS)
-		panel_profile_save_id_list (PANEL_GCONF_OBJECTS, NULL, TRUE);
-
-	if (type != PANEL_GCONF_APPLETS)
-		panel_profile_save_id_list (PANEL_GCONF_APPLETS, NULL, TRUE);
-}
-
 void
 panel_profile_add_to_list (PanelGConfKeyType  type,
 			   const char        *id)
@@ -220,43 +176,6 @@ panel_profile_add_to_list (PanelGConfKeyType  type,
 	list = g_slist_append (list, new_id);
 
 	panel_profile_save_id_list (type, list, FALSE);
-	panel_profile_save_other_id_lists (type);
-}
-
-void
-panel_profile_remove_from_list (PanelGConfKeyType  type,
-				const char        *id)
-{
-	GConfClient *client;
-	GSList      *list, *l;
-	const char  *key;
-	const char  *id_list;
-
-	client = panel_gconf_get_client ();
-
-	id_list = panel_gconf_key_type_to_id_list (type);
-
-	key = panel_gconf_general_key (id_list);
-	list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
-
-	/* Remove all occurrence of id and not just the first. We're more solid
-	 * this way (see bug #137308 for example). */
-	l = list;
-	while (l) {
-		GSList *next;
-
-		next = l->next;
-
-		if (!strcmp (id, l->data)) {
-			g_free (l->data);
-			list = g_slist_delete_link (list, l);
-		}
-
-		l = next;
-	}
-
-	panel_profile_save_id_list (type, list, FALSE);
-	panel_profile_save_other_id_lists (type);
 }
 
 static gboolean
@@ -377,121 +296,6 @@ panel_profile_create_toplevel (GdkScreen *screen)
 	g_free (id);
 }
 
-static void
-panel_profile_delete_toplevel_objects (const char        *toplevel_id,
-				       PanelGConfKeyType  key_type)
-{
-	GConfClient *client;
-	const char  *key;
-	GSList      *new_list = NULL,*list, *l;
-
-	client = panel_gconf_get_client ();
-
-	key = panel_gconf_general_key (panel_gconf_key_type_to_id_list (key_type));
-	list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
-
-	for (l = list; l; l = l->next) {
-		char *id = l->data;
-		char *parent_toplevel_id;
-
-		key = panel_gconf_full_key (key_type, id, "toplevel_id");
-		parent_toplevel_id = gconf_client_get_string (client, key, NULL);
-
-		if (parent_toplevel_id && !strcmp (toplevel_id, parent_toplevel_id)) {
-			g_free (id);
-			g_free (parent_toplevel_id);
-			continue;
-		}
-
-		new_list = g_slist_prepend (new_list, id);
-
-		g_free (parent_toplevel_id);
-	}
-	g_slist_free (list);
-
-	key = panel_gconf_general_key (panel_gconf_key_type_to_id_list (key_type));
-	gconf_client_set_list (client, key, GCONF_VALUE_STRING, new_list, NULL);
-
-	for (l = new_list; l; l = l->next)
-		g_free (l->data);
-	g_slist_free (new_list);
-}
-
-void
-panel_profile_delete_toplevel (PanelToplevel *toplevel)
-{
-	const char *toplevel_id;
-
-	toplevel_id = panel_toplevel_get_toplevel_id (toplevel);
-
-	panel_profile_delete_toplevel_objects (toplevel_id, PANEL_GCONF_OBJECTS);
-	panel_profile_delete_toplevel_objects (toplevel_id, PANEL_GCONF_APPLETS);
-
-	panel_profile_remove_from_list (PANEL_GCONF_TOPLEVELS, toplevel_id);
-}
-
-static void
-panel_profile_load_and_show_toplevel (GConfClient       *client,
-				      const char        *profile_dir,
-				      PanelGConfKeyType  type,
-				      const char        *toplevel_id)
-{
-	PanelToplevel *toplevel;
-	const char    *id_list;
-	const char    *key;
-	GConfValue    *value;
-	gboolean       loading_queued_applets;
-
-	toplevel = NULL;
-	if (!toplevel)
-		return;
-
-	loading_queued_applets = FALSE;
-
-	/* reload list of objects to get those that might be on the new
-	 * toplevel */
-	id_list = panel_gconf_key_type_to_id_list (PANEL_GCONF_OBJECTS);
-	key = panel_gconf_sprintf ("%s/general/%s", profile_dir, id_list);
-	value = gconf_client_get (client, key, NULL);
-	if (value) {
-		panel_profile_object_id_list_update (client, value,
-						     PANEL_GCONF_OBJECTS);
-		loading_queued_applets = TRUE;
-		gconf_value_free (value);
-	}
-
-	id_list = panel_gconf_key_type_to_id_list (PANEL_GCONF_APPLETS);
-	key = panel_gconf_sprintf ("%s/general/%s", profile_dir, id_list);
-	value = gconf_client_get (client, key, NULL);
-	if (value) {
-		panel_profile_object_id_list_update (client, value,
-						     PANEL_GCONF_APPLETS);
-		loading_queued_applets = TRUE;
-		gconf_value_free (value);
-	}
-
-	if (!loading_queued_applets)
-		panel_object_loader_do_load (FALSE);
-}
-
-static void
-panel_profile_load_and_show_toplevel_startup (GConfClient       *client,
-					      const char        *profile_dir,
-					      PanelGConfKeyType  type,
-					      const char        *toplevel_id)
-{
-}
-
-static void
-panel_profile_destroy_toplevel (const char *id)
-{
-	PanelToplevel *toplevel;
-
-	if (!(toplevel = panel_toplevel_get_by_id (id)))
-		return;
-
-	gtk_widget_destroy (GTK_WIDGET (toplevel));
-}
 
 char *
 panel_profile_prepare_object_with_id (PanelObjectType  object_type,
@@ -549,359 +353,6 @@ panel_profile_prepare_object (PanelObjectType  object_type,
 }
 
 void
-panel_profile_delete_object (AppletInfo *applet_info)
-{
-	PanelGConfKeyType  type;
-	const char        *id;
-
-	type = (applet_info->type) == PANEL_OBJECT_APPLET ? PANEL_GCONF_APPLETS :
-							    PANEL_GCONF_OBJECTS;
-	id = panel_applet_get_id (applet_info);
-
-	panel_profile_remove_from_list (type, id);
-}
-
-static void
-panel_profile_load_object (GConfClient       *client,
-			   const char        *profile_dir,
-			   PanelGConfKeyType  type,
-			   const char        *id)
-{
-}
-
-static void
-panel_profile_destroy_object (const char *id)
-{
-	AppletInfo *info;
-
-	info = panel_applet_get_by_id (id);
-
-	panel_applet_clean (info);
-}
-
-static void
-panel_profile_delete_dir (GConfClient       *client,
-			  PanelGConfKeyType  type,
-			  const char        *id)
-{
-	const char *key;
-	char       *type_str;
-
-	switch (type) {
-	case PANEL_GCONF_TOPLEVELS:
-		type_str = "toplevels";
-		break;
-	case PANEL_GCONF_OBJECTS:
-		type_str = "objects";
-		break;
-	case PANEL_GCONF_APPLETS:
-		type_str = "applets";
-		break;
-	default:
-		type_str = NULL;
-		g_assert_not_reached ();
-		break;
-	}
-
-	if (type == PANEL_GCONF_TOPLEVELS) {
-		key = panel_gconf_sprintf (PANEL_CONFIG_DIR "/%s/%s/background",
-					   type_str, id);
-		gconf_client_remove_dir (client, key, NULL);
-	}
-
-	key = panel_gconf_sprintf (PANEL_CONFIG_DIR "/%s/%s",
-				   type_str, id);
-	gconf_client_remove_dir (client, key, NULL);
-
-	gconf_client_recursive_unset (client,
-				      key,
-				      GCONF_UNSET_INCLUDING_SCHEMA_NAMES,
-				      NULL);
-}
-
-static gboolean
-panel_profile_object_exists (GSList                *list,
-			     const char            *id,
-			     PanelProfileGetIdFunc  get_id_func)
-{
-	GSList *l;
-
-	if (!list || !id)
-		return FALSE;
-
-	for (l = list; l; l = l->next) {
-		const char *check_id;
-
-		check_id = get_id_func (l->data);
-		g_assert (check_id != NULL);
-
-		if (!strcmp (check_id, id))
-			return TRUE;
-	}
-
-	return FALSE;
-}
-
-static gboolean
-panel_profile_id_exists (GSList     *id_list,
-			 const char *id)
-{
-	GSList *l;
-
-	if (!id_list || !id)
-		return FALSE;
-
-	for (l = id_list; l; l = l->next) {
-		const char *check_id = gconf_value_get_string (l->data);
-
-		if (!strcmp (id, check_id))
-			return TRUE;
-	}
-
-	return FALSE;
-}
-
-static void
-panel_profile_load_added_ids (GConfClient            *client,
-			      PanelGConfKeyType       type,
-			      GSList                 *list,
-			      GSList                 *id_list,
-			      PanelProfileGetIdFunc   get_id_func,
-			      PanelProfileLoadFunc    load_handler,
-			      PanelProfileOnLoadQueue on_load_queue)
-{
-	GSList *added_ids = NULL;
-	GSList *l;
-
-	for (l = id_list; l; l = l->next) {
-		const char *id = gconf_value_get_string (l->data);
-
-		if (!panel_profile_object_exists (list, id, get_id_func) &&
-		    (on_load_queue == NULL || !on_load_queue (id)))
-			added_ids = g_slist_prepend (added_ids, g_strdup (id));
-	}
-
-	for (l = added_ids; l; l = l->next) {
-		char *id;
-		id = (char *) l->data;
-
-		if (id && id[0])
-			load_handler (client, PANEL_CONFIG_DIR, type, id);
-
-		g_free (l->data);
-		l->data = NULL;
-	}
-
-	g_slist_free (added_ids);
-}
-
-static void
-panel_profile_delete_removed_ids (GConfClient             *client,
-				  PanelGConfKeyType        type,
-				  GSList                  *list,
-				  GSList                  *id_list,
-				  PanelProfileGetIdFunc    get_id_func,
-				  PanelProfileDestroyFunc  destroy_handler)
-{
-	GSList *removed_ids = NULL;
-	GSList *l;
-
-	for (l = list; l; l = l->next) {
-		const char *id;
-
-		id = get_id_func (l->data);
-
-		if (!panel_profile_id_exists (id_list, id))
-			removed_ids = g_slist_prepend (removed_ids, g_strdup (id));
-	}
-
-	for (l = removed_ids; l; l = l->next) {
-		const char *id = l->data;
-
-		panel_profile_delete_dir (client, type, id);
-		destroy_handler (id);
-
-		g_free (l->data);
-		l->data = NULL;
-	}
-	g_slist_free (removed_ids);
-}
-
-static void
-panel_profile_toplevel_id_list_notify (GConfClient *client,
-				       guint        cnxn_id,
-				       GConfEntry  *entry)
-{
-	GConfValue *value;
-	GSList     *l, *existing_toplevels;
-	GSList     *toplevel_ids;
-
-	if (!(value = gconf_entry_get_value (entry)))
-		return;
-
-	if (value->type != GCONF_VALUE_LIST ||
-	    gconf_value_get_list_type (value) != GCONF_VALUE_STRING) {
-		gconf_value_free (value);
-		return;
-	}
-
-	toplevel_ids = g_slist_copy (gconf_value_get_list (value));
-	toplevel_ids = panel_g_slist_make_unique (toplevel_ids,
-						  panel_gconf_value_strcmp,
-						  FALSE);
-
-	existing_toplevels = NULL;
-	for (l = panel_toplevel_list_toplevels (); l; l = l->next) {
-		PanelToplevel *toplevel = l->data;
-		existing_toplevels = g_slist_prepend (existing_toplevels, toplevel);
-	}
-
-	panel_profile_load_added_ids (client,
-				      PANEL_GCONF_TOPLEVELS,
-				      existing_toplevels,
-				      toplevel_ids,
-				      (PanelProfileGetIdFunc) panel_toplevel_get_toplevel_id,
-				      (PanelProfileLoadFunc) panel_profile_load_and_show_toplevel,
-				      (PanelProfileOnLoadQueue) NULL);
-
-	panel_profile_delete_removed_ids (client,
-					  PANEL_GCONF_TOPLEVELS,
-					  existing_toplevels,
-					  toplevel_ids,
-					  (PanelProfileGetIdFunc) panel_toplevel_get_toplevel_id,
-					  (PanelProfileDestroyFunc) panel_profile_destroy_toplevel);
-
-	g_slist_free (existing_toplevels);
-	g_slist_free (toplevel_ids);
-}
-
-static void
-panel_profile_object_id_list_update (GConfClient       *client,
-				     GConfValue        *value,
-				     PanelGConfKeyType  type)
-{
-	GSList *existing_applets;
-	GSList *sublist = NULL, *l;
-	GSList *object_ids;
-
-	if (value->type != GCONF_VALUE_LIST ||
-	    gconf_value_get_list_type (value) != GCONF_VALUE_STRING) {
-		gconf_value_free (value);
-		return;
-	}
-
-	object_ids = g_slist_copy (gconf_value_get_list (value));
-	object_ids = panel_g_slist_make_unique (object_ids,
-						panel_gconf_value_strcmp,
-						FALSE);
-
-	existing_applets = panel_applet_list_applets ();
-
-	for (l = existing_applets; l; l = l->next) {
-		AppletInfo *info = l->data;
-
-		if ((type == PANEL_GCONF_APPLETS && info->type == PANEL_OBJECT_APPLET) ||
-		    (type == PANEL_GCONF_OBJECTS && info->type != PANEL_OBJECT_APPLET))
-			sublist = g_slist_prepend (sublist, info);
-	}
-
-	panel_profile_load_added_ids (client,
-				      type,
-				      sublist,
-				      object_ids,
-				      (PanelProfileGetIdFunc) panel_applet_get_id,
-				      (PanelProfileLoadFunc) panel_profile_load_object,
-				      (PanelProfileOnLoadQueue) panel_object_loader_is_queued);
-
-	panel_profile_delete_removed_ids (client,
-					  type,
-					  sublist,
-					  object_ids,
-					  (PanelProfileGetIdFunc) panel_applet_get_id,
-					  (PanelProfileDestroyFunc) panel_profile_destroy_object);
-
-	g_slist_free (sublist);
-	g_slist_free (object_ids);
-
-	panel_object_loader_do_load (FALSE);
-}
-
-static void
-panel_profile_object_id_list_notify (GConfClient *client,
-				     guint        cnxn_id,
-				     GConfEntry  *entry,
-				     gpointer     data)
-{
-	GConfValue        *value;
-	PanelGConfKeyType  type = GPOINTER_TO_INT (data);
-
-	if (!(value = gconf_entry_get_value (entry)))
-		return;
-
-	panel_profile_object_id_list_update (client, value, type);
-}
-
-static void
-panel_profile_load_list (GConfClient           *client,
-			 const char            *profile_dir,
-			 PanelGConfKeyType      type,
-			 PanelProfileLoadFunc   load_handler,
-			 GConfClientNotifyFunc  notify_handler)
-{
-
-	const char *key;
-	GSList     *list;
-	GSList     *l;
-	const char *id_list;
-
-	id_list = panel_gconf_key_type_to_id_list (type);
-
-	key = panel_gconf_sprintf ("%s/general/%s", profile_dir, id_list);
-
-	gconf_client_notify_add (client, key, notify_handler,
-				 GINT_TO_POINTER (type),
-				 NULL, NULL);
-
-	list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
-	list = panel_g_slist_make_unique (list,
-					  (GCompareFunc) strcmp,
-					  TRUE);
-
-	for (l = list; l; l = l->next) {
-		char *id;
-		id = (char *) l->data;
-
-		if (id && id[0])
-			load_handler (client, profile_dir, type, id);
-
-		g_free (l->data);
-		l->data = NULL;
-	}
-	g_slist_free (list);
-}
-
-void
 panel_profile_load (void)
 {
-	GConfClient *client;
-
-	client  = panel_gconf_get_client ();
-
-	gconf_client_add_dir (client, PANEL_CONFIG_DIR "/general", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
-
-	panel_profile_load_list (client,
-				 PANEL_CONFIG_DIR,
-				 PANEL_GCONF_TOPLEVELS,
-				 panel_profile_load_and_show_toplevel_startup,
-				 (GConfClientNotifyFunc) panel_profile_toplevel_id_list_notify);
-	panel_profile_load_list (client,
-				 PANEL_CONFIG_DIR,
-				 PANEL_GCONF_OBJECTS,
-				 panel_profile_load_object,
-				 (GConfClientNotifyFunc) panel_profile_object_id_list_notify);
-	panel_profile_load_list (client,
-				 PANEL_CONFIG_DIR,
-				 PANEL_GCONF_APPLETS,
-				 panel_profile_load_object,
-				 (GConfClientNotifyFunc) panel_profile_object_id_list_notify);
 }
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index f16efb4..77f527f 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -42,6 +42,7 @@
 #include "panel-globals.h"
 #include "panel-lockdown.h"
 #include "panel-icon-names.h"
+#include "panel-layout.h"
 #include "panel-schemas.h"
 
 enum {
@@ -817,12 +818,16 @@ drop_internal_icon (PanelWidget *panel,
 		return FALSE;
 
 	if (old_launcher && old_launcher->button) {
+		const char *object_id;
+
 		if (old_launcher->prop_dialog) {
 			g_signal_handler_disconnect (old_launcher->button,
 						     old_launcher->destroy_handler);
 			launcher_properties_destroy (old_launcher);
 		}
-		panel_profile_delete_object (old_launcher->info);
+
+		object_id = panel_applet_get_id (old_launcher->info);
+		panel_layout_delete_object (object_id);
 	}
 
 	return TRUE;
@@ -945,7 +950,7 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
 		info = g_slist_nth_data (applet_list, applet_index);
 
 		if (info)
-			panel_profile_delete_object (info);
+			panel_layout_delete_object (panel_applet_get_id (info));
 	}
 
 	return success;
@@ -1338,7 +1343,7 @@ panel_is_applet_right_stick (GtkWidget *applet)
 static void
 panel_delete_without_query (PanelToplevel *toplevel)
 {
-	panel_profile_delete_toplevel (toplevel);
+	panel_layout_delete_toplevel (panel_toplevel_get_toplevel_id (toplevel));
 } 
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]