[gnome-panel/wip/3.0-freeze-break] panel: Port addition of objects to GSettings (first part)



commit 50325b0abb8c806f11f56ae7f056d34c885dede6
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Mar 25 19:29:12 2011 +0100

    panel: Port addition of objects to GSettings (first part)
    
    This adds the required API for the migration, and as a proof of example,
    it makes it possible to add applets. Other objects will follow.

 gnome-panel/panel-applet-frame.c  |   18 ++------
 gnome-panel/panel-layout.c        |   81 +++++++++++++++++++++++++++++++++++++
 gnome-panel/panel-layout.h        |   16 +++++++-
 gnome-panel/panel-object-loader.c |   35 +++++++++++++++-
 gnome-panel/panel-object-loader.h |    9 +++-
 5 files changed, 140 insertions(+), 19 deletions(-)
---
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index cf6ef69..27b3a93 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -1002,20 +1002,10 @@ panel_applet_frame_create (PanelToplevel *toplevel,
 			   int            position,
 			   const char    *iid)
 {
-	GConfClient *client;
-	const char  *key;
-	char        *id;
-
 	g_return_if_fail (iid != NULL);
 
-	client =  panel_gconf_get_client ();
-
-	id = panel_profile_prepare_object (PANEL_OBJECT_APPLET, toplevel, position, FALSE);
-
-	key = panel_gconf_full_key (PANEL_GCONF_APPLETS, id, "applet_iid");
-	gconf_client_set_string (client, key, iid, NULL);
-
-	panel_profile_add_to_list (PANEL_GCONF_APPLETS, id);
-
-	g_free (id);
+	panel_layout_object_create (PANEL_OBJECT_APPLET,
+				    iid,
+				    panel_toplevel_get_toplevel_id (toplevel),
+				    position, FALSE);
 }
diff --git a/gnome-panel/panel-layout.c b/gnome-panel/panel-layout.c
index e13b1e5..ab686ee 100644
--- a/gnome-panel/panel-layout.c
+++ b/gnome-panel/panel-layout.c
@@ -594,6 +594,87 @@ panel_layout_toplevel_create (GdkScreen *screen)
         g_free (unique_id);
 }
 
+void
+panel_layout_object_create (PanelObjectType   type,
+                            const char       *type_detail,
+                            const char       *toplevel_id,
+                            int               position,
+                            gboolean          pack_end)
+{
+        char *id;
+
+        id = panel_layout_object_create_start (type, type_detail,
+                                               toplevel_id, position, pack_end,
+                                               NULL);
+
+        if (!id)
+                return;
+
+        panel_layout_object_create_finish (id);
+
+        g_free (id);
+}
+
+char *
+panel_layout_object_create_start (PanelObjectType   type,
+                                  const char       *type_detail,
+                                  const char       *toplevel_id,
+                                  int               position,
+                                  gboolean          pack_end,
+                                  GSettings       **settings)
+{
+        char      *unique_id;
+        char      *path;
+        GSettings *settings_object;
+        char      *iid;
+
+        if (settings)
+                *settings = NULL;
+
+        iid = panel_object_type_to_iid (type, type_detail);
+        if (!iid)
+                return NULL;
+
+        unique_id = panel_layout_find_free_id (PANEL_LAYOUT_OBJECT_ID_LIST_KEY,
+                                               PANEL_OBJECT_SCHEMA,
+                                               PANEL_LAYOUT_OBJECT_PATH,
+                                               NULL, -1);
+
+        path = g_strdup_printf ("%s%s/", PANEL_LAYOUT_OBJECT_PATH, unique_id);
+        settings_object = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
+        g_free (path);
+
+        g_settings_set_string (settings_object,
+                               PANEL_OBJECT_IID_KEY,
+                               iid);
+        g_settings_set_string (settings_object,
+                               PANEL_OBJECT_TOPLEVEL_ID_KEY,
+                               toplevel_id);
+        g_settings_set_int (settings_object,
+                            PANEL_OBJECT_POSITION_KEY,
+                            position);
+        g_settings_set_boolean (settings_object,
+                                PANEL_OBJECT_PACK_END_KEY,
+                                pack_end);
+
+        g_free (iid);
+
+        if (settings)
+                *settings = settings_object;
+        else
+                g_object_unref (settings_object);
+
+        return unique_id;
+}
+
+void
+panel_layout_object_create_finish (const char *object_id)
+{
+        panel_gsettings_append_strv (layout_settings,
+                                     PANEL_LAYOUT_OBJECT_ID_LIST_KEY,
+                                     object_id);
+}
+
 
 /*******************\
  * Changing layout *
diff --git a/gnome-panel/panel-layout.h b/gnome-panel/panel-layout.h
index 2689002..73aaf03 100644
--- a/gnome-panel/panel-layout.h
+++ b/gnome-panel/panel-layout.h
@@ -36,7 +36,21 @@ gboolean panel_layout_load         (void);
 
 gboolean panel_layout_is_writable  (void);
 
-void panel_layout_toplevel_create (GdkScreen  *screen);
+void  panel_layout_toplevel_create      (GdkScreen        *screen);
+void  panel_layout_object_create        (PanelObjectType   type,
+					 const char       *type_detail,
+					 const char       *toplevel_id,
+					 int               position,
+					 gboolean          pack_end);
+
+char *panel_layout_object_create_start  (PanelObjectType   type,
+					 const char       *type_detail,
+					 const char       *toplevel_id,
+					 int               position,
+					 gboolean          pack_end,
+					 GSettings       **settings);
+void  panel_layout_object_create_finish (const char       *object_id);
+
 void panel_layout_delete_toplevel (const char *toplevel_id);
 void panel_layout_delete_object   (const char *object_id);
 
diff --git a/gnome-panel/panel-object-loader.c b/gnome-panel/panel-object-loader.c
index 42a7cb8..1610bd3 100644
--- a/gnome-panel/panel-object-loader.c
+++ b/gnome-panel/panel-object-loader.c
@@ -347,6 +347,8 @@ panel_object_loader_is_queued (const char *id)
  * iid <=> object type mapping *
 \*******************************/
 
+#define PANEL_INTERNAL_FACTORY "PanelInternalFactory"
+
 static struct {
         PanelObjectType  type;
         const char      *id;
@@ -359,6 +361,37 @@ static struct {
         { PANEL_OBJECT_SEPARATOR, "Separator"    , FALSE }
 };
 
+char *
+panel_object_type_to_iid (PanelObjectType  type,
+                          const char      *detail)
+{
+        int i;
+
+        if (type == PANEL_OBJECT_APPLET)
+                return g_strdup (detail);
+
+        for (i = 0; i < G_N_ELEMENTS (panel_object_iid_map); i++) {
+                if (panel_object_iid_map[i].type != type)
+                        continue;
+
+                if (panel_object_iid_map[i].has_detail &&
+                    PANEL_GLIB_STR_EMPTY (detail))
+                        return NULL;
+
+                if (panel_object_iid_map[i].has_detail)
+                        return g_strdup_printf ("%s::%s:%s",
+                                                PANEL_INTERNAL_FACTORY,
+                                                panel_object_iid_map[i].id,
+                                                detail);
+                else
+                        return g_strdup_printf ("%s::%s",
+                                                PANEL_INTERNAL_FACTORY,
+                                                panel_object_iid_map[i].id);
+        }
+
+        return NULL;
+}
+
 gboolean
 panel_object_iid_to_type (const char       *iid,
                           PanelObjectType  *type,
@@ -377,7 +410,7 @@ panel_object_iid_to_type (const char       *iid,
                 return FALSE;
 
 	factory_id = g_strndup (iid, strlen (iid) - strlen (instance_id));
-        is_applet = (g_strcmp0 (factory_id, "PanelInternalFactory") != 0);
+        is_applet = (g_strcmp0 (factory_id, PANEL_INTERNAL_FACTORY) != 0);
         g_free (factory_id);
 
         if (is_applet) {
diff --git a/gnome-panel/panel-object-loader.h b/gnome-panel/panel-object-loader.h
index d2603bd..ca8dec7 100644
--- a/gnome-panel/panel-object-loader.h
+++ b/gnome-panel/panel-object-loader.h
@@ -41,9 +41,12 @@ void     panel_object_loader_stop_loading  (const char *id);
  * iid <=> object type mapping *
 \*******************************/
 
-gboolean panel_object_iid_to_type (const char       *iid,
-                                   PanelObjectType  *type,
-                                   char            **detail);
+char     *panel_object_type_to_iid (PanelObjectType  type,
+                                    const char      *detail);
+
+gboolean  panel_object_iid_to_type (const char       *iid,
+                                    PanelObjectType  *type,
+                                    char            **detail);
 
 G_END_DECLS
 



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