Skip to content

Commit

Permalink
datetime: Use Gio's dbus implementation.
Browse files Browse the repository at this point in the history
This removes dbus as a dependency.

Fedora and Suse need to be tested.
  • Loading branch information
mtwebster committed Jun 9, 2022
1 parent b4f0f87 commit 813790b
Show file tree
Hide file tree
Showing 12 changed files with 578 additions and 632 deletions.
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Build-Depends:
libcolord-dev (>= 0.1.27),
libcups2-dev,
libcvc-dev (>= 3.4~),
libdbus-glib-1-dev (>= 0.88),
libfontconfig1-dev,
libglib2.0-dev (>= 2.37.3),
libgnomekbd-dev (>= 3.6.0),
Expand Down
9 changes: 0 additions & 9 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ xi = dependency('xi')
xklavier = dependency('libxklavier', version: '>= 5.0')
xtst = dependency('xtst')

# currently we only use dbus if we're also using polkit if this changes in the future we can
# simply remove the required field here
dbus = dependency('dbus-1', version: '>= 1.1.2', required: polkit.found())
dbus_glib = dependency('dbus-glib-1', required: polkit.found())

# currently only used for the wacom plugin
librsvg = dependency('librsvg-2.0', version: '>= 2.36.2', required: wacom.found())
xorg_wacom = dependency('xorg-wacom', required: wacom.found())
Expand Down Expand Up @@ -103,10 +98,6 @@ endif
cc = meson.get_compiler('c')
math = cc.find_library('m', required: false)

# currently used by the datetime plugin, but dbus-glib is deprecated so we
# should port it to gdbus asap, and this should be removed at that point
dbus_binding_tool = find_program('dbus-binding-tool')

csd_conf = configuration_data()
csd_conf.set_quoted('GTKBUILDERDIR', gtkbuilderdir)
csd_conf.set_quoted('CINNAMON_SETTINGS_LOCALEDIR', localedir)
Expand Down
20 changes: 9 additions & 11 deletions plugins/datetime/csd-datetime-mechanism-debian.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,22 @@ _get_using_ntpd (gboolean *can_use, gboolean *is_using, GError ** error)
}

gboolean
_get_using_ntp_debian (DBusGMethodInvocation *context)
_get_using_ntp_debian (GDBusMethodInvocation *invocation,
gboolean *can_use_ntp,
gboolean *is_using_ntp)
{
gboolean can_use_ntp = FALSE;
gboolean is_using_ntp = FALSE;
GError *error = NULL;

/* In Debian, ntpdate is used whenever the network comes up. So if
either ntpdate or ntpd is installed and available, can_use is true.
If either is active, is_using is true. */
_get_using_ntpdate (&can_use_ntp, &is_using_ntp, &error);
_get_using_ntpd (&can_use_ntp, &is_using_ntp, &error);
_get_using_ntpdate (can_use_ntp, is_using_ntp, &error);
_get_using_ntpd (can_use_ntp, is_using_ntp, &error);

if (error == NULL) {
dbus_g_method_return (context, can_use_ntp, is_using_ntp);
return TRUE;
} else {
dbus_g_method_return_error (context, error);
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
return FALSE;
}
Expand Down Expand Up @@ -177,8 +176,8 @@ _set_using_ntpd (gboolean using_ntp, GError **error)
}

gboolean
_set_using_ntp_debian (DBusGMethodInvocation *context,
gboolean using_ntp)
_set_using_ntp_debian (GDBusMethodInvocation *invocation,
gboolean using_ntp)
{
GError *error = NULL;

Expand All @@ -189,10 +188,9 @@ _set_using_ntp_debian (DBusGMethodInvocation *context,
_set_using_ntpd (using_ntp, &error);

if (error == NULL) {
dbus_g_method_return (context);
return TRUE;
} else {
dbus_g_method_return_error (context, error);
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
return FALSE;
}
Expand Down
10 changes: 6 additions & 4 deletions plugins/datetime/csd-datetime-mechanism-debian.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
*/

#include <glib.h>
#include <dbus/dbus-glib.h>
#include <gio/gio.h>

gboolean _get_using_ntp_debian (DBusGMethodInvocation *context);
gboolean _set_using_ntp_debian (DBusGMethodInvocation *context,
gboolean using_ntp);
gboolean _get_using_ntp_debian (GDBusMethodInvocation *invocation,
gboolean *can_use_ntp,
gboolean *is_using_ntp);
gboolean _set_using_ntp_debian (GDBusMethodInvocation *invocation,
gboolean using_ntp);
36 changes: 18 additions & 18 deletions plugins/datetime/csd-datetime-mechanism-fedora.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ get_ntp_client ()
}

gboolean
_get_using_ntp_fedora (DBusGMethodInvocation *context)
_get_using_ntp_fedora (GDBusMethodInvocation *invocation,
gboolean *can_use_ntp,
gboolean *is_using_ntp)
{
int exit_status;
GError *error = NULL;
gboolean can_use_ntp;
gboolean is_using_ntp;
const char *ntp_client;
char *cmd;

ntp_client = get_ntp_client ();
if (ntp_client) {
can_use_ntp = TRUE;
*can_use_ntp = TRUE;
cmd = g_strconcat ("/sbin/service ", ntp_client, " status", NULL);
if (!g_spawn_command_line_sync (cmd,
NULL, NULL, &exit_status, &error)) {
Expand All @@ -61,28 +61,27 @@ _get_using_ntp_fedora (DBusGMethodInvocation *context)
CSD_DATETIME_MECHANISM_ERROR_GENERAL,
"Error spawning /sbin/service: %s", error->message);
g_error_free (error);
dbus_g_method_return_error (context, error2);
g_dbus_method_invocation_return_gerror (invocation, error2);
g_error_free (error2);
g_free (cmd);
return FALSE;
}
g_free (cmd);
if (exit_status == 0)
is_using_ntp = TRUE;
*is_using_ntp = TRUE;
else
is_using_ntp = FALSE;
*is_using_ntp = FALSE;
}
else {
can_use_ntp = FALSE;
is_using_ntp = FALSE;
*can_use_ntp = FALSE;
*is_using_ntp = FALSE;
}

dbus_g_method_return (context, can_use_ntp, is_using_ntp);
return TRUE;
}

gboolean
_set_using_ntp_fedora (DBusGMethodInvocation *context,
_set_using_ntp_fedora (GDBusMethodInvocation *invocation,
gboolean using_ntp)
{
GError *error;
Expand All @@ -105,7 +104,7 @@ _set_using_ntp_fedora (DBusGMethodInvocation *context,
CSD_DATETIME_MECHANISM_ERROR_GENERAL,
"Error spawning '%s': %s", cmd, error->message);
g_error_free (error);
dbus_g_method_return_error (context, error2);
g_dbus_method_invocation_return_gerror (invocation, error2);
g_error_free (error2);
g_free (cmd);
return FALSE;
Expand All @@ -122,20 +121,21 @@ _set_using_ntp_fedora (DBusGMethodInvocation *context,
CSD_DATETIME_MECHANISM_ERROR_GENERAL,
"Error spawning '%s': %s", cmd, error->message);
g_error_free (error);
dbus_g_method_return_error (context, error2);
g_dbus_method_invocation_return_gerror (invocation, error2);
g_error_free (error2);
g_free (cmd);
return FALSE;
}

g_free (cmd);

dbus_g_method_return (context);
return TRUE;
}

gboolean
_update_etc_sysconfig_clock_fedora (DBusGMethodInvocation *context, const char *key, const char *value)
_update_etc_sysconfig_clock_fedora (GDBusMethodInvocation *invocation,
const char *key,
const char *value)
{
char **lines;
int n;
Expand All @@ -149,7 +149,7 @@ _update_etc_sysconfig_clock_fedora (DBusGMethodInvocation *context, const char *
error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
CSD_DATETIME_MECHANISM_ERROR_GENERAL,
"Error reading /etc/sysconfig/clock file: %s", "No such file");
dbus_g_method_return_error (context, error);
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
return FALSE;
}
Expand All @@ -162,7 +162,7 @@ _update_etc_sysconfig_clock_fedora (DBusGMethodInvocation *context, const char *
CSD_DATETIME_MECHANISM_ERROR_GENERAL,
"Error reading /etc/sysconfig/clock file: %s", error->message);
g_error_free (error);
dbus_g_method_return_error (context, error2);
g_dbus_method_invocation_return_gerror (invocation, error2);
g_error_free (error2);
return FALSE;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ _update_etc_sysconfig_clock_fedora (DBusGMethodInvocation *context, const char *
CSD_DATETIME_MECHANISM_ERROR_GENERAL,
"Error updating /etc/sysconfig/clock: %s", error->message);
g_error_free (error);
dbus_g_method_return_error (context, error2);
g_dbus_method_invocation_return_gerror (invocation, error2);
g_error_free (error2);
g_free (data);
return FALSE;
Expand Down
15 changes: 8 additions & 7 deletions plugins/datetime/csd-datetime-mechanism-fedora.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
*/

#include <glib.h>
#include <dbus/dbus-glib.h>
#include <gio/gio.h>

gboolean _get_using_ntp_fedora (DBusGMethodInvocation *context);
gboolean _set_using_ntp_fedora (DBusGMethodInvocation *context,
gboolean _get_using_ntp_fedora (GDBusMethodInvocation *invocation,
gboolean *can_use_ntp,
gboolean *is_using_ntp);
gboolean _set_using_ntp_fedora (GDBusMethodInvocation *invocation,
gboolean using_ntp);
gboolean _update_etc_sysconfig_clock_fedora
(DBusGMethodInvocation *context,
const char *key,
const char *value);
gboolean _update_etc_sysconfig_clock_fedora (GDBusMethodInvocation *invocation,
const char *key,
const char *value);
Loading

0 comments on commit 813790b

Please sign in to comment.