From 553105d997c3a29e9983ef1f1995d9593273de55 Mon Sep 17 00:00:00 2001 From: william Date: Wed, 25 Mar 2015 22:57:32 +0100 Subject: display some filesystem's information on the statusbar in a thread safe manier --- lumina-fm/BackgroundWorker.cpp | 29 +++++++++++++++++++++++++- lumina-fm/BackgroundWorker.h | 7 ++++++- lumina-fm/MainUI.cpp | 46 ++++++++++++++---------------------------- lumina-fm/MainUI.h | 4 ++++ 4 files changed, 53 insertions(+), 33 deletions(-) (limited to 'lumina-fm') diff --git a/lumina-fm/BackgroundWorker.cpp b/lumina-fm/BackgroundWorker.cpp index 1438f71e..c8d7cb17 100644 --- a/lumina-fm/BackgroundWorker.cpp +++ b/lumina-fm/BackgroundWorker.cpp @@ -85,4 +85,31 @@ void BackgroundWorker::startDirChecks(QString path){ if(!snapDirs.isEmpty()){ emit SnapshotsAvailable(baseSnapDir, snapDirs); } qDebug() << "Found snapshots"; } -} \ No newline at end of file +} + + +void BackgroundWorker::createStatusBarMsg(QFileInfoList fileList, QString path, QString message){ + //collect some statistics of dir and display them in statusbar + int i = 0; + qreal totalSizes = 0; + foreach (QFileInfo fileInfo, fileList ) + { + if (fileInfo.isFile()) totalSizes += fileInfo.size(); + i += 1; + } + QString msgStatusBar = QString(tr("%1: %2")).arg(message).arg(i); + if (i>0 and totalSizes>1024*1024*1024) + msgStatusBar += QString(tr(", size: %1 Gb")).arg(totalSizes/1024/1024/1024, 0,'f', 2); + else if (i>0 and totalSizes>1024*1024) + msgStatusBar += QString(tr(", size: %1 Mb")).arg(totalSizes/1024/1024, 0,'f',2); + else if (i>0 and totalSizes>1024) + msgStatusBar += QString(tr(", size: %1 Kb")).arg(totalSizes/1024, 0, 'f' , 2); + else + if (totalSizes > 0) { msgStatusBar += QString(tr(", size: %1 b")).arg(totalSizes, 0, 'f' , 2);} + if (!path.isEmpty()) { //path could be empty when fileList is based on user's selection + QString capacity = LOS::FileSystemCapacity(path) ; + if (msgStatusBar.isEmpty()) msgStatusBar += tr("Capacity: ") + capacity; + else msgStatusBar += tr(", Capacity: ") + capacity; + } + if (!msgStatusBar.isEmpty()) emit Si_DisplayStatusBar(msgStatusBar); +} diff --git a/lumina-fm/BackgroundWorker.h b/lumina-fm/BackgroundWorker.h index 25becb53..d50612fa 100644 --- a/lumina-fm/BackgroundWorker.h +++ b/lumina-fm/BackgroundWorker.h @@ -16,6 +16,8 @@ #include #include +#include + class BackgroundWorker : public QObject{ Q_OBJECT @@ -26,17 +28,20 @@ public: private: QStringList multiFilter, imgFilter; QString cdir, csnapdir; //last directory checked (and base snapshot dir found) + QString ItemsInstatusBar(QFileInfoList, QString); public slots: //Kickoff processes with these slots // and then listen for the appropriate signals when finished void startDirChecks(QString path); + void createStatusBarMsg(QFileInfoList fileList, QString path, QString message); signals: void ImagesAvailable(QStringList files); void MultimediaAvailable(QStringList files); void SnapshotsAvailable(QString basedir, QStringList snappaths); + void Si_DisplayStatusBar(QString); }; -#endif \ No newline at end of file +#endif diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp index 1f5a65d0..59cb09bf 100644 --- a/lumina-fm/MainUI.cpp +++ b/lumina-fm/MainUI.cpp @@ -12,6 +12,8 @@ #define DEBUG 0 MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ + //for Signal/slot we must register the Typedef of QFileInfoList + qRegisterMetaType("QFileInfoList"); ui->setupUi(this); if(DEBUG){ qDebug() << "Initilization:"; } //Be careful about the QSettings setup, it must match the lumina-desktop setup @@ -214,6 +216,10 @@ void MainUI::setupConnections(){ connect(worker, SIGNAL(ImagesAvailable(QStringList)), this, SLOT(AvailablePictures(QStringList)) ); connect(worker, SIGNAL(MultimediaAvailable(QStringList)), this, SLOT(AvailableMultimediaFiles(QStringList)) ); connect(worker, SIGNAL(SnapshotsAvailable(QString, QStringList)), this, SLOT(AvailableBackups(QString, QStringList)) ); + + //Background worker class for statusbar + connect(this, SIGNAL(Si_AdaptStatusBar(QFileInfoList, QString, QString)), worker, SLOT(createStatusBarMsg(QFileInfoList, QString, QString)) ); + connect(worker, SIGNAL(Si_DisplayStatusBar(QString)), this, SLOT(DisplayStatusBar(QString)) ); //Action buttons on browser page connect(ui->tool_act_run, SIGNAL(clicked()), this, SLOT(OpenItem()) ); @@ -396,27 +402,6 @@ 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 @@ -465,19 +450,12 @@ void MainUI::setCurrentDir(QString dir){ ui->tool_goToImages->setVisible(false); //if(olddir!=rawdir){ emit DirChanged(rawdir); //This will be automatically run when a new dir is loaded + emit Si_AdaptStatusBar(fsmod->rootDirectory().entryInfoList(), rawdir, tr("Items")); //} if(isUserWritable){ ui->label_dir_stats->setText(""); } else{ ui->label_dir_stats->setText(tr("Limited Access Directory")); } - //collect some statistics of dir and display them in statusbar - QFileInfoList fileList = fsmod->rootDirectory().entryInfoList(); - QString msgStatusBar = ItemsInstatusBar(fileList, tr("Items")); - QString capacity = LOS::FileSystemCapacity(dir) ; - if (msgStatusBar.isEmpty()) msgStatusBar += tr("Capacity: ") + capacity; - else msgStatusBar += tr(", Capacity: ") + capacity; - if (!msgStatusBar.isEmpty()) ui->statusbar->showMessage(msgStatusBar); - ui->tool_addToDir->setVisible(isUserWritable); ui->tool_addNewFile->setVisible(isUserWritable); ui->actionUpDir->setEnabled(dir!="/"); @@ -570,6 +548,11 @@ void MainUI::AvailableBackups(QString basedir, QStringList snapdirs){ ui->tool_goToRestore->setVisible(!snapDirs.isEmpty()); } +void MainUI::DisplayStatusBar(QString msg){ + qDebug() << "in main thread:" << msg; + ui->statusbar->showMessage(msg); +} + void MainUI::AvailablePictures(QStringList pics){ if(!pics.isEmpty()){ QString citem = ui->combo_image_name->currentText(); @@ -990,8 +973,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); + //display info related to files selected. + //TO CHECK: impact if filesystem is very slow + if (sel.size()>0) worker->createStatusBarMsg(sel, "", tr("Items selected")); ui->tool_act_run->setEnabled(sel.length()==1); ui->tool_act_runwith->setEnabled(sel.length()==1); diff --git a/lumina-fm/MainUI.h b/lumina-fm/MainUI.h index 43607be0..4744fe2a 100644 --- a/lumina-fm/MainUI.h +++ b/lumina-fm/MainUI.h @@ -220,9 +220,13 @@ private slots: void CopyItems(); void PasteItems(); void ChecksumItems(); + + //file info in status bar + void DisplayStatusBar(QString); signals: void DirChanged(QString path); + void Si_AdaptStatusBar(QFileInfoList fileList, QString path, QString message); protected: void resizeEvent(QResizeEvent*); -- cgit