summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-01-02 12:21:41 (GMT)
committerSwift Review <review@swift.im>2014-01-15 11:05:41 (GMT)
commit09108f5ac3c1a6567730b5bbd0c847f8422ff4a2 (patch)
treeb7054e421da9dd8227b3bbe11b2ea20575b760df /Swiften/Base
parent9cf1fe4ec5d3729ceb53385aeb245a4a688823e0 (diff)
downloadswift-09108f5ac3c1a6567730b5bbd0c847f8422ff4a2.zip
swift-09108f5ac3c1a6567730b5bbd0c847f8422ff4a2.tar.bz2
Improved plaintext chat view for screen-reader support.
Change-Id: Ib7c10350b56683db95f4c6be49f79f8a9d9e80ec
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/FileSize.cpp23
-rw-r--r--Swiften/Base/FileSize.h17
-rw-r--r--Swiften/Base/SConscript3
3 files changed, 42 insertions, 1 deletions
diff --git a/Swiften/Base/FileSize.cpp b/Swiften/Base/FileSize.cpp
new file mode 100644
index 0000000..90fdc9a
--- /dev/null
+++ b/Swiften/Base/FileSize.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2010-2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Base/FileSize.h>
+#include <boost/format.hpp>
+
+namespace Swift {
+
+std::string formatSize(const boost::uintmax_t bytes) {
+ static const char *siPrefix[] = {"k", "M", "G", "T", "P", "E", "Z", "Y", NULL};
+ int power = 0;
+ double engBytes = bytes;
+ while (engBytes >= 1000) {
+ ++power;
+ engBytes = engBytes / 1000.0;
+ }
+ return str( boost::format("%.1lf %sB") % engBytes % (power > 0 ? siPrefix[power-1] : "") );
+}
+
+}
diff --git a/Swiften/Base/FileSize.h b/Swiften/Base/FileSize.h
new file mode 100644
index 0000000..c9ed5fe
--- /dev/null
+++ b/Swiften/Base/FileSize.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2010-2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/API.h>
+#include <boost/cstdint.hpp>
+#include <string>
+
+namespace Swift {
+
+SWIFTEN_API std::string formatSize(const boost::uintmax_t bytes);
+
+}
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index 094059a..d7fd7cc 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -16,6 +16,7 @@ objects = swiften_env.SwiftenObject([
"BoostRandomGenerator.cpp",
"sleep.cpp",
"URL.cpp",
- "Regex.cpp"
+ "Regex.cpp",
+ "FileSize.cpp"
])
swiften_env.Append(SWIFTEN_OBJECTS = [objects])