Skip to content
Merged
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
44 changes: 29 additions & 15 deletions src/Views/Wallpaper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
private Gtk.ComboBoxText combo;
private Gtk.ColorButton color_button;

private GLib.ListStore wallpaper_model;
private WallpaperContainer active_wallpaper = null;
private SolidColorContainer solid_color = null;
private WallpaperContainer wallpaper_for_removal = null;
Expand All @@ -53,16 +54,18 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
construct {
var drop_target = new Gtk.DropTarget (typeof (Gdk.FileList), Gdk.DragAction.COPY);

wallpaper_model = new GLib.ListStore (typeof (WallpaperContainer));

wallpaper_view = new Gtk.FlowBox () {
activate_on_single_click = true,
homogeneous = true,
selection_mode = SINGLE,
min_children_per_line = 3,
max_children_per_line = 5
};
wallpaper_view.bind_model (wallpaper_model, create_widget_func);
wallpaper_view.add_css_class (Granite.STYLE_CLASS_VIEW);
wallpaper_view.child_activated.connect (update_checked_wallpaper);
wallpaper_view.set_sort_func (wallpapers_sort_function);
wallpaper_view.add_controller (drop_target);

var color = gnome_background_settings.get_string ("primary-color");
Expand Down Expand Up @@ -120,6 +123,10 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
drop_target.drop.connect (on_drag_data_received);
}

private Gtk.Widget create_widget_func (Object object) {
return (WallpaperContainer) object;
}

private void show_wallpaper_chooser () {
var filter = new Gtk.FileFilter ();
filter.add_mime_type ("image/*");
Expand Down Expand Up @@ -220,7 +227,9 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
if (finished) {
set_combo_disabled_if_necessary ();
create_solid_color_container (color_button.rgba.to_string ());
wallpaper_view.append (solid_color);

wallpaper_model.insert_sorted (solid_color, wallpapers_sort_function);

wallpaper_view.select_child (solid_color);

if (active_wallpaper != null) {
Expand Down Expand Up @@ -324,7 +333,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {

if (toplevel_folder) {
create_solid_color_container (color_button.rgba.to_string ());
wallpaper_view.append (solid_color);
wallpaper_model.append (solid_color);
finished = true;

if (gnome_background_settings.get_string ("picture-options") == "none") {
Expand All @@ -349,18 +358,20 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
private void create_solid_color_container (string color) {
if (solid_color != null) {
wallpaper_view.unselect_child (solid_color);
wallpaper_view.remove (solid_color);

uint pos = -1;
if (wallpaper_model.find (solid_color, out pos)) {
wallpaper_model.remove (pos);
}

solid_color.destroy ();
}

solid_color = new SolidColorContainer (color);
}

private void clean_wallpapers () {
while (wallpaper_view.get_first_child () != null) {
wallpaper_view.remove (wallpaper_view.get_first_child ());
}

wallpaper_model.remove_all ();
solid_color = null;
}

Expand Down Expand Up @@ -391,7 +402,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
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_view.append (wallpaper);
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);

wallpaper.trash.connect (() => {
send_undo_toast ();
Expand All @@ -418,9 +429,9 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
}
}

private int wallpapers_sort_function (Gtk.FlowBoxChild _child1, Gtk.FlowBoxChild _child2) {
var child1 = (WallpaperContainer) _child1;
var child2 = (WallpaperContainer) _child2;
private int wallpapers_sort_function (Object object1, Object object2) {
var child1 = (WallpaperContainer) object1;
var child2 = (WallpaperContainer) object2;
var uri1 = child1.uri;
var uri2 = child2.uri;

Expand Down Expand Up @@ -486,8 +497,11 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
}

private void mark_for_removal (WallpaperContainer wallpaper) {
wallpaper_view.remove (wallpaper);
wallpaper_for_removal = wallpaper;
uint pos = -1;
if (wallpaper_model.find (wallpaper, out pos)) {
wallpaper_model.remove (pos);
wallpaper_for_removal = wallpaper;
}
}

public void confirm_removal () {
Expand All @@ -502,7 +516,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
}

private void undo_removal () {
wallpaper_view.append (wallpaper_for_removal);
wallpaper_model.append (wallpaper_for_removal);
wallpaper_for_removal = null;
}
}