[Xfce4-commits] <xfce4-panel:devel> Fix some crashes and problems related to xfconf.

Nick Schermer noreply at xfce.org
Mon Nov 16 15:26:03 CET 2009


Updating branch refs/heads/devel
         to 71ce262e78ed6a28cc909e9d5179bea25c4d3459 (commit)
       from acc4e99fd23f46c9356936aee9f19ad2bc1e9972 (commit)

commit 71ce262e78ed6a28cc909e9d5179bea25c4d3459
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Nov 15 11:57:43 2009 +0100

    Fix some crashes and problems related to xfconf.

 common/panel-xfconf.c            |   40 ++++++++++++++++++--
 panel/panel-application.c        |   76 ++++++++++++++++++++++++-------------
 panel/panel-preferences-dialog.c |   16 ++++----
 panel/panel-window.c             |    3 +-
 4 files changed, 95 insertions(+), 40 deletions(-)

diff --git a/common/panel-xfconf.c b/common/panel-xfconf.c
index 0f1a329..6a32833 100644
--- a/common/panel-xfconf.c
+++ b/common/panel-xfconf.c
@@ -25,6 +25,37 @@
 
 
 
+static void
+panel_properties_store_value (XfconfChannel *channel,
+                              const gchar   *xfconf_property,
+                              GType          xfconf_property_type,
+                              GObject       *object,
+                              const gchar   *object_property)
+{
+  GValue      value = { 0, };
+#ifndef NDEBUG
+  GParamSpec *pspec;
+#endif
+
+  panel_return_if_fail (G_IS_OBJECT (object));
+  panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
+
+#ifndef NDEBUG
+  /* check if the types match */
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), object_property);
+  panel_assert (pspec != NULL);
+  panel_assert (G_PARAM_SPEC_VALUE_TYPE (pspec) == xfconf_property_type);
+#endif
+
+  /* write the property to the xfconf channel */
+  g_value_init (&value, xfconf_property_type);
+  g_object_get_property (G_OBJECT (object), object_property, &value);
+  xfconf_channel_set_property (channel, xfconf_property, &value);
+  g_value_unset (&value);
+}
+
+
+
 XfconfChannel *
 panel_properties_get_channel (GObject *object_for_weak_ref)
 {
@@ -71,12 +102,13 @@ panel_properties_bind (XfconfChannel       *channel,
   for (prop = properties; prop->property != NULL; prop++)
     {
       property = g_strconcat (property_base, "/", prop->property, NULL);
-      xfconf_g_property_bind (channel, property, prop->type, object, prop->property);
-      g_free (property);
 
-      /* notify the property to it gets saved */
       if (save_properties)
-        g_object_notify (G_OBJECT (object), prop->property);
+        panel_properties_store_value (channel, property, prop->type, object, prop->property);
+
+      xfconf_g_property_bind (channel, property, prop->type, object, prop->property);
+
+      g_free (property);
     }
 }
 
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 91f61bf..9d09654 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -437,6 +437,18 @@ panel_application_plugin_delete_config (PanelApplication *application,
 
 
 static void
+panel_application_plugin_remove (GtkWidget *widget,
+                                 gpointer   user_data)
+{
+  panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (widget));
+
+  xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (widget),
+                                          PROVIDER_SIGNAL_REMOVE_PLUGIN);
+}
+
+
+
+static void
 panel_application_plugin_provider_signal (XfcePanelPluginProvider       *provider,
                                           XfcePanelPluginProviderSignal  provider_signal,
                                           PanelApplication              *application)
@@ -635,10 +647,11 @@ static void
 panel_application_window_destroyed (GtkWidget        *window,
                                     PanelApplication *application)
 {
-  guint     n;
-  gchar     buf[100];
-  GSList   *li, *lnext;
-  gboolean  passed_destroyed_window = FALSE;
+  guint      n;
+  gchar     *property;
+  GSList    *li, *lnext;
+  gboolean   passed_destroyed_window = FALSE;
+  GtkWidget *itembar;
 
   panel_return_if_fail (PANEL_IS_WINDOW (window));
   panel_return_if_fail (PANEL_IS_APPLICATION (application));
@@ -649,31 +662,39 @@ panel_application_window_destroyed (GtkWidget        *window,
     {
       lnext = li->next;
 
-      /* skip window if we're not passed the active window */
-      if (!passed_destroyed_window && li->data != window)
-        continue;
-
-      /* keep updating from now on */
-      passed_destroyed_window = TRUE;
+      if (passed_destroyed_window)
+        {
+          /* save this panel again at it's new position */
+          panel_properties_unbind (G_OBJECT (li->data));
+          panel_application_xfconf_window_bindings (application,
+                                                    PANEL_WINDOW (li->data),
+                                                    TRUE);
+        }
+      else if (li->data == window)
+        {
+          /* disconnect bindings from this panel */
+          panel_properties_unbind (G_OBJECT (window));
 
-      /* disconnect bindings from this panel */
-      panel_properties_unbind (G_OBJECT (li->data));
+          /* remove all the plugins from the itembar */
+          itembar = gtk_bin_get_child (GTK_BIN (window));
+          gtk_container_foreach (GTK_CONTAINER (itembar),
+              panel_application_plugin_remove, NULL);
 
-      /* remove the properties of this panel */
-      g_snprintf (buf, sizeof (buf), "/panels/panel-%u", n);
-      if (xfconf_channel_has_property (application->xfconf, buf))
-        xfconf_channel_reset_property (application->xfconf, buf, TRUE);
+          /* remove from the internal list */
+          application->windows = g_slist_delete_link (application->windows, li);
 
-      /* either remove the window or add the bindings */
-      if (li->data == window)
-        application->windows = g_slist_delete_link (application->windows, li);
-      else
-        panel_application_xfconf_window_bindings (application,
-                                                  PANEL_WINDOW (li->data),
-                                                  TRUE);
+          /* keep updating the bindings for the remaining windows */
+          passed_destroyed_window = TRUE;
+        }
     }
 
-  /* force a panel save to store plugins and panel count */
+  /* remove the last property from the channel */
+  property = g_strdup_printf ("/panels/panel-%u", n - 1);
+  panel_assert (n - 1 == g_slist_length (application->windows));
+  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);
 
   /* quit if there are no windows opened */
@@ -1160,6 +1181,7 @@ panel_application_new_window (PanelApplication *application,
   GtkWidget *window;
   GtkWidget *itembar;
   gchar     *property;
+  gint       idx;
 
   panel_return_val_if_fail (PANEL_IS_APPLICATION (application), NULL);
   panel_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), NULL);
@@ -1185,9 +1207,9 @@ panel_application_new_window (PanelApplication *application,
   if (new_window)
     {
       /* remove the xfconf properties */
-      property = g_strdup_printf ("/panels/panel-%d", g_slist_index (application->windows, window));
-      if (xfconf_channel_has_property (application->xfconf, property))
-        xfconf_channel_reset_property (application->xfconf, property, TRUE);
+      idx = g_slist_index (application->windows, window);
+      property = g_strdup_printf ("/panels/panel-%d", idx);
+      xfconf_channel_reset_property (application->xfconf, property, TRUE);
       g_free (property);
 
       /* set default position */
diff --git a/panel/panel-preferences-dialog.c b/panel/panel-preferences-dialog.c
index 47fa285..814364a 100644
--- a/panel/panel-preferences-dialog.c
+++ b/panel/panel-preferences-dialog.c
@@ -54,7 +54,7 @@ static void panel_preferences_dialog_panel_remove (GtkWidget *widget, PanelPrefe
 
 
 static XfcePanelPluginProvider *panel_preferences_dialog_item_get_selected (PanelPreferencesDialog *dialog, GtkTreeIter *return_iter);
-static void panel_preferences_dialog_item_store_rebuild (PanelPreferencesDialog *dialog);
+static void panel_preferences_dialog_item_store_rebuild (GtkWidget *itembar, PanelPreferencesDialog *dialog);
 static void panel_preferences_dialog_item_move (GtkWidget *button, PanelPreferencesDialog *dialog);
 static void panel_preferences_dialog_item_remove (GtkWidget *button, PanelPreferencesDialog *dialog);
 static void panel_preferences_dialog_item_add (GtkWidget *button, PanelPreferencesDialog *dialog);
@@ -354,15 +354,15 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox            *combobo
     {
       itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
       dialog->changed_handler_id =
-          g_signal_connect_swapped (G_OBJECT (itembar), "changed",
-                                    G_CALLBACK (panel_preferences_dialog_item_store_rebuild),
-                                    dialog);
+          g_signal_connect (G_OBJECT (itembar), "changed",
+                            G_CALLBACK (panel_preferences_dialog_item_store_rebuild),
+                            dialog);
 
       /* rebind the dialog bindings */
       panel_preferences_dialog_bindings_update (dialog);
 
       /* update the items treeview */
-      panel_preferences_dialog_item_store_rebuild (dialog);
+      panel_preferences_dialog_item_store_rebuild (itembar, dialog);
     }
 
   /* sensitivity of the add button in item tab */
@@ -518,21 +518,21 @@ panel_preferences_dialog_item_get_selected (PanelPreferencesDialog *dialog,
 
 
 static void
-panel_preferences_dialog_item_store_rebuild (PanelPreferencesDialog *dialog)
+panel_preferences_dialog_item_store_rebuild (GtkWidget              *itembar,
+                                             PanelPreferencesDialog *dialog)
 {
-  GtkWidget   *itembar;
   GList       *items, *li;
   guint        i;
   PanelModule *module;
 
   panel_return_if_fail (PANEL_IS_PREFERENCES_DIALOG (dialog));
   panel_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+  panel_return_if_fail (PANEL_IS_ITEMBAR (itembar));
 
   /* clear the store */
   gtk_list_store_clear (dialog->store);
 
   /* get the panel items */
-  itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
   items = gtk_container_get_children (GTK_CONTAINER (itembar));
 
   /* add items to the store */
diff --git a/panel/panel-window.c b/panel/panel-window.c
index 6190ff0..0adbc8d 100644
--- a/panel/panel-window.c
+++ b/panel/panel-window.c
@@ -550,7 +550,8 @@ panel_window_set_property (GObject      *object,
 
       case PROP_POSITION:
         val_string = g_value_get_string (value);
-        if (sscanf (val_string, "p=%d;x=%d;y=%d", &snap_position, &x, &y) == 3)
+        if (!exo_str_is_empty (val_string)
+            && sscanf (val_string, "p=%d;x=%d;y=%d", &snap_position, &x, &y) == 3)
           {
             window->snap_position = CLAMP (snap_position, SNAP_POSITION_NONE, SNAP_POSITION_S);
             window->base_x = x;



More information about the Xfce4-commits mailing list