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

Use g_auto and G_VARIANT_BUILDER_INIT for all GVariantBuilders #1503

Merged
merged 8 commits into from
Nov 5, 2024
9 changes: 4 additions & 5 deletions src/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ send_response_in_thread_func (GTask *task,
Request *request = task_data;
guint response;
GVariant *results;
GVariantBuilder new_results;
g_auto(GVariantBuilder) new_results =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autoptr(GVariant) idv = NULL;
g_autoptr(GVariant) namev = NULL;
const char *image;

g_variant_builder_init (&new_results, G_VARIANT_TYPE_VARDICT);

REQUEST_AUTOLOCK (request);

response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "response"));
Expand Down Expand Up @@ -184,7 +183,8 @@ handle_get_user_information (XdpDbusAccount *object,
const char *app_id = xdp_app_info_get_id (request->app_info);
g_autoptr(GError) error = NULL;
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
GVariantBuilder options;
g_auto(GVariantBuilder) options =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

g_debug ("Handling GetUserInformation");

Expand All @@ -204,7 +204,6 @@ handle_get_user_information (XdpDbusAccount *object,
request_set_impl_request (request, impl_request);
request_export (request, g_dbus_method_invocation_get_connection (invocation));

g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
xdp_filter_options (arg_options, &options,
user_information_options, G_N_ELEMENTS (user_information_options),
NULL);
Expand Down
44 changes: 24 additions & 20 deletions src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,18 @@ remove_outdated_instances (int stamp)
static void
update_background_monitor_properties (void)
{
GVariantBuilder builder;
g_auto(GVariantBuilder) builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aa{sv}"));
GHashTableIter iter;
InstanceData *data;
char *id;

g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));

G_LOCK (applications);
g_hash_table_iter_init (&iter, applications);
while (g_hash_table_iter_next (&iter, (gpointer *)&id, (gpointer *)&data))
{
GVariantBuilder app_builder;
g_auto(GVariantBuilder) app_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
const char *app_id;
const char *id;

Expand All @@ -377,7 +377,6 @@ update_background_monitor_properties (void)
app_id = flatpak_instance_get_app (data->instance);
g_assert (app_id != NULL);

g_variant_builder_init (&app_builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&app_builder, "{sv}", "app_id", g_variant_new_string (app_id));
g_variant_builder_add (&app_builder, "{sv}", "instance", g_variant_new_string (id));
if (data->status_message)
Expand Down Expand Up @@ -710,8 +709,6 @@ enable_autostart_sync (XdpAppInfo *app_info,
return FALSE;
}

cmd = g_strjoinv (" ", exec);

file = g_strconcat (appid, ".desktop", NULL);
dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL);
path = g_build_filename (dir, file, NULL);
Expand Down Expand Up @@ -741,15 +738,22 @@ enable_autostart_sync (XdpAppInfo *app_info,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_NAME,
appid); /* FIXME: The app id isn't the name */
g_key_file_set_string (keyfile,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_EXEC,
cmd);
g_key_file_set_string (keyfile,
G_KEY_FILE_DESKTOP_GROUP,
"X-XDP-Autostart",
appid);

if (exec)
cmd = g_strjoinv (" ", exec);

if (cmd)
{
g_key_file_set_string (keyfile,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_EXEC,
cmd);
}

if (activatable)
{
g_key_file_set_boolean (keyfile,
Expand Down Expand Up @@ -784,7 +788,7 @@ handle_request_background_in_thread_func (GTask *task,
gboolean autostart_enabled;
gboolean allowed;
g_autoptr(GError) error = NULL;
const char * const *autostart_exec = { NULL };
g_autofree const char **autostart_exec = { NULL };
gboolean activatable = FALSE;

REQUEST_AUTOLOCK (request);
Expand All @@ -806,7 +810,8 @@ handle_request_background_in_thread_func (GTask *task,

if (permission == PERMISSION_ASK)
{
GVariantBuilder opt_builder;
g_auto(GVariantBuilder) opt_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autofree char *app_id = NULL;
g_autofree char *title = NULL;
g_autofree char *subtitle = NULL;
Expand All @@ -830,7 +835,6 @@ handle_request_background_in_thread_func (GTask *task,

g_debug ("Calling backend for background access for: %s", id);

g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&opt_builder, "{sv}", "deny_label", g_variant_new_string (_("Don't allow")));
g_variant_builder_add (&opt_builder, "{sv}", "grant_label", g_variant_new_string (_("Allow")));
if (!xdp_dbus_impl_access_call_access_dialog_sync (access_impl,
Expand Down Expand Up @@ -878,9 +882,9 @@ handle_request_background_in_thread_func (GTask *task,
if (request->exported)
{
XdgDesktopPortalResponseEnum portal_response;
GVariantBuilder results;
g_auto(GVariantBuilder) results =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

g_variant_builder_init (&results, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&results, "{sv}", "background", g_variant_new_boolean (allowed));
g_variant_builder_add (&results, "{sv}", "autostart", g_variant_new_boolean (autostart_enabled));

Expand Down Expand Up @@ -970,12 +974,12 @@ handle_request_background (XdpDbusBackground *object,
g_autoptr(GError) error = NULL;
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
g_autoptr(GTask) task = NULL;
GVariantBuilder opt_builder;
g_auto(GVariantBuilder) opt_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autoptr(GVariant) options = NULL;

REQUEST_AUTOLOCK (request);

g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options, &opt_builder,
background_options, G_N_ELEMENTS (background_options),
&error))
Expand Down Expand Up @@ -1155,7 +1159,8 @@ handle_set_status (XdpDbusBackground *object,
g_autoptr(GVariant) options = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = NULL;
GVariantBuilder opt_builder;
g_auto(GVariantBuilder) opt_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
const char *id = NULL;
Call *call;

Expand All @@ -1182,7 +1187,6 @@ handle_set_status (XdpDbusBackground *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options, &opt_builder,
set_status_options,
G_N_ELEMENTS (set_status_options),
Expand Down
9 changes: 4 additions & 5 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ query_permission_sync (Request *request)
permission = get_permission_sync (app_id, PERMISSION_TABLE, PERMISSION_DEVICE_CAMERA);
if (permission == PERMISSION_ASK || permission == PERMISSION_UNSET)
{
GVariantBuilder opt_builder;
g_auto(GVariantBuilder) opt_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autofree char *title = NULL;
g_autofree char *body = NULL;
guint32 response = 2;
Expand All @@ -98,7 +99,6 @@ query_permission_sync (Request *request)
info = (GAppInfo*)g_desktop_app_info_new (desktop_id);
}

g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&opt_builder, "{sv}", "icon", g_variant_new_string ("camera-web-symbolic"));

if (info)
Expand Down Expand Up @@ -173,11 +173,10 @@ handle_access_camera_in_thread_func (GTask *task,

if (request->exported)
{
GVariantBuilder results;
g_auto(GVariantBuilder) results =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
guint32 response;

g_variant_builder_init (&results, G_VARIANT_TYPE_VARDICT);

response = allowed ? XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS
: XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED;
g_debug ("Camera: sending response %d", response);
Expand Down
4 changes: 2 additions & 2 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ handle_set_selection (XdpDbusClipboard *object,
{
Call *call = call_from_invocation (invocation);
Session *session;
GVariantBuilder options_builder;
g_auto(GVariantBuilder) options_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autoptr(GVariant) options = NULL;
g_autoptr(GError) error = NULL;

Expand Down Expand Up @@ -148,7 +149,6 @@ handle_set_selection (XdpDbusClipboard *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

g_variant_builder_init (&options_builder, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options,
&options_builder,
clipboard_set_selection_options,
Expand Down
13 changes: 4 additions & 9 deletions src/dynamic-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,11 @@ prepare_install_done (GObject *source,
guint response = 2;
g_autoptr(GVariant) results = NULL;
g_autoptr(GError) error = NULL;
GVariantBuilder results_builder;
g_auto(GVariantBuilder) results_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

REQUEST_AUTOLOCK (request);

g_variant_builder_init (&results_builder, G_VARIANT_TYPE_VARDICT);

if (!xdp_dbus_impl_dynamic_launcher_call_prepare_install_finish (XDP_DBUS_IMPL_DYNAMIC_LAUNCHER (source),
&response,
&results,
Expand Down Expand Up @@ -542,10 +541,6 @@ prepare_install_done (GObject *source,

request_unexport (request);
}
else
{
g_variant_builder_clear (&results_builder);
}
}

static gboolean
Expand Down Expand Up @@ -620,7 +615,8 @@ handle_prepare_install (XdpDbusDynamicLauncher *object,
const char *app_id = xdp_app_info_get_id (request->app_info);
g_autoptr(GError) error = NULL;
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
GVariantBuilder opt_builder;
g_auto(GVariantBuilder) opt_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autofree char *icon_format = NULL;
g_autofree char *icon_size = NULL;
g_autoptr(GVariant) icon_v = NULL;
Expand All @@ -641,7 +637,6 @@ handle_prepare_install (XdpDbusDynamicLauncher *object,
request_set_impl_request (request, impl_request);
request_export (request, g_dbus_method_invocation_get_connection (invocation));

g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options, &opt_builder,
prepare_install_options, G_N_ELEMENTS (prepare_install_options), &error))
{
Expand Down
13 changes: 6 additions & 7 deletions src/email.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ send_response_in_thread_func (GTask *task,

if (request->exported)
{
GVariantBuilder new_results;
g_auto(GVariantBuilder) new_results =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

g_variant_builder_init (&new_results, G_VARIANT_TYPE_VARDICT);
xdp_dbus_request_emit_response (XDP_DBUS_REQUEST (request),
response,
g_variant_builder_end (&new_results));
Expand Down Expand Up @@ -213,13 +213,12 @@ handle_compose_email (XdpDbusEmail *object,
const char *app_id = xdp_app_info_get_id (request->app_info);
g_autoptr(GError) error = NULL;
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
g_auto(GVariantBuilder) options;
g_auto(GVariantBuilder) options =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autoptr(GVariant) attachment_fds = NULL;

g_debug ("Handling ComposeEmail");

g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);

REQUEST_AUTOLOCK (request);

impl_request = xdp_dbus_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)),
Expand All @@ -236,10 +235,10 @@ handle_compose_email (XdpDbusEmail *object,
attachment_fds = g_variant_lookup_value (arg_options, "attachment_fds", G_VARIANT_TYPE ("ah"));
if (attachment_fds)
{
GVariantBuilder attachments;
g_auto(GVariantBuilder) attachments =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_STRING_ARRAY);
int i;

g_variant_builder_init (&attachments, G_VARIANT_TYPE_STRING_ARRAY);
for (i = 0; i < g_variant_n_children (attachment_fds); i++)
{
g_autofree char *path = NULL;
Expand Down
21 changes: 10 additions & 11 deletions src/file-chooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ send_response_in_thread_func (GTask *task,
GCancellable *cancellable)
{
Request *request = task_data;
GVariantBuilder results;
GVariantBuilder ruris;
g_auto(GVariantBuilder) results =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_auto(GVariantBuilder) ruris =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_STRING_ARRAY);
guint response;
GVariant *options;
DocumentFlags flags = DOCUMENT_FLAG_WRITABLE | DOCUMENT_FLAG_DIRECTORY;
Expand All @@ -83,9 +85,6 @@ send_response_in_thread_func (GTask *task,
GVariant *current_filter;
GVariant *writable;

g_variant_builder_init (&results, G_VARIANT_TYPE_VARDICT);
g_variant_builder_init (&ruris, G_VARIANT_TYPE_STRING_ARRAY);

REQUEST_AUTOLOCK (request);

if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "for-save")) == TRUE)
Expand Down Expand Up @@ -531,14 +530,14 @@ handle_open_file (XdpDbusFileChooser *object,
const char *app_id = xdp_app_info_get_id (request->app_info);
g_autoptr(GError) error = NULL;
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
GVariantBuilder options;
g_auto(GVariantBuilder) options =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
g_autoptr(GVariant) dir_option = NULL;

g_debug ("Handling OpenFile");

REQUEST_AUTOLOCK (request);

g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options, &options,
open_file_options, G_N_ELEMENTS (open_file_options),
&error))
Expand Down Expand Up @@ -660,7 +659,8 @@ handle_save_file (XdpDbusFileChooser *object,
const char *app_id = xdp_app_info_get_id (request->app_info);
g_autoptr(GError) error = NULL;
XdpDbusImplRequest *impl_request;
GVariantBuilder options;
g_auto(GVariantBuilder) options =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

g_debug ("Handling SaveFile");

Expand All @@ -676,7 +676,6 @@ handle_save_file (XdpDbusFileChooser *object,

REQUEST_AUTOLOCK (request);

g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options, &options,
save_file_options, G_N_ELEMENTS (save_file_options),
&error))
Expand Down Expand Up @@ -819,7 +818,8 @@ handle_save_files (XdpDbusFileChooser *object,
const char *app_id = xdp_app_info_get_id (request->app_info);
g_autoptr(GError) error = NULL;
XdpDbusImplRequest *impl_request;
GVariantBuilder options;
g_auto(GVariantBuilder) options =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

if (xdp_dbus_impl_lockdown_get_disable_save_to_disk (lockdown))
{
Expand All @@ -833,7 +833,6 @@ handle_save_files (XdpDbusFileChooser *object,

REQUEST_AUTOLOCK (request);

g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
if (!xdp_filter_options (arg_options, &options,
save_files_options, G_N_ELEMENTS (save_files_options),
&error))
Expand Down
Loading
Loading