diff options
author | william <william.os4y@gmail.com> | 2015-03-21 00:02:20 +0100 |
---|---|---|
committer | william <william.os4y@gmail.com> | 2015-03-21 00:02:20 +0100 |
commit | 3386ba378052c028cf34fd22f72101847365380a (patch) | |
tree | 6bf24ba11b5ccc78dc0fc6e908fb69c2bc67ad89 | |
parent | Add in statusBar, side to the number of items displayed, the size of the files (diff) | |
download | lumina-3386ba378052c028cf34fd22f72101847365380a.tar.gz lumina-3386ba378052c028cf34fd22f72101847365380a.tar.bz2 lumina-3386ba378052c028cf34fd22f72101847365380a.zip |
Add possibility to calculate the file size of the selected items.
Refactoring of the procedure
-rw-r--r-- | lumina-fm/MainUI.cpp | 46 | ||||
-rw-r--r-- | lumina-fm/MainUI.h | 3 |
2 files changed, 28 insertions, 21 deletions
diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp index 711022ec..a7043195 100644 --- a/lumina-fm/MainUI.cpp +++ b/lumina-fm/MainUI.cpp @@ -396,6 +396,27 @@ QString MainUI::getCurrentDir(){ return currentDir->whatsThis(); } +QString MainUI::ItemsInstatusBar(QFileInfoList fileList, QString message){ + int i = 0; + qreal totalSizes = 0; + foreach (QFileInfo fileInfo, fileList ) + { + if (fileInfo.isFile()) totalSizes += fileInfo.size(); + i += 1; + } + if (i==0) return ""; + QString strSize = QString(tr("%1: %2")).arg(message).arg(i); + if (i>0 and totalSizes>1024*1024*1024) + strSize += QString(tr(", size: %1 Gb")).arg(totalSizes/1024/1024/1024, 0,'f', 2); + else if (i>0 and totalSizes>1024*1024) + strSize += QString(tr(", size: %1 Mb")).arg(totalSizes/1024/1024, 0,'f',2); + else if (i>0 and totalSizes>1024) + strSize += QString(tr(", size: %1 Kb")).arg(totalSizes/1024, 0, 'f' , 2); + else + if (totalSizes > 0) { strSize += QString(tr(", size: %1 b")).arg(totalSizes, 0, 'f' , 2);} + return strSize; +} + void MainUI::setCurrentDir(QString dir){ if(dir.isEmpty()){ return; } if(syncTimer->isActive()){ syncTimer->stop(); } //already loading the info @@ -449,27 +470,9 @@ void MainUI::setCurrentDir(QString dir){ else{ ui->label_dir_stats->setText(tr("Limited Access Directory")); } QFileInfoList fileList = fsmod->rootDirectory().entryInfoList(); - int i = 0; - qreal totalSizes = 0; - foreach (QFileInfo fileInfo, fileList ) - { - if (fileInfo.isFile()) { - totalSizes += fileInfo.size(); - i += 1; - } - } - QString strSize = QString(tr("Items: %1")).arg(i); - if (i>0 and totalSizes>1024*1024*1024) - strSize += QString(tr(", size: %1 Gb")).arg(totalSizes/1024/1024/1024, 0,'f', 2); - else if (i>0 and totalSizes>1024*1024) - strSize += QString(tr(", size: %1 Mb")).arg(totalSizes/1024/1024, 0,'f',2); - else if (i>0 and totalSizes>1024) - strSize += QString(tr(", size: %1 Kb")).arg(totalSizes/1024, 0, 'f' , 2); - else - if (i>0) { strSize += QString(tr(", size: %1 b")).arg(totalSizes, 0, 'f' , 2);} - + QString msgStatusBar = ItemsInstatusBar(fileList, tr("Items")); + if (!msgStatusBar.isEmpty()) ui->statusbar->showMessage(msgStatusBar); - ui->statusbar->showMessage(strSize); ui->tool_addToDir->setVisible(isUserWritable); ui->tool_addNewFile->setVisible(isUserWritable); ui->actionUpDir->setEnabled(dir!="/"); @@ -982,6 +985,9 @@ void MainUI::OpenContextMenu(const QPoint &pt){ void MainUI::ItemSelectionChanged(){ //Enable/disable the action buttons QFileInfoList sel = getSelectedItems(); + QString msgStatusBar = ItemsInstatusBar(sel, tr("Items selected")); + if (!msgStatusBar.isEmpty()) ui->statusbar->showMessage(msgStatusBar); + ui->tool_act_run->setEnabled(sel.length()==1); ui->tool_act_runwith->setEnabled(sel.length()==1); ui->tool_act_rm->setEnabled(!sel.isEmpty() && isUserWritable); diff --git a/lumina-fm/MainUI.h b/lumina-fm/MainUI.h index 97cadf86..43607be0 100644 --- a/lumina-fm/MainUI.h +++ b/lumina-fm/MainUI.h @@ -114,6 +114,7 @@ private: //Common functions for browser info/usage QString getCurrentDir(); + QString ItemsInstatusBar(QFileInfoList fileList, QString message); void setCurrentDir(QString); QFileInfoList getSelectedItems(); //QModelIndexList getVisibleItems(); @@ -228,4 +229,4 @@ protected: }; -#endif
\ No newline at end of file +#endif |