Skip to content

Commit cf809d9

Browse files
committed
UDisks2 migration.
Migrate away from dbus-glib-1 wihich is deprecated. Migrate from Udisks to Udisks2 DBus API.
1 parent 695d3e8 commit cf809d9

20 files changed

+1324
-3019
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Changes on 1.4.0 since 1.3.2:
2+
3+
* Migrated away from dbus-glib-1 which is deprecated for years.
4+
5+
* Migrated from Udisks (which is not used anymore anywhere) to Udisks2 DBus API.
6+
7+
18
Changes on 1.3.2 since 1.3.1:
29

310
* Fixed all/allfiles parse conditions in FmAction, it was inverted.

configure.ac

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fi
184184

185185
AC_ARG_ENABLE(udisks,
186186
[AC_HELP_STRING([--enable-udisks],
187-
[build libfm with udisks support (Linux only) @<:@default=yes@:>@])],
187+
[build libfm with udisks support (Linux only) @<:@default=no@:>@])],
188188
[enable_udisks="${enableval}"],
189189
[enable_udisks=no]
190190
)
@@ -194,12 +194,6 @@ AM_CONDITIONAL(ENABLE_UDISKS, test x"$enable_udisks" = x"yes")
194194
if test x"$enable_udisks" = x"yes"; then
195195
# turn on udisks support
196196
AC_DEFINE_UNQUOTED(USE_UDISKS, [1], [Enable UDisks support])
197-
198-
# test for availability of dbus
199-
dbus_modules="dbus-glib-1"
200-
PKG_CHECK_MODULES(DBUS, [$dbus_modules])
201-
AC_SUBST(DBUS_CFLAGS)
202-
AC_SUBST(DBUS_LIBS)
203197
fi
204198

205199
AC_ARG_ENABLE([exif],

po/POTFILES.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ src/modules/gtk-fileprop-x-desktop.c
4848
src/modules/gtk-menu-trash.c
4949
src/tools/libfm-pref-apps.c
5050
src/tools/lxshortcut.c
51-
src/udisks/g-udisks-device.c
51+
src/udisks/g-udisks-drive.c
52+
src/udisks/g-udisks-mount.c
53+
src/udisks/g-udisks-volume.c

src/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ libfm_la_SOURCES = \
260260
libfm_la_CFLAGS = \
261261
$(GIO_CFLAGS) \
262262
$(MENU_CACHE_CFLAGS) \
263-
$(DBUS_CFLAGS) \
264263
$(EXIF_CFLAGS) \
265264
-DPACKAGE_DATA_DIR=\""$(datadir)/libfm"\" \
266265
-DPACKAGE_MODULES_DIR=\""$(libdir)/@PACKAGE@/modules"\" \
@@ -269,7 +268,6 @@ libfm_la_CFLAGS = \
269268
libfm_la_LIBADD = \
270269
$(GIO_LIBS) \
271270
$(MENU_CACHE_LIBS) \
272-
$(DBUS_LIBS) \
273271
$(EXIF_LIBS) \
274272
$(INTLLIBS) \
275273
$(NULL)

src/base/fm-action.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,10 @@ static gboolean _matches_cond(FmFileInfoList *files, FmFileInfo *location,
17291729
gsize len;
17301730
int num;
17311731
gboolean match = TRUE, found, match_num;
1732+
#if GLIB_CHECK_VERSION(2, 24, 0)
1733+
GDBusConnection *conn;
1734+
GVariant *result;
1735+
#endif
17321736

17331737
if (files != NULL)
17341738
flist = fm_file_info_list_peek_head_link(files);
@@ -1832,8 +1836,8 @@ static gboolean _matches_cond(FmFileInfoList *files, FmFileInfo *location,
18321836
g_string_free(str, TRUE);
18331837
break;
18341838
case CONDITION_TYPE_DBUS: /* ShowIfRegistered */
1835-
#if defined(ENABLE_DBUS) && GLIB_CHECK_VERSION(2, 24, 0)
1836-
str = g_string_size_new(64);
1839+
#if GLIB_CHECK_VERSION(2, 24, 0)
1840+
str = g_string_sized_new(64);
18371841
_expand_params(str, cond->str, root, TRUE, NULL);
18381842
/* DBus call is taken from GLib sources: gio/tests/gdbus-names.c */
18391843
conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
@@ -1852,6 +1856,7 @@ static gboolean _matches_cond(FmFileInfoList *files, FmFileInfo *location,
18521856
g_variant_unref(result);
18531857
}
18541858
g_string_free(str, TRUE);
1859+
g_object_unref(conn);
18551860
#endif
18561861
break;
18571862
case CONDITION_TYPE_OUT_TRUE: /* ShowIfTrue */

src/udisks/dbus-utils.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,13 @@
2626
#include "dbus-utils.h"
2727
#include <gio/gio.h>
2828

29-
GHashTable* dbus_get_all_props(DBusGProxy* proxy, const char* iface, GError** err)
30-
{
31-
GHashTable* props = NULL;
32-
dbus_g_proxy_call(proxy, "GetAll", err,
33-
G_TYPE_STRING, iface, G_TYPE_INVALID,
34-
dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID);
35-
return props;
36-
}
37-
38-
3929
GError* g_udisks_error_to_gio_error(GError* error)
4030
{
4131
if(error)
4232
{
4333
int code = G_IO_ERROR_FAILED;
4434
error = g_error_new_literal(G_IO_ERROR, code, error->message);
45-
return error;
4635
}
47-
return NULL;
36+
return error;
4837
}
4938

src/udisks/dbus-utils.h

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* dbus-utils.h
33
*
44
* Copyright 2010 PCMan <[email protected]>
5+
* Copyright 2021 Andriy Grytsenko (LStranger) <[email protected]>
56
*
67
* This program is free software; you can redistribute it and/or modify
78
* it under the terms of the GNU General Public License as published by
@@ -22,83 +23,42 @@
2223
#ifndef __DBUS_UTILS_H__
2324
#define __DBUS_UTILS_H__
2425

25-
#include <glib.h>
26-
#include <dbus/dbus-glib.h>
26+
#include <gio/gio.h>
2727

2828
G_BEGIN_DECLS
2929

30-
// char* dbus_get_prop(DBusGProxy* proxy, const char* iface, const char* prop);
31-
GHashTable* dbus_get_all_props(DBusGProxy* proxy, const char* iface, GError** err);
32-
33-
static inline const char* dbus_prop_str(GHashTable* props, const char* name)
34-
{
35-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
36-
return val ? g_value_get_string(val) : NULL;
37-
}
38-
39-
static inline const char* dbus_prop_obj_path(GHashTable* props, const char* name)
40-
{
41-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
42-
return val ? (char*)g_value_get_boxed(val) : NULL;
43-
}
44-
45-
static inline const char** dbus_prop_strv(GHashTable* props, const char* name)
46-
{
47-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
48-
return val ? (const char**)g_value_get_boxed(val) : NULL;
49-
}
50-
51-
static inline char* dbus_prop_dup_str(GHashTable* props, const char* name)
30+
static inline char* dbus_prop_dup_str(GDBusProxy* proxy, const char* name)
5231
{
53-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
54-
return val ? g_value_dup_string(val) : NULL;
32+
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
33+
char *str = var ? g_variant_dup_string(var, NULL) : NULL;
34+
if (var) g_variant_unref(var);
35+
return str;
5536
}
5637

57-
static inline char* dbus_prop_dup_obj_path(GHashTable* props, const char* name)
38+
static inline char** dbus_prop_dup_strv(GDBusProxy* proxy, const char* name)
5839
{
59-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
60-
return val ? g_strdup((char*)g_value_get_boxed(val)) : NULL;
40+
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
41+
char **strv = var ? g_variant_dup_bytestring_array(var, NULL) : NULL;
42+
if (var) g_variant_unref(var);
43+
return strv;
6144
}
6245

63-
static inline char** dbus_prop_dup_strv(GHashTable* props, const char* name)
46+
static inline gboolean dbus_prop_bool(GDBusProxy* proxy, const char* name)
6447
{
65-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
66-
return val ? g_value_dup_boxed(val) : NULL;
48+
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
49+
gboolean val = var ? g_variant_get_boolean(var) : FALSE;
50+
if (var) g_variant_unref(var);
51+
return val;
6752
}
6853

69-
static inline gboolean dbus_prop_bool(GHashTable* props, const char* name)
54+
static inline guint dbus_prop_uint(GDBusProxy* proxy, const char* name)
7055
{
71-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
72-
return val ? g_value_get_boolean(val) : FALSE;
56+
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
57+
guint val = var ? g_variant_get_uint32(var) : 0;
58+
if (var) g_variant_unref(var);
59+
return val;
7360
}
7461

75-
static inline gint dbus_prop_int(GHashTable* props, const char* name)
76-
{
77-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
78-
return val ? g_value_get_int(val) : 0;
79-
}
80-
81-
static inline guint dbus_prop_uint(GHashTable* props, const char* name)
82-
{
83-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
84-
return val ? g_value_get_uint(val) : 0;
85-
}
86-
87-
static inline gint64 dbus_prop_int64(GHashTable* props, const char* name)
88-
{
89-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
90-
return val ? g_value_get_int64(val) : 0;
91-
}
92-
93-
static inline guint64 dbus_prop_uint64(GHashTable* props, const char* name)
94-
{
95-
GValue* val = (GValue*)g_hash_table_lookup(props, name);
96-
return val ? g_value_get_uint64(val) : 0;
97-
}
98-
99-
// GHashTable* dbus_get_prop_async();
100-
// GHashTable* dbus_get_all_props_async();
101-
10262
GError* g_udisks_error_to_gio_error(GError* error);
10363

10464
G_END_DECLS

0 commit comments

Comments
 (0)