mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
gfileinfo: add file_path methods for language bindings
Including some tests by Philip Withnall.
This commit is contained in:
parent
7a82da2992
commit
04b683c34f
@ -391,6 +391,7 @@ g_file_info_get_attribute_status
|
|||||||
g_file_info_get_attribute_string
|
g_file_info_get_attribute_string
|
||||||
g_file_info_get_attribute_stringv
|
g_file_info_get_attribute_stringv
|
||||||
g_file_info_get_attribute_byte_string
|
g_file_info_get_attribute_byte_string
|
||||||
|
g_file_info_get_attribute_file_path
|
||||||
g_file_info_get_attribute_boolean
|
g_file_info_get_attribute_boolean
|
||||||
g_file_info_get_attribute_uint32
|
g_file_info_get_attribute_uint32
|
||||||
g_file_info_get_attribute_int32
|
g_file_info_get_attribute_int32
|
||||||
@ -402,6 +403,7 @@ g_file_info_set_attribute_status
|
|||||||
g_file_info_set_attribute_string
|
g_file_info_set_attribute_string
|
||||||
g_file_info_set_attribute_stringv
|
g_file_info_set_attribute_stringv
|
||||||
g_file_info_set_attribute_byte_string
|
g_file_info_set_attribute_byte_string
|
||||||
|
g_file_info_set_attribute_file_path
|
||||||
g_file_info_set_attribute_boolean
|
g_file_info_set_attribute_boolean
|
||||||
g_file_info_set_attribute_uint32
|
g_file_info_set_attribute_uint32
|
||||||
g_file_info_set_attribute_int32
|
g_file_info_set_attribute_int32
|
||||||
|
@ -966,6 +966,30 @@ g_file_info_get_attribute_byte_string (GFileInfo *info,
|
|||||||
return _g_file_attribute_value_get_byte_string (value);
|
return _g_file_attribute_value_get_byte_string (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_file_info_get_attribute_file_path:
|
||||||
|
* @info: a #GFileInfo.
|
||||||
|
* @attribute: a file attribute key.
|
||||||
|
*
|
||||||
|
* Gets the value of a byte string attribute as a file path.
|
||||||
|
*
|
||||||
|
* If the attribute does not contain a byte string, `NULL` will be returned.
|
||||||
|
*
|
||||||
|
* This function is meant to be used by language bindings that have specific
|
||||||
|
* handling for Unix paths.
|
||||||
|
*
|
||||||
|
* Returns: (type filename) (nullable): the contents of the @attribute value as
|
||||||
|
* a file path, or %NULL otherwise.
|
||||||
|
*
|
||||||
|
* Since: 2.78
|
||||||
|
**/
|
||||||
|
const char *
|
||||||
|
g_file_info_get_attribute_file_path (GFileInfo *info,
|
||||||
|
const char *attribute)
|
||||||
|
{
|
||||||
|
return g_file_info_get_attribute_byte_string (info, attribute);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_file_info_get_attribute_stringv:
|
* g_file_info_get_attribute_stringv:
|
||||||
* @info: a #GFileInfo.
|
* @info: a #GFileInfo.
|
||||||
@ -1318,6 +1342,28 @@ g_file_info_set_attribute_byte_string (GFileInfo *info,
|
|||||||
attr_value);
|
attr_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_file_info_set_attribute_file_path:
|
||||||
|
* @info: a #GFileInfo.
|
||||||
|
* @attribute: a file attribute key.
|
||||||
|
* @attr_value: (type filename): a file path.
|
||||||
|
*
|
||||||
|
* Sets the @attribute to contain the given @attr_value,
|
||||||
|
* if possible.
|
||||||
|
*
|
||||||
|
* This function is meant to be used by language bindings that have specific
|
||||||
|
* handling for Unix paths.
|
||||||
|
*
|
||||||
|
* Since: 2.78
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
g_file_info_set_attribute_file_path (GFileInfo *info,
|
||||||
|
const char *attribute,
|
||||||
|
const char *attr_value)
|
||||||
|
{
|
||||||
|
g_file_info_set_attribute_byte_string (info, attribute, attr_value);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_g_file_info_set_attribute_boolean_by_id (GFileInfo *info,
|
_g_file_info_set_attribute_boolean_by_id (GFileInfo *info,
|
||||||
guint32 attribute,
|
guint32 attribute,
|
||||||
|
@ -1360,6 +1360,9 @@ GObject * g_file_info_get_attribute_object (GFileInfo *info,
|
|||||||
GIO_AVAILABLE_IN_ALL
|
GIO_AVAILABLE_IN_ALL
|
||||||
char ** g_file_info_get_attribute_stringv (GFileInfo *info,
|
char ** g_file_info_get_attribute_stringv (GFileInfo *info,
|
||||||
const char *attribute);
|
const char *attribute);
|
||||||
|
GIO_AVAILABLE_IN_2_78
|
||||||
|
const char * g_file_info_get_attribute_file_path (GFileInfo *info,
|
||||||
|
const char *attribute);
|
||||||
|
|
||||||
GIO_AVAILABLE_IN_ALL
|
GIO_AVAILABLE_IN_ALL
|
||||||
void g_file_info_set_attribute (GFileInfo *info,
|
void g_file_info_set_attribute (GFileInfo *info,
|
||||||
@ -1402,6 +1405,10 @@ GIO_AVAILABLE_IN_ALL
|
|||||||
void g_file_info_set_attribute_stringv (GFileInfo *info,
|
void g_file_info_set_attribute_stringv (GFileInfo *info,
|
||||||
const char *attribute,
|
const char *attribute,
|
||||||
char **attr_value);
|
char **attr_value);
|
||||||
|
GIO_AVAILABLE_IN_2_78
|
||||||
|
void g_file_info_set_attribute_file_path (GFileInfo *info,
|
||||||
|
const char *attribute,
|
||||||
|
const char *attr_value);
|
||||||
|
|
||||||
GIO_AVAILABLE_IN_ALL
|
GIO_AVAILABLE_IN_ALL
|
||||||
void g_file_info_clear_status (GFileInfo *info);
|
void g_file_info_clear_status (GFileInfo *info);
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
static void
|
static void
|
||||||
test_assigned_values (GFileInfo *info)
|
test_assigned_values (GFileInfo *info)
|
||||||
{
|
{
|
||||||
const char *name, *display_name, *mistake;
|
const char *name, *name_filepath, *display_name, *mistake;
|
||||||
guint64 size;
|
guint64 size;
|
||||||
GFileType type;
|
GFileType type;
|
||||||
|
|
||||||
@ -56,12 +56,14 @@ test_assigned_values (GFileInfo *info)
|
|||||||
/* Retrieve data back and compare */
|
/* Retrieve data back and compare */
|
||||||
|
|
||||||
name = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME);
|
name = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME);
|
||||||
|
name_filepath = g_file_info_get_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME);
|
||||||
display_name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
|
display_name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
|
||||||
mistake = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME);
|
mistake = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME);
|
||||||
size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
|
size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
|
||||||
type = g_file_info_get_file_type (info);
|
type = g_file_info_get_file_type (info);
|
||||||
|
|
||||||
g_assert_cmpstr (name, ==, TEST_NAME);
|
g_assert_cmpstr (name, ==, TEST_NAME);
|
||||||
|
g_assert_cmpstr (name_filepath, ==, name);
|
||||||
g_assert_cmpstr (display_name, ==, TEST_DISPLAY_NAME);
|
g_assert_cmpstr (display_name, ==, TEST_DISPLAY_NAME);
|
||||||
g_assert_null (mistake);
|
g_assert_null (mistake);
|
||||||
g_assert_cmpint (size, ==, TEST_SIZE);
|
g_assert_cmpint (size, ==, TEST_SIZE);
|
||||||
@ -103,6 +105,11 @@ test_g_file_info (void)
|
|||||||
|
|
||||||
test_assigned_values (info);
|
test_assigned_values (info);
|
||||||
|
|
||||||
|
/* Test the file path encoding functions */
|
||||||
|
g_file_info_set_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME, "something different");
|
||||||
|
g_assert_cmpstr (g_file_info_get_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME), ==, "something different");
|
||||||
|
g_file_info_set_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME, TEST_NAME);
|
||||||
|
|
||||||
/* Test dups */
|
/* Test dups */
|
||||||
info_dup = g_file_info_dup (info);
|
info_dup = g_file_info_dup (info);
|
||||||
g_assert_nonnull (info_dup);
|
g_assert_nonnull (info_dup);
|
||||||
|
Loading…
Reference in New Issue
Block a user