diff options
author | Ken Moore <ken@pcbsd.org> | 2014-11-05 14:50:53 -0500 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2014-11-05 14:50:53 -0500 |
commit | db428a4da0be7672ddcaa48747fd063b8e6a08b6 (patch) | |
tree | 6810c67c6b73ee23534b950a4d98b83d05170cbe /lumina-fm | |
parent | Fix the display of a few of the search results in lumina-search (diff) | |
download | lumina-db428a4da0be7672ddcaa48747fd063b8e6a08b6.tar.gz lumina-db428a4da0be7672ddcaa48747fd063b8e6a08b6.tar.bz2 lumina-db428a4da0be7672ddcaa48747fd063b8e6a08b6.zip |
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.
Diffstat (limited to 'lumina-fm')
-rw-r--r-- | lumina-fm/BackgroundWorker.cpp | 74 | ||||
-rw-r--r-- | lumina-fm/BackgroundWorker.h | 41 | ||||
-rw-r--r-- | lumina-fm/MainUI.cpp | 50 | ||||
-rw-r--r-- | lumina-fm/MainUI.h | 19 | ||||
-rw-r--r-- | lumina-fm/lumina-fm.pro | 6 |
5 files changed, 169 insertions, 21 deletions
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 <LuminaXDG.h> +#include <Phonon/BackendCapabilities> +#include <QImageReader> + +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<QByteArray> fmt = QImageReader::supportedImageFormats(); + for(int i=0; i<fmt.length(); i++){ imgFilter << "*."+QString(fmt[i]).toLower(); } + qDebug() << "Supported Image Formats:" << imgFilter; + } + QStringList pics = dir.entryList(imgFilter, QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); + if(!pics.isEmpty() && !imgFilter.isEmpty()){ emit ImagesAvailable(pics); } + + //Now check for multimedia files + if(multiFilter.isEmpty()){ + //Initial Run - load supported multimedia extensions + QStringList mimes = Phonon::BackendCapabilities::availableMimeTypes(); + mimes = mimes.filter("audio/") + mimes.filter("video/"); + for(int i=0; i<mimes.length(); i++){ + multiFilter << LXDG::findFilesForMime(mimes[i]); + } + multiFilter.removeDuplicates(); + qDebug() << "Supported Multimedia Formats:" << multiFilter; + } + QStringList files = dir.entryList(multiFilter, QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); + if(!files.isEmpty() && !multiFilter.isEmpty()){ emit MultimediaAvailable(files); } + + //Now check for ZFS snapshots of the directory + if(!QFileInfo(path).isWritable() ){ return; } //skip ZFS checks if can't restore to this dir + QStringList snapDirs; + QString baseSnapDir; + bool found = false; + while(dir.absolutePath()!="/" && !found){ + if(dir.exists(".zfs/snapshot")){ found = true;} + else{ dir.cdUp(); } + } + //Now find the snapshots that contain this directory and save them + if(found){ + QString reldir = path; + reldir.remove(dir.absolutePath()); //convert to a relative path + dir.cd(".zfs/snapshot"); + baseSnapDir = dir.canonicalPath(); //set the base snapshot dir as the new root + snapDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time); + //Check that the current directory exists in each snapshot + for(int i=0; i<snapDirs.length(); i++){ + if( !dir.exists(snapDirs[i]+"/"+reldir) ){ + snapDirs.removeAt(i); + i--; + }else{ + snapDirs[i] = QFileInfo(dir, snapDirs[i]+"/"+reldir).created().toString("yyyyMMddhhmmsszzz")+"::::"+snapDirs[i]; + } + } + snapDirs.sort(); + //Sort the snapshots by time (newest last) and format them + for(int i=0; i<snapDirs.length(); i++){ + snapDirs[i] = dir.absolutePath()+"/"+snapDirs[i].section("::::",1,50)+"/"+reldir; + } + if(!snapDirs.isEmpty()){ emit SnapshotsAvailable(baseSnapDir, snapDirs); } + //qDebug() << "Found snapshots:" << snapDirs; + } +}
\ No newline at end of file diff --git a/lumina-fm/BackgroundWorker.h b/lumina-fm/BackgroundWorker.h new file mode 100644 index 00000000..3f0410bf --- /dev/null +++ b/lumina-fm/BackgroundWorker.h @@ -0,0 +1,41 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is the background class for running long-lived calculations +//=========================================== +#ifndef _LUMINA_FILE_MANAGER_BACKGROUND_WORKER_H +#define _LUMINA_FILE_MANAGER_BACKGROUND_WORKER_H + +#include <QObject> +#include <QStringList> +#include <QString> +#include <QFileInfo> +#include <QDir> +#include <QDateTime> + + +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<QByteArray> 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 <QDesktopWidget> #include <QThread> #include <QUrl> +#include <QThread> //Phonon widgets -#include <Phonon/BackendCapabilities> +//#include <Phonon/BackendCapabilities> #include <Phonon/MediaObject> #include <Phonon/VideoWidget> #include <Phonon/AudioOutput> @@ -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 \ |