Skip to content

Commit 84d661d

Browse files
committed
Wallpaper: DRY add_wallpaper_from_file
1 parent d61681c commit 84d661d

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

src/IOHelper.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
*/
1818
public class PantheonShell.IOHelper : GLib.Object {
1919
private const string[] ACCEPTED_TYPES = {
20+
"image/gif",
21+
"image/heic",
2022
"image/jpeg",
2123
"image/png",
22-
"image/tiff",
2324
"image/svg+xml",
24-
"image/gif"
25+
"image/tiff"
2526
};
2627

2728
// Check if the filename has a picture file extension.

src/Views/Wallpaper.vala

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
157157
continue;
158158
}
159159

160-
var local_uri = file.get_uri ();
161-
var dest = WallpaperOperation.copy_for_library (file);
162-
if (dest != null) {
163-
local_uri = dest.get_uri ();
164-
}
165-
166-
add_wallpaper_from_file (file, local_uri);
160+
add_wallpaper_from_file (file);
167161
}
168162
}
169163
});
@@ -329,15 +323,10 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
329323
var subdir = directory.resolve_relative_path (file_info.get_name ());
330324
yield load_wallpapers (subdir.get_path (), cancellable, false);
331325
continue;
332-
} else if (!IOHelper.is_valid_file_type (file_info)) {
333-
// Skip non-picture files
334-
continue;
335326
}
336327

337328
var file = directory.resolve_relative_path (file_info.get_name ());
338-
string uri = file.get_uri ();
339-
340-
add_wallpaper_from_file (file, uri);
329+
add_wallpaper_from_file (file);
341330
}
342331

343332
if (toplevel_folder) {
@@ -387,30 +376,39 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
387376
private bool on_drag_data_received (Value val, double x, double y) {
388377
var file_list = (Gdk.FileList) val;
389378
foreach (var file in file_list.get_files ()) {
390-
var local_uri = file.get_uri ();
391-
392-
var dest = WallpaperOperation.copy_for_library (file);
393-
if (dest != null) {
394-
local_uri = dest.get_uri ();
395-
}
396-
397-
add_wallpaper_from_file (file, local_uri);
379+
add_wallpaper_from_file (file);
398380
}
399381

400382
return true;
401383
}
402384

403-
private void add_wallpaper_from_file (GLib.File file, string uri) {
385+
private void add_wallpaper_from_file (GLib.File file) {
386+
var uri = file.get_uri ();
387+
404388
// don't load 'removed' wallpaper on plug reload
405389
if (wallpaper_for_removal != null && wallpaper_for_removal.uri == uri) {
406390
return;
407391
}
408392

409393
try {
410394
var info = file.query_info (string.joinv (",", REQUIRED_FILE_ATTRS), 0);
395+
396+
if (!IOHelper.is_valid_file_type (info)) {
397+
Gdk.Display.get_default ().beep ();
398+
return;
399+
}
400+
401+
if (!WallpaperOperation.get_is_file_in_bg_dir (file)) {
402+
var local_file = WallpaperOperation.copy_for_library (file);
403+
if (local_file != null) {
404+
uri = local_file.get_uri ();
405+
}
406+
}
407+
411408
var thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH);
412409
var thumb_valid = info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID);
413410
var wallpaper = new WallpaperContainer (uri, thumb_path, thumb_valid);
411+
414412
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);
415413

416414
wallpaper.trash.connect (() => {

0 commit comments

Comments
 (0)