[gnome-panel] panel-applet-frame: add support for initial settings



commit 73ef380439604791f27835eb234cf14371937bac
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Sep 15 21:55:31 2018 +0300

    panel-applet-frame: add support for initial settings

 data/Makefile.am                                   |  1 +
 ...gnome-panel.applet.initial-settings.gschema.xml |  7 +++++
 gnome-panel/launcher.c                             |  2 +-
 .../libpanel-applet-private/gp-applet-manager.c    | 35 +++++++++++++++++++++-
 gnome-panel/panel-action-button.c                  |  3 +-
 gnome-panel/panel-addto-dialog.c                   |  3 +-
 gnome-panel/panel-applet-frame.c                   | 19 ++++++++++--
 gnome-panel/panel-applet-frame.h                   |  4 ++-
 gnome-panel/panel-layout.c                         | 17 +++++++++--
 gnome-panel/panel-layout.h                         |  4 ++-
 gnome-panel/panel-menu-button.c                    |  2 +-
 gnome-panel/panel.c                                |  4 +--
 po/POTFILES.skip                                   |  1 +
 13 files changed, 89 insertions(+), 13 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index e825c5b5a..ce9c18d00 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -14,6 +14,7 @@ gsettings_SCHEMAS = \
        org.gnome.gnome-panel.applet.window-list.gschema.xml \
        org.gnome.gnome-panel.applet.workspace-switcher.gschema.xml \
        org.gnome.gnome-panel.applet.clock.gschema.xml \
+       org.gnome.gnome-panel.applet.initial-settings.gschema.xml \
        org.gnome.gnome-panel.gschema.xml \
        org.gnome.gnome-panel.launcher.gschema.xml \
        org.gnome.gnome-panel.menu-button.gschema.xml \
diff --git a/data/org.gnome.gnome-panel.applet.initial-settings.gschema.xml 
b/data/org.gnome.gnome-panel.applet.initial-settings.gschema.xml
new file mode 100644
index 000000000..b3b124383
--- /dev/null
+++ b/data/org.gnome.gnome-panel.applet.initial-settings.gschema.xml
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id="org.gnome.gnome-panel.applet.initial-settings">
+    <key name="settings" type="a{sv}">
+      <default>{}</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gnome-panel/launcher.c b/gnome-panel/launcher.c
index 39c45cdc4..ed6378e35 100644
--- a/gnome-panel/launcher.c
+++ b/gnome-panel/launcher.c
@@ -1188,7 +1188,7 @@ panel_launcher_create_with_id (const char          *toplevel_id,
        id = panel_layout_object_create_start (PANEL_OBJECT_LAUNCHER,
                                               NULL,
                                               toplevel_id, pack_type, pack_index,
-                                              &settings);
+                                              NULL, &settings);
 
        no_uri = NULL;
        /* if we have an URI, it might contain escaped characters (? : etc)
diff --git a/gnome-panel/libpanel-applet-private/gp-applet-manager.c 
b/gnome-panel/libpanel-applet-private/gp-applet-manager.c
index 2ae6bfcd1..6e12c0b93 100644
--- a/gnome-panel/libpanel-applet-private/gp-applet-manager.c
+++ b/gnome-panel/libpanel-applet-private/gp-applet-manager.c
@@ -34,6 +34,37 @@ struct _GpAppletManager
 
 G_DEFINE_TYPE (GpAppletManager, gp_applet_manager, PANEL_TYPE_APPLETS_MANAGER)
 
+static GVariant *
+get_initial_settings (PanelAppletFrameActivating *frame_act)
+{
+  gchar *path;
+  GSettings *settings;
+  GVariant *initial_settings;
+
+  path = panel_applet_frame_activating_get_initial_settings_path (frame_act);
+  settings = g_settings_new_with_path ("org.gnome.gnome-panel.applet.initial-settings", path);
+  g_free (path);
+
+  initial_settings = g_settings_get_user_value (settings, "settings");
+  g_object_unref (settings);
+
+  return initial_settings;
+}
+
+static void
+remove_initial_settings (PanelAppletFrameActivating *frame_act)
+{
+  gchar *path;
+  GSettings *settings;
+
+  path = panel_applet_frame_activating_get_initial_settings_path (frame_act);
+  settings = g_settings_new_with_path ("org.gnome.gnome-panel.applet.initial-settings", path);
+  g_free (path);
+
+  g_settings_reset (settings, "settings");
+  g_object_unref (settings);
+}
+
 static void
 get_applet_infos (GpAppletManager *manager,
                   const gchar     *id,
@@ -239,7 +270,7 @@ gp_applet_manager_load_applet (PanelAppletsManager        *manager,
         break;
     }
 
-  initial_settings = NULL;
+  initial_settings = get_initial_settings (frame_act);
 
   error = NULL;
   applet = gp_module_applet_new (module, applet_id, settings_path,
@@ -256,6 +287,8 @@ gp_applet_manager_load_applet (PanelAppletsManager        *manager,
       return FALSE;
     }
 
+  remove_initial_settings (frame_act);
+
   gp_applet_set_locked_down (applet, locked_down);
   gp_applet_set_orientation (applet, orientation);
   gp_applet_set_position (applet, position);
diff --git a/gnome-panel/panel-action-button.c b/gnome-panel/panel-action-button.c
index 3f80ce870..40bf2a571 100644
--- a/gnome-panel/panel-action-button.c
+++ b/gnome-panel/panel-action-button.c
@@ -732,7 +732,8 @@ panel_action_button_create (PanelToplevel         *toplevel,
        panel_layout_object_create (PANEL_OBJECT_ACTION,
                                    panel_enum_to_string (type),
                                    panel_toplevel_get_id (toplevel),
-                                   pack_type, pack_index);
+                                   pack_type, pack_index,
+                                   NULL);
 }
 
 void
diff --git a/gnome-panel/panel-addto-dialog.c b/gnome-panel/panel-addto-dialog.c
index b671361c4..f405900e9 100644
--- a/gnome-panel/panel-addto-dialog.c
+++ b/gnome-panel/panel-addto-dialog.c
@@ -682,7 +682,8 @@ panel_addto_add_item (PanelAddtoDialog   *dialog,
                panel_applet_frame_create (dialog->panel_widget->toplevel,
                                           dialog->insert_pack_type,
                                           pack_index,
-                                          item_info->iid);
+                                          item_info->iid,
+                                          NULL);
                break;
        case PANEL_ADDTO_ACTION:
                panel_action_button_create (dialog->panel_widget->toplevel,
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index 3b0cd2f3f..771668b64 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -716,6 +716,19 @@ panel_applet_frame_activating_get_settings_path (PanelAppletFrameActivating *fra
        return path_instance;
 }
 
+gchar *
+panel_applet_frame_activating_get_initial_settings_path (PanelAppletFrameActivating *frame_act)
+{
+        char *path;
+        char *path_instance;
+
+        g_object_get (frame_act->settings, "path", &path, NULL);
+        path_instance = g_strdup_printf ("%sinitial-settings/", path);
+        g_free (path);
+
+        return path_instance;
+}
+
 static void
 panel_applet_frame_loading_failed_response (GtkWidget *dialog,
                                            guint      response,
@@ -865,14 +878,16 @@ void
 panel_applet_frame_create (PanelToplevel       *toplevel,
                           PanelObjectPackType  pack_type,
                           int                  pack_index,
-                          const char          *iid)
+                          const char          *iid,
+                          GVariant            *initial_settings)
 {
        g_return_if_fail (iid != NULL);
 
        panel_layout_object_create (PANEL_OBJECT_APPLET,
                                    iid,
                                    panel_toplevel_get_id (toplevel),
-                                   pack_type, pack_index);
+                                   pack_type, pack_index,
+                                   initial_settings);
 }
 
 gboolean
diff --git a/gnome-panel/panel-applet-frame.h b/gnome-panel/panel-applet-frame.h
index 5e1e75d9d..84df78495 100644
--- a/gnome-panel/panel-applet-frame.h
+++ b/gnome-panel/panel-applet-frame.h
@@ -79,7 +79,8 @@ GType panel_applet_frame_get_type           (void) G_GNUC_CONST;
 void  panel_applet_frame_create             (PanelToplevel       *toplevel,
                                             PanelObjectPackType  pack_type,
                                             int                  pack_index,
-                                            const char          *iid);
+                                            const char          *iid,
+                                            GVariant            *initial_settings);
 
 void  panel_applet_frame_load               (PanelWidget         *panel_widget,
                                             const char          *id,
@@ -99,6 +100,7 @@ typedef struct _PanelAppletFrameActivating        PanelAppletFrameActivating;
 PanelOrientation  panel_applet_frame_activating_get_orientation (PanelAppletFrameActivating *frame_act);
 gboolean          panel_applet_frame_activating_get_locked_down (PanelAppletFrameActivating *frame_act);
 gchar            *panel_applet_frame_activating_get_settings_path (PanelAppletFrameActivating *frame_act);
+gchar            *panel_applet_frame_activating_get_initial_settings_path (PanelAppletFrameActivating 
*frame_act);
 
 void  _panel_applet_frame_set_iid               (PanelAppletFrame           *frame,
                                                 const gchar                *iid);
diff --git a/gnome-panel/panel-layout.c b/gnome-panel/panel-layout.c
index 1ca11594b..bde670936 100644
--- a/gnome-panel/panel-layout.c
+++ b/gnome-panel/panel-layout.c
@@ -646,13 +646,14 @@ panel_layout_object_create (PanelObjectType      type,
                             const char          *type_detail,
                             const char          *toplevel_id,
                             PanelObjectPackType  pack_type,
-                            int                  pack_index)
+                            int                  pack_index,
+                            GVariant            *initial_settings)
 {
         char *id;
 
         id = panel_layout_object_create_start (type, type_detail,
                                                toplevel_id, pack_type, pack_index,
-                                               NULL);
+                                               initial_settings, NULL);
 
         if (!id)
                 return;
@@ -719,6 +720,7 @@ panel_layout_object_create_start (PanelObjectType       type,
                                   const char           *toplevel_id,
                                   PanelObjectPackType   pack_type,
                                   int                   pack_index,
+                                  GVariant             *initial_settings,
                                   GSettings           **settings)
 {
         char      *unique_id;
@@ -757,6 +759,17 @@ panel_layout_object_create_start (PanelObjectType       type,
                             PANEL_OBJECT_PACK_INDEX_KEY,
                             pack_index);
 
+        if (initial_settings != NULL) {
+                GSettings *tmp;
+
+                path = g_strdup_printf ("%s%s/initial-settings/", PANEL_LAYOUT_OBJECT_PATH, unique_id);
+                tmp = g_settings_new_with_path ("org.gnome.gnome-panel.applet.initial-settings", path);
+                g_free (path);
+
+                g_settings_set_value (tmp, "settings", initial_settings);
+                g_object_unref (tmp);
+        }
+
         g_free (try_id);
         g_free (iid);
 
diff --git a/gnome-panel/panel-layout.h b/gnome-panel/panel-layout.h
index 93ef0e2a3..a9ca52a35 100644
--- a/gnome-panel/panel-layout.h
+++ b/gnome-panel/panel-layout.h
@@ -41,7 +41,8 @@ void  panel_layout_object_create        (PanelObjectType       type,
                                          const char           *type_detail,
                                          const char           *toplevel_id,
                                          PanelObjectPackType   pack_type,
-                                         int                   pack_index);
+                                         int                   pack_index,
+                                         GVariant             *initial_settings);
 
 char      *panel_layout_object_get_gconf_path (const char *object_id);
 GSettings *panel_layout_get_instance_settings (GSettings  *settings_object,
@@ -52,6 +53,7 @@ char *panel_layout_object_create_start  (PanelObjectType       type,
                                          const char           *toplevel_id,
                                          PanelObjectPackType   pack_type,
                                          int                   pack_index,
+                                         GVariant             *initial_settings,
                                          GSettings           **settings);
 void  panel_layout_object_create_finish (const char           *object_id);
 
diff --git a/gnome-panel/panel-menu-button.c b/gnome-panel/panel-menu-button.c
index ec63bab9a..235e0b6ae 100644
--- a/gnome-panel/panel-menu-button.c
+++ b/gnome-panel/panel-menu-button.c
@@ -794,7 +794,7 @@ panel_menu_button_create (PanelToplevel       *toplevel,
        id = panel_layout_object_create_start (PANEL_OBJECT_MENU, NULL,
                                               panel_toplevel_get_id (toplevel),
                                               pack_type, pack_index,
-                                              &settings);
+                                              NULL, &settings);
 
        settings_instance = panel_layout_get_instance_settings (settings,
                                                                PANEL_MENU_BUTTON_SCHEMA);
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index e98f7db82..e63740d87 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -512,7 +512,7 @@ drop_nautilus_desktop_uri (PanelWidget         *panel,
 
        if (strncmp (basename, "trash", strlen ("trash")) == 0)
                panel_applet_frame_create (panel->toplevel, pack_type, pack_index,
-                                          "OAFIID:GNOME_Panel_TrashApplet");
+                                          "OAFIID:GNOME_Panel_TrashApplet", NULL);
        else if (strncmp (basename, "home", strlen ("home")) == 0) {
                char  *name;
                char  *uri_tmp;
@@ -1081,7 +1081,7 @@ panel_receive_dnd_data (PanelWidget         *panel,
                if (panel_layout_is_writable ()) {
                        panel_applet_frame_create (panel->toplevel,
                                                   pack_type, pack_index,
-                                                  (char *) data);
+                                                  (char *) data, NULL);
                        success = TRUE;
                } else {
                        success = FALSE;
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 0fb3682e8..d14b0ee9b 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,2 +1,3 @@
 # List of source files that should *not* be translated.
 # Please keep this file sorted alphabetically.
+data/org.gnome.gnome-panel.applet.initial-settings.gschema.xml


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