[Xfce4-commits] <xfce4-settings:master> Only update the mime type if is differs from the default.

Nick Schermer noreply at xfce.org
Sat Jan 21 22:16:07 CET 2012


Updating branch refs/heads/master
         to 6c9c62b4aff94d74928a2f12bdb744c52cc11b0a (commit)
       from d1b0b934f8352430a7df97d676bb31fecaa958ff (commit)

commit 6c9c62b4aff94d74928a2f12bdb744c52cc11b0a
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Jan 21 17:51:57 2012 +0100

    Only update the mime type if is differs from the default.
    
    Also drop resizing for the status column, width doesn't matter here.

 dialogs/mime-settings/xfce-mime-window.c |   55 +++++++++++++++++++-----------
 1 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/dialogs/mime-settings/xfce-mime-window.c b/dialogs/mime-settings/xfce-mime-window.c
index c6a550f..bc44d00 100644
--- a/dialogs/mime-settings/xfce-mime-window.c
+++ b/dialogs/mime-settings/xfce-mime-window.c
@@ -233,7 +233,6 @@ xfce_mime_window_init (XfceMimeWindow *window)
     column = gtk_tree_view_column_new ();
     gtk_tree_view_column_set_title (column, _("Status"));
     gtk_tree_view_column_set_clickable (column, TRUE);
-    gtk_tree_view_column_set_resizable (column, TRUE);
     g_signal_connect (G_OBJECT (column), "clicked",
         G_CALLBACK (xfce_mime_window_column_clicked), window);
     gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
@@ -583,6 +582,7 @@ xfce_mime_window_chooser_response (GtkWidget       *chooser,
     GAppInfo    *app_info;
     GtkTreeIter  iter;
     GError      *error = NULL;
+    GAppInfo    *app_default;
 
     gtk_widget_hide (chooser);
 
@@ -592,7 +592,10 @@ xfce_mime_window_chooser_response (GtkWidget       *chooser,
             return;
 
         app_info = xfce_mime_chooser_get_app_info (XFCE_MIME_CHOOSER (chooser));
-        if (G_LIKELY (app_info != NULL))
+        app_default = g_app_info_get_default_for_type (data->mime_type, FALSE);
+
+        if (app_info != NULL
+            && (app_default == NULL || !g_app_info_equal (app_default, app_info)))
         {
             if (g_app_info_set_as_default_for_type (app_info, data->mime_type, &error))
             {
@@ -609,9 +612,12 @@ xfce_mime_window_chooser_response (GtkWidget       *chooser,
                     g_app_info_get_name (app_info), data->mime_type);
                 g_error_free (error);
             }
-
-            g_object_unref (G_OBJECT (app_info));
         }
+
+        if (app_info != NULL)
+          g_object_unref (G_OBJECT (app_info));
+        if (app_default != NULL)
+          g_object_unref (G_OBJECT (app_default));
     }
 
     xfce_mime_window_combo_unref_data (data);
@@ -673,8 +679,9 @@ xfce_mime_window_combo_changed (GtkWidget       *combo,
     GAppInfo       *app_info;
     GError         *error = NULL;
     GtkTreeIter     mime_iter;
-    GtkWidget *dialog;
-    gchar *primary;
+    GtkWidget      *dialog;
+    gchar          *primary;
+    GAppInfo       *app_default;
 
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
     if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
@@ -687,25 +694,33 @@ xfce_mime_window_combo_changed (GtkWidget       *combo,
     if (type == APP_TYPE_APP
         && app_info != NULL)
     {
-        if (g_app_info_set_as_default_for_type (app_info, data->mime_type, &error))
+        /* only change if it differs from the default */
+        app_default = g_app_info_get_default_for_type (data->mime_type, FALSE);
+        if (app_default == NULL || !g_app_info_equal (app_default, app_info))
         {
-            if (gtk_tree_model_get_iter (window->mime_model, &mime_iter, data->path))
+            /* set the new mime handler */
+            if (g_app_info_set_as_default_for_type (app_info, data->mime_type, &error))
             {
-                gtk_list_store_set (GTK_LIST_STORE (window->mime_model), &mime_iter,
-                                    COLUMN_MIME_DEFAULT, g_app_info_get_name (app_info),
-                                    COLUMN_MIME_STATUS, _("User Set"),
-                                    COLUMN_MIME_ATTRS, window->attrs_bold,
-                                    -1);
+                if (gtk_tree_model_get_iter (window->mime_model, &mime_iter, data->path))
+                {
+                    gtk_list_store_set (GTK_LIST_STORE (window->mime_model), &mime_iter,
+                                        COLUMN_MIME_DEFAULT, g_app_info_get_name (app_info),
+                                        COLUMN_MIME_STATUS, _("User Set"),
+                                        COLUMN_MIME_ATTRS, window->attrs_bold,
+                                        -1);
+                }
+            }
+            else
+            {
+                xfce_dialog_show_error (GTK_WINDOW (window), error,
+                    _("Failed to set application \"%s\" for mime type \"%s\"."),
+                    g_app_info_get_name (app_info), data->mime_type);
+                g_error_free (error);
             }
-        }
-        else
-        {
-            xfce_dialog_show_error (GTK_WINDOW (window), error,
-                _("Failed to set application \"%s\" for mime type \"%s\"."),
-                g_app_info_get_name (app_info), data->mime_type);
-            g_error_free (error);
         }
 
+        if (app_default != NULL)
+            g_object_unref (app_default);
         g_object_unref (app_info);
     }
     else if (type == APP_TYPE_CHOOSER)


More information about the Xfce4-commits mailing list