[Xfce4-commits] <xfce4-panel:master> Panel: Only save what is required.
Nick Schermer
noreply at xfce.org
Thu Dec 29 17:36:05 CET 2011
Updating branch refs/heads/master
to f0b084486e981518b19eaa978df3615e3c250738 (commit)
from 6196070242a05a7f208f2b59fb7b5b5b3e4441ae (commit)
commit f0b084486e981518b19eaa978df3615e3c250738
Author: Nick Schermer <nick at xfce.org>
Date: Thu Dec 29 17:32:45 2011 +0100
Panel: Only save what is required.
Also remove auto save from the session mananger and
improve what is saved.
panel/main.c | 22 -----
panel/panel-application.c | 210 +++++++++++++++++++++++++++-----------------
panel/panel-application.h | 12 +++-
panel/panel-dbus-service.c | 2 +-
4 files changed, 143 insertions(+), 103 deletions(-)
diff --git a/panel/main.c b/panel/main.c
index e5d7839..44ebf3c 100644
--- a/panel/main.c
+++ b/panel/main.c
@@ -61,7 +61,6 @@ static gboolean opt_version = FALSE;
static gboolean opt_disable_wm_check = FALSE;
static gchar *opt_plugin_event = NULL;
static gchar **opt_arguments = NULL;
-static gboolean sm_client_saved_state = FALSE;
@@ -156,23 +155,6 @@ panel_sm_client_quit (XfceSMClient *sm_client)
static void
-panel_sm_client_save_state (XfceSMClient *sm_client,
- PanelApplication *application)
-{
- panel_return_if_fail (XFCE_IS_SM_CLIENT (sm_client));
- panel_return_if_fail (PANEL_IS_APPLICATION (application));
-
- panel_debug (PANEL_DEBUG_MAIN,
- "save configuration for session manager");
-
- panel_application_save (application, TRUE);
-
- sm_client_saved_state = TRUE;
-}
-
-
-
-static void
panel_debug_notify_proxy (void)
{
gchar *path;
@@ -349,10 +331,6 @@ main (gint argc, gchar **argv)
application = panel_application_get ();
panel_application_load (application, opt_disable_wm_check);
- /* save the state before the quit signal if we can, this is a bit safer */
- g_signal_connect (G_OBJECT (sm_client), "save-state",
- G_CALLBACK (panel_sm_client_save_state), application);
-
/* open dialog if we started from launch_panel */
if (opt_preferences >= 0)
panel_preferences_dialog_show_from_id (opt_preferences);
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 4ea4074..c064a6d 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -96,6 +96,9 @@ static void panel_application_drag_leave (GtkWidget *w
GdkDragContext *context,
guint drag_time,
PanelApplication *application);
+static void panel_application_save_window (PanelApplication *application,
+ PanelWindow *window,
+ PanelSaveTypes save_types);
@@ -828,8 +831,8 @@ panel_application_window_destroyed (GtkWidget *window,
xfconf_channel_reset_property (application->xfconf, property, TRUE);
g_free (property);
- /* schedule a save to store the new number of panels */
- panel_application_save (application, FALSE);
+ /* save updated panel ids */
+ panel_application_save (application, SAVE_PANEL_IDS);
/* quit if there are no windows */
/* TODO, allow removing all windows and ask user what to do */
@@ -889,6 +892,7 @@ panel_application_drag_data_received (PanelWindow *window,
PanelApplication *application;
GtkWidget *provider;
gboolean succeed = FALSE;
+ gboolean save_application = FALSE;
const gchar *name;
guint old_position;
gchar **uris;
@@ -979,6 +983,9 @@ panel_application_drag_data_received (PanelWindow *window,
/* send all the needed panel information to the plugin */
panel_window_set_povider_info (window, provider, TRUE);
+
+ /* moved between panels, save everything */
+ save_application = TRUE;
}
/* everything went fine */
@@ -1008,9 +1015,11 @@ panel_application_drag_data_received (PanelWindow *window,
break;
}
- /* save the panel configuration if we succeeded */
- if (G_LIKELY (succeed))
- panel_application_save (application, FALSE);
+ /* save the new plugin ids */
+ if (G_LIKELY (save_application))
+ panel_application_save (application, SAVE_PLUGIN_IDS);
+ else if (succeed)
+ panel_application_save_window (application, window, SAVE_PLUGIN_IDS);
/* tell the peer that we handled the drop */
gtk_drag_finish (context, succeed, FALSE, drag_time);
@@ -1166,6 +1175,89 @@ panel_application_window_id_exists (PanelApplication *application,
+static void
+panel_application_save_window (PanelApplication *application,
+ PanelWindow *window,
+ PanelSaveTypes save_types)
+{
+ GList *children, *lp;
+ GtkWidget *itembar;
+ XfcePanelPluginProvider *provider;
+ gchar buf[50];
+ XfconfChannel *channel = application->xfconf;
+ GPtrArray *array = NULL;
+ GValue *value;
+ gint plugin_id;
+ gint panel_id;
+
+ /* skip this window if it is locked */
+ if (panel_window_get_locked (window)
+ || !PANEL_HAS_FLAG (save_types, SAVE_PLUGIN_IDS | SAVE_PLUGIN_PROVIDERS))
+ return;
+
+ panel_id = panel_window_get_id (window);
+ panel_debug (PANEL_DEBUG_APPLICATION,
+ "saving /panels/panel-%d: ids=%s, providers=%s",
+ panel_id,
+ PANEL_DEBUG_BOOL (PANEL_HAS_FLAG (save_types, SAVE_PLUGIN_IDS)),
+ PANEL_DEBUG_BOOL (PANEL_HAS_FLAG (save_types, SAVE_PLUGIN_PROVIDERS)));
+
+ /* get the itembar children */
+ itembar = gtk_bin_get_child (GTK_BIN (window));
+ children = gtk_container_get_children (GTK_CONTAINER (itembar));
+
+ /* only cleanup and continue if there are no children */
+ if (PANEL_HAS_FLAG (save_types, SAVE_PLUGIN_IDS))
+ {
+ if (G_UNLIKELY (children == NULL))
+ {
+ g_snprintf (buf, sizeof (buf), "/panels/panel-%d/plugin-ids", panel_id);
+ if (xfconf_channel_has_property (channel, buf))
+ xfconf_channel_reset_property (channel, buf, FALSE);
+ return;
+ }
+
+ array = g_ptr_array_new ();
+ }
+
+ /* walk all the plugin children */
+ for (lp = children; lp != NULL; lp = lp->next)
+ {
+ provider = XFCE_PANEL_PLUGIN_PROVIDER (lp->data);
+
+ if (array != NULL)
+ {
+ plugin_id = xfce_panel_plugin_provider_get_unique_id (provider);
+
+ /* add plugin id to the array */
+ value = g_new0 (GValue, 1);
+ g_value_init (value, G_TYPE_INT);
+ g_value_set_int (value, plugin_id);
+ g_ptr_array_add (array, value);
+
+ /* make sure the plugin type-name is store in the plugin item */
+ g_snprintf (buf, sizeof (buf), "/plugins/plugin-%d", plugin_id);
+ xfconf_channel_set_string (channel, buf, xfce_panel_plugin_provider_get_name (provider));
+ }
+
+ /* ask the plugin to save */
+ if (PANEL_HAS_FLAG (save_types, SAVE_PLUGIN_PROVIDERS))
+ xfce_panel_plugin_provider_save (provider);
+ }
+
+ if (array != NULL)
+ {
+ /* store the plugin ids for this panel */
+ g_snprintf (buf, sizeof (buf), "/panels/panel-%d/plugin-ids", panel_id);
+ xfconf_channel_set_arrayv (channel, buf, array);
+ xfconf_array_free (array);
+ }
+
+ g_list_free (children);
+}
+
+
+
PanelApplication *
panel_application_get (void)
{
@@ -1237,95 +1329,47 @@ panel_application_load (PanelApplication *application,
void
panel_application_save (PanelApplication *application,
- gboolean save_plugin_providers)
+ PanelSaveTypes save_types)
{
- GSList *li;
- GList *children, *lp;
- GtkWidget *itembar;
- XfcePanelPluginProvider *provider;
- guint i;
- gchar buf[50];
- XfconfChannel *channel = application->xfconf;
- GPtrArray *array;
- GValue *value;
- GPtrArray *panels;
- gint panel_id;
+ GSList *li;
+ XfconfChannel *channel = application->xfconf;
+ GValue *value;
+ GPtrArray *panels = NULL;
+ gint panel_id;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
- panels = g_ptr_array_new ();
-
- for (li = application->windows, i = 0; li != NULL; li = li->next, i++)
- {
- /* store the panel id */
- value = g_new0 (GValue, 1);
- panel_id = panel_window_get_id (li->data);
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, panel_id);
- g_ptr_array_add (panels, value);
-
- /* skip this window if it is locked */
- if (panel_window_get_locked (li->data))
- continue;
-
- panel_debug (PANEL_DEBUG_APPLICATION,
- "saving /panels/panel-%d, save-plugins=%s",
- panel_id, PANEL_DEBUG_BOOL (save_plugin_providers));
-
- /* get the itembar children */
- itembar = gtk_bin_get_child (GTK_BIN (li->data));
- children = gtk_container_get_children (GTK_CONTAINER (itembar));
-
- /* only cleanup and continue if there are no children */
- if (G_UNLIKELY (children == NULL))
- {
- g_snprintf (buf, sizeof (buf), "/panels/panel-%d/plugin-ids", panel_id);
- if (xfconf_channel_has_property (channel, buf))
- xfconf_channel_reset_property (channel, buf, FALSE);
- continue;
- }
+ /* leave if the whole application is locked */
+ if (xfconf_channel_is_property_locked (channel, "/panels"))
+ return;
- /* create empty pointer array */
- array = g_ptr_array_new ();
+ if (PANEL_HAS_FLAG (save_types, SAVE_PANEL_IDS))
+ panels = g_ptr_array_new ();
- /* walk all the plugin children */
- for (lp = children; lp != NULL; lp = lp->next)
+ for (li = application->windows; li != NULL; li = li->next)
+ {
+ if (panels != NULL)
{
- provider = XFCE_PANEL_PLUGIN_PROVIDER (lp->data);
-
- /* add plugin id to the array */
+ /* store the panel id */
value = g_new0 (GValue, 1);
+ panel_id = panel_window_get_id (li->data);
g_value_init (value, G_TYPE_INT);
- g_value_set_int (value,
- xfce_panel_plugin_provider_get_unique_id (provider));
- g_ptr_array_add (array, value);
-
- /* make sure the plugin type is store in the plugin item */
- g_snprintf (buf, sizeof (buf), "/plugins/plugin-%d", g_value_get_int (value));
- xfconf_channel_set_string (channel, buf, xfce_panel_plugin_provider_get_name (provider));
-
- /* ask the plugin to save */
- if (save_plugin_providers)
- xfce_panel_plugin_provider_save (provider);
+ g_value_set_int (value, panel_id);
+ g_ptr_array_add (panels, value);
}
- /* store the plugins for this panel */
- g_snprintf (buf, sizeof (buf), "/panels/panel-%d/plugin-ids", panel_id);
- xfconf_channel_set_arrayv (channel, buf, array);
-
- g_list_free (children);
- xfconf_array_free (array);
+ /* save the panel settings */
+ panel_application_save_window (application, li->data, save_types);
}
- /* store the panel ids */
- if (!xfconf_channel_is_property_locked (channel, "/panels"))
+ if (panels != NULL)
{
+ /* store the panel ids */
if (!xfconf_channel_set_arrayv (channel, "/panels", panels))
g_warning ("Failed to store the number of panels");
+ xfconf_array_free (panels);
}
-
- xfconf_array_free (panels);
}
@@ -1411,9 +1455,13 @@ panel_application_add_new_item (PanelApplication *application,
if (window != NULL && !panel_window_get_locked (window))
{
/* insert plugin at the end of the panel */
- panel_application_plugin_insert (application, window,
- plugin_name, -1,
- arguments, -1);
+ if (panel_application_plugin_insert (application, window,
+ plugin_name, -1,
+ arguments, -1))
+ {
+ /* save the new plugin ids */
+ panel_application_save_window (application, window, SAVE_PLUGIN_IDS);
+ }
}
}
else
@@ -1509,6 +1557,10 @@ panel_application_new_window (PanelApplication *application,
g_free (position);
}
+ /* save the new panel layout */
+ if (new_window)
+ panel_application_save (application, SAVE_PANEL_IDS);
+
return PANEL_WINDOW (window);
}
diff --git a/panel/panel-application.h b/panel/panel-application.h
index ee1d719..3dcf1b6 100644
--- a/panel/panel-application.h
+++ b/panel/panel-application.h
@@ -34,6 +34,16 @@ typedef struct _PanelApplication PanelApplication;
#define PANEL_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLICATION))
#define PANEL_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANEL_TYPE_APPLICATION, PanelApplicationClass))
+typedef enum
+{
+ SAVE_PLUGIN_PROVIDERS = 1 << 1,
+ SAVE_PLUGIN_IDS = 1 << 2,
+ SAVE_PANEL_IDS = 1 << 3,
+}
+PanelSaveTypes;
+#define SAVE_EVERYTHING (SAVE_PLUGIN_PROVIDERS | SAVE_PLUGIN_IDS | SAVE_PANEL_IDS)
+
+
GType panel_application_get_type (void) G_GNUC_CONST;
PanelApplication *panel_application_get (void);
@@ -42,7 +52,7 @@ void panel_application_load (PanelApplication *applic
gboolean disable_wm_check);
void panel_application_save (PanelApplication *application,
- gboolean save_plugin_providers);
+ PanelSaveTypes save_types);
void panel_application_take_dialog (PanelApplication *application,
GtkWindow *dialog);
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index 955e466..3947c43 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -230,7 +230,7 @@ panel_dbus_service_save (PanelDBusService *service,
/* save the configuration */
application = panel_application_get ();
- panel_application_save (application, TRUE);
+ panel_application_save (application, SAVE_EVERYTHING);
g_object_unref (G_OBJECT (application));
return TRUE;
More information about the Xfce4-commits
mailing list