Bug 466468

Summary: Implement a spinbox for byte values respecting BinaryUnitDialect
Product: [Frameworks and Libraries] frameworks-kcoreaddons Reporter: Karl Ove Hufthammer <karl>
Component: generalAssignee: Michael Pyne <mpyne>
Status: CONFIRMED ---    
Severity: wishlist CC: kdelibs-bugs, nate
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=364321
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Karl Ove Hufthammer 2023-02-26 12:00:42 UTC
There is a need for a QSpinBox for byte values (bytes, KiB, kB, MiB, MB etc.) that supports BinaryUnitDialect (see bug 364321) and localisation (KFormat does supoprt localisation, https://api.kde.org/frameworks/kcoreaddons/html/classKFormat.html). Suggested name: KByteSpinBox

The idea is that it would hold a byte value, but it would be formatted as either bytes, KiB, kB, MiB, MB etc. depending on the user’s BinaryUnitDialect and language/locale settings. In other words, when displaying the byte value, it would be divided 1000, 1024 etc., and the suffix would be set to kB/KB/KiB.

This is needed in Dolphin (bug 453853), Konqueror (bug 466257) and probably other applications too.

It should be possible to specify a fixed ‘major’ unit (e.g., *always* shows the value as KiB/kB/KB, even for very large values) or have the widget (by default) automatically choose the unit based on the value (bytes for values < 1000 or 1024, kB/KiB for larger values, MB/MiB for even larger values), cf. the AutoAdjust feature in KFormat::UnitPrefix.

Advantages:
* BinaryUnitDialect would be respected (bug 364321)
* The unit suffix would be automatically localised
* The implementation of byte value widgets in applications would be simpler:
  * No need for manually dividing by 1000, 1024 etc. in various functions
  * No need for manually handling large ranges (e.g., from bytes to GiB)
  * No need for manually formatting the values when getting/setting byte values, adding/stripping suffixes