[glibmm] Add Glib::format_size()
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Add Glib::format_size()
- Date: Wed, 15 Apr 2015 15:09:00 +0000 (UTC)
commit 78d99915f1c2bd11d89c165188cb74c354db52c7
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Wed Apr 15 16:44:37 2015 +0200
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.
.gitignore | 2 +
glib/glibmm/filelist.am | 2 -
glib/src/filelist.am | 1 +
glib/{glibmm/miscutils.cc => src/miscutils.ccg} | 8 +++--
glib/{glibmm/miscutils.h => src/miscutils.hg} | 32 +++++++++++++++--------
5 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index dc64b96..c3aa740 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 97170ce..909ef6d 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 133f6be..9434132 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
similarity index 98%
rename from glib/glibmm/miscutils.cc
rename to glib/src/miscutils.ccg
index 95226b8..d87936d 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
similarity index 96%
rename from glib/glibmm/miscutils.h
rename to glib/src/miscutils.hg
index 12c9677..9f3fecf 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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]