[nautilus] files-view: Drop non-portal wallpaper setting code



commit 6af38c29d23deb6be571f560cc33740f6ac6348c
Author: António Fernandes <antoniojpfernandes gmail com>
Date:   Sat May 21 15:54:51 2022 +0000

    files-view: Drop non-portal wallpaper setting code
    
    When the Wallpaper portal is not available, the "Set as Wallpaper" action falls back into the old 
implementation.
    
    This fallback offers a subpar user experience:
    
      - there is no preview: the user might find a weirdly resized image at the desktop at a later moment;
      - there may be interruptions by file conflict dialogs, if setting a picture which had already been set 
this way in the past;
      - it's often out of sync with other implementations (a recent example being the new dark mode 
wallpaper); this is also aggravates the maintenance burden.
    
    This old implementation "Set as Wallpaper" action has been originally introduced in a time when portals 
didn't exist yet and the Settings background panel did not provide the ability to pick a file to set as 
wallpaper. The action in the Files app was, therefore, essential.
    
    Nowadays, the Settings Appearance panel provides a button to pick any picture file, so this action is no 
longer essential. As such, we can just drop the old implementation and hide the action if libportal is not 
available.
    
    Closes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1677

 src/nautilus-files-view.c         | 114 ++------------------------------------
 src/nautilus-global-preferences.c |   2 -
 src/nautilus-global-preferences.h |   1 -
 3 files changed, 5 insertions(+), 112 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 1d491c2e4..ef30c9139 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -349,8 +349,6 @@ static void     set_search_query_internal (NautilusFilesView *files_view,
                                            NautilusDirectory *base_model);
 
 static gboolean nautilus_files_view_is_read_only (NautilusFilesView *view);
-static void     set_wallpaper_fallback (NautilusFile *file,
-                                        gpointer      user_data);
 
 G_DEFINE_TYPE_WITH_CODE (NautilusFilesView,
                          nautilus_files_view,
@@ -6530,60 +6528,14 @@ action_run_in_terminal (GSimpleAction *action,
     g_chdir (old_working_dir);
 }
 
-#define BG_KEY_PRIMARY_COLOR      "primary-color"
-#define BG_KEY_SECONDARY_COLOR    "secondary-color"
-#define BG_KEY_COLOR_TYPE         "color-shading-type"
-#define BG_KEY_PICTURE_PLACEMENT  "picture-options"
-#define BG_KEY_PICTURE_URI        "picture-uri"
-
-static void
-set_uri_as_wallpaper (const char *uri)
-{
-    GSettings *settings;
-
-    settings = gnome_background_preferences;
-
-    g_settings_delay (settings);
-
-    if (uri == NULL)
-    {
-        uri = "";
-    }
-
-    g_settings_set_string (settings, BG_KEY_PICTURE_URI, uri);
-    g_settings_set_string (settings, BG_KEY_PRIMARY_COLOR, "#000000");
-    g_settings_set_string (settings, BG_KEY_SECONDARY_COLOR, "#000000");
-    g_settings_set_enum (settings, BG_KEY_COLOR_TYPE, G_DESKTOP_BACKGROUND_SHADING_SOLID);
-    g_settings_set_enum (settings, BG_KEY_PICTURE_PLACEMENT, G_DESKTOP_BACKGROUND_STYLE_ZOOM);
-
-    /* Apply changes atomically. */
-    g_settings_apply (settings);
-}
-
-static void
-wallpaper_copy_done_callback (GHashTable *debuting_files,
-                              gboolean    success,
-                              gpointer    data)
-{
-    GHashTableIter iter;
-    gpointer key, value;
-
-    g_hash_table_iter_init (&iter, debuting_files);
-    while (g_hash_table_iter_next (&iter, &key, &value))
-    {
-        char *uri;
-        uri = g_file_get_uri (G_FILE (key));
-        set_uri_as_wallpaper (uri);
-        g_free (uri);
-        break;
-    }
-}
-
 static gboolean
 can_set_wallpaper (GList *selection)
 {
     NautilusFile *file;
 
+#ifndef HAVE_LIBPORTAL
+    return FALSE;
+#else
     if (g_list_length (selection) != 1)
     {
         return FALSE;
@@ -6598,15 +6550,10 @@ can_set_wallpaper (GList *selection)
     /* FIXME: check file size? */
 
     return TRUE;
+#endif
 }
 
 #ifdef HAVE_LIBPORTAL
-typedef struct
-{
-    NautilusFile *file;
-    NautilusFilesView *view;
-} WallpaperData;
-
 static void
 set_wallpaper_with_portal_cb (GObject      *source,
                               GAsyncResult *result,
@@ -6614,18 +6561,12 @@ set_wallpaper_with_portal_cb (GObject      *source,
 {
     XdpPortal *portal = XDP_PORTAL (source);
     g_autoptr (GError) error = NULL;
-    WallpaperData *data = user_data;
 
     if (!xdp_portal_set_wallpaper_finish (portal, result, &error)
         && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
     {
         g_warning ("Failed to set wallpaper via portal: %s", error->message);
-        set_wallpaper_fallback (data->file, data->view);
     }
-
-    nautilus_file_unref (data->file);
-    g_object_unref (data->view);
-    g_free (data);
 }
 
 static void
@@ -6636,11 +6577,6 @@ set_wallpaper_with_portal (NautilusFile *file,
     g_autofree gchar *uri = NULL;
     XdpParent *parent = NULL;
     GtkWidget *toplevel;
-    WallpaperData *data;
-
-    data = g_new0 (WallpaperData, 1);
-    data->file = nautilus_file_ref (file);
-    data->view = g_object_ref (user_data);
 
     portal = xdp_portal_new ();
     toplevel = gtk_widget_get_ancestor (GTK_WIDGET (user_data), GTK_TYPE_WINDOW);
@@ -6653,49 +6589,11 @@ set_wallpaper_with_portal (NautilusFile *file,
                               XDP_WALLPAPER_FLAG_BACKGROUND | XDP_WALLPAPER_FLAG_PREVIEW,
                               NULL,
                               set_wallpaper_with_portal_cb,
-                              data);
+                              NULL);
     xdp_parent_free (parent);
 }
 #endif /* HAVE_LIBPORTAL */
 
-static void
-set_wallpaper_fallback (NautilusFile *file,
-                        gpointer      user_data)
-{
-    g_autoptr (GFile) target = NULL;
-    g_autofree char *file_uri = NULL;
-    g_autoptr (GFile) file_parent = NULL;
-
-    /* Copy the item to Pictures/Wallpaper (internationalized),
-     * if it's not already there, since it may be remote.
-     * Then set it as the current wallpaper. */
-    target = g_file_new_build_filename (g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
-                                        _("Wallpapers"),
-                                        NULL);
-    g_file_make_directory_with_parents (target, NULL, NULL);
-
-    file_parent = nautilus_file_get_parent_location (file);
-    file_uri = nautilus_file_get_uri (file);
-
-    if (!g_file_equal (file_parent, target))
-    {
-        g_autofree char *target_uri = g_file_get_uri (target);
-        g_autoptr (GList) uris = g_list_prepend (NULL, file_uri);
-
-        nautilus_file_operations_copy_move (uris,
-                                            target_uri,
-                                            GDK_ACTION_COPY,
-                                            GTK_WIDGET (user_data),
-                                            NULL,
-                                            wallpaper_copy_done_callback,
-                                            NULL);
-    }
-    else
-    {
-        set_uri_as_wallpaper (file_uri);
-    }
-}
-
 static void
 action_set_as_wallpaper (GSimpleAction *action,
                          GVariant      *state,
@@ -6714,8 +6612,6 @@ action_set_as_wallpaper (GSimpleAction *action,
 
 #ifdef HAVE_LIBPORTAL
         set_wallpaper_with_portal (file, user_data);
-#else
-        set_wallpaper_fallback (file, user_data);
 #endif
     }
 }
diff --git a/src/nautilus-global-preferences.c b/src/nautilus-global-preferences.c
index 6b3a82bf1..fd6d53e08 100644
--- a/src/nautilus-global-preferences.c
+++ b/src/nautilus-global-preferences.c
@@ -38,7 +38,6 @@ GSettings *nautilus_list_view_preferences;
 GSettings *nautilus_window_state;
 GSettings *gtk_filechooser_preferences;
 GSettings *gnome_lockdown_preferences;
-GSettings *gnome_background_preferences;
 GSettings *gnome_interface_preferences;
 GSettings *gnome_privacy_preferences;
 
@@ -63,7 +62,6 @@ nautilus_global_preferences_init (void)
     gtk_filechooser_preferences = g_settings_new_with_path ("org.gtk.Settings.FileChooser",
                                                             "/org/gtk/settings/file-chooser/");
     gnome_lockdown_preferences = g_settings_new ("org.gnome.desktop.lockdown");
-    gnome_background_preferences = g_settings_new ("org.gnome.desktop.background");
     gnome_interface_preferences = g_settings_new ("org.gnome.desktop.interface");
     gnome_privacy_preferences = g_settings_new ("org.gnome.desktop.privacy");
 }
diff --git a/src/nautilus-global-preferences.h b/src/nautilus-global-preferences.h
index e7b158001..c5a7b6b5c 100644
--- a/src/nautilus-global-preferences.h
+++ b/src/nautilus-global-preferences.h
@@ -144,7 +144,6 @@ extern GSettings *nautilus_list_view_preferences;
 extern GSettings *nautilus_window_state;
 extern GSettings *gtk_filechooser_preferences;
 extern GSettings *gnome_lockdown_preferences;
-extern GSettings *gnome_background_preferences;
 extern GSettings *gnome_interface_preferences;
 extern GSettings *gnome_privacy_preferences;
 


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