Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions src/Views/Wallpaper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -406,30 +406,21 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
return;
}

try {
var info = file.query_info (string.joinv (",", REQUIRED_FILE_ATTRS), 0);
var thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH);
var thumb_valid = info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID);
var wallpaper = new WallpaperContainer (uri, thumb_path, thumb_valid);
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);

wallpaper.trash.connect (() => {
send_undo_toast ();
mark_for_removal (wallpaper);
});

// Select the wallpaper if it is the current wallpaper
if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") {
this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ());
// Set the widget activated without activating it
wallpaper.checked = true;
active_wallpaper = wallpaper;
}
} catch (Error e) {
critical ("Unable to add wallpaper: %s", e.message);
}
var wallpaper = new WallpaperContainer (uri);
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);

wallpaper_view.invalidate_sort ();
wallpaper.trash.connect (() => {
send_undo_toast ();
mark_for_removal (wallpaper);
});

// Select the wallpaper if it is the current wallpaper
if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") {
this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ());
// Set the widget activated without activating it
wallpaper.checked = true;
active_wallpaper = wallpaper;
}
}

public void cancel_thumbnail_generation () {
Expand Down
35 changes: 14 additions & 21 deletions src/Widgets/WallpaperContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
protected const int THUMB_HEIGHT = 144;
protected Gtk.Picture image;

private Gtk.Box card_box;
private Gtk.Revealer check_revealer;

public string? thumb_path { get; construct set; }
public bool thumb_valid { get; construct; }
public string uri { get; construct; }
private string? thumb_path = null;

public string? uri { get; construct; default = null; }
public uint64 creation_date = 0;

public bool checked {
Expand All @@ -49,8 +48,8 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
}
}

public WallpaperContainer (string uri, string? thumb_path, bool thumb_valid) {
Object (uri: uri, thumb_path: thumb_path, thumb_valid: thumb_valid);
public WallpaperContainer (string uri) {
Object (uri: uri);
}

construct {
Expand Down Expand Up @@ -95,6 +94,15 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
var file = File.new_for_uri (uri);
try {
var info = file.query_info ("*", FileQueryInfoFlags.NONE);

thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH);

if (thumb_path != null && info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID)) {
update_thumb.begin ();
} else {
generate_and_load_thumb ();
}

creation_date = info.get_attribute_uint64 (GLib.FileAttribute.TIME_CREATED);
remove_wallpaper_action.set_enabled (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE));
} catch (Error e) {
Expand Down Expand Up @@ -124,21 +132,6 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {

add_controller (secondary_click_gesture);
}

try {
if (uri != null) {
if (thumb_path != null && thumb_valid) {
update_thumb.begin ();
} else {
generate_and_load_thumb ();
}
} else {
image.set_filename (thumb_path);
}
} catch (Error e) {
critical ("Failed to load wallpaper thumbnail: %s", e.message);
return;
}
}

private void generate_and_load_thumb () {
Expand Down