diff options
author | Ken Moore <ken@ixsystems.com> | 2017-06-16 14:59:08 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-06-16 14:59:08 -0400 |
commit | 6169281e880cdf64f24876babd4a0be13bb21a6e (patch) | |
tree | 71eed97a8da195d5c126ea08329dffc20cc675b7 /src-qt5 | |
parent | Minor debugging change in lumina-fm (diff) | |
download | lumina-6169281e880cdf64f24876babd4a0be13bb21a6e.tar.gz lumina-6169281e880cdf64f24876babd4a0be13bb21a6e.tar.bz2 lumina-6169281e880cdf64f24876babd4a0be13bb21a6e.zip |
Speed up the loading of thumbnails in lumina-fm. Now all the scaling and such is done in the external thread - so images appear as they are ready instead of bogging down the main thread..
Diffstat (limited to 'src-qt5')
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/Browser.cpp | 35 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/Browser.h | 5 |
2 files changed, 22 insertions, 18 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.cpp b/src-qt5/desktop-utils/lumina-fm/Browser.cpp index b7eb9709..010196a4 100644 --- a/src-qt5/desktop-utils/lumina-fm/Browser.cpp +++ b/src-qt5/desktop-utils/lumina-fm/Browser.cpp @@ -20,7 +20,7 @@ Browser::Browser(QObject *parent) : QObject(parent){ showHidden = false; showThumbs = false; imageFormats = LUtils::imageExtensions(false); //lowercase suffixes - connect(this, SIGNAL(threadDone(QString, QByteArray)), this, SLOT(futureFinished(QString, QByteArray))); //will always be between different threads + connect(this, SIGNAL(threadDone(QString, QImage)), this, SLOT(futureFinished(QString, QImage))); //will always be between different threads } Browser::~Browser(){ @@ -53,20 +53,25 @@ bool Browser::showingThumbnails(){ // PRIVATE void Browser::loadItem(QString info, Browser *obj){ //qDebug() << "LoadItem:" << info; - QByteArray bytes; + QImage pix; if(imageFormats.contains(info.section(".",-1).toLower()) ){ QFile file(info); if(file.open(QIODevice::ReadOnly)){ - bytes = file.readAll(); + QByteArray bytes = file.readAll(); file.close(); + pix.loadFromData(bytes); + if(bytes.size() > (512*1024) ){ //more than 512 KB + pix = pix.scaled(256,256, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } } } + //qDebug() << " - done with item:" << info; - obj->emit threadDone(info, bytes); + obj->emit threadDone(info, pix); } QIcon Browser::loadIcon(QString icon){ - if(!mimeIcons.contains(icon)){ + if(!mimeIcons.contains(icon)){ mimeIcons.insert(icon, LXDG::findIcon(icon, "unknown")); } @@ -76,7 +81,7 @@ QIcon Browser::loadIcon(QString icon){ // PRIVATE SLOTS void Browser::fileChanged(QString file){ - if(file.startsWith(currentDir+"/") ){ + if(file.startsWith(currentDir+"/") ){ if(QFile::exists(file) ){ QtConcurrent::run(this, &Browser::loadItem, file, this); } //file modified but not removed else{ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); } //file removed - need to update entire dir }else if(file==currentDir){ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); } @@ -87,20 +92,20 @@ void Browser::dirChanged(QString dir){ else if(dir.startsWith(currentDir)){ QtConcurrent::run(this, &Browser::loadItem, dir, this ); } } -void Browser::futureFinished(QString name, QByteArray icon){ +void Browser::futureFinished(QString name, QImage icon){ //Note: this will be called once for every item that loads qDebug() << "Future Finished:" << name; QIcon ico; LFileInfo info(name); - if(!icon.isEmpty()){ + if(!icon.isNull()){ //qDebug() << " -- Data:"; - QPixmap pix; - if(pix.loadFromData(icon) ){ ico.addPixmap(pix); } + QPixmap pix = QPixmap::fromImage(icon); + ico.addPixmap(pix); }else if(info.isDir()){ //qDebug() << " -- Folder:"; - ico = loadIcon("folder"); + ico = loadIcon("folder"); } - if(ico.isNull()){ + if(ico.isNull()){ //qDebug() << " -- MimeType:" << info.fileName() << info.mimetype(); ico = loadIcon(info.iconfile()); } @@ -116,8 +121,8 @@ void Browser::loadDirectory(QString dir){ qDebug() << "Load Directory" << dir; if(currentDir != dir){ //let the main widget know to clear all current items (completely different dir) oldFiles.clear(); - emit clearItems(); - } + emit clearItems(); + } currentDir = dir; //save this for later //clean up the watcher first QStringList watched; watched << watcher->files() << watcher->directories(); @@ -141,7 +146,7 @@ void Browser::loadDirectory(QString dir){ QtConcurrent::run(this, &Browser::loadItem, path, this); }else{ //No special icon loading - just skip the file read step - futureFinished(path, QByteArray()); //loadItem(path, this); + futureFinished(path, QImage()); //loadItem(path, this); } } watcher->addPath(directory.absolutePath()); diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.h b/src-qt5/desktop-utils/lumina-fm/Browser.h index b96a7281..40e98753 100644 --- a/src-qt5/desktop-utils/lumina-fm/Browser.h +++ b/src-qt5/desktop-utils/lumina-fm/Browser.h @@ -46,7 +46,6 @@ private: bool showHidden, showThumbs; QStringList imageFormats, oldFiles; QHash<QString, QIcon> mimeIcons; //cache for quickly re-using QIcons - void loadItem(QString info, Browser *obj); //this is the main loader class - multiple instances each run in a separate thread QIcon loadIcon(QString icon); //simplification for using/populating the mimIcons cache @@ -55,7 +54,7 @@ private slots: void fileChanged(QString); //tied into the watcher - for file change notifications void dirChanged(QString); // tied into the watcher - for new/removed files in the current dir - void futureFinished(QString, QByteArray); + void futureFinished(QString, QImage); public slots: void loadDirectory(QString dir = ""); @@ -70,7 +69,7 @@ signals: void itemsLoading(int); //number of items which are getting loaded //Internal signal for the alternate threads - void threadDone(QString, QByteArray); + void threadDone(QString, QImage); }; #endif |