[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Add option to use traditional binary units instead of
From:       Michael Pyne <mpyne () kde ! org>
Date:       2009-07-02 0:23:30
Message-ID: 200907012023.30293.mpyne () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


This is forwarded from a discussion on kde-devel regarding binary units.

I would like to commit the attached patch to trunk by the end of this week, if 
there are no major issues.

Please please please do not email or flame about adding an option to use KB/MB 
instead of KiB/MiB without at least reading the kde-devel thread first.

Forwarded message follows
-------------------------------------------------------
And since this has been bugging me since 4.0 came out, I finally decided to 
take time out to hack together a fix (attached).

With the patch, you should be able to add "HistoricalBinaryUnits=true" to your 
$KDEHOME/share/config/kdeglobals and applications which start up afterwards 
should use KB/MB/etc. instead of KiB/MiB/etc.

If there's interest I'll forward to kde-core-devel for evaluation as well.

Regards,
 - Michael Pyne
-------------------------------------------------------

["0001-klocale-use-si-binary.patch" (text/x-patch)]

Index: kdecore/localization/klocale.cpp
===================================================================
--- kdecore/localization/klocale.cpp	(revision 988903)
+++ kdecore/localization/klocale.cpp	(working copy)
@@ -228,6 +228,7 @@
   int workingWeekEndDay;
   int weekDayOfPray;
   KLocale::DigitSet dateTimeDigitSet;
+  bool historicalBinaryUnits; // See IEC 60027-2 i.e. kibibyte, mebibyte, etc.
 
   // FIXME: Temporary until full language-sensitivity implemented.
   bool languageSensitiveDigits;
@@ -443,6 +444,8 @@
   readConfigEntry("PositiveSign", "", positiveSign);
   readConfigEntry("NegativeSign", "-", negativeSign);
 
+  readConfigEntry("HistoricalBinaryUnits", false, historicalBinaryUnits);
+
   readConfigNumEntry("DigitSet", KLocale::ArabicDigits,
                      digitSet, KLocale::DigitSet);
   // FIXME: Temporary until full language-sensitivity implemented.
@@ -1354,27 +1357,43 @@
     //Mebi-byte             MiB             2^20    1,048,576 bytes
     //Kibi-byte             KiB             2^10    1,024 bytes
 
+    KLocalizedString TiB(ki18n("%1 TiB"));
+    KLocalizedString GiB(ki18n("%1 GiB"));
+    KLocalizedString MiB(ki18n("%1 MiB"));
+    KLocalizedString KiB(ki18n("%1 KiB"));
+
+    // If using historic prefixes, convert units.
+    // If we were to be doing this often, it may pay to cache the user
+    // preference
+    if (d->historicalBinaryUnits) {
+        TiB = ki18n("%1 TB");
+        GiB = ki18n("%1 GB");
+        MiB = ki18n("%1 MB");
+        KiB = ki18n("%1 KB");
+    }
+
     QString s;
+
     // Gibi-byte
     if ( size >= 1073741824.0 )
     {
         size /= 1073741824.0;
         if ( size > 1024 ) // Tebi-byte
-            s = i18n( "%1 TiB", formatNumber(size / 1024.0, 1));
+            s = TiB.subs( formatNumber(size / 1024.0, 1) ).toString();
         else
-            s = i18n( "%1 GiB", formatNumber(size, 1));
+            s = GiB.subs( formatNumber(size, 1) ).toString();
     }
     // Mebi-byte
     else if ( size >= 1048576.0 )
     {
         size /= 1048576.0;
-        s = i18n( "%1 MiB", formatNumber(size, 1));
+        s = MiB.subs( formatNumber(size, 1) ).toString();
     }
     // Kibi-byte
     else if ( size >= 1024.0 )
     {
         size /= 1024.0;
-        s = i18n( "%1 KiB", formatNumber(size, 1));
+        s = KiB.subs( formatNumber(size, 1) ).toString();
     }
     // Just byte
     else if ( size > 0 )

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic