aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-fm/Browser.cpp
diff options
context:
space:
mode:
authorWeblate <noreply@weblate.org>2016-10-03 12:12:45 +0000
committerWeblate <noreply@weblate.org>2016-10-03 12:12:45 +0000
commitc8f94dc7519dab04b08f286fc760bb490dbb6f9b (patch)
tree9808abd67d538dd5ce66c517412603d6f9a0b1b5 /src-qt5/desktop-utils/lumina-fm/Browser.cpp
parentTranslated using Weblate (lumina_DESKTOP@es (generated)) (diff)
parentMerge remote-tracking branch 'origin/master' (diff)
downloadlumina-c8f94dc7519dab04b08f286fc760bb490dbb6f9b.tar.gz
lumina-c8f94dc7519dab04b08f286fc760bb490dbb6f9b.tar.bz2
lumina-c8f94dc7519dab04b08f286fc760bb490dbb6f9b.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src-qt5/desktop-utils/lumina-fm/Browser.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.cpp109
1 files changed, 85 insertions, 24 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.cpp b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
index 0aeb5648..7455e5ea 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
@@ -6,17 +6,28 @@
//===========================================
#include "Browser.h"
+#include <QStringList>
+#include <QTimer>
+#include <QtConcurrent>
+#include <QDebug>
+
+#include <LuminaUtils.h>
+
Browser::Browser(QObject *parent) : QObject(parent){
watcher = new QFileSystemWatcher(this);
connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(QString)) );
connect(watcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(dirChanged(QString)) );
showHidden = false;
+ imageFormats = LUtils::imageExtensions(false); //lowercase suffixes
+ connect(this, SIGNAL(threadDone(QString, QByteArray)), this, SLOT(futureFinished(QString, QByteArray)), Qt::QueuedConnection); //will always be between different threads
}
Browser::~Browser(){
watcher->deleteLater();
}
+QString Browser::currentDirectory(){ return currentDir; }
+
void Browser::showHiddenFiles(bool show){
if(show !=showHidden){
showHidden = show;
@@ -24,54 +35,104 @@ void Browser::showHiddenFiles(bool show){
}
}
bool Browser::showingHiddenFiles(){
-
+ return showHidden;
}
// PRIVATE
-void Browser::loadItem(QFileInfo info){
- LFileInfo linfo(info);
- QIcon ico;
- if(linfo.isImage()){
- QPixmap pix;
- if(pix.load(info.absoluteFilePath()) ){
- if(pix.height()>128){ pix = pix.scaled(128, 128, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); }
- ico.addPixmap(pix);
+void Browser::loadItem(QString info){
+ //qDebug() << "LoadItem:" << info;
+ ////FileItem item;
+ //itemame = info;
+ QByteArray bytes;
+ if(imageFormats.contains(info.section(".",-1).toLower()) ){
+ QFile file(info);
+ if(file.open(QIODevice::ReadOnly)){
+ bytes = file.readAll();
+ file.close();
}
- }else if(linfo.isDirectory()){
- ico = LXDG::findIcon("folder","inode/directory");
+
+ /*QPixmap pix;
+ if(pix.load(item.info.absoluteFilePath()) ){
+ if(pix.height()>128){ pix = pix.scaled(128, 128, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); }
+ item.icon.addPixmap(pix);
+ }*/
+ }/*else if(item.info.isDir()){
+ item.icon = LXDG::findIcon("folder","inode/directory");
}
- if(ico.isNull()){ ico = LXDG::findIcon(linfo.mimetype(), "unknown"); }
- emit ItemDataAvailable(ico, linfo);
+ if(item.icon.isNull()){ item.icon = LXDG::findIcon(item.info.mimetype(), "unknown"); }*/
+ //qDebug() << " - done with item:" << info;
+ emit threadDone(info, bytes);
+ //return item;
}
// PRIVATE SLOTS
-void Browser::fileChanged(QString){
-
+void Browser::fileChanged(QString file){
+ if(file.startsWith(currentDir+"/")){ QtConcurrent::run(this, &Browser::loadItem, file ); }
+ else if(file==currentDir){ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); }
}
-void Browser::dirChanged(QString){
+void Browser::dirChanged(QString dir){
+ if(dir==currentDir){ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); }
+ else if(dir.startsWith(currentDir)){ QtConcurrent::run(this, &Browser::loadItem, dir ); }
+}
+void Browser::futureFinished(QString name, QByteArray icon){
+ //Note: this will be called once for every item that loads
+ QIcon ico;
+ LFileInfo info(name);
+ if(!icon.isEmpty()){
+ QPixmap pix;
+ if(pix.loadFromData(icon) ){ ico.addPixmap(pix); }
+ }else if(info.isDir()){
+ ico = LXDG::findIcon("folder","inode/directory");
+ }
+ if(ico.isNull()){
+ //qDebug() << "MimeType:" << info.fileName() << info.mimetype();
+ ico = LXDG::findIcon( info.iconfile(), "unknown" );
+ }
+ this->emit itemDataAvailable( ico, info );
}
// PUBLIC SLOTS
-QString Browser::loadDirectory(QString dir){
+void Browser::loadDirectory(QString dir){
+ //qDebug() << "Load Directory" << dir;
if(dir.isEmpty()){ dir = currentDir; } //reload current directory
if(dir.isEmpty()){ return; } //nothing to do - nothing previously loaded
+ if(currentDir != dir){ //let the main widget know to clear all current items (completely different dir)
+ oldFiles.clear();
+ emit clearItems();
+ }
+ currentDir = dir; //save this for later
//clean up the watcher first
QStringList watched; watched << watcher->files() << watcher->directories();
if(!watched.isEmpty()){ watcher->removePaths(watched); }
- emit clearItems(); //let the main widget know to clear all current items
- //QApplication::processEvents();
+ QStringList old = oldFiles; //copy this over for the moment (both lists will change in a moment)
+ oldFiles.clear(); //get ready for re-creating this list
// read the given directory
QDir directory(dir);
if(directory.exists()){
- QFileInfoList files;
- if(showHidden){ files = directory.entryInfoList( QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotOrDotDot, QDir::NoSort); }
- else{ files = directory.entryInfoList( QDir::Dirs | QDir::Files | QDir::NoDotOrDotDot, QDir::NoSort); }
+ QStringList files;
+ if(showHidden){ files = directory.entryList( QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDir::NoSort); }
+ else{ files = directory.entryList( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::NoSort); }
+ emit itemsLoading(files.length());
+ QCoreApplication::processEvents();
for(int i=0; i<files.length(); i++){
- watcher->addPath(files[i].absoluteFilePath());
- QtConcurrent::run(this, &Browser::loadDirectory, files[i]);
+ watcher->addPath(directory.absoluteFilePath(files[i]));
+ //qDebug() << "Future Starting:" << files[i];
+ QString path = directory.absoluteFilePath(files[i]);
+ if(old.contains(path)){ old.removeAll(path); }
+ oldFiles << path; //add to list for next time
+ QtConcurrent::run(this, &Browser::loadItem, path );
+ QCoreApplication::sendPostedEvents();
}
watcher->addPath(directory.absolutePath());
+ if(!old.isEmpty()){
+ old.removeAll(directory.absolutePath());
+ for(int i=0; i<old.length(); i++){
+ emit itemRemoved(old[i]);
+ }
+ }
+ }else{
+ emit itemsLoading(0); //nothing to load
}
}
bgstack15