Skip to content

Commit 700aa05

Browse files
committed
WallpaperContainer: fewer construction args
1 parent d61681c commit 700aa05

2 files changed

Lines changed: 28 additions & 44 deletions

File tree

src/Views/Wallpaper.vala

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -406,30 +406,21 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
406406
return;
407407
}
408408

409-
try {
410-
var info = file.query_info (string.joinv (",", REQUIRED_FILE_ATTRS), 0);
411-
var thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH);
412-
var thumb_valid = info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID);
413-
var wallpaper = new WallpaperContainer (uri, thumb_path, thumb_valid);
414-
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);
415-
416-
wallpaper.trash.connect (() => {
417-
send_undo_toast ();
418-
mark_for_removal (wallpaper);
419-
});
420-
421-
// Select the wallpaper if it is the current wallpaper
422-
if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") {
423-
this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ());
424-
// Set the widget activated without activating it
425-
wallpaper.checked = true;
426-
active_wallpaper = wallpaper;
427-
}
428-
} catch (Error e) {
429-
critical ("Unable to add wallpaper: %s", e.message);
430-
}
409+
var wallpaper = new WallpaperContainer (uri);
410+
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);
431411

432-
wallpaper_view.invalidate_sort ();
412+
wallpaper.trash.connect (() => {
413+
send_undo_toast ();
414+
mark_for_removal (wallpaper);
415+
});
416+
417+
// Select the wallpaper if it is the current wallpaper
418+
if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") {
419+
this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ());
420+
// Set the widget activated without activating it
421+
wallpaper.checked = true;
422+
active_wallpaper = wallpaper;
423+
}
433424
}
434425

435426
public void cancel_thumbnail_generation () {

src/Widgets/WallpaperContainer.vala

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
2525
protected const int THUMB_HEIGHT = 144;
2626
protected Gtk.Picture image;
2727

28-
private Gtk.Box card_box;
2928
private Gtk.Revealer check_revealer;
3029

31-
public string? thumb_path { get; construct set; }
32-
public bool thumb_valid { get; construct; }
33-
public string uri { get; construct; }
30+
private string? thumb_path = null;
31+
32+
public string? uri { get; construct; default = null; }
3433
public uint64 creation_date = 0;
3534

3635
public bool checked {
@@ -49,8 +48,8 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
4948
}
5049
}
5150

52-
public WallpaperContainer (string uri, string? thumb_path, bool thumb_valid) {
53-
Object (uri: uri, thumb_path: thumb_path, thumb_valid: thumb_valid);
51+
public WallpaperContainer (string uri) {
52+
Object (uri: uri);
5453
}
5554

5655
construct {
@@ -95,6 +94,15 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
9594
var file = File.new_for_uri (uri);
9695
try {
9796
var info = file.query_info ("*", FileQueryInfoFlags.NONE);
97+
98+
thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH);
99+
100+
if (thumb_path != null && info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID)) {
101+
update_thumb.begin ();
102+
} else {
103+
generate_and_load_thumb ();
104+
}
105+
98106
creation_date = info.get_attribute_uint64 (GLib.FileAttribute.TIME_CREATED);
99107
remove_wallpaper_action.set_enabled (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE));
100108
} catch (Error e) {
@@ -124,21 +132,6 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
124132

125133
add_controller (secondary_click_gesture);
126134
}
127-
128-
try {
129-
if (uri != null) {
130-
if (thumb_path != null && thumb_valid) {
131-
update_thumb.begin ();
132-
} else {
133-
generate_and_load_thumb ();
134-
}
135-
} else {
136-
image.set_filename (thumb_path);
137-
}
138-
} catch (Error e) {
139-
critical ("Failed to load wallpaper thumbnail: %s", e.message);
140-
return;
141-
}
142135
}
143136

144137
private void generate_and_load_thumb () {

0 commit comments

Comments
 (0)