1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-28 14:35:28 +00:00

portal: Introduce implementation stub

From now on nautilus claims to implement the FileChooser portal.

For now it's a lie. But the next few commits will make it true.
This commit is contained in:
António Fernandes 2024-04-20 11:51:51 +01:00
parent 80130fc32a
commit 040dc0d641
6 changed files with 136 additions and 0 deletions

View File

@ -146,5 +146,15 @@ if appstreamcli.found()
)
endif
portal_impl_conf = configuration_data()
portal_impl_conf.set('appid', application_id)
configure_file(
input: 'nautilus.portal.in',
output: 'nautilus.portal',
configuration: portal_impl_conf,
install_dir: datadir / 'xdg-desktop-portal' / 'portals',
)
subdir('ontology')
subdir('tracker')

4
data/nautilus.portal.in Normal file
View File

@ -0,0 +1,4 @@
[portal]
DBusName=@appid@
Interfaces=org.freedesktop.impl.portal.FileChooser;
UseIn=gnome

View File

@ -210,6 +210,8 @@ libnautilus_sources = [
'nautilus-module.h',
'nautilus-monitor.c',
'nautilus-monitor.h',
'nautilus-portal.c',
'nautilus-portal.h',
'nautilus-progress-info.c',
'nautilus-progress-info.h',
'nautilus-progress-info-manager.c',

View File

@ -54,6 +54,7 @@
#include "nautilus-global-preferences.h"
#include "nautilus-icon-info.h"
#include "nautilus-module.h"
#include "nautilus-portal.h"
#include "nautilus-preferences-window.h"
#include "nautilus-previewer.h"
#include "nautilus-progress-persistence-handler.h"
@ -73,6 +74,7 @@ typedef struct
NautilusProgressPersistenceHandler *progress_handler;
NautilusDBusManager *dbus_manager;
NautilusFreedesktopDBus *fdb_manager;
NautilusPortal *portal_implementation;
NautilusBookmarkList *bookmark_list;
@ -1203,6 +1205,13 @@ nautilus_application_dbus_register (GApplication *app,
return FALSE;
}
priv->portal_implementation = nautilus_portal_new ();
if (g_strcmp0 (g_getenv ("RUNNING_TESTS"), "TRUE") != 0 &&
!nautilus_portal_register (priv->portal_implementation, connection, error))
{
return FALSE;
}
priv->search_provider = nautilus_shell_search_provider_new ();
if (!nautilus_shell_search_provider_register (priv->search_provider, connection, error))
{
@ -1235,6 +1244,12 @@ nautilus_application_dbus_unregister (GApplication *app,
g_clear_object (&priv->fdb_manager);
}
if (priv->portal_implementation != NULL)
{
nautilus_portal_unregister (priv->portal_implementation);
g_clear_object (&priv->portal_implementation);
}
if (priv->search_provider)
{
nautilus_shell_search_provider_unregister (priv->search_provider);

79
src/nautilus-portal.c Normal file
View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2024 GNOME Foundation Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Original Author: António Fernandes <antoniof@gnome.org>
*/
#define G_LOG_DOMAIN "nautilus-dbus"
#include "nautilus-portal.h"
#include <config.h>
#include <xdp-gnome/request.h>
#include <xdp-gnome/xdg-desktop-portal-dbus.h>
#define DESKTOP_PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
struct _NautilusPortal
{
GObject parent;
XdpImplFileChooser *implementation_skeleton;
};
G_DEFINE_TYPE (NautilusPortal, nautilus_portal, G_TYPE_OBJECT);
static void
nautilus_portal_dispose (GObject *object)
{
NautilusPortal *self = (NautilusPortal *) object;
g_signal_handlers_disconnect_by_data (self->implementation_skeleton, self);
g_clear_object (&self->implementation_skeleton);
G_OBJECT_CLASS (nautilus_portal_parent_class)->dispose (object);
}
static void
nautilus_portal_class_init (NautilusPortalClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = nautilus_portal_dispose;
}
static void
nautilus_portal_init (NautilusPortal *self)
{
self->implementation_skeleton = xdp_impl_file_chooser_skeleton_new ();
}
NautilusPortal *
nautilus_portal_new (void)
{
return g_object_new (NAUTILUS_TYPE_PORTAL, NULL);
}
gboolean
nautilus_portal_register (NautilusPortal *self,
GDBusConnection *connection,
GError **error)
{
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->implementation_skeleton),
connection,
DESKTOP_PORTAL_OBJECT_PATH,
error))
{
return FALSE;
}
return TRUE;
}
void
nautilus_portal_unregister (NautilusPortal *self)
{
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->implementation_skeleton));
}

26
src/nautilus-portal.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (C) 2024 GNOME Foundation Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Original Author: António Fernandes <antoniof@gnome.org>
*/
#pragma once
#include <gio/gio.h>
G_BEGIN_DECLS
#define NAUTILUS_TYPE_PORTAL (nautilus_portal_get_type())
G_DECLARE_FINAL_TYPE (NautilusPortal, nautilus_portal, NAUTILUS, PORTAL, GObject)
NautilusPortal * nautilus_portal_new (void);
void nautilus_portal_unregister (NautilusPortal *self);
gboolean nautilus_portal_register (NautilusPortal *self,
GDBusConnection *connection,
GError **error);
G_END_DECLS