summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2015-04-15 16:44:37 +0200
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2015-04-15 16:44:37 +0200
commit78d99915f1c2bd11d89c165188cb74c354db52c7 (patch)
treebdd5401930b2fecab1e173c220d1b7b0e6653985
parent6641ac99f95e02c7ef9e4259f6b6b8af1dcbb3f4 (diff)
downloadglibmm-78d99915f1c2bd11d89c165188cb74c354db52c7.tar.gz
Add Glib::format_size()
* .gitignore: Ignore glib/glibmm/miscutils.[h|cc]. * glib/src/filelist.am: Add miscutils.hg. * glib/glibmm/filelist.am: Remove miscutils.[h|cc]. * glib/glibmm/miscutils.[h|cc]: Move to glib/src and rename to miscutils.[hg|ccg]. * glib/src/miscutils.[hg|ccg]: New files. Move from glib/glibmm and rename. Add _WRAP_ENUM(FormatSizeFlags,...). Add Glib::format_size(). Bug #747311.
-rw-r--r--.gitignore2
-rw-r--r--glib/glibmm/filelist.am2
-rw-r--r--glib/src/filelist.am1
-rw-r--r--glib/src/miscutils.ccg (renamed from glib/glibmm/miscutils.cc)8
-rw-r--r--glib/src/miscutils.hg (renamed from glib/glibmm/miscutils.h)32
5 files changed, 29 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index dc64b965..c3aa740e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -119,6 +119,8 @@ giommconfig.h
/glib/glibmm/keyfile.h
/glib/glibmm/markup.cc
/glib/glibmm/markup.h
+/glib/glibmm/miscutils.cc
+/glib/glibmm/miscutils.h
/glib/glibmm/module.cc
/glib/glibmm/module.h
/glib/glibmm/nodetree.cc
diff --git a/glib/glibmm/filelist.am b/glib/glibmm/filelist.am
index 97170ce0..909ef6d5 100644
--- a/glib/glibmm/filelist.am
+++ b/glib/glibmm/filelist.am
@@ -17,7 +17,6 @@ glibmm_files_extra_cc = \
init.cc \
interface.cc \
main.cc \
- miscutils.cc \
object.cc \
objectbase.cc \
pattern.cc \
@@ -59,7 +58,6 @@ glibmm_files_extra_h = \
interface.h \
listhandle.h \
main.h \
- miscutils.h \
object.h \
objectbase.h \
pattern.h \
diff --git a/glib/src/filelist.am b/glib/src/filelist.am
index 133f6bef..94341328 100644
--- a/glib/src/filelist.am
+++ b/glib/src/filelist.am
@@ -26,6 +26,7 @@ glibmm_files_any_hg = \
iochannel.hg \
keyfile.hg \
markup.hg \
+ miscutils.hg \
module.hg \
nodetree.hg \
optioncontext.hg \
diff --git a/glib/glibmm/miscutils.cc b/glib/src/miscutils.ccg
index 95226b8f..d87936d9 100644
--- a/glib/glibmm/miscutils.cc
+++ b/glib/src/miscutils.ccg
@@ -1,6 +1,3 @@
-// -*- c++ -*-
-/* $Id$ */
-
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -266,4 +263,9 @@ std::string find_program_in_path(const std::string& program)
return convert_return_gchar_ptr_to_stdstring(g_find_program_in_path(program.c_str()));
}
+Glib::ustring format_size(guint64 size, FormatSizeFlags flags)
+{
+ return convert_return_gchar_ptr_to_ustring(g_format_size_full(size, (GFormatSizeFlags)flags));
+}
+
} // namespace Glib
diff --git a/glib/glibmm/miscutils.h b/glib/src/miscutils.hg
index 12c9677b..9f3fecfd 100644
--- a/glib/glibmm/miscutils.h
+++ b/glib/src/miscutils.hg
@@ -1,9 +1,3 @@
-// -*- c++ -*-
-#ifndef _GLIBMM_MISCUTILS_H
-#define _GLIBMM_MISCUTILS_H
-
-/* $Id$ */
-
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -21,12 +15,14 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+_DEFS(glibmm,glib)
+
#include <glibmm/arrayhandle.h>
#include <glibmm/ustring.h>
-
namespace Glib
{
+_WRAP_ENUM(FormatSizeFlags, GFormatSizeFlags, NO_GTYPE)
/** @defgroup MiscUtils Miscellaneous Utility Functions
* Miscellaneous Utility Functions -- a selection of portable utility functions.
@@ -81,7 +77,7 @@ void set_prgname(const std::string& prgname);
* environment variables, they are expanded.
*
* @param variable The environment variable to get.
- * @retval found <tt>true</tt> Whether the environment variable has been found.
+ * @param[out] found Whether the environment variable has been found.
* @return The value of the environment variable, or <tt>""</tt> if not found.
*/
std::string getenv(const std::string& variable, bool& found);
@@ -459,9 +455,23 @@ std::string build_path(const std::string& separator,
*/
std::string find_program_in_path(const std::string& program);
+/** Formats a size (for example the size of a file) into a human readable string.
+ *
+ * Sizes are rounded to the nearest size prefix (kB, MB, GB)
+ * and are displayed rounded to the nearest tenth. E.g. the file size
+ * 3292528 bytes will be converted into the string "3.2 MB".
+ *
+ * The prefix units base is 1000 (i.e. 1 kB is 1000 bytes), unless the
+ * Glib::FORMAT_SIZE_IEC_UNITS flag is set.
+ *
+ * @param size A size in bytes.
+ * @param flags Flags to modify the output.
+ * @return A formatted string containing a human readable file size.
+ *
+ * @newin{2,46}
+ */
+Glib::ustring format_size(guint64 size, FormatSizeFlags flags = FORMAT_SIZE_DEFAULT);
+
/** @} group MiscUtils */
} // namespace Glib
-
-
-#endif /* _GLIBMM_FILEUTILS_H */