summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-18 21:22:18 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-18 21:22:18 -0600
commit7dc3aa5b3c7b626e7faffe4306f0b282d4c415a4 (patch)
tree552afdc9711812436b2bf078cc68c4819bdab97b /ui
parent4517e98110af93568523dad82ceab455b0b08682 (diff)
downloadhorizon-7dc3aa5b3c7b626e7faffe4306f0b282d4c415a4.tar.gz
horizon-7dc3aa5b3c7b626e7faffe4306f0b282d4c415a4.tar.bz2
horizon-7dc3aa5b3c7b626e7faffe4306f0b282d4c415a4.tar.xz
horizon-7dc3aa5b3c7b626e7faffe4306f0b282d4c415a4.zip
Qt UI: Make @alyx and @tecuane happy
Diffstat (limited to 'ui')
-rw-r--r--ui/qt5/partitiondiskpage.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/ui/qt5/partitiondiskpage.cc b/ui/qt5/partitiondiskpage.cc
index b47000b..c5eb17f 100644
--- a/ui/qt5/partitiondiskpage.cc
+++ b/ui/qt5/partitiondiskpage.cc
@@ -36,6 +36,23 @@ QIcon iconForDisk(Horizon::DiskMan::Disk disk) {
return QIcon::fromTheme(iconName);
}
+QString prettySizeForMB(uint32_t mbyte) {
+ static const char prefixes[5] = {'M', 'G', 'T', 'E', 'Z'};
+ size_t prefix = 0;
+ float size = mbyte;
+
+ while(size > 2048) {
+ size /= 1024;
+ prefix++;
+ }
+ while(prefix > sizeof(prefixes)) {
+ size *= 1024;
+ prefix--;
+ }
+
+ return QString{"%1 %2B"}.arg(size, 0, 'f', 2).arg(prefixes[prefix]);
+}
+
PartitionDiskPage::PartitionDiskPage(QWidget *parent)
: HorizonWizardPage(parent) {
loadWatermark("disk");
@@ -91,10 +108,11 @@ PartitionDiskPage::PartitionDiskPage(QWidget *parent)
void PartitionDiskPage::initializePage() {
#ifdef HAS_INSTALL_ENV
for(auto disk : horizonWizard()->disks) {
- QString name{QString("%1 (%2)\n%3 MB available of %4 MB")
+ QString name{QString("%1 (%2)\n%3 available of %4")
.arg(QString::fromStdString(disk.model()))
.arg(QString::fromStdString(disk.name()))
- .arg(disk.contiguous_block()).arg(disk.total_size())};
+ .arg(prettySizeForMB(disk.contiguous_block()))
+ .arg(prettySizeForMB(disk.total_size()))};
QListWidgetItem *item = new QListWidgetItem(iconForDisk(disk), name, diskChooser);
item->setToolTip(QString::fromStdString(disk.dev_path()));
item->setData(Qt::UserRole, QString::fromStdString(disk.node()));