Skip to content

Commit

Permalink
documents: Move it to the xdp namespace
Browse files Browse the repository at this point in the history
Rename the DocumentFlags enum and related functions to have an XDP
prefix.
  • Loading branch information
swick authored and GeorgesStavracas committed Nov 28, 2024
1 parent 322b0db commit 40d1777
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ send_response_in_thread_func (GTask *task,
if (xdp_app_info_is_host (request->app_info))
ruri = g_strdup (image);
else
ruri = register_document (image, xdp_app_info_get_id (request->app_info), DOCUMENT_FLAG_NONE, &error);
ruri = xdp_register_document (image, xdp_app_info_get_id (request->app_info), XDP_DOCUMENT_FLAG_NONE, &error);

if (ruri == NULL)
g_warning ("Failed to register %s: %s", image, error->message);
Expand Down
30 changes: 15 additions & 15 deletions src/documents.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static XdpDbusDocuments *documents = NULL;
static char *documents_mountpoint = NULL;

gboolean
init_document_proxy (GDBusConnection *connection,
GError **error)
xdp_init_document_proxy (GDBusConnection *connection,
GError **error)
{
documents = xdp_dbus_documents_proxy_new_sync (connection, 0,
"org.freedesktop.portal.Documents",
Expand All @@ -61,10 +61,10 @@ init_document_proxy (GDBusConnection *connection,
}

char *
register_document (const char *uri,
const char *app_id,
DocumentFlags flags,
GError **error)
xdp_register_document (const char *uri,
const char *app_id,
XdpDocumentFlags flags,
GError **error)
{
g_autofree char *doc_id = NULL;
g_auto(GStrv) doc_ids = NULL;
Expand All @@ -89,7 +89,7 @@ register_document (const char *uri,
basename = g_path_get_basename (path);
dirname = g_path_get_dirname (path);

if (flags & DOCUMENT_FLAG_FOR_SAVE)
if (flags & XDP_DOCUMENT_FLAG_FOR_SAVE)
fd = open (dirname, O_PATH | O_CLOEXEC);
else
fd = open (path, O_PATH | O_CLOEXEC);
Expand All @@ -109,19 +109,19 @@ register_document (const char *uri,

i = 0;
permissions[i++] = "read";
if ((flags & DOCUMENT_FLAG_WRITABLE) || (flags & DOCUMENT_FLAG_FOR_SAVE))
if ((flags & XDP_DOCUMENT_FLAG_WRITABLE) || (flags & XDP_DOCUMENT_FLAG_FOR_SAVE))
permissions[i++] = "write";
permissions[i++] = "grant-permissions";
if (flags & DOCUMENT_FLAG_DELETABLE)
if (flags & XDP_DOCUMENT_FLAG_DELETABLE)
permissions[i++] = "delete";
permissions[i++] = NULL;

version = xdp_dbus_documents_get_version (documents);
full_flags = DOCUMENT_ADD_FLAGS_REUSE_EXISTING | DOCUMENT_ADD_FLAGS_PERSISTENT | DOCUMENT_ADD_FLAGS_AS_NEEDED_BY_APP;
if (flags & DOCUMENT_FLAG_DIRECTORY)
if (flags & XDP_DOCUMENT_FLAG_DIRECTORY)
full_flags |= DOCUMENT_ADD_FLAGS_DIRECTORY;

if (flags & DOCUMENT_FLAG_FOR_SAVE)
if (flags & XDP_DOCUMENT_FLAG_FOR_SAVE)
{
if (version >= 3)
{
Expand Down Expand Up @@ -211,8 +211,8 @@ register_document (const char *uri,
}

char *
get_real_path_for_doc_path (const char *path,
XdpAppInfo *app_info)
xdp_get_real_path_for_doc_path (const char *path,
XdpAppInfo *app_info)
{
g_autofree char *doc_id = NULL;
gboolean ret = FALSE;
Expand All @@ -234,11 +234,11 @@ get_real_path_for_doc_path (const char *path,
return g_strdup (path);
}

return get_real_path_for_doc_id (doc_id);
return xdp_get_real_path_for_doc_id (doc_id);
}

char *
get_real_path_for_doc_id (const char *doc_id)
xdp_get_real_path_for_doc_id (const char *doc_id)
{
gboolean ret = FALSE;
char *real_path = NULL;
Expand Down
30 changes: 15 additions & 15 deletions src/documents.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
#include <gio/gio.h>

typedef enum {
DOCUMENT_FLAG_NONE = 0,
DOCUMENT_FLAG_FOR_SAVE = (1 << 0),
DOCUMENT_FLAG_WRITABLE = (1 << 1),
DOCUMENT_FLAG_DIRECTORY = (1 << 2),
DOCUMENT_FLAG_DELETABLE = (1 << 3),
} DocumentFlags;
XDP_DOCUMENT_FLAG_NONE = 0,
XDP_DOCUMENT_FLAG_FOR_SAVE = (1 << 0),
XDP_DOCUMENT_FLAG_WRITABLE = (1 << 1),
XDP_DOCUMENT_FLAG_DIRECTORY = (1 << 2),
XDP_DOCUMENT_FLAG_DELETABLE = (1 << 3),
} XdpDocumentFlags;

gboolean init_document_proxy (GDBusConnection *connection,
GError **error);
gboolean xdp_init_document_proxy (GDBusConnection *connection,
GError **error);

char *register_document (const char *uri,
const char *app_id,
DocumentFlags flags,
GError **error);
char *xdp_register_document (const char *uri,
const char *app_id,
XdpDocumentFlags flags,
GError **error);

char *get_real_path_for_doc_path (const char *path,
XdpAppInfo *app_info);
char *xdp_get_real_path_for_doc_path (const char *path,
XdpAppInfo *app_info);

char *get_real_path_for_doc_id (const char *doc_id);
char *xdp_get_real_path_for_doc_id (const char *doc_id);
16 changes: 8 additions & 8 deletions src/file-chooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ send_response_in_thread_func (GTask *task,
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_STRING_ARRAY);
guint response;
GVariant *options;
DocumentFlags flags = DOCUMENT_FLAG_WRITABLE | DOCUMENT_FLAG_DIRECTORY;
XdpDocumentFlags flags = XDP_DOCUMENT_FLAG_WRITABLE | XDP_DOCUMENT_FLAG_DIRECTORY;
g_autofree char **uris = NULL;
GVariant *choices;
GVariant *current_filter;
Expand All @@ -88,9 +88,9 @@ send_response_in_thread_func (GTask *task,
REQUEST_AUTOLOCK (request);

if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "for-save")) == TRUE)
flags |= DOCUMENT_FLAG_FOR_SAVE;
flags |= XDP_DOCUMENT_FLAG_FOR_SAVE;
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "directory")) == FALSE)
flags &= ~DOCUMENT_FLAG_DIRECTORY;
flags &= ~XDP_DOCUMENT_FLAG_DIRECTORY;
response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "response"));
options = (GVariant *)g_object_get_data (G_OBJECT (request), "options");

Expand All @@ -99,7 +99,7 @@ send_response_in_thread_func (GTask *task,

writable = g_variant_lookup_value (options, "writable", G_VARIANT_TYPE("b"));
if (writable && !g_variant_get_boolean (writable))
flags &= ~DOCUMENT_FLAG_WRITABLE;
flags &= ~XDP_DOCUMENT_FLAG_WRITABLE;

choices = g_variant_lookup_value (options, "choices", G_VARIANT_TYPE ("a(ss)"));
if (choices)
Expand Down Expand Up @@ -129,7 +129,7 @@ send_response_in_thread_func (GTask *task,
if (xdp_app_info_is_host (request->app_info))
ruri = g_strdup (uris[i]);
else
ruri = register_document (uris[i], xdp_app_info_get_id (request->app_info), flags, &error);
ruri = xdp_register_document (uris[i], xdp_app_info_get_id (request->app_info), flags, &error);

if (ruri == NULL)
{
Expand Down Expand Up @@ -193,7 +193,7 @@ looks_like_document_portal_path (const char *path,
static char *
get_host_folder_for_doc_id (const char *doc_id)
{
g_autofree char *real_path = get_real_path_for_doc_id (doc_id);
g_autofree char *real_path = xdp_get_real_path_for_doc_id (doc_id);
g_autofree char *host_folder = NULL;

if (real_path != NULL)
Expand Down Expand Up @@ -692,13 +692,13 @@ handle_save_file (XdpDbusFileChooser *object,
if (value)
{
const char *path = g_variant_get_bytestring (value);
g_autofree char *host_path = get_real_path_for_doc_path (path, request->app_info);
g_autofree char *host_path = xdp_get_real_path_for_doc_path (path, request->app_info);
g_autofree char *doc_id = NULL;

if (strcmp (path, host_path) == 0 &&
looks_like_document_portal_path (path, &doc_id))
{
char *real_path = get_real_path_for_doc_id (doc_id);
char *real_path = xdp_get_real_path_for_doc_id (doc_id);

if (real_path)
{
Expand Down
10 changes: 5 additions & 5 deletions src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ launch_application_with_uri (const char *choice_id,
g_autoptr(XdpAppLaunchContext) xdp_context = xdp_app_launch_context_new ();
GAppLaunchContext *context = G_APP_LAUNCH_CONTEXT (xdp_context);
g_autofree char *ruri = NULL;
DocumentFlags flags = DOCUMENT_FLAG_NONE;
XdpDocumentFlags flags = XDP_DOCUMENT_FLAG_NONE;
GList uris;

if (info == NULL)
Expand All @@ -263,9 +263,9 @@ launch_application_with_uri (const char *choice_id,

g_debug ("Registering %s for %s", uri, choice_id);
if (writable)
flags |= DOCUMENT_FLAG_WRITABLE;
flags |= XDP_DOCUMENT_FLAG_WRITABLE;

ruri = register_document (uri, choice_id, flags, &local_error);
ruri = xdp_register_document (uri, choice_id, flags, &local_error);
if (ruri == NULL)
{
g_warning ("Error registering %s for %s: %s", uri, choice_id, local_error->message);
Expand Down Expand Up @@ -688,7 +688,7 @@ handle_open_in_thread_func (GTask *task,

if (path != NULL)
{
host_path = get_real_path_for_doc_path (path, request->app_info);
host_path = xdp_get_real_path_for_doc_path (path, request->app_info);
if (host_path)
{
g_debug ("OpenFile: translating path value '%s' to host path '%s'", path, host_path);
Expand Down Expand Up @@ -724,7 +724,7 @@ handle_open_in_thread_func (GTask *task,

if (open_dir)
{
g_autofree char *real_path = get_real_path_for_doc_path (path, request->app_info);
g_autofree char *real_path = xdp_get_real_path_for_doc_path (path, request->app_info);
/* Try opening the directory via the file manager interface, then
fall back to a plain URI open */
g_autoptr(GError) local_error = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ send_response_in_thread_func (GTask *task,
if (xdp_app_info_is_host (request->app_info))
ruri = g_strdup (uri);
else
ruri = register_document (uri, xdp_app_info_get_id (request->app_info), DOCUMENT_FLAG_DELETABLE, &error);
ruri = xdp_register_document (uri, xdp_app_info_get_id (request->app_info), XDP_DOCUMENT_FLAG_DELETABLE, &error);

if (ruri == NULL)
g_warning ("Failed to register %s: %s", uri, error->message);
Expand Down
2 changes: 1 addition & 1 deletion src/xdg-desktop-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ on_bus_acquired (GDBusConnection *connection,
return;
}

if (!init_document_proxy (connection, &error))
if (!xdp_init_document_proxy (connection, &error))
{
g_critical ("No document portal: %s", error->message);
exit_with_status (1);
Expand Down

0 comments on commit 40d1777

Please sign in to comment.