From 074f55e344c4d36fad52acadf344dae9cd7bda75 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Mon, 19 Aug 2013 19:00:48 +0000
Subject: background: Add support for lock screen background

https://bugzilla.gnome.org/show_bug.cgi?id=696166
---
--- a/panels/background/background.ui
+++ b/panels/background/background.ui
@@ -4,115 +4,286 @@
   <object class="GtkHBox" id="background-panel">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
+    <property name="margin_left">6</property>
+    <property name="margin_right">6</property>
+    <property name="margin_top">6</property>
+    <property name="margin_bottom">6</property>
     <property name="border_width">10</property>
     <property name="spacing">12</property>
-    <property name="margin-left">6</property>
-    <property name="margin-right">6</property>
-    <property name="margin-top">6</property>
-    <property name="margin-bottom">6</property>
     <child>
-      <object class="GtkVBox" id="vbox3">
+      <object class="GtkBox" id="box1">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="spacing">6</property>
+        <property name="margin_top">100</property>
+        <property name="margin_bottom">100</property>
         <child>
-          <object class="GtkAspectFrame" id="aspectframe1">
+          <object class="GtkVBox" id="vbox3">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="margin_left">12</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">none</property>
             <child>
-              <object class="GtkButton" id="background-set-button">
-                <property name="use_action_appearance">False</property>
+              <object class="GtkAspectFrame" id="aspectframe1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="valign">center</property>
+                <property name="can_focus">False</property>
+                <property name="margin_right">12</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
                 <child>
-                  <object class="GtkDrawingArea" id="background-desktop-drawingarea">
-                    <property name="width_request">417</property>
-                    <property name="height_request">250</property>
+                  <object class="GtkButton" id="background-set-button">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
                     <property name="valign">center</property>
-                    <property name="margin_left">6</property>
-                    <property name="margin_right">6</property>
-                    <property name="margin_top">6</property>
-                    <property name="margin_bottom">6</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
+                    <child>
+                      <object class="GtkBox" id="box2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                          <object class="GtkDrawingArea" id="background-desktop-drawingarea">
+                            <property name="width_request">310</property>
+                            <property name="height_request">170</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="valign">center</property>
+                            <property name="margin_left">6</property>
+                            <property name="margin_right">6</property>
+                            <property name="margin_top">6</property>
+                            <property name="margin_bottom">6</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Background</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
             </child>
-          </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkHBox" id="bottom-hbox">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="spacing">12</property>
             <child>
-              <object class="GtkHBox" id="hbox2">
+              <object class="GtkHBox" id="bottom-hbox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="halign">center</property>
-                <property name="spacing">2</property>
+                <property name="spacing">12</property>
                 <child>
-                  <object class="GtkImage" id="slide_image">
+                  <object class="GtkHBox" id="hbox2">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="icon_name">slideshow-symbolic</property>
+                    <property name="halign">center</property>
+                    <property name="margin_top">12</property>
+                    <property name="spacing">2</property>
+                    <child>
+                      <object class="GtkImage" id="slide_image">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">slideshow-symbolic</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="strut">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label"> </property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="slide-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes" comments="This refers to a slideshow background">Changes throughout the day</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
+                    <property name="expand">True</property>
                     <property name="fill">True</property>
                     <property name="position">0</property>
                   </packing>
                 </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkAspectFrame" id="aspectframe2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_left">12</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
                 <child>
-                  <object class="GtkLabel" id="strut">
+                  <object class="GtkButton" id="background-lock-set-button">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label"> </property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="valign">center</property>
+                    <child>
+                      <object class="GtkBox" id="box3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                          <object class="GtkDrawingArea" id="background-lock-drawingarea">
+                            <property name="width_request">310</property>
+                            <property name="height_request">170</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="valign">center</property>
+                            <property name="margin_left">6</property>
+                            <property name="margin_right">6</property>
+                            <property name="margin_top">6</property>
+                            <property name="margin_bottom">6</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Lock Screen</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHBox" id="bottom-hbox1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="spacing">12</property>
                 <child>
-                  <object class="GtkLabel" id="slide-label">
+                  <object class="GtkHBox" id="hbox1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes" comments="This refers to a slideshow background">Changes throughout the day</property>
+                    <property name="halign">center</property>
+                    <property name="margin_top">12</property>
+                    <property name="spacing">2</property>
+                    <child>
+                      <object class="GtkImage" id="slide_image1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">slideshow-symbolic</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="strut1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label"> </property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="slide-label1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes" comments="This refers to a slideshow background">Changes throughout the day</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
+                    <property name="expand">True</property>
                     <property name="fill">True</property>
-                    <property name="position">1</property>
+                    <property name="position">0</property>
                   </packing>
                 </child>
               </object>
               <packing>
-                <property name="expand">True</property>
+                <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">0</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
             <property name="fill">True</property>
-            <property name="position">2</property>
+            <property name="position">1</property>
           </packing>
         </child>
       </object>
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -38,6 +38,7 @@
 #include "bg-pictures-source.h"
 
 #define WP_PATH_ID "org.gnome.desktop.background"
+#define WP_LOCK_PATH_ID "org.gnome.desktop.screensaver"
 #define WP_URI_KEY "picture-uri"
 #define WP_OPTIONS_KEY "picture-options"
 #define WP_SHADING_KEY "color-shading-type"
@@ -55,10 +56,12 @@
   GDBusConnection *connection;
 
   GSettings *settings;
+  GSettings *lock_settings;
 
   GnomeDesktopThumbnailFactory *thumb_factory;
 
   CcBackgroundItem *current_background;
+  CcBackgroundItem *current_lock_background;
 
   GCancellable *copy_cancellable;
   GCancellable *capture_cancellable;
@@ -70,6 +73,8 @@
 };
 
 #define WID(y) (GtkWidget *) gtk_builder_get_object (priv->builder, y)
+#define CURRENT_BG (settings == priv->settings ? priv->current_background : priv->current_lock_background)
+#define SAVE_PATH (settings == priv->settings ? "last-edited.xml" : "last-edited-lock.xml")
 
 static const char *
 cc_background_panel_get_help_uri (CcPanel *panel)
@@ -88,6 +93,7 @@
   priv->spinner = NULL;
 
   g_clear_object (&priv->settings);
+  g_clear_object (&priv->lock_settings);
 
   if (priv->copy_cancellable)
     {
@@ -124,6 +130,7 @@
   CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
 
   g_clear_object (&priv->current_background);
+  g_clear_object (&priv->current_lock_background);
 
   G_OBJECT_CLASS (cc_background_panel_parent_class)->finalize (object);
 }
@@ -144,59 +151,77 @@
 
 static void
 update_preview (CcBackgroundPanelPrivate *priv,
+                GSettings                *settings,
                 CcBackgroundItem         *item)
 {
   gboolean changes_with_time;
+  CcBackgroundItem *current_background;
+
+  current_background = CURRENT_BG;
 
-  if (item && priv->current_background)
+  if (item && current_background)
     {
-      g_object_unref (priv->current_background);
-      priv->current_background = cc_background_item_copy (item);
-      cc_background_item_load (priv->current_background, NULL);
+      g_object_unref (current_background);
+      current_background = cc_background_item_copy (item);
+      if (settings == priv->settings)
+        priv->current_background = current_background;
+      else
+        priv->current_lock_background = current_background;
+      cc_background_item_load (current_background, NULL);
     }
 
   changes_with_time = FALSE;
 
-  if (priv->current_background)
+  if (current_background)
     {
-      changes_with_time = cc_background_item_changes_with_time (priv->current_background);
+      changes_with_time = cc_background_item_changes_with_time (current_background);
     }
 
-  gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
-  gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
+  if (settings == priv->settings)
+    {
+      gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
+      gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
+
+      gtk_widget_queue_draw (WID ("background-desktop-drawingarea"));
+    }
+  else
+    {
+      gtk_widget_set_visible (WID ("slide_image1"), changes_with_time);
+      gtk_widget_set_visible (WID ("slide-label1"), changes_with_time);
 
-  gtk_widget_queue_draw (WID ("background-desktop-drawingarea"));
+      gtk_widget_queue_draw (WID ("background-lock-drawingarea"));
+    }
 }
 
 static char *
-get_save_path (void)
+get_save_path (const char *filename)
 {
   return g_build_filename (g_get_user_config_dir (),
                            "gnome-control-center",
                            "backgrounds",
-                           "last-edited.xml",
+                           filename,
                            NULL);
 }
 
 static void
-update_display_preview (CcBackgroundPanel *panel)
+update_display_preview (CcBackgroundPanel *panel,
+                        GtkWidget         *widget,
+                        CcBackgroundItem  *current_background)
 {
   CcBackgroundPanelPrivate *priv = panel->priv;
-  GtkWidget *widget;
   GtkAllocation allocation;
-  const gint preview_width = 416;
-  const gint preview_height = 248;
+  const gint preview_width = 309;
+  const gint preview_height = 168;
   GdkPixbuf *pixbuf;
   GIcon *icon;
   cairo_t *cr;
 
-  widget = WID ("background-desktop-drawingarea");
   gtk_widget_get_allocation (widget, &allocation);
 
-  if (!priv->current_background)
+  if (!current_background)
     return;
 
-  icon = cc_background_item_get_frame_thumbnail (priv->current_background,
+  icon = cc_background_item_get_frame_thumbnail (current_background,
                                                  priv->thumb_factory,
                                                  preview_width,
                                                  preview_height,
@@ -211,11 +236,14 @@
   g_object_unref (pixbuf);
 
   pixbuf = NULL;
-  if (panel->priv->display_screenshot != NULL)
-    pixbuf = gdk_pixbuf_scale_simple (panel->priv->display_screenshot,
-                                      preview_width,
-                                      preview_height,
-                                      GDK_INTERP_BILINEAR);
+  if (current_background == priv->current_background &&
+      panel->priv->display_screenshot != NULL)
+    {
+      pixbuf = gdk_pixbuf_scale_simple (panel->priv->display_screenshot,
+                                        preview_width,
+                                        preview_height,
+                                        GDK_INTERP_BILINEAR);
+    }
 
   if (pixbuf)
     {
@@ -260,6 +288,7 @@
              error->message);
     g_error_free (error);
     /* fallback? */
+    priv = panel->priv;
     goto out;
   }
 
@@ -307,7 +336,7 @@
   cairo_surface_destroy (surface);
 
  out:
-  update_display_preview (panel);
+  update_display_preview (panel, WID ("background-desktop-drawingarea"), priv->current_background);
 }
 
 static void
@@ -356,6 +385,7 @@
                  cairo_t           *cr,
                  CcBackgroundPanel *panel)
 {
+  CcBackgroundPanelPrivate *priv = panel->priv;
   /* we have another shot in flight or an existing cache */
   if (panel->priv->display_screenshot == NULL
       && panel->priv->screenshot_path == NULL)
@@ -368,13 +398,24 @@
       get_screenshot_async (panel, &rect);
     }
   else
-    update_display_preview (panel);
+    update_display_preview (panel, widget, priv->current_background);
+
+  return TRUE;
+}
 
+static gboolean
+on_lock_preview_draw (GtkWidget         *widget,
+                      cairo_t           *cr,
+                      CcBackgroundPanel *panel)
+{
+  CcBackgroundPanelPrivate *priv = panel->priv;
+  update_display_preview (panel, widget, priv->current_lock_background);
   return TRUE;
 }
 
 static void
-reload_current_bg (CcBackgroundPanel *self)
+reload_current_bg (CcBackgroundPanel *self,
+                   GSettings         *settings)
 {
   CcBackgroundPanelPrivate *priv;
   CcBackgroundItem *saved, *configured;
@@ -383,12 +424,12 @@
   priv = self->priv;
 
   /* Load the saved configuration */
-  uri = get_save_path ();
+  uri = get_save_path (SAVE_PATH);
   saved = cc_background_xml_get_item (uri);
   g_free (uri);
 
   /* initalise the current background information from settings */
-  uri = g_settings_get_string (priv->settings, WP_URI_KEY);
+  uri = g_settings_get_string (settings, WP_URI_KEY);
   if (uri && *uri == '\0')
     {
       g_free (uri);
@@ -404,12 +445,12 @@
   configured = cc_background_item_new (uri);
   g_free (uri);
 
-  pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
-  scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
+  pcolor = g_settings_get_string (settings, WP_PCOLOR_KEY);
+  scolor = g_settings_get_string (settings, WP_SCOLOR_KEY);
   g_object_set (G_OBJECT (configured),
                 "name", _("Current background"),
-                "placement", g_settings_get_enum (priv->settings, WP_OPTIONS_KEY),
-                "shading", g_settings_get_enum (priv->settings, WP_SHADING_KEY),
+                "placement", g_settings_get_enum (settings, WP_OPTIONS_KEY),
+                "shading", g_settings_get_enum (settings, WP_SHADING_KEY),
                 "primary-color", pcolor,
                 "secondary-color", scolor,
                 NULL);
@@ -433,9 +474,17 @@
   if (saved != NULL)
     g_object_unref (saved);
 
-  g_clear_object (&priv->current_background);
-  priv->current_background = configured;
-  cc_background_item_load (priv->current_background, NULL);
+  if (settings == priv->settings)
+    {
+      g_clear_object (&priv->current_background);
+      priv->current_background = configured;
+    }
+  else
+    {
+      g_clear_object (&priv->current_lock_background);
+      priv->current_lock_background = configured;
+    }
+  cc_background_item_load (configured, NULL);
 }
 
 static gboolean
@@ -466,6 +515,8 @@
   CcBackgroundPanel *panel = (CcBackgroundPanel *) pointer;
   CcBackgroundPanelPrivate *priv = panel->priv;
   CcBackgroundItem *item;
+  CcBackgroundItem *current_background;
+  GSettings *settings;
 
   if (!g_file_copy_finish (G_FILE (source_object), result, &err))
     {
@@ -477,8 +528,10 @@
       g_error_free (err);
     }
   item = g_object_get_data (source_object, "item");
+  settings = g_object_get_data (source_object, "settings");
+  current_background = CURRENT_BG;
 
-  g_settings_apply (priv->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 */
@@ -489,19 +542,19 @@
       priv->spinner = NULL;
     }
 
-  if (priv->current_background)
-    cc_background_item_load (priv->current_background, NULL);
+  if (current_background)
+    cc_background_item_load (current_background, NULL);
 
   if (priv->builder)
     {
       char *filename;
 
-      update_preview (priv, item);
+      update_preview (priv, settings, item);
 
       /* Save the source XML if there is one */
-      filename = get_save_path ();
+      filename = get_save_path (SAVE_PATH);
       if (create_save_dir ())
-        cc_background_xml_save (priv->current_background, filename);
+        cc_background_xml_save (current_background, filename);
     }
 
   /* remove the reference taken when the copy was set up */
@@ -510,6 +563,7 @@
 
 static void
 set_background (CcBackgroundPanel *panel,
+                GSettings         *settings,
                 CcBackgroundItem  *item)
 {
   CcBackgroundPanelPrivate *priv = panel->priv;
@@ -527,8 +581,8 @@
 
   if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL)
     {
-      g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE);
-      g_settings_set_string (priv->settings, WP_URI_KEY, "");
+      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))
@@ -585,6 +639,7 @@
        * 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, priv->copy_cancellable,
                          NULL, NULL,
@@ -593,7 +648,7 @@
       dest_uri = g_file_get_uri (dest);
       g_object_unref (dest);
 
-      g_settings_set_string (priv->settings, WP_URI_KEY, dest_uri);
+      g_settings_set_string (settings, WP_URI_KEY, dest_uri);
       g_object_set (G_OBJECT (item),
                     "uri", dest_uri,
                     "needs-download", FALSE,
@@ -607,37 +662,37 @@
     }
   else
     {
-      g_settings_set_string (priv->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)
     {
-      g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
+      g_settings_set_enum (settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
     }
   else if (uri != NULL)
     {
-      style = g_settings_get_enum (priv->settings, WP_OPTIONS_KEY);
+      style = g_settings_get_enum (settings, WP_OPTIONS_KEY);
       if (style == G_DESKTOP_BACKGROUND_STYLE_NONE)
-        g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
+        g_settings_set_enum (settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
     }
 
   if (flags & CC_BACKGROUND_ITEM_HAS_SHADING)
-    g_settings_set_enum (priv->settings, WP_SHADING_KEY, cc_background_item_get_shading (item));
+    g_settings_set_enum (settings, WP_SHADING_KEY, cc_background_item_get_shading (item));
 
-  g_settings_set_string (priv->settings, WP_PCOLOR_KEY, cc_background_item_get_pcolor (item));
-  g_settings_set_string (priv->settings, WP_SCOLOR_KEY, cc_background_item_get_scolor (item));
+  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)
     {
       /* Apply all changes */
-      g_settings_apply (priv->settings);
+      g_settings_apply (settings);
 
       /* Save the source XML if there is one */
-      filename = get_save_path ();
+      filename = get_save_path (SAVE_PATH);
       if (create_save_dir ())
-        cc_background_xml_save (priv->current_background, filename);
+        cc_background_xml_save (CURRENT_BG, filename);
     }
 }
 
@@ -653,7 +708,7 @@
       item = cc_background_chooser_dialog_get_item (CC_BACKGROUND_CHOOSER_DIALOG (dialog));
       if (item != NULL)
         {
-          set_background (self, item);
+          set_background (self, g_object_get_data (G_OBJECT (dialog), "settings"), item);
           g_object_unref (item);
         }
     }
@@ -662,13 +717,14 @@
 }
 
 static void
-on_background_button_clicked (GtkButton         *button,
-                              CcBackgroundPanel *self)
+launch_chooser (CcBackgroundPanel *self,
+                GSettings         *settings)
 {
   CcBackgroundPanelPrivate *priv = self->priv;
   GtkWidget *dialog;
 
   dialog = cc_background_chooser_dialog_new ();
+  g_object_set_data (G_OBJECT (dialog), "settings", settings);
   gtk_window_set_transient_for (GTK_WINDOW (dialog),
                                 GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))));
   gtk_widget_show (dialog);
@@ -676,12 +732,26 @@
 }
 
 static void
+on_background_button_clicked (GtkButton         *button,
+                              CcBackgroundPanel *self)
+{
+  launch_chooser (self, self->priv->settings);
+}
+
+static void
+on_lock_button_clicked (GtkButton         *button,
+                        CcBackgroundPanel *self)
+{
+  launch_chooser (self, self->priv->lock_settings);
+}
+
+static void
 on_settings_changed (GSettings         *settings,
                      gchar             *key,
                      CcBackgroundPanel *self)
 {
-  reload_current_bg (self);
-  update_preview (self->priv, NULL);
+  reload_current_bg (self, settings);
+  update_preview (self->priv, settings, NULL);
 }
 
 static void
@@ -711,6 +781,9 @@
   priv->settings = g_settings_new (WP_PATH_ID);
   g_settings_delay (priv->settings);
 
+  priv->lock_settings = g_settings_new (WP_LOCK_PATH_ID);
+  g_settings_delay (priv->lock_settings);
+
   /* add the top level widget */
   widget = WID ("background-panel");
 
@@ -719,21 +792,30 @@
 
   /* setup preview area */
   widget = WID ("background-desktop-drawingarea");
-  g_signal_connect (widget, "draw", G_CALLBACK (on_preview_draw),
-                    self);
+  g_signal_connect (widget, "draw", G_CALLBACK (on_preview_draw), self);
+  widget = WID ("background-lock-drawingarea");
+  g_signal_connect (widget, "draw", G_CALLBACK (on_lock_preview_draw), self);
 
   priv->copy_cancellable = g_cancellable_new ();
   priv->capture_cancellable = g_cancellable_new ();
 
   priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
 
-  reload_current_bg (self);
-  update_preview (priv, NULL);
+  /* Load the backgrounds */
+  reload_current_bg (self, priv->settings);
+  update_preview (priv, priv->settings, NULL);
+  reload_current_bg (self, priv->lock_settings);
+  update_preview (priv, priv->lock_settings, NULL);
 
+  /* Background settings */
   g_signal_connect (priv->settings, "changed", G_CALLBACK (on_settings_changed), self);
+  g_signal_connect (priv->lock_settings, "changed", G_CALLBACK (on_settings_changed), self);
 
+  /* Background buttons */
   widget = WID ("background-set-button");
   g_signal_connect (widget, "clicked", G_CALLBACK (on_background_button_clicked), self);
+  widget = WID ("background-lock-set-button");
+  g_signal_connect (widget, "clicked", G_CALLBACK (on_lock_button_clicked), self);
 }
 
 void
