Miscellaneous Utilities

Miscellaneous Utilities — Miscellaneous utilities

Functions

Description

An assortment of simple utility functions.

Functions

fcmdr_json_value_to_variant ()

GVariant *
fcmdr_json_value_to_variant (JsonNode *json_node);

Converts a JsonNode containing a fundamental type to a GVariant. The resulting GVariantType will be one of G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_DOUBLE, G_VARIANT_TYPE_BOOLEAN or G_VARIANT_TYPE_STRING.

Parameters

json_node

a JsonNode

 

Returns

a floating reference to a new GVariant instance


fcmdr_json_array_to_strv ()

gchar **
fcmdr_json_array_to_strv (JsonArray *json_array);

Builds a NULL-terminated string array from the string elements in json_array . Free the returned string array with g_strfreev().

Parameters

json_array

a JsonArray

 

Returns

a new NULL-terminated string array


fcmdr_strv_to_json_array ()

JsonArray *
fcmdr_strv_to_json_array (gchar **strv);

Converts a NULL-terminated string array to a JsonArray with equivalent string elements. If strv is NULL, the function returns an empty JsonArray.

Parameters

strv

a NULL-terminated string array, or NULL

 

Returns

a new JsonArray


fcmdr_strv_find ()

gint
fcmdr_strv_find (gchar **haystack,
                 const gchar *needle);

Returns the array index of needle in haystack , or -1 if not found. As a convenience, haystack may be NULL, in which case the function returns -1.

Parameters

haystack

a NULL-terminated string array to search, or NULL

 

needle

a string to search for

 

Returns

an array index in haystack , or -1


fcmdr_compare_uints ()

gint
fcmdr_compare_uints (gconstpointer a,
                     gconstpointer b);

Compares two unsigned integers stuffed into pointers with GUINT_TO_POINTER. For use with functions that take a GCompareFunc.

Parameters

a

an unsigned integer stuffed in a pointer

 

b

an unsigned integer stuffed in a pointer

 

Returns

negative value if a < b ; zero if a = b ; positive value if a > b


fcmdr_replace_variables ()

gchar *
fcmdr_replace_variables (const gchar *string,
                         GHashTable *symbol_table);

Scans string for occurrences of the pattern "${SYMBOL}" and replaces them with the string value for "SYMBOL" in symbol_table (if it exists). Free the returned string with g_free().

Parameters

string

a string which may have variables

 

symbol_table

a table of variable names and string values

 

Returns

a newly-allocated copy of string with variables replaced


fcmdr_recursive_delete_sync ()

gboolean
fcmdr_recursive_delete_sync (GFile *file,
                             GCancellable *cancellable,
                             GError **error);

Deletes file . If file is a directory, its contents are deleted recursively before file itself is deleted. The recursive delete operation will stop on the first error.

If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned.

Parameters

file

a GFile to delete

 

cancellable

optional GCancellable object, or NULL

 

error

return location for a GError, or NULL

 

Returns

TRUE if the file was deleted, FALSE otherwise


fcmdr_get_connection_unix_user_sync ()

gboolean
fcmdr_get_connection_unix_user_sync (GDBusConnection *connection,
                                     const gchar *bus_name,
                                     uid_t *out_uid,
                                     GCancellable *cancellable,
                                     GError **error);

Returns the UNIX user ID of the process owning the given bus_name . If unable to determine it, the function sets error and returns FALSE.

This function synchronously invokes the "GetConnectionUnixUser" method of the "org.freedesktop.DBus" interface on the message bus represented by connection .

Parameters

connection

a GDBusConnection

 

bus_name

a name owned by connection

 

out_uid

return location for a user ID

 

cancellable

optional GCancellable object, or NULL

 

error

return location for a GError, or NULL

 

Returns

TRUE if the method call succeeded, FALSE if error is set

Types and Values