Skip to content

Commit

Permalink
UDisks2 migration.
Browse files Browse the repository at this point in the history
Migrate away from dbus-glib-1 wihich is deprecated.
Migrate from Udisks to Udisks2 DBus API.
  • Loading branch information
LStranger committed Feb 18, 2021
1 parent 695d3e8 commit cf809d9
Show file tree
Hide file tree
Showing 20 changed files with 1,324 additions and 3,019 deletions.
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes on 1.4.0 since 1.3.2:

* Migrated away from dbus-glib-1 which is deprecated for years.

* Migrated from Udisks (which is not used anymore anywhere) to Udisks2 DBus API.


Changes on 1.3.2 since 1.3.1:

* Fixed all/allfiles parse conditions in FmAction, it was inverted.
Expand Down
8 changes: 1 addition & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fi

AC_ARG_ENABLE(udisks,
[AC_HELP_STRING([--enable-udisks],
[build libfm with udisks support (Linux only) @<:@default=yes@:>@])],
[build libfm with udisks support (Linux only) @<:@default=no@:>@])],
[enable_udisks="${enableval}"],
[enable_udisks=no]
)
Expand All @@ -194,12 +194,6 @@ AM_CONDITIONAL(ENABLE_UDISKS, test x"$enable_udisks" = x"yes")
if test x"$enable_udisks" = x"yes"; then
# turn on udisks support
AC_DEFINE_UNQUOTED(USE_UDISKS, [1], [Enable UDisks support])

# test for availability of dbus
dbus_modules="dbus-glib-1"
PKG_CHECK_MODULES(DBUS, [$dbus_modules])
AC_SUBST(DBUS_CFLAGS)
AC_SUBST(DBUS_LIBS)
fi

AC_ARG_ENABLE([exif],
Expand Down
4 changes: 3 additions & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ src/modules/gtk-fileprop-x-desktop.c
src/modules/gtk-menu-trash.c
src/tools/libfm-pref-apps.c
src/tools/lxshortcut.c
src/udisks/g-udisks-device.c
src/udisks/g-udisks-drive.c
src/udisks/g-udisks-mount.c
src/udisks/g-udisks-volume.c
2 changes: 0 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ libfm_la_SOURCES = \
libfm_la_CFLAGS = \
$(GIO_CFLAGS) \
$(MENU_CACHE_CFLAGS) \
$(DBUS_CFLAGS) \
$(EXIF_CFLAGS) \
-DPACKAGE_DATA_DIR=\""$(datadir)/libfm"\" \
-DPACKAGE_MODULES_DIR=\""$(libdir)/@PACKAGE@/modules"\" \
Expand All @@ -269,7 +268,6 @@ libfm_la_CFLAGS = \
libfm_la_LIBADD = \
$(GIO_LIBS) \
$(MENU_CACHE_LIBS) \
$(DBUS_LIBS) \
$(EXIF_LIBS) \
$(INTLLIBS) \
$(NULL)
Expand Down
9 changes: 7 additions & 2 deletions src/base/fm-action.c
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,10 @@ static gboolean _matches_cond(FmFileInfoList *files, FmFileInfo *location,
gsize len;
int num;
gboolean match = TRUE, found, match_num;
#if GLIB_CHECK_VERSION(2, 24, 0)
GDBusConnection *conn;
GVariant *result;
#endif

if (files != NULL)
flist = fm_file_info_list_peek_head_link(files);
Expand Down Expand Up @@ -1832,8 +1836,8 @@ static gboolean _matches_cond(FmFileInfoList *files, FmFileInfo *location,
g_string_free(str, TRUE);
break;
case CONDITION_TYPE_DBUS: /* ShowIfRegistered */
#if defined(ENABLE_DBUS) && GLIB_CHECK_VERSION(2, 24, 0)
str = g_string_size_new(64);
#if GLIB_CHECK_VERSION(2, 24, 0)
str = g_string_sized_new(64);
_expand_params(str, cond->str, root, TRUE, NULL);
/* DBus call is taken from GLib sources: gio/tests/gdbus-names.c */
conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
Expand All @@ -1852,6 +1856,7 @@ static gboolean _matches_cond(FmFileInfoList *files, FmFileInfo *location,
g_variant_unref(result);
}
g_string_free(str, TRUE);
g_object_unref(conn);
#endif
break;
case CONDITION_TYPE_OUT_TRUE: /* ShowIfTrue */
Expand Down
13 changes: 1 addition & 12 deletions src/udisks/dbus-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,13 @@
#include "dbus-utils.h"
#include <gio/gio.h>

GHashTable* dbus_get_all_props(DBusGProxy* proxy, const char* iface, GError** err)
{
GHashTable* props = NULL;
dbus_g_proxy_call(proxy, "GetAll", err,
G_TYPE_STRING, iface, G_TYPE_INVALID,
dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID);
return props;
}


GError* g_udisks_error_to_gio_error(GError* error)
{
if(error)
{
int code = G_IO_ERROR_FAILED;
error = g_error_new_literal(G_IO_ERROR, code, error->message);
return error;
}
return NULL;
return error;
}

84 changes: 22 additions & 62 deletions src/udisks/dbus-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* dbus-utils.h
*
* Copyright 2010 PCMan <[email protected]>
* Copyright 2021 Andriy Grytsenko (LStranger) <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,83 +23,42 @@
#ifndef __DBUS_UTILS_H__
#define __DBUS_UTILS_H__

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

G_BEGIN_DECLS

// char* dbus_get_prop(DBusGProxy* proxy, const char* iface, const char* prop);
GHashTable* dbus_get_all_props(DBusGProxy* proxy, const char* iface, GError** err);

static inline const char* dbus_prop_str(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_get_string(val) : NULL;
}

static inline const char* dbus_prop_obj_path(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? (char*)g_value_get_boxed(val) : NULL;
}

static inline const char** dbus_prop_strv(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? (const char**)g_value_get_boxed(val) : NULL;
}

static inline char* dbus_prop_dup_str(GHashTable* props, const char* name)
static inline char* dbus_prop_dup_str(GDBusProxy* proxy, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_dup_string(val) : NULL;
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
char *str = var ? g_variant_dup_string(var, NULL) : NULL;
if (var) g_variant_unref(var);
return str;
}

static inline char* dbus_prop_dup_obj_path(GHashTable* props, const char* name)
static inline char** dbus_prop_dup_strv(GDBusProxy* proxy, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_strdup((char*)g_value_get_boxed(val)) : NULL;
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
char **strv = var ? g_variant_dup_bytestring_array(var, NULL) : NULL;
if (var) g_variant_unref(var);
return strv;
}

static inline char** dbus_prop_dup_strv(GHashTable* props, const char* name)
static inline gboolean dbus_prop_bool(GDBusProxy* proxy, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_dup_boxed(val) : NULL;
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
gboolean val = var ? g_variant_get_boolean(var) : FALSE;
if (var) g_variant_unref(var);
return val;
}

static inline gboolean dbus_prop_bool(GHashTable* props, const char* name)
static inline guint dbus_prop_uint(GDBusProxy* proxy, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_get_boolean(val) : FALSE;
GVariant *var = g_dbus_proxy_get_cached_property(proxy, name);
guint val = var ? g_variant_get_uint32(var) : 0;
if (var) g_variant_unref(var);
return val;
}

static inline gint dbus_prop_int(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_get_int(val) : 0;
}

static inline guint dbus_prop_uint(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_get_uint(val) : 0;
}

static inline gint64 dbus_prop_int64(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_get_int64(val) : 0;
}

static inline guint64 dbus_prop_uint64(GHashTable* props, const char* name)
{
GValue* val = (GValue*)g_hash_table_lookup(props, name);
return val ? g_value_get_uint64(val) : 0;
}

// GHashTable* dbus_get_prop_async();
// GHashTable* dbus_get_all_props_async();

GError* g_udisks_error_to_gio_error(GError* error);

G_END_DECLS
Expand Down
Loading

0 comments on commit cf809d9

Please sign in to comment.