Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractDirectoryView: add set as wallpaper option #2432

Merged
merged 5 commits into from
May 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y libgee-0.8-dev libglib2.0-dev libgranite-dev libgtk-3-dev libhandy-1-dev libcanberra-dev
apt install -y libgee-0.8-dev libglib2.0-dev libgranite-dev libgtk-3-dev libhandy-1-dev libcanberra-dev libportal-gtk3-dev
apt install -y libcloudproviders-dev libdbus-glib-1-dev libpango1.0-dev
apt install -y libsqlite3-dev libunity-dev libzeitgeist-2.0-dev policykit-1 libgit2-glib-1.0-dev
apt install -y meson valac
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ You'll need the following dependencies:
* libgtk-3-dev
* libhandy-1-dev >= 1.2.0
* libpango1.0-dev
* libportal-dev
* libportal-gtk3-dev
* libsqlite3-dev
* libunity-dev
* libzeitgeist-2.0-dev
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ gee_dep = dependency('gee-0.8')
gtk_dep = dependency('gtk+-3.0', version: '>=3.22.25')
granite_dep = dependency('granite', version: '>=6.1.0')
handy_dep = dependency('libhandy-1', version: '>=0.83.0')
portal_dep = dependency('libportal')
portal_gtk3_dep = dependency('libportal-gtk3')

common_deps = [
glib_dep,
Expand Down
21 changes: 20 additions & 1 deletion src/View/AbstractDirectoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ namespace Files {
{"bookmark", on_common_action_bookmark},
{"properties", on_common_action_properties},
{"copy-link", on_common_action_copy_link},
{"select-all", toggle_select_all}
{"select-all", toggle_select_all},
{"set-wallpaper", action_set_wallpaper}
};

GLib.SimpleActionGroup common_actions;
Expand Down Expand Up @@ -1291,6 +1292,15 @@ namespace Files {
}

/** Common actions */
private void action_set_wallpaper (GLib.SimpleAction action, GLib.Variant? param) {
var file = get_files_for_action ().nth_data (0);

var active_window = (Gtk.Window) get_toplevel ();
Xdp.Parent? parent = active_window != null ? Xdp.parent_new_gtk (active_window) : null;

var portal = new Xdp.Portal ();
portal.set_wallpaper.begin (parent, file.uri, NONE, null);
}

private void on_common_action_open_in (GLib.SimpleAction action, GLib.Variant? param) {
default_app = null;
Expand Down Expand Up @@ -2319,6 +2329,14 @@ namespace Files {
// We send the actual files - it is up to the plugin to extract target
// if needed. Color tag plugin needs actual file, others need target
plugins.hook_context_menu (menu as Gtk.Widget, get_selected_files ());

if (selection.length () == 1 && "image" in selection.nth_data (0).info.get_content_type ()) {
var wallpaper_menuitem = new Gtk.MenuItem.with_label (_("Set as Wallpaper")) {
action_name = "common.set-wallpaper"
};

menu.add (wallpaper_menuitem);
}
}

menu.set_screen (null);
Expand Down Expand Up @@ -2523,6 +2541,7 @@ namespace Files {
action_set_enabled (common_actions, "copy", !renaming && !in_trash && can_copy);
action_set_enabled (common_actions, "copy-link", !renaming && !in_trash && !in_recent && can_copy);
action_set_enabled (common_actions, "bookmark", !renaming && !more_than_one_selected);
action_set_enabled (common_actions, "set-wallpaper", !renaming && !more_than_one_selected);

update_default_app (selection);
update_menu_actions_sort ();
Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pantheon_files_deps = [
pantheon_files_core_dep,
zeitgeist_dep,
project_config_dep,
portal_dep,
portal_gtk3_dep
]

pantheon_files_exec = executable (
Expand Down