Author: aschnell
Date: Wed May 21 15:21:40 2008
New Revision: 47763
URL: http://svn.opensuse.org/viewcvs/yast?rev=47763&view=rev
Log:
- export byteToHumanString in StorageInterface.h
Modified:
branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.cc
branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.h
branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc
branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h
branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h
branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc
branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp
branches/tmp/aschnell/part-redesign/storage/src/include/ep-lvm-dialogs.ycp
branches/tmp/aschnell/part-redesign/storage/src/include/partition_defines.ycp
branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp
branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp
branches/tmp/aschnell/part-redesign/storage/src/modules/StorageFields.ycp
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.cc?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.cc Wed May 21 15:21:40 2008
@@ -202,36 +202,6 @@
S_ISREG(Stat_ri.st_mode));
}
-string kbyteToHumanString( unsigned long long sizeK )
- {
- unsigned num;
- unsigned fract;
- string unit;
- if( sizeK<1024*1024 )
- {
- num = (unsigned)(sizeK / 1024);
- sizeK -= num*1024;
- fract = (unsigned)(sizeK / 103);
- unit = " MB";
- }
- else if( sizeK<1024*1024*1024 )
- {
- num = (unsigned)(sizeK / (1024*1024));
- sizeK -= num * (1024*1024);
- fract = (unsigned)(sizeK / 104858);
- unit = " GB";
- }
- else
- {
- num = (unsigned)(sizeK / (1024*1024*1024));
- sizeK -= num * (1024*1024*1024);
- fract = (unsigned)(sizeK / 107374183);
- unit = " TB";
- }
- return( decString(num)+"."+decString(fract)+unit );
- }
-
-
string extractNthWord(int Num_iv, string Line_Cv, bool GetRest_bi)
{
string::size_type pos;
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.h?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/AppUtil.h Wed May 21 15:21:40 2008
@@ -44,7 +44,6 @@
bool unique=true );
void getFindRevMap( const char* path, std::map& m );
void removeLastIf(string& Text_Cr, char Char_cv);
-string kbyteToHumanString( unsigned long long size );
string normalizeDevice( const string& dev );
void normalizeDevice( string& dev );
string undevDevice( const string& dev );
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc Wed May 21 15:21:40 2008
@@ -6366,6 +6366,44 @@
no_evms=val;
}
+
+string Storage::byteToHumanString(unsigned long long size, int precision, bool omit_zeroes) const
+{
+ const char* prefixes[] = {
+ /* Byte abbreviated */
+ _("B"),
+ /* KiloByte abbreviated */
+ _("kB"),
+ /* MegaByte abbreviated */
+ _("MB"),
+ /* GigaByte abbreviated */
+ _("GB"),
+ /* TeraByte abbreviated */
+ _("TB")
+ };
+
+ double f = (double)(size);
+ unsigned int prefix = 0;
+
+ while (f >= 1024.0 && prefix + 1 < lengthof(prefixes))
+ {
+ f /= 1024.0;
+ prefix++;
+ }
+
+ if (omit_zeroes && (f == (unsigned long long)(f)))
+ {
+ precision = 0;
+ }
+
+ ostringstream s;
+ s.setf(ios::fixed);
+ s.precision(precision);
+ s << f << ' ' << prefixes[prefix];
+ return s.str();
+}
+
+
namespace storage
{
std::ostream& operator<< (std::ostream& s, Storage &v )
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h Wed May 21 15:21:40 2008
@@ -469,6 +469,8 @@
void updateDmEmptyPeMap();
void dumpObjectList();
+ string byteToHumanString(unsigned long long size, int precision, bool omit_zeroes) const;
+
void setCallbackProgressBar( storage::CallbackProgressBar pfnc )
{ progress_bar_cb=pfnc; }
storage::CallbackProgressBar getCallbackProgressBar() const
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h Wed May 21 15:21:40 2008
@@ -2156,6 +2156,22 @@
*/
virtual int getContVolInfo( const string& dev, ContVolInfo& info) = 0;
+ /**
+ * Return a pretty description of a size with required precision
+ * and using B, kB, MB, GB or TB as unit as appropriate.
+ *
+ * @param size size in bytes
+ * @param precision number of fraction digits in output
+ * @param omit_zeroes if true omit trailing zeroes for exact values
+ * @return formatted string
+ *
+ * @example byteToHumanString(128, 2, true) -> "128 B"
+ * @example byteToHumanString(4096, 2, true) -> "4 kB"
+ * @example byteToHumanString(4096, 2, false) -> "4.00 kB"
+ * @example byteToHumanString(1024*1024, 2, true) -> "1 MB"
+ */
+ virtual string byteToHumanString(unsigned long long size, int precision,
+ bool omit_zeroes) const = 0;
};
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc Wed May 21 15:21:40 2008
@@ -2557,9 +2557,9 @@
}
string Volume::sizeString() const
- {
- return( kbyteToHumanString( size_k ));
- }
+{
+ return cont->getStorage()->byteToHumanString(1024 * size_k, 2, false);
+}
bool Volume::canUseDevice() const
{
Modified: branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp Wed May 21 15:21:40 2008
@@ -26,13 +26,13 @@
term cyl = `Empty();
if (flavour == `part)
- cyl = `Left(`Label(sformat(_("Cylinder size is %1"), String::FormatSizeWithPrecision(data["cyl_size"]:0, 2, false))));
+ cyl = `Left(`Label(sformat(_("Cylinder size is %1"), Storage::ByteToHumanString(data["cyl_size"]:0))));
term frames = `VStackFrames();
list slot = data["slots", data["type"]:`unknown]:[];
integer max_size = slot[1]:0 * data["cyl_size"]:0;
- string tmp = String::FormatSizeWithPrecision(max_size, 2, false);
+ string tmp = Storage::ByteToHumanString(max_size);
frames = add(frames,
`Frame(_("Size"),
Modified: branches/tmp/aschnell/part-redesign/storage/src/include/ep-lvm-dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/include/ep-lvm-dialogs.ycp?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/include/ep-lvm-dialogs.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/include/ep-lvm-dialogs.ycp Wed May 21 15:21:40 2008
@@ -32,7 +32,7 @@
if (preferred_displayname == `id)
line = line + " " + candidate["udev_id", 0]:"";
integer size_k = candidate["size_k"]:0;
- line = line + " " + ByteToHumanStringWithZero(size_k*1024);
+ line = line + " " + Storage::ByteToHumanString(size_k*1024);
return `item(`id(device), line);
});
@@ -54,10 +54,10 @@
UI::ReplaceWidget(`id(`unsel_rp),
`Left(`Label(sformat(_("Total size: %1"),
- Partitions::ByteToHumanStringWithZero(unsel_size_k*1024)))));
+ Storage::ByteToHumanString(unsel_size_k*1024)))));
UI::ReplaceWidget(`id(`sel_rp),
`Left(`Label(sformat(_("Total size: %1"),
- Partitions::ByteToHumanStringWithZero(sel_size_k*1024)))));
+ Storage::ByteToHumanString(sel_size_k*1024)))));
}
Modified: branches/tmp/aschnell/part-redesign/storage/src/include/partition_defines.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/include/partition_defines.ycp?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/include/partition_defines.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/include/partition_defines.ycp Wed May 21 15:21:40 2008
@@ -70,6 +70,7 @@
* see also ByteToHumanStringWithZero !
* Return value: string "unknown" if input == 0
*----------------------------------------------------------------------
+ * TODO: remove
*/
string ByteToHumanString(integer number)
{
@@ -122,6 +123,7 @@
* see also ByteToHumanString !
* Return value: string "0" if input == 0
*----------------------------------------------------------------------
+ * TODO: remove
*/
string ByteToHumanStringWithZero(integer number)
{
Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp Wed May 21 15:21:40 2008
@@ -755,41 +755,4 @@
return( text );
}
-
-/*---------------------------------------------------------------------
- * Convert <number-of-bytes> to XXX.X KB, XXX.X MB, XXX.X GB or XXX.X TB
- *
- * see also ByteToHumanString
- *
- * Return value: string "0.0 KB" if input == 0
- *----------------------------------------------------------------------
- *
- * TODO: also defined in partition_defines.ycp and AppUtils.cc, keep only one
- * TODO: has different rounding than before; check if ok
- */
-global string ByteToHumanStringWithZero(integer number)
-{
- return String::FormatSizeWithPrecision(number, 2, false);
-};
-
-
-/*---------------------------------------------------------------------
- * Convert <number-of-bytes> to XXX.X KB, XXX.X MB, XXX.X GB or XXX.X TB
- *
- * see also ByteToHumanStringWithZero
- *
- * Return value: string "unknown" if input == 0
- *----------------------------------------------------------------------
- */
-global string ByteToHumanString(integer number)
-{
- if (number == 0)
- {
- // column description, if disk space is not known
- return _("unknown");
- }
-
- return ByteToHumanStringWithZero(number);
-};
-
}
Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp Wed May 21 15:21:40 2008
@@ -319,6 +319,19 @@
}
}
+
+global string ByteToHumanString(integer bytes)
+{
+ return LibStorage::StorageInterface::byteToHumanString(sint, bytes, 2, false);
+}
+
+
+global string ByteToHumanStringWithPrecision(integer bytes, integer precision, boolean omit_zeroes)
+{
+ return LibStorage::StorageInterface::byteToHumanString(sint, bytes, precision, omit_zeroes);
+}
+
+
global define map GetTargetMap();
/**
*
@@ -3637,7 +3650,7 @@
disk = getDiskInfo( dev, disk );
integer s = disk["size_k"]:0 * 1024;
disk["name"] = disk["dname"]:"" +
- Partitions::ByteToHumanString( s ) + ", " +
+ Storage::ByteToHumanString( s ) + ", " +
disk["device"]:"" + ", ";
if( size( disk["vendor"]:"")>0 )
disk["name"] = disk["name"]:"" + disk["vendor"]:"" + "-";
Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/StorageFields.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/StorageFields.ycp?rev=47763&r1=47762&r2=47763&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/modules/StorageFields.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/modules/StorageFields.ycp Wed May 21 15:21:40 2008
@@ -14,7 +14,6 @@
import "Storage";
import "FileSystems";
import "Partitions";
- import "String";
import "Arch";
import "Mode";
@@ -211,7 +210,7 @@
case `size:
{
- string value = String::FormatSizeWithPrecision(data["size_k"]:0*1024, 2, false);
+ string value = Storage::ByteToHumanString(data["size_k"]:0*1024);
if (style == `table)
return value;
else
@@ -446,7 +445,7 @@
{
string value = "";
if (disk["type"]:`CT_UNKNOWN == `CT_LVM && part == nil)
- value = String::FormatSizeWithPrecision(disk["pesize"]:0, 2, true);
+ value = Storage::ByteToHumanStringWithPrecision(disk["pesize"]:0, 2, true);
if (style == `table)
return value;
else
@@ -463,7 +462,7 @@
if (stripes == 1)
value = sformat("%1", stripes);
else
- value = sformat("%1 (%2)", stripes, String::FormatSizeWithPrecision(stripesize*1024, 2, true));
+ value = sformat("%1 (%2)", stripes, Storage::ByteToHumanStringWithPrecision(stripesize*1024, 2, true));
}
if (style == `table)
return value;
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org