Author: aschnell Date: Thu Mar 20 14:45:07 2008 New Revision: 45653 URL: http://svn.opensuse.org/viewcvs/yast?rev=45653&view=rev Log: - use String::FormatSizeWithPrecision Modified: branches/tmp/aschnell/part-redesign/storage/src/include/partition_defines.ycp branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp 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=45653&r1=45652&r2=45653&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 Thu Mar 20 14:45:07 2008 @@ -26,7 +26,7 @@ import "Partitions"; import "FileSystems"; import "Report"; - + import "String"; import "Popup"; // include "partitioning/custom_part_testdata.ycp"; @@ -64,28 +64,6 @@ }; - /*--------------------------------------------------------------------- - * returns for a string a string with a minimum of 9 characters: - * "1" -> " 1" - * "22" -> " 22" - * "145" -> " 145" - * "2134" -> " 2134" - *---------------------------------------------------------------------- - */ - define string sto8string( string str ) - ``{ - integer nb = size( str ); - if ( nb > 8 ) return( sformat( "%1", str )); - if ( nb > 7 ) return( sformat( " %1", str )); - if ( nb > 6 ) return( sformat( " %1", str )); - if ( nb > 5 ) return( sformat( " %1", str )); - if ( nb > 4 ) return( sformat( " %1", str )); - if ( nb > 3 ) return( sformat( " %1", str )); - if ( nb > 2 ) return( sformat( " %1", str )); - if ( nb > 1 ) return( sformat( " %1", str )); - return( sformat( " %1", str )); - }; - /*--------------------------------------------------------------------- * Convert <number-of-bytes> to XXX.X MB or XXX.X GB or XXX.X TB * @@ -93,35 +71,16 @@ * Return value: string "unknown" if input == 0 *---------------------------------------------------------------------- */ -define string ByteToHumanString ( integer number ) - ``{ - // column description, if disk space is not known - if( number == 0 ) return( _("unknown") ); - - if( number < 1073741824 ) - { - // < 1 GB - integer MB = number / 1048576; - integer hunKB = (number - (MB * 1048576)) / 104858; - return( sto8string(sformat( "%1.%2 MB", MB,hunKB ))); - } - else if ( number < 1099511627776 ) - { - // < 1 TB - integer GB = number / 1073741824; - integer hunMB = (number - (GB * 1073741824)) / 107374183; - return( sto8string(sformat( "%1.%2 GB", GB,hunMB ))); - } - else - { - // >= 1 TB - integer TB = number / 1099511627776; - integer hunGB = (number - (TB * 1099511627776)) / 109951162778; - return( sto8string(sformat( "%1.%2 TB", TB,hunGB ))); - } - }; - +string ByteToHumanString(integer number) +{ + if (number == 0) + { + // column description, if disk space is not known + return _("unknown"); + } + return String::FormatSizeWithPrecision(number, 2, false); +}; /*--------------------------------------------------------------------- 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=45653&r1=45652&r2=45653&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp (original) +++ branches/tmp/aschnell/part-redesign/storage/src/modules/Partitions.ycp Thu Mar 20 14:45:07 2008 @@ -16,6 +16,7 @@ import "Mode"; import "Stage"; import "AsciiFile"; + import "String"; // The filesystem ids for the partitions global integer fsid_empty = 0; @@ -767,34 +768,7 @@ */ global string ByteToHumanStringWithZero(integer number) { - if( number < 1048576 ) - { - // < 1 MB - integer KB = number / 1024; - integer hunB = (number - (KB * 1024)) / 103; - return sformat("%1.%2 KB", KB, hunB); - } - else if( number < 1073741824 ) - { - // < 1 GB - integer MB = number / 1048576; - integer hunKB = (number - (MB * 1048576)) / 104858; - return sformat("%1.%2 MB", MB, hunKB); - } - else if ( number < 1099511627776 ) - { - // < 1 TB - integer GB = number / 1073741824; - integer hunMB = (number - (GB * 1073741824)) / 107374183; - return sformat("%1.%2 GB", GB, hunMB); - } - else - { - // >= 1 TB - integer TB = number / 1099511627776; - integer hunGB = (number - (TB * 1099511627776)) / 109951162778; - return sformat("%1.%2 TB", TB, hunGB); - } + return String::FormatSizeWithPrecision(number, 2, false); }; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org