aboutsummaryrefslogtreecommitdiff
path: root/lumina-fm/widgets
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2015-10-15 09:42:10 -0400
committerKen Moore <moorekou@gmail.com>2015-10-15 09:42:10 -0400
commitdfc87d6d2cfd8ffd3274d8a101b2b476faf65ea9 (patch)
tree3122775cd6aaedd9cb07a9f45af9881a4c0644de /lumina-fm/widgets
parentoops - now the "New Tab" item should read "New Browser" (only changed tooltip... (diff)
downloadlumina-dfc87d6d2cfd8ffd3274d8a101b2b476faf65ea9.tar.gz
lumina-dfc87d6d2cfd8ffd3274d8a101b2b476faf65ea9.tar.bz2
lumina-dfc87d6d2cfd8ffd3274d8a101b2b476faf65ea9.zip
Update the lumina-fm thumbnail loader to run in a *truly* separate thread from the main process using QtConcurrent. This keeps the ui completely interactive while still loading all the images.
Diffstat (limited to 'lumina-fm/widgets')
-rw-r--r--lumina-fm/widgets/DirWidget.cpp28
-rw-r--r--lumina-fm/widgets/DirWidget.h4
2 files changed, 26 insertions, 6 deletions
diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp
index b154b708..21029fb5 100644
--- a/lumina-fm/widgets/DirWidget.cpp
+++ b/lumina-fm/widgets/DirWidget.cpp
@@ -15,6 +15,7 @@
#include <QInputDialog>
#include <QScrollBar>
#include <QSettings>
+#include <QtConcurrent/QtConcurrentRun>
#include <LuminaOS.h>
#include <LuminaXDG.h>
@@ -74,7 +75,12 @@ DirWidget::DirWidget(QString objID, QWidget *parent) : QWidget(parent), ui(new U
}
DirWidget::~DirWidget(){
-
+ stopload = true; //just in case another thread is still loading/running
+}
+
+void DirWidget::cleanup(){
+ stopload = true; //just in case another thread is still loading/running
+ if(thumbThread.isRunning()){ thumbThread.waitForFinished(); } //this will stop really quickly with the flag set
}
void DirWidget::ChangeDir(QString dirpath){
@@ -473,7 +479,7 @@ void DirWidget::LoadDir(QString dir, QList<LFileInfo> list){
if(!canmodify){ stats.prepend(tr("(Limited Access) ")); }
ui->label_status->setText( stats.simplified() );
if(DEBUG){ qDebug() << "DONE:" << time.elapsed(); }
- if(showThumbs){ QTimer::singleShot(0,this, SLOT(startLoadThumbs())); }
+ if(showThumbs){ thumbThread = QtConcurrent::run(this, &DirWidget::startLoadThumbs); }
}
void DirWidget::LoadSnaps(QString basedir, QStringList snaps){
@@ -603,22 +609,24 @@ void DirWidget::startLoadThumbs(){
if(DEBUG){ qDebug() << "Start Loading Thumbnails:" << needThumbs; }
if(needThumbs.isEmpty()){ return; }
needThumbs.removeDuplicates(); //just in case
- QTime updatetime = QTime::currentTime().addMSecs(500);
+ //QTime updatetime = QTime::currentTime().addMSecs(500);
for(int i=0; i<needThumbs.length() && !stopload; i++){
if(showDetails){
//Use the tree widget
QList<QTreeWidgetItem*> items = treeWidget->findItems(needThumbs[i], Qt::MatchExactly);
if(items.isEmpty()){ continue; } //invalid item for some reason
+ if(stopload){ return; } //stop right now
QTreeWidgetItem *it = items.first();
it->setIcon(0, QIcon( QPixmap(it->whatsThis(0).section("::::",1,100)).scaled(listWidget->iconSize(),Qt::IgnoreAspectRatio, Qt::FastTransformation) ) );
}else{
//Use the list widget
QList<QListWidgetItem*> items = listWidget->findItems(needThumbs[i], Qt::MatchExactly);
if(items.isEmpty()){ continue; }
+ if(stopload){ return; } //stop right now
QListWidgetItem *it = items.first();
it->setIcon(QIcon( QPixmap(it->whatsThis().section("::::",1,100)).scaled(listWidget->iconSize(),Qt::IgnoreAspectRatio, Qt::FastTransformation) ) );
}
- if(QTime::currentTime() > updatetime){ QApplication::processEvents(); updatetime = QTime::currentTime().addMSecs(500); }//keep the UI snappy while loading a directory
+ //if(QTime::currentTime() > updatetime){ QApplication::processEvents(); updatetime = QTime::currentTime().addMSecs(500); }//keep the UI snappy while loading a directory
}
}
@@ -780,8 +788,8 @@ void DirWidget::on_slider_snap_valueChanged(int val){
ui->tool_snap_older->setEnabled(val > ui->slider_snap->minimum());
if(val >= snapshots.length() || val < 0){
ui->label_snap->setText(tr("Current"));
- }else{
- ui->label_snap->setText( QFileInfo(snapbasedir+snapshots[val]).created().toString(Qt::DefaultLocaleShortDate) );
+ }else if(QFile::exists(snapbasedir+snapshots[val])){
+ ui->label_snap->setText( QFileInfo(snapbasedir+snapshots[val]).lastModified().toString(Qt::DefaultLocaleShortDate) );
}
//Exit if a non-interactive snapshot change
if(!ui->group_snaps->isEnabled()){ return; } //internal change - do not try to change the actual info
@@ -794,6 +802,14 @@ void DirWidget::on_slider_snap_valueChanged(int val){
dir = normalbasedir;
}else{
dir = snapbasedir+snapshots[val]+"/";
+ if(!QFile::exists(dir)){
+ //This snapshot must have been removed in the background by pruning tools
+ // move to a newer snapshot or the current base dir as necessary
+ qDebug() << "Snapshot no longer available:" << dir;
+ qDebug() << " - Reloading available snapshots";
+ emit findSnaps(ID, normalbasedir);
+ return;
+ }
if(snaprelpath.isEmpty()){
//Need to figure out the relative path within the snapshot
snaprelpath = normalbasedir.section(snapbasedir.section(ZSNAPDIR,0,0), 1,1000);
diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h
index f26002af..274873e2 100644
--- a/lumina-fm/widgets/DirWidget.h
+++ b/lumina-fm/widgets/DirWidget.h
@@ -16,6 +16,7 @@
#include <QShortcut>
#include <QFileSystemWatcher>
#include <QTimer>
+#include <QFuture>
#include "../DirData.h"
#include "DDListWidgets.h"
@@ -33,6 +34,8 @@ public:
DirWidget(QString objID, QWidget *parent = 0); //needs a unique ID (to distinguish from other DirWidgets)
~DirWidget();
+ void cleanup(); //called before the browser is closed down
+
//Directory Managment
void ChangeDir(QString dirpath);
void setDirCompleter(QCompleter *comp);
@@ -77,6 +80,7 @@ private:
bool showDetails, showThumbs, canmodify, stopload; //which widget to use for showing items
QList<DETAILTYPES> listDetails;
QMenu *contextMenu;
+ QFuture<void> thumbThread;
//The Toolbar and associated items
QToolBar *toolbar;
QLineEdit *line_dir;
bgstack15