From: Alexander Larsson Date: Tue, 27 Nov 2007 14:30:31 +0000 (+0000) Subject: Move g_format_file_size_for_display from gio to glib X-Git-Tag: GLIB_2_15_1~296 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68c74ba68ffd89be6e285b3c9a5c3c141fab1226;p=platform%2Fupstream%2Fglib.git Move g_format_file_size_for_display from gio to glib 2007-11-27 Alexander Larsson * gio/gfileinfo.[ch]: * glib/gfileutils.[ch]: Move g_format_file_size_for_display from gio to glib svn path=/trunk/; revision=5954 --- diff --git a/ChangeLog b/ChangeLog index 9adc1bc..06bc4fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-11-27 Alexander Larsson + * gio/gfileinfo.[ch]: + * glib/gfileutils.[ch]: + Move g_format_file_size_for_display from gio to glib + +2007-11-27 Alexander Larsson + * configure.in: Allow configuration of gio-module-dir diff --git a/gio/gfileinfo.c b/gio/gfileinfo.c index 6986615..f72e3ee 100644 --- a/gio/gfileinfo.c +++ b/gio/gfileinfo.c @@ -1703,48 +1703,6 @@ g_file_info_set_sort_order (GFileInfo *info, } -#define KILOBYTE_FACTOR 1024.0 -#define MEGABYTE_FACTOR (1024.0 * 1024.0) -#define GIGABYTE_FACTOR (1024.0 * 1024.0 * 1024.0) - -/** - * g_format_file_size_for_display: - * @size: a file size. - * - * Formats a file size into a human readable string. Sizes are rounded - * to the nearest metric prefix and are displayed rounded to the nearest - * tenth. E.g. the file size 3292528 bytes will be converted into the string - * "3.1 MB". - * - * Returns: a formatted string containing a human readable file size. - **/ -char * -g_format_file_size_for_display (goffset size) -{ - if (size < (goffset) KILOBYTE_FACTOR) - return g_strdup_printf (dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size), (guint) size); - else - { - gdouble displayed_size; - - if (size < (goffset) MEGABYTE_FACTOR) - { - displayed_size = (gdouble) size / KILOBYTE_FACTOR; - return g_strdup_printf (_("%.1f KB"), displayed_size); - } - else if (size < (goffset) GIGABYTE_FACTOR) - { - displayed_size = (gdouble) size / MEGABYTE_FACTOR; - return g_strdup_printf (_("%.1f MB"), displayed_size); - } - else - { - displayed_size = (gdouble) size / GIGABYTE_FACTOR; - return g_strdup_printf (_("%.1f GB"), displayed_size); - } - } -} - #define ON_STACK_MATCHERS 5 typedef struct { diff --git a/gio/gfileinfo.h b/gio/gfileinfo.h index c8ab326..201f7cd 100644 --- a/gio/gfileinfo.h +++ b/gio/gfileinfo.h @@ -24,6 +24,7 @@ #define __G_FILE_INFO_H__ #include +#include #include #include @@ -717,10 +718,6 @@ void g_file_info_set_symlink_target (GFileInfo *info, void g_file_info_set_sort_order (GFileInfo *info, gint32 sort_order); -/* Helper functions for attributes: */ -/* TODO: Move this to glib when merging */ -char *g_format_file_size_for_display (goffset size); - GFileAttributeMatcher *g_file_attribute_matcher_new (const char *attributes); GFileAttributeMatcher *g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher); void g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher); diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 5025b3a..8921188 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -1800,6 +1800,51 @@ g_build_filename (const gchar *first_element, return str; } +#define KILOBYTE_FACTOR 1024.0 +#define MEGABYTE_FACTOR (1024.0 * 1024.0) +#define GIGABYTE_FACTOR (1024.0 * 1024.0 * 1024.0) + +/** + * g_format_file_size_for_display: + * @size: a file size. + * + * Formats a file size into a human readable string. Sizes are rounded + * to the nearest metric prefix and are displayed rounded to the nearest + * tenth. E.g. the file size 3292528 bytes will be converted into the string + * "3.1 MB". + * + * Returns: a formatted string containing a human readable file size. + * + * Since: 2.16 + **/ +char * +g_format_file_size_for_display (goffset size) +{ + if (size < (goffset) KILOBYTE_FACTOR) + return g_strdup_printf (dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size), (guint) size); + else + { + gdouble displayed_size; + + if (size < (goffset) MEGABYTE_FACTOR) + { + displayed_size = (gdouble) size / KILOBYTE_FACTOR; + return g_strdup_printf (_("%.1f KB"), displayed_size); + } + else if (size < (goffset) GIGABYTE_FACTOR) + { + displayed_size = (gdouble) size / MEGABYTE_FACTOR; + return g_strdup_printf (_("%.1f MB"), displayed_size); + } + else + { + displayed_size = (gdouble) size / GIGABYTE_FACTOR; + return g_strdup_printf (_("%.1f GB"), displayed_size); + } + } +} + + /** * g_file_read_link: * @filename: the symbolic link diff --git a/glib/gfileutils.h b/glib/gfileutils.h index 0aa0852..989fe8a 100644 --- a/glib/gfileutils.h +++ b/glib/gfileutils.h @@ -101,6 +101,8 @@ gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error); +char *g_format_file_size_for_display (goffset size); + gchar *g_build_path (const gchar *separator, const gchar *first_element, ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;