[gnome-photos/bilelmoussaoui/portal] set as background: Switch to using Wallpaper portal
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/bilelmoussaoui/portal] set as background: Switch to using Wallpaper portal
- Date: Fri, 5 Aug 2022 14:40:52 +0000 (UTC)
commit 1a0e021aecce9c8770591218e8ccd78656d23523
Author: Bilal Elmoussaoui <belmouss redhat com>
Date: Fri Aug 5 16:27:06 2022 +0200
set as background: Switch to using Wallpaper portal
flatpak/org.gnome.Photos.json | 16 ++++++++++
meson.build | 2 ++
src/meson.build | 2 ++
src/photos-application.c | 69 ++++++++++++++++++++++++-------------------
4 files changed, 58 insertions(+), 31 deletions(-)
---
diff --git a/flatpak/org.gnome.Photos.json b/flatpak/org.gnome.Photos.json
index 711914b6..ebbddf6e 100644
--- a/flatpak/org.gnome.Photos.json
+++ b/flatpak/org.gnome.Photos.json
@@ -284,6 +284,22 @@
}
]
},
+ {
+ "name": "libportal",
+ "buildsystem": "meson",
+ "config-opts": [
+ "-Dbackends=gtk3",
+ "-Dintrospection=false",
+ "-Dvapi=false",
+ "-Ddocs=false",
+ "-Dtests=false"
+ ],
+ "sources": [{
+ "type": "git",
+ "url": "https://github.com/flatpak/libportal",
+ "branch": "main"
+ }]
+ },
{
"name": "gnome-photos",
"buildsystem": "meson",
diff --git a/meson.build b/meson.build
index b3240247..cbe13c08 100644
--- a/meson.build
+++ b/meson.build
@@ -161,6 +161,8 @@ gexiv_dep = dependency('gexiv2', version: '>= 0.14.0')
gio_dep = dependency('gio-2.0')
gio_unix_dep = dependency('gio-unix-2.0')
glib_dep = dependency('glib-2.0', version: '>= 2.62.0')
+libportal_dep = dependency('libportal')
+libportal_gtk3_dep = dependency('libportal-gtk3')
goa_dep = dependency('goa-1.0', version: '>= 3.8.0')
config_h.set('GOA_API_IS_SUBJECT_TO_CHANGE', true)
diff --git a/src/meson.build b/src/meson.build
index 36ff204a..77b1bbc0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -388,6 +388,8 @@ deps = [
#libgdata_dep,
libgnome_photos_dep,
libhandy_dep,
+ libportal_dep,
+ libportal_gtk3_dep,
m_dep,
tracker_sparql_dep,
]
diff --git a/src/photos-application.c b/src/photos-application.c
index 91d3aec6..29058738 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -37,6 +37,8 @@
#include <glib/gi18n.h>
#include <grilo.h>
#include <handy.h>
+#include <libportal/portal.h>
+#include <libportal-gtk3/portal-gtk3.h>
#include <tracker-sparql.h>
#include "photos-application.h"
@@ -80,8 +82,6 @@ struct _PhotosApplication
GHashTable *refresh_miner_ids;
GList *miners;
GList *miners_running;
- GSettings *bg_settings;
- GSettings *ss_settings;
GSimpleAction *blacks_exposure_action;
GSimpleAction *contrast_action;
GSimpleAction *crop_action;
@@ -170,13 +170,6 @@ static const GOptionEntry COMMAND_LINE_OPTIONS[] =
{ NULL }
};
-static const gchar *DESKTOP_BACKGROUND_SCHEMA = "org.gnome.desktop.background";
-static const gchar *DESKTOP_SCREENSAVER_SCHEMA = "org.gnome.desktop.screensaver";
-static const gchar *DESKTOP_KEY_PICTURE_URI = "picture-uri";
-static const gchar *DESKTOP_KEY_PICTURE_OPTIONS = "picture-options";
-static const gchar *DESKTOP_KEY_COLOR_SHADING_TYPE = "color-shading-type";
-static const gchar *DESKTOP_KEY_PRIMARY_COLOR = "primary-color";
-static const gchar *DESKTOP_KEY_SECONDARY_COLOR = "secondary-color";
static const gchar *MINER_FILES_NAME_PRIVATE = "org.gnome.Photos.Tracker3.Miner.Files";
static const gchar *MINER_FILES_NAME_PRIVATE_CONTROL = "org.gnome.Photos.Tracker3.Miner.Files.Control";
static const gchar *MINER_FILES_NAME_SESSION = "org.freedesktop.Tracker3.Miner.Files";
@@ -218,7 +211,7 @@ struct _PhotosApplicationSetBackgroundData
{
PhotosApplication *application;
GFile *file;
- GSettings *settings;
+ XdpWallpaperFlags flags;
};
static void photos_application_import_file_copy (GObject *source_object, GAsyncResult *res, gpointer
user_data);
@@ -315,7 +308,7 @@ photos_application_refresh_data_free (PhotosApplicationRefreshData *data)
static PhotosApplicationSetBackgroundData *
-photos_application_set_background_data_new (PhotosApplication *application, GFile *file, GSettings *settings)
+photos_application_set_background_data_new (PhotosApplication *application, GFile *file, XdpWallpaperFlags
flags)
{
PhotosApplicationSetBackgroundData *data;
@@ -323,7 +316,7 @@ photos_application_set_background_data_new (PhotosApplication *application, GFil
g_application_hold (G_APPLICATION (application));
data->application = application;
data->file = g_object_ref (file);
- data->settings = g_object_ref (settings);
+ data->flags = flags;
return data;
}
@@ -333,7 +326,6 @@ photos_application_set_background_data_free (PhotosApplicationSetBackgroundData
{
g_application_release (G_APPLICATION (data->application));
g_object_unref (data->file);
- g_object_unref (data->settings);
g_slice_free (PhotosApplicationSetBackgroundData, data);
}
@@ -1981,13 +1973,29 @@ photos_application_save (PhotosApplication *self)
g_signal_connect (dialog, "response", G_CALLBACK (photos_application_save_response), self);
}
+static void
+photos_application_xdp_set_wallpaper_finish (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ g_autoptr (GError) error = NULL;
+ XdpPortal *portal = XDP_PORTAL (source_object);
+ g_autoptr (GFile) wallpaper_file = user_data;
+
+ if (!xdp_portal_set_wallpaper_finish (portal, res, &error))
+ g_warning ("Unable to set wallpaper: %s", error->message);
+
+ if (!g_file_delete (wallpaper_file, NULL, &error))
+ g_warning ("Unable to delete wallpaper file: %s", error->message);
+}
static void
photos_application_set_bg_common_save_to_file (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
PhotosApplicationSetBackgroundData *data = (PhotosApplicationSetBackgroundData *) user_data;
- g_autofree gchar *path = NULL;
+ XdpPortal *portal;
+ g_autofree gchar *uri = NULL;
+ GtkWindow *parent;
+ XdpParent * parent_window;
{
g_autoptr (GError) error = NULL;
@@ -1999,21 +2007,25 @@ photos_application_set_bg_common_save_to_file (GObject *source_object, GAsyncRes
}
}
- path = g_file_get_path (data->file);
-
- g_settings_set_string (data->settings, DESKTOP_KEY_PICTURE_URI, path);
- g_settings_set_enum (data->settings, DESKTOP_KEY_PICTURE_OPTIONS, G_DESKTOP_BACKGROUND_STYLE_ZOOM);
- g_settings_set_enum (data->settings, DESKTOP_KEY_COLOR_SHADING_TYPE, G_DESKTOP_BACKGROUND_SHADING_SOLID);
- g_settings_set_string (data->settings, DESKTOP_KEY_PRIMARY_COLOR, "#000000000000");
- g_settings_set_string (data->settings, DESKTOP_KEY_SECONDARY_COLOR, "#000000000000");
-
+ uri = g_file_get_uri (data->file);
+ portal = xdp_portal_new ();
+ parent = gtk_application_get_active_window (GTK_APPLICATION (data->application));
+ parent_window = xdp_parent_new_gtk (parent);
+
+ xdp_portal_set_wallpaper (portal,
+ parent_window,
+ uri,
+ data->flags,
+ NULL,
+ photos_application_xdp_set_wallpaper_finish,
+ g_object_ref (data->file));
out:
photos_application_set_background_data_free (data);
}
static void
-photos_application_set_bg_common (PhotosApplication *self, GSettings *settings)
+photos_application_set_bg_common (PhotosApplication *self, XdpWallpaperFlags flags)
{
g_autoptr (GFile) backgrounds_file = NULL;
PhotosApplicationSetBackgroundData *data;
@@ -2045,7 +2057,7 @@ photos_application_set_bg_common (PhotosApplication *self, GSettings *settings)
backgrounds_path = g_build_filename (backgrounds_dir, backgrounds_filename, NULL);
backgrounds_file = g_file_new_for_path (backgrounds_path);
- data = photos_application_set_background_data_new (self, backgrounds_file, settings);
+ data = photos_application_set_background_data_new (self, backgrounds_file, flags |
XDP_WALLPAPER_FLAG_PREVIEW);
photos_base_item_save_to_file_async (item,
backgrounds_file,
G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION,
@@ -2059,14 +2071,14 @@ photos_application_set_bg_common (PhotosApplication *self, GSettings *settings)
static void
photos_application_set_background (PhotosApplication *self)
{
- photos_application_set_bg_common (self, self->bg_settings);
+ photos_application_set_bg_common (self, XDP_WALLPAPER_FLAG_BACKGROUND);
}
static void
photos_application_set_screensaver (PhotosApplication *self)
{
- photos_application_set_bg_common (self, self->ss_settings);
+ photos_application_set_bg_common (self, XDP_WALLPAPER_FLAG_LOCKSCREEN);
}
@@ -2637,9 +2649,6 @@ photos_application_startup (GApplication *application)
self->create_window_cancellable = g_cancellable_new ();
self->refresh_miner_ids = g_hash_table_new (g_direct_hash, g_direct_equal);
- self->bg_settings = g_settings_new (DESKTOP_BACKGROUND_SCHEMA);
- self->ss_settings = g_settings_new (DESKTOP_SCREENSAVER_SCHEMA);
-
icon_theme = gtk_icon_theme_get_default ();
gtk_icon_theme_add_resource_path (icon_theme, "/org/gnome/Photos/icons");
@@ -2945,8 +2954,6 @@ photos_application_dispose (GObject *object)
}
g_clear_object (&self->create_window_cancellable);
- g_clear_object (&self->bg_settings);
- g_clear_object (&self->ss_settings);
g_clear_object (&self->blacks_exposure_action);
g_clear_object (&self->contrast_action);
g_clear_object (&self->crop_action);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]