Commit 2fca14c9 authored by Daniel Landau's avatar Daniel Landau Committed by Jim Nelson

Allow setting background on lock screen: Bug #724755

Add checkboxes to the slideshow dialog to select whether to set the
desktop background, the lock screen, or both. Add the same checkboxes to
a new dialog for setting a background photo.
parent 8a55f071
......@@ -701,17 +701,21 @@ public abstract class CollectionPage : MediaPage {
MediaSourceCollection.filter_media((Gee.Collection<MediaSource>) get_view().get_selected_sources(),
photos, null);
bool desktop, screensaver;
if (photos.size == 1) {
AppWindow.get_instance().set_busy_cursor();
DesktopIntegration.set_background(photos[0]);
AppWindow.get_instance().set_normal_cursor();
SetBackgroundPhotoDialog dialog = new SetBackgroundPhotoDialog();
if (dialog.execute(out desktop, out screensaver)) {
AppWindow.get_instance().set_busy_cursor();
DesktopIntegration.set_background(photos[0], desktop, screensaver);
AppWindow.get_instance().set_normal_cursor();
}
} else if (photos.size > 1) {
SetBackgroundSlideshowDialog dialog = new SetBackgroundSlideshowDialog();
int delay;
if (dialog.execute(out delay)) {
if (dialog.execute(out delay, out desktop, out screensaver)) {
AppWindow.get_instance().set_busy_cursor();
DesktopIntegration.set_background_slideshow(photos, delay,
DESKTOP_SLIDESHOW_TRANSITION_SEC);
DESKTOP_SLIDESHOW_TRANSITION_SEC, desktop, screensaver);
AppWindow.get_instance().set_normal_cursor();
}
}
......
......@@ -16,6 +16,9 @@ private ExporterUI desktop_slideshow_exporter = null;
private double desktop_slideshow_transition = 0.0;
private double desktop_slideshow_duration = 0.0;
private bool set_desktop_background = false;
private bool set_screensaver = false;
public void init() {
if (init_count++ != 0)
return;
......@@ -152,7 +155,7 @@ private void on_send_to_export_completed(Exporter exporter, bool is_cancelled) {
send_to_exporter = null;
}
public void set_background(Photo photo) {
public void set_background(Photo photo, bool desktop, bool screensaver) {
// attempt to set the wallpaper to the photo's native format, but if not writeable, go to the
// system default
PhotoFileFormat file_format = photo.get_best_export_file_format();
......@@ -174,7 +177,12 @@ public void set_background(Photo photo) {
return;
}
Config.Facade.get_instance().set_desktop_background(save_as.get_path());
if (desktop) {
Config.Facade.get_instance().set_desktop_background(save_as.get_path());
}
if (screensaver) {
Config.Facade.get_instance().set_screensaver(save_as.get_path());
}
GLib.FileUtils.chmod(save_as.get_parse_name(), 0644);
}
......@@ -254,10 +262,14 @@ private class BackgroundSlideshowXMLBuilder {
}
}
public void set_background_slideshow(Gee.Collection<Photo> photos, double duration, double transition) {
public void set_background_slideshow(Gee.Collection<Photo> photos, double duration, double transition,
bool desktop_background, bool screensaver) {
if (desktop_slideshow_exporter != null)
return;
set_desktop_background = desktop_background;
set_screensaver = screensaver;
File wallpaper_dir = AppDirs.get_data_subdir("wallpaper");
Gee.Set<string> exceptions = new Gee.HashSet<string>();
......@@ -302,7 +314,12 @@ private void on_desktop_slideshow_exported(Exporter exporter, bool is_cancelled)
return;
}
Config.Facade.get_instance().set_desktop_background(xml_file.get_path());
if (set_desktop_background) {
Config.Facade.get_instance().set_desktop_background(xml_file.get_path());
}
if (set_screensaver) {
Config.Facade.get_instance().set_screensaver(xml_file.get_path());
}
}
}
......@@ -1067,14 +1067,16 @@ public class EntryMultiCompletion : Gtk.EntryCompletion {
}
}
public class SetBackgroundSlideshowDialog {
private Gtk.Dialog dialog;
private Gtk.Label delay_value_label;
private Gtk.Scale delay_scale;
private int delay_value = 0;
public SetBackgroundSlideshowDialog() {
Gtk.Builder builder = AppWindow.create_builder("set_background_dialog.glade", this);
public abstract class SetBackgroundDialog {
protected Gtk.Dialog dialog;
protected Gtk.CheckButton desktop_background_button;
protected Gtk.CheckButton screensaver_button;
protected Gtk.Button ok_button;
// the checkbuttons themselves are initialized to these values
protected bool desktop = true;
protected bool screensaver = false;
public SetBackgroundDialog(Gtk.Builder builder) {
dialog = builder.get_object("dialog1") as Gtk.Dialog;
dialog.set_type_hint(Gdk.WindowTypeHint.DIALOG);
......@@ -1082,13 +1084,69 @@ public class SetBackgroundSlideshowDialog {
dialog.set_transient_for(AppWindow.get_instance());
dialog.set_default_response(Gtk.ResponseType.OK);
desktop_background_button = builder.get_object("desktop_background_checkbox") as Gtk.CheckButton;
desktop_background_button.active = desktop;
desktop_background_button.toggled.connect(on_checkbox_clicked);
screensaver_button = builder.get_object("screensaver_checkbox") as Gtk.CheckButton;
screensaver_button.active = screensaver;
screensaver_button.toggled.connect(on_checkbox_clicked);
ok_button = builder.get_object("ok_button") as Gtk.Button;
}
protected void on_checkbox_clicked() {
desktop = desktop_background_button.active;
screensaver = screensaver_button.active;
if (!desktop && !screensaver) {
ok_button.sensitive = false;
} else {
ok_button.sensitive = true;
}
}
protected bool execute_base() {
dialog.show_all();
bool result = dialog.run() == Gtk.ResponseType.OK;
dialog.destroy();
return result;
}
}
public class SetBackgroundPhotoDialog : SetBackgroundDialog {
public SetBackgroundPhotoDialog() {
Gtk.Builder builder = AppWindow.create_builder("set_background_dialog.glade", this);
base(builder);
}
public bool execute(out bool desktop_background, out bool screensaver) {
bool result = execute_base();
desktop_background = this.desktop;
screensaver = this.screensaver;
return result;
}
}
public class SetBackgroundSlideshowDialog : SetBackgroundDialog {
private Gtk.Label delay_value_label;
private Gtk.Scale delay_scale;
private int delay_value = 0;
public SetBackgroundSlideshowDialog() {
Gtk.Builder builder = AppWindow.create_builder("set_background_slideshow_dialog.glade", this);
base(builder);
delay_value_label = builder.get_object("delay_value_label") as Gtk.Label;
delay_scale = builder.get_object("delay_scale") as Gtk.Scale;
delay_scale.value_changed.connect(on_delay_scale_value_changed);
delay_scale.adjustment.value = 50;
}
private void on_delay_scale_value_changed() {
double value = delay_scale.adjustment.value;
......@@ -1116,15 +1174,13 @@ public class SetBackgroundSlideshowDialog {
delay_value_label.label = text;
}
public bool execute(out int delay_value) {
dialog.show_all();
bool result = dialog.run() == Gtk.ResponseType.OK;
dialog.destroy();
public bool execute(out int delay_value, out bool desktop_background, out bool screensaver) {
bool result = execute_base();
delay_value = this.delay_value;
desktop_background = this.desktop;
screensaver = this.screensaver;
return result;
}
......
......@@ -1999,8 +1999,15 @@ public abstract class EditingHostPage : SinglePhotoPage {
}
public void on_set_background() {
if (has_photo())
DesktopIntegration.set_background(get_photo());
if (has_photo()) {
SetBackgroundPhotoDialog dialog = new SetBackgroundPhotoDialog();
bool desktop, screensaver;
if (dialog.execute(out desktop, out screensaver)) {
AppWindow.get_instance().set_busy_cursor();
DesktopIntegration.set_background(get_photo(), desktop, screensaver);
AppWindow.get_instance().set_normal_cursor();
}
}
}
protected override bool on_ctrl_pressed(Gdk.EventKey? event) {
......
......@@ -25,6 +25,8 @@ public enum ConfigurableProperty {
COMMIT_METADATA_TO_MASTERS,
DESKTOP_BACKGROUND_FILE,
DESKTOP_BACKGROUND_MODE,
SCREENSAVER_FILE,
SCREENSAVER_MODE,
DIRECTORY_PATTERN,
DIRECTORY_PATTERN_CUSTOM,
DIRECT_WINDOW_HEIGHT,
......@@ -101,6 +103,12 @@ public enum ConfigurableProperty {
case DESKTOP_BACKGROUND_MODE:
return "DESKTOP_BACKGROUND_MODE";
case SCREENSAVER_FILE:
return "SCREENSAVER_FILE";
case SCREENSAVER_MODE:
return "SCREENSAVER_MODE";
case DIRECTORY_PATTERN:
return "DIRECTORY_PATTERN";
......@@ -460,6 +468,30 @@ public abstract class ConfigurationFacade : Object {
}
}
//
// screensaver background
//
public virtual string get_screensaver() {
try {
return get_engine().get_string_property(ConfigurableProperty.SCREENSAVER_FILE);
} catch (ConfigurationError err) {
on_configuration_error(err);
return "";
}
}
public virtual void set_screensaver(string filename) {
try {
get_engine().set_string_property(ConfigurableProperty.SCREENSAVER_FILE,
filename);
get_engine().set_string_property(ConfigurableProperty.SCREENSAVER_MODE,
"zoom");
} catch (ConfigurationError err) {
on_configuration_error(err);
}
}
//
// directory pattern
//
......
......@@ -18,6 +18,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private const string IMPORTING_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".dataimports";
private const string CROP_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".crop-settings";
private const string SYSTEM_DESKTOP_SCHEMA_NAME = "org.gnome.desktop.background";
private const string SYSTEM_SCREENSAVER_SCHEMA_NAME = "org.gnome.desktop.screensaver";
private const string PLUGINS_ENABLE_DISABLE_SCHEMA_NAME = ROOT_SCHEMA_NAME +
".plugins.enable-state";
......@@ -38,6 +39,8 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
schema_names[ConfigurableProperty.COMMIT_METADATA_TO_MASTERS] = FILES_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_FILE] = SYSTEM_DESKTOP_SCHEMA_NAME;
schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_MODE] = SYSTEM_DESKTOP_SCHEMA_NAME;
schema_names[ConfigurableProperty.SCREENSAVER_FILE] = SYSTEM_SCREENSAVER_SCHEMA_NAME;
schema_names[ConfigurableProperty.SCREENSAVER_MODE] = SYSTEM_SCREENSAVER_SCHEMA_NAME;
schema_names[ConfigurableProperty.DIRECTORY_PATTERN] = FILES_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.DIRECTORY_PATTERN_CUSTOM] = FILES_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.DIRECT_WINDOW_HEIGHT] = WINDOW_PREFS_SCHEMA_NAME;
......@@ -101,6 +104,8 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
key_names[ConfigurableProperty.COMMIT_METADATA_TO_MASTERS] = "commit-metadata";
key_names[ConfigurableProperty.DESKTOP_BACKGROUND_FILE] = "picture-uri";
key_names[ConfigurableProperty.DESKTOP_BACKGROUND_MODE] = "picture-options";
key_names[ConfigurableProperty.SCREENSAVER_FILE] = "picture-uri";
key_names[ConfigurableProperty.SCREENSAVER_MODE] = "picture-options";
key_names[ConfigurableProperty.DIRECTORY_PATTERN] = "directory-pattern";
key_names[ConfigurableProperty.DIRECTORY_PATTERN_CUSTOM] = "directory-pattern-custom";
key_names[ConfigurableProperty.DIRECT_WINDOW_HEIGHT] = "direct-height";
......@@ -308,9 +313,10 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
}
public void set_string_property(ConfigurableProperty p, string val) throws ConfigurationError {
// if we're setting the desktop background file, convert the filename into a file URI
// if we're setting the desktop background/screensaver file, convert the filename into a file URI
string converted_val = val;
if (p == ConfigurableProperty.DESKTOP_BACKGROUND_FILE) {
if (p == ConfigurableProperty.DESKTOP_BACKGROUND_FILE
|| p == ConfigurableProperty.SCREENSAVER_FILE) {
converted_val = "file://" + val;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.2 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>
<property name="step_increment">10</property>
......@@ -11,7 +12,7 @@
<property name="width_request">400</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Set as Desktop Slideshow</property>
<property name="title" translatable="yes">Set as Desktop Background</property>
<property name="type_hint">normal</property>
<property name="skip_taskbar_hint">True</property>
<child internal-child="vbox">
......@@ -33,7 +34,6 @@
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
......@@ -51,9 +51,6 @@
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_text" translatable="yes">Generate desktop background slideshow</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
......@@ -71,15 +68,19 @@
</packing>
</child>
<child>
<object class="GtkBox" id="hbox1">
<object class="GtkBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<object class="GtkCheckButton" id="desktop_background_checkbox">
<property name="label" translatable="yes">Use for Desktop</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Show each photo for</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5899999737739563</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -88,13 +89,13 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="delay_value_label">
<object class="GtkCheckButton" id="screensaver_checkbox">
<property name="label" translatable="yes">Use for Lock Screen</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">period of time</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -106,21 +107,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScale" id="delay_scale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">How long each photo is shown on the desktop background</property>
<property name="adjustment">adjustment1</property>
<property name="draw_value">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
</object>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.2 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>
<property name="step_increment">10</property>
<property name="page_increment">10</property>
<property name="page_size">10</property>
</object>
<object class="GtkDialog" id="dialog1">
<property name="width_request">400</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Set as Desktop Slideshow</property>
<property name="type_hint">normal</property>
<property name="skip_taskbar_hint">True</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Show each photo for</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="delay_value_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">period of time</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</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="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok_button">
<property name="label">gtk-ok</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_text" translatable="yes">Generate desktop background slideshow</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScale" id="delay_scale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">How long each photo is shown on the desktop background</property>
<property name="adjustment">adjustment1</property>
<property name="draw_value">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkCheckButton" id="desktop_background_checkbox">
<property name="label" translatable="yes">Use for Desktop</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5899999737739563</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="screensaver_checkbox">
<property name="label" translatable="yes">Use for Lock Screen</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</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="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">cancel_button</action-widget>
<action-widget response="-5">ok_button</action-widget>
</action-widgets>
</object>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment