From db428a4da0be7672ddcaa48747fd063b8e6a08b6 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 5 Nov 2014 14:50:53 -0500 Subject: Streamline the file manager quite a bit by putting the long-lived checks in a seperate thread. This speeds up the loading of a directory quite a bit. --- lumina-fm/BackgroundWorker.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++ lumina-fm/BackgroundWorker.h | 41 +++++++++++++++++++++++ lumina-fm/MainUI.cpp | 50 ++++++++++++++++++++-------- lumina-fm/MainUI.h | 19 +++++++---- lumina-fm/lumina-fm.pro | 6 ++-- 5 files changed, 169 insertions(+), 21 deletions(-) create mode 100644 lumina-fm/BackgroundWorker.cpp create mode 100644 lumina-fm/BackgroundWorker.h (limited to 'lumina-fm') diff --git a/lumina-fm/BackgroundWorker.cpp b/lumina-fm/BackgroundWorker.cpp new file mode 100644 index 00000000..1e6ef28d --- /dev/null +++ b/lumina-fm/BackgroundWorker.cpp @@ -0,0 +1,74 @@ +#include "BackgroundWorker.h" + +#include +#include +#include + +BackgroundWorker::BackgroundWorker() : QObject(){ + +} + +BackgroundWorker::~BackgroundWorker(){ + +} + +void BackgroundWorker::startDirChecks(QString path){ + QDir dir(path); + //First check for image files + if(imgFilter.isEmpty()){ + //Initial Run - load supported image extensions + QList fmt = QImageReader::supportedImageFormats(); + for(int i=0; i +#include +#include +#include +#include +#include + + +class BackgroundWorker : public QObject{ + Q_OBJECT +public: + BackgroundWorker(); + ~BackgroundWorker(); + +private: + QStringList multiFilter, imgFilter; + +public slots: + //Kickoff processes with these slots + // and then listen for the appropriate signals when finished + void startDirChecks(QString path); + +signals: + void ImagesAvailable(QStringList files); + void MultimediaAvailable(QStringList files); + void SnapshotsAvailable(QString basedir, QStringList snappaths); + +}; + +#endif \ No newline at end of file diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp index 50cb798c..c70e3918 100644 --- a/lumina-fm/MainUI.cpp +++ b/lumina-fm/MainUI.cpp @@ -28,6 +28,12 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ currentDir = new QLineEdit(this); ui->toolBar->insertWidget(ui->actionBookMark, currentDir); currentDir->setFocusPolicy(Qt::StrongFocus); + + workThread = new QThread; + workThread->setObjectName("Lumina-fm filesystem worker"); + worker = new BackgroundWorker; + worker->moveToThread(workThread); + fsmod = new QFileSystemModel(this); fsmod->setRootPath("/"); ui->tree_dir_view->setModel(fsmod); @@ -81,6 +87,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ pasteFilesShort = new QShortcut( QKeySequence(tr("Ctrl+V")), this); deleteFilesShort = new QShortcut( QKeySequence(tr("Delete")), this); //Finish loading the interface + workThread->start(); setupIcons(); setupConnections(); loadSettings(); @@ -91,6 +98,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ } MainUI::~MainUI(){ + workThread->quit(); + workThread->wait(); } void MainUI::OpenDirs(QStringList dirs){ @@ -166,7 +175,13 @@ void MainUI::setupConnections(){ connect(radio_view_details, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool)) ); connect(radio_view_list, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool)) ); connect(radio_view_icons, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool)) ); - + + //Background worker class + connect(this, SIGNAL(DirChanged(QString)), worker, SLOT(startDirChecks(QString)) ); + 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)) ); + //Action buttons on browser page connect(ui->tool_act_run, SIGNAL(clicked()), this, SLOT(OpenItem()) ); connect(ui->tool_act_runwith, SIGNAL(clicked()), this, SLOT(OpenItemWith()) ); @@ -366,9 +381,13 @@ void MainUI::setCurrentDir(QString dir){ //qDebug() << "History:" << history; tabBar->setTabData(tabBar->currentIndex(), history); //Now adjust the items as necessary - QTimer::singleShot(0, this, SLOT(checkForMultimediaFiles())); - QTimer::singleShot(0, this, SLOT(checkForBackups())); - QTimer::singleShot(0, this, SLOT(checkForPictures())); + ui->tool_goToPlayer->setVisible(false); + ui->tool_goToRestore->setVisible(false); + ui->tool_goToImages->setVisible(false); + emit DirChanged(rawdir); + //QTimer::singleShot(0, this, SLOT(checkForMultimediaFiles())); + //QTimer::singleShot(0, this, SLOT(checkForBackups())); + //QTimer::singleShot(0, this, SLOT(checkForPictures())); if(isUserWritable){ ui->label_dir_stats->setText(""); } else{ ui->label_dir_stats->setText(tr("Limited Access Directory")); } ui->tool_addToDir->setVisible(isUserWritable); @@ -403,9 +422,9 @@ QFileInfoList MainUI::getSelectedItems(){ // PRIVATE SLOTS //============== //General button check functions -void MainUI::checkForMultimediaFiles(){ - ui->tool_goToPlayer->setVisible(false); - //Check for multimedia files not implemented yet! +void MainUI::AvailableMultimediaFiles(QStringList files){ + /*ui->tool_goToPlayer->setVisible(false); + QDir dir(getCurrentDir()); if(multiFilter.isEmpty()){ QStringList mimes = Phonon::BackendCapabilities::availableMimeTypes(); @@ -417,7 +436,8 @@ void MainUI::checkForMultimediaFiles(){ qDebug() << "Supported Multimedia Formats:" << multiFilter; } QStringList files = dir.entryList(multiFilter, QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); - if(!files.isEmpty() && !multiFilter.isEmpty()){ + */ + if(!files.isEmpty()){ ui->combo_player_list->clear(); ui->combo_player_list->addItems(files); ui->tool_goToPlayer->setVisible(true); @@ -427,8 +447,8 @@ void MainUI::checkForMultimediaFiles(){ } -void MainUI::checkForBackups(){ - ui->tool_goToRestore->setVisible(false); +void MainUI::AvailableBackups(QString basedir, QStringList snapdirs){ + /*ui->tool_goToRestore->setVisible(false); snapDirs.clear(); //clear the internal variable if(!isUserWritable){ //cannot restore files into a non-writable directory @@ -472,13 +492,16 @@ void MainUI::checkForBackups(){ }else{ //No dir found: put the snapmod on the lumina directory (someplace out of the way) snapmod->setRootPath(QDir::homePath()+"/.lumina"); - } + }*/ + snapmod->setRootPath(basedir); //set the base snapshot dir as the new root + snapDirs = snapdirs; + //Now enable the button if any snapshots available ui->tool_goToRestore->setVisible(!snapDirs.isEmpty()); } -void MainUI::checkForPictures(){ - ui->tool_goToImages->setVisible(false); +void MainUI::AvailablePictures(QStringList pics){ + /*ui->tool_goToImages->setVisible(false); QDir dir(getCurrentDir()); if(imgFilter.isEmpty()){ QList fmt = QImageReader::supportedImageFormats(); @@ -486,6 +509,7 @@ void MainUI::checkForPictures(){ qDebug() << "Supported Image Formats:" << imgFilter; } QStringList pics = dir.entryList(imgFilter, QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); + */ if(!pics.isEmpty()){ ui->combo_image_name->clear(); ui->combo_image_name->addItems(pics); diff --git a/lumina-fm/MainUI.h b/lumina-fm/MainUI.h index 31a0269e..61e34ffe 100644 --- a/lumina-fm/MainUI.h +++ b/lumina-fm/MainUI.h @@ -38,9 +38,10 @@ #include #include #include +#include //Phonon widgets -#include +//#include #include #include #include @@ -55,6 +56,7 @@ #include "FODialog.h" //file operation dialog #include "BMMDialog.h" //bookmark manager dialog #include "MimeIconProvider.h" //icon provider for the view widgets +#include "BackgroundWorker.h" namespace Ui{ class MainUI; @@ -73,6 +75,8 @@ public slots: private: Ui::MainUI *ui; + QThread *workThread; + BackgroundWorker *worker; //Internal non-ui widgets QTabBar *tabBar; QLineEdit *currentDir; @@ -94,7 +98,7 @@ private: //Internal variables QStringList snapDirs; //internal saved variable for the discovered zfs snapshot dirs QString CItem; //the item that was right-clicked (for the context menu) - QStringList imgFilter, multiFilter; //image/multimedia filters + //QStringList imgFilter, multiFilter; //image/multimedia filters QSettings *settings; QShortcut *nextTabLShort, *nextTabRShort, *closeTabShort, *copyFilesShort, *pasteFilesShort, *deleteFilesShort; QCompleter *dirCompleter; @@ -122,10 +126,10 @@ private slots: this->OpenDirs(in.split("\n")); } - //General button check functions (start in a new thread!) - void checkForMultimediaFiles(); - void checkForBackups(); - void checkForPictures(); + //General button check functions (started in a seperate thread!) + void AvailableMultimediaFiles(QStringList files); + void AvailableBackups(QString basedir, QStringList snapdirs); + void AvailablePictures(QStringList files); //General page switching void goToMultimediaPage(); @@ -202,6 +206,9 @@ private slots: void CopyItems(); void PasteItems(); +signals: + void DirChanged(QString path); + protected: void resizeEvent(QResizeEvent*); diff --git a/lumina-fm/lumina-fm.pro b/lumina-fm/lumina-fm.pro index a192d3d7..cc9ad275 100644 --- a/lumina-fm/lumina-fm.pro +++ b/lumina-fm/lumina-fm.pro @@ -12,12 +12,14 @@ TEMPLATE = app SOURCES += main.cpp \ MainUI.cpp \ FODialog.cpp \ - BMMDialog.cpp + BMMDialog.cpp \ + BackgroundWorker.cpp HEADERS += MainUI.h \ FODialog.h \ BMMDialog.h \ - MimeIconProvider.h + MimeIconProvider.h \ + BackgroundWorker.h FORMS += MainUI.ui \ FODialog.ui \ -- cgit