[gnome-control-center/gbsneto/background] background: Remove dead code



commit 31ae96f54145bc1620b1a5de13bdef3d7608551f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat May 25 22:58:00 2019 -0300

    background: Remove dead code
    
    We do not download pictures anymore; the BgRecentSource
    always copies the wallpapers before actually adding them,
    and the BgWallpapersSource handles system-wide wallpapers,
    which typically do not change.
    
    Remove this dead code, and the unecessary widgets that were
    kept to keep this code working -- essentially, a few boxes
    around the previewes.

 panels/background/cc-background-panel.c  | 160 +++----------------------------
 panels/background/cc-background-panel.ui |  30 +-----
 2 files changed, 14 insertions(+), 176 deletions(-)
---
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index ab62fdcf6..821edc3ef 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -63,7 +63,6 @@ struct _CcBackgroundPanel
 
   CcBackgroundChooser *background_chooser;
   GtkWidget *add_picture_button;
-  GtkWidget *bottom_hbox;
   CcBackgroundPreview *desktop_preview;
   CcBackgroundPreview *lock_screen_preview;
 
@@ -136,14 +135,8 @@ reload_current_bg (CcBackgroundPanel *panel,
   /* initalise the current background information from settings */
   uri = g_settings_get_string (settings, WP_URI_KEY);
   if (uri && *uri == '\0')
-    {
-      g_clear_pointer (&uri, g_free);
-    }
-  else
-    {
-      g_autoptr(GFile) file = NULL;
-      file = g_file_new_for_commandline_arg (uri);
-    }
+    g_clear_pointer (&uri, g_free);
+
   configured = cc_background_item_new (uri);
 
   pcolor = g_settings_get_string (settings, WP_PCOLOR_KEY);
@@ -201,61 +194,15 @@ create_save_dir (void)
   return TRUE;
 }
 
-static void
-copy_finished_cb (GObject      *source_object,
-                  GAsyncResult *result,
-                  gpointer      pointer)
-{
-  g_autoptr(CcBackgroundPanel) panel = (CcBackgroundPanel *) pointer;
-  g_autoptr(GError) err = NULL;
-  g_autofree gchar *filename = NULL;
-  CcBackgroundItem *item;
-  CcBackgroundItem *current_background;
-  GSettings *settings;
-
-  if (!g_file_copy_finish (G_FILE (source_object), result, &err))
-    {
-      if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-        return;
-      }
-      g_warning ("Failed to copy image to cache location: %s", err->message);
-    }
-  item = g_object_get_data (source_object, "item");
-  settings = g_object_get_data (source_object, "settings");
-  current_background = get_current_background (panel, settings);
-
-  g_settings_apply (settings);
-
-  /* the panel may have been destroyed before the callback is run, so be sure
-   * to check the widgets are not NULL */
-
-  if (panel->spinner)
-    {
-      gtk_widget_destroy (GTK_WIDGET (panel->spinner));
-      panel->spinner = NULL;
-    }
-
-  if (current_background)
-    cc_background_item_load (current_background, NULL);
-
-  update_preview (panel, settings, item);
-  current_background = get_current_background (panel, settings);
-
-  /* Save the source XML if there is one */
-  filename = get_save_path (panel, settings);
-  if (create_save_dir ())
-    cc_background_xml_save (current_background, filename);
-}
-
 static void
 set_background (CcBackgroundPanel *panel,
                 GSettings         *settings,
                 CcBackgroundItem  *item)
 {
   GDesktopBackgroundStyle style;
-  gboolean save_settings = TRUE;
-  const char *uri;
   CcBackgroundItemFlags flags;
+  g_autofree gchar *filename = NULL;
+  const char *uri;
 
   if (item == NULL)
     return;
@@ -263,85 +210,7 @@ set_background (CcBackgroundPanel *panel,
   uri = cc_background_item_get_uri (item);
   flags = cc_background_item_get_flags (item);
 
-  if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL)
-    {
-      g_settings_set_enum (settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE);
-      g_settings_set_string (settings, WP_URI_KEY, "");
-    }
-  else if (cc_background_item_get_source_url (item) != NULL &&
-           cc_background_item_get_needs_download (item))
-    {
-      g_autoptr(GFile) source = NULL;
-      g_autoptr(GFile) dest = NULL;
-      g_autofree gchar *cache_path = NULL;
-      g_autofree gchar *basename = NULL;
-      g_autofree gchar *display_name = NULL;
-      g_autofree gchar *dest_path = NULL;
-      g_autofree gchar *dest_uri = NULL;
-      g_autoptr(GdkPixbuf) pixbuf = NULL;
-
-      cache_path = bg_pictures_source_get_cache_path ();
-      if (g_mkdir_with_parents (cache_path, USER_DIR_MODE) < 0)
-        {
-          g_warning ("Failed to create directory '%s'", cache_path);
-          return;
-        }
-
-      dest_path = bg_pictures_source_get_unique_path (cc_background_item_get_source_url (item));
-      dest = g_file_new_for_path (dest_path);
-      source = g_file_new_for_uri (cc_background_item_get_source_url (item));
-      basename = g_file_get_basename (source);
-      display_name = g_filename_display_name (basename);
-      dest_path = g_file_get_path (dest);
-
-      /* create a blank image to use until the source image is ready */
-      pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
-      gdk_pixbuf_fill (pixbuf, 0x00000000);
-      gdk_pixbuf_save (pixbuf, dest_path, "png", NULL, NULL);
-
-      if (panel->copy_cancellable)
-        {
-          g_cancellable_cancel (panel->copy_cancellable);
-          g_cancellable_reset (panel->copy_cancellable);
-        }
-
-      if (panel->spinner)
-        {
-          gtk_widget_destroy (GTK_WIDGET (panel->spinner));
-          panel->spinner = NULL;
-        }
-
-      /* create a spinner while the file downloads */
-      panel->spinner = gtk_spinner_new ();
-      gtk_spinner_start (GTK_SPINNER (panel->spinner));
-      gtk_box_pack_start (GTK_BOX (panel->bottom_hbox), panel->spinner, FALSE, FALSE, 6);
-      gtk_widget_show (panel->spinner);
-
-      /* reference the panel in case it is removed before the copy is
-       * finished */
-      g_object_ref (panel);
-      g_object_set_data_full (G_OBJECT (source), "item", g_object_ref (item), g_object_unref);
-      g_object_set_data (G_OBJECT (source), "settings", settings);
-      g_file_copy_async (source, dest, G_FILE_COPY_OVERWRITE,
-                         G_PRIORITY_DEFAULT, panel->copy_cancellable,
-                         NULL, NULL,
-                         copy_finished_cb, panel);
-      dest_uri = g_file_get_uri (dest);
-
-      g_settings_set_string (settings, WP_URI_KEY, dest_uri);
-      g_object_set (G_OBJECT (item),
-                    "uri", dest_uri,
-                    "needs-download", FALSE,
-                    "name", display_name,
-                    NULL);
-
-      /* delay the updated drawing of the preview until the copy finishes */
-      save_settings = FALSE;
-    }
-  else
-    {
-      g_settings_set_string (settings, WP_URI_KEY, uri);
-    }
+  g_settings_set_string (settings, WP_URI_KEY, uri);
 
   /* Also set the placement if we have a URI and the previous value was none */
   if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT)
@@ -361,19 +230,13 @@ set_background (CcBackgroundPanel *panel,
   g_settings_set_string (settings, WP_PCOLOR_KEY, cc_background_item_get_pcolor (item));
   g_settings_set_string (settings, WP_SCOLOR_KEY, cc_background_item_get_scolor (item));
 
-  /* update the preview information */
-  if (save_settings != FALSE)
-    {
-      g_autofree gchar *filename = NULL;
-
-      /* Apply all changes */
-      g_settings_apply (settings);
+  /* Apply all changes */
+  g_settings_apply (settings);
 
-      /* Save the source XML if there is one */
-      filename = get_save_path (panel, settings);
-      if (create_save_dir ())
-        cc_background_xml_save (get_current_background (panel, settings), filename);
-    }
+  /* Save the source XML if there is one */
+  filename = get_save_path (panel, settings);
+  if (create_save_dir ())
+    cc_background_xml_save (get_current_background (panel, settings), filename);
 }
 
 
@@ -467,7 +330,6 @@ cc_background_panel_class_init (CcBackgroundPanelClass *klass)
 
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPanel, add_picture_button);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPanel, background_chooser);
-  gtk_widget_class_bind_template_child (widget_class, CcBackgroundPanel, bottom_hbox);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPanel, desktop_preview);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPanel, lock_screen_preview);
 
diff --git a/panels/background/cc-background-panel.ui b/panels/background/cc-background-panel.ui
index 066d3874a..25cc62ea5 100644
--- a/panels/background/cc-background-panel.ui
+++ b/panels/background/cc-background-panel.ui
@@ -18,43 +18,19 @@
             <property name="margin">32</property>
             <property name="halign">center</property>
             <child>
-              <object class="GtkBox" id="vbox3">
+              <object class="CcBackgroundPreview" id="desktop_preview">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="CcBackgroundPreview" id="desktop_preview">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="valign">center</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkBox" id="bottom_hbox">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="spacing">12</property>
-                  </object>
-                </child>
               </object>
             </child>
             <child>
-              <object class="GtkBox">
+              <object class="CcBackgroundPreview" id="lock_screen_preview">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="orientation">vertical</property>
-                <property name="halign">start</property>
+                <property name="is-lock-screen">True</property>
                 <property name="valign">center</property>
-                <child>
-                  <object class="CcBackgroundPreview" id="lock_screen_preview">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="is-lock-screen">True</property>
-                    <property name="valign">center</property>
-                  </object>
-                </child>
               </object>
             </child>
           </object>


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