Use defines for bus names

This helps eradicate typos (we had some here).

Closes https://gitlab.gnome.org/GNOME/gtk/issues/1267
This commit is contained in:
Matthias Clasen 2018-08-15 22:53:05 +00:00
parent b4d4f73d9f
commit a01feae15b
5 changed files with 47 additions and 34 deletions

View File

@ -24,9 +24,13 @@
#include "gtkapplicationprivate.h"
#include "gtksettings.h"
#include "gtkprivate.h"
G_DEFINE_TYPE (GtkApplicationImplDBus, gtk_application_impl_dbus, GTK_TYPE_APPLICATION_IMPL)
#define DBUS_BUS_NAME "org.freedesktop.DBus"
#define DBUS_OBJECT_PATH "/org/freedesktop/DBus"
#define DBUS_BUS_INTERFACE "org.freedesktop.DBus"
#define GNOME_DBUS_NAME "org.gnome.SessionManager"
#define GNOME_DBUS_OBJECT_PATH "/org/gnome/SessionManager"
#define GNOME_DBUS_INTERFACE "org.gnome.SessionManager"
@ -304,9 +308,9 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
if (id && id[0])
{
res = g_dbus_connection_call_sync (dbus->session,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_BUS_NAME,
DBUS_OBJECT_PATH,
DBUS_BUS_INTERFACE,
"GetId",
NULL,
NULL,
@ -340,9 +344,9 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
{
dbus->inhibit_proxy = gtk_application_get_proxy_if_service_present (dbus->session,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Inhibit",
PORTAL_BUS_NAME,
PORTAL_OBJECT_PATH,
PORTAL_INHIBIT_INTERFACE,
&error);
if (error)
{
@ -608,9 +612,9 @@ gtk_application_impl_dbus_uninhibit (GtkApplicationImpl *impl,
if (handle->cookie == cookie)
{
g_dbus_connection_call (dbus->session,
"org.freedesktop.portal.Desktop",
PORTAL_BUS_NAME,
handle->handle,
"org.freedesktop.portal.Request",
PORTAL_REQUEST_INTERFACE,
"Close",
g_variant_new ("()"),
G_VARIANT_TYPE_UNIT,

View File

@ -59,9 +59,9 @@ gtk_color_picker_portal_initable_init (GInitable *initable,
picker->portal_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Screenshot",
PORTAL_BUS_NAME,
PORTAL_OBJECT_PATH,
PORTAL_SCREENSHOT_INTERFACE,
NULL,
error);
@ -74,7 +74,7 @@ gtk_color_picker_portal_initable_init (GInitable *initable,
owner = g_dbus_proxy_get_name_owner (picker->portal_proxy);
if (owner == NULL)
{
g_debug ("org.freedesktop.portal.Screenshot not provided");
g_debug ("%s not provided", PORTAL_SCREENSHOT_INTERFACE);
g_clear_object (&picker->portal_proxy);
return FALSE;
}
@ -197,10 +197,10 @@ gtk_color_picker_portal_pick (GtkColorPicker *cp,
if (sender[i] == '.')
sender[i] = '_';
handle = g_strdup_printf ("/org/freedesktop/portal/desktop/request/%s/%s", sender, token);
handle = g_strconcat (PORTAL_OBJECT_PATH "/request/", sender, "/", token, NULL);
picker->portal_signal_id = g_dbus_connection_signal_subscribe (connection,
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Request",
PORTAL_BUS_NAME,
PORTAL_REQUEST_INTERFACE,
"Response",
handle,
NULL,

View File

@ -152,9 +152,9 @@ send_close (FilechooserPortalData *data)
GDBusMessage *message;
GError *error = NULL;
message = g_dbus_message_new_method_call ("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.FileChooser",
message = g_dbus_message_new_method_call (PORTAL_BUS_NAME,
PORTAL_OBJECT_PATH,
PORTAL_FILECHOOSER_INTERFACE,
"Close");
g_dbus_message_set_body (message,
g_variant_new ("(o)", data->portal_handle));
@ -216,8 +216,8 @@ open_file_msg_cb (GObject *source_object,
data->portal_response_signal_id =
g_dbus_connection_signal_subscribe (data->connection,
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Request",
PORTAL_BUS_NAME,
PORTAL_REQUEST_INTERFACE,
"Response",
data->portal_handle,
NULL,
@ -299,9 +299,9 @@ show_portal_file_chooser (GtkFileChooserNative *self,
char *sender;
int i;
message = g_dbus_message_new_method_call ("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.FileChooser",
message = g_dbus_message_new_method_call (PORTAL_BUS_NAME,
PORTAL_OBJECT_PATH,
PORTAL_FILECHOOSER_INTERFACE,
data->method_name);
token = g_strdup_printf ("gtk%d", g_random_int_range (0, G_MAXINT));
@ -310,13 +310,13 @@ show_portal_file_chooser (GtkFileChooserNative *self,
if (sender[i] == '.')
sender[i] = '_';
data->portal_handle = g_strdup_printf ("/org/fredesktop/portal/desktop/request/%s/%s", sender, token);
data->portal_handle = g_strconcat (PORTAL_OBJECT_PATH "/request/", sender, "/", token, NULL);
g_free (sender);
data->portal_response_signal_id =
g_dbus_connection_signal_subscribe (data->connection,
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Request",
PORTAL_BUS_NAME,
PORTAL_REQUEST_INTERFACE,
"Response",
data->portal_handle,
NULL,

View File

@ -37,6 +37,7 @@
#include "gtkshow.h"
#include "gtkintl.h"
#include "gtkwindowprivate.h"
#include "gtkprivate.h"
typedef struct {
@ -461,8 +462,8 @@ prepare_print_called (GObject *source,
portal->response_signal_id);
portal->response_signal_id =
g_dbus_connection_signal_subscribe (g_dbus_proxy_get_connection (G_DBUS_PROXY (portal->proxy)),
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Request",
PORTAL_BUS_NAME,
PORTAL_REQUEST_INTERFACE,
"Response",
handle,
NULL,
@ -491,9 +492,9 @@ create_portal_data (GtkPrintOperation *op,
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Print",
PORTAL_BUS_NAME,
PORTAL_OBJECT_PATH,
PORTAL_PRINT_INTERFACE,
NULL,
&error);
@ -564,13 +565,13 @@ call_prepare_print (GtkPrintOperation *op,
if (sender[i] == '.')
sender[i] = '_';
portal->prepare_print_handle = g_strdup_printf ("/org/fredesktop/portal/desktop/request/%s/%s", sender, token);
portal->prepare_print_handle = g_strconcat (PORTAL_OBJECT_PATH "/request/", sender, "/", token, NULL);
g_free (sender);
portal->response_signal_id =
g_dbus_connection_signal_subscribe (g_dbus_proxy_get_connection (G_DBUS_PROXY (portal->proxy)),
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Request",
PORTAL_BUS_NAME,
PORTAL_REQUEST_INTERFACE,
"Response",
portal->prepare_print_handle,
NULL,

View File

@ -111,6 +111,14 @@ void _gtk_set_slowdown (gdouble slowdown_factor);
gboolean gtk_should_use_portal (void);
#define PORTAL_BUS_NAME "org.freedesktop.portal.Desktop"
#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
#define PORTAL_REQUEST_INTERFACE "org.freedesktop.portal.Request"
#define PORTAL_FILECHOOSER_INTERFACE "org.freedesktop.portal.FileChooser"
#define PORTAL_PRINT_INTERFACE "org.freedesktop.portal.Print"
#define PORTAL_SCREENSHOT_INTERFACE "org.freedesktop.portal.Screenshot"
#define PORTAL_INHIBIT_INTERFACE "org.freedesktop.portal.Inhibit"
#ifdef G_OS_WIN32
void _gtk_load_dll_with_libgtk3_manifest (const char *dllname);
#endif