diff options
Diffstat (limited to 'src-qt5/desktop-utils')
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/Browser.cpp | 68 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/Browser.h | 8 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp | 22 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/BrowserWidget.h | 3 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp | 2 |
5 files changed, 61 insertions, 42 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.cpp b/src-qt5/desktop-utils/lumina-fm/Browser.cpp index 3ebef38f..4a3c8fef 100644 --- a/src-qt5/desktop-utils/lumina-fm/Browser.cpp +++ b/src-qt5/desktop-utils/lumina-fm/Browser.cpp @@ -27,7 +27,7 @@ Browser::Browser(QObject *parent) : QObject(parent){ imageFormats = LUtils::imageExtensions(false); //lowercase suffixes //connect(surface, SIGNAL(frameReceived(QImage)), this, SLOT(captureFrame(QImage))); //connect(player, &QMediaPlayer::mediaStatusChanged, this, [&]{ stopVideo(player, player->mediaStatus()); }); - connect(this, SIGNAL(threadDone(QString, const QImage*)), this, SLOT(futureFinished(QString, const QImage*))); //will always be between different threads + connect(this, SIGNAL(threadDone(const QString, const QImage)), this, SLOT(futureFinished(const QString, const QImage))); //will always be between different threads } Browser::~Browser(){ @@ -60,30 +60,34 @@ bool Browser::showingThumbnails(){ } // PRIVATE -void Browser::loadItem(QString info, Browser *obj){ - QImage* pix = 0; //this needs to return 0 if a standard icon is to be used - if(imageFormats.contains(info.section(".",-1).toLower()) ){ - QFile file(info); - if(file.open(QIODevice::ReadOnly)){ - QByteArray bytes = file.readAll(); - file.close(); - QImage *tmppix = new QImage(); - tmppix->loadFromData(bytes); - if(tmppix->width() > 256 || tmppix->height() > 256 ){ - *pix = tmppix->scaled(256,256, Qt::KeepAspectRatio, Qt::FastTransformation); - } - delete tmppix; +void Browser::loadItem(const QString info, Browser *obj){ + //qDebug() << "Load Thumbnail in separate thread:" << info; + const QImage pix(info); + obj->emit threadDone(info, pix); + //qDebug() << " - Done:" << info; + /* QImage* pix = new QImage(); + qDebug() << "Load Thumbnail"; + QFile file(info); + if(file.open(QIODevice::ReadOnly)){ + QByteArray bytes = file.readAll(); + pix->loadFromData(bytes); + if(pix->width() > 256 || pix->height() > 256 ){ + *pix = pix->scaled(256,256, Qt::KeepAspectRatio, Qt::FastTransformation); } + file.close(); } - //qDebug() << " - done with item:" << info; - obj->emit threadDone(info, pix); + qDebug() << "Loading Thumbnail Done:" << info; + obj->emit threadDone(info, pix);*/ } QIcon* Browser::loadIcon(QString icon){ + hashMutex.lock(); if(!mimeIcons.contains(icon)){ mimeIcons.insert(icon, LXDG::findIcon(icon, "unknown")); } - return &mimeIcons[icon]; + QIcon *tmp = &mimeIcons[icon]; + hashMutex.unlock(); + return tmp; } @@ -111,15 +115,15 @@ void Browser::dirChanged(QString dir){ //else if(dir.startsWith(currentDir)){ QtConcurrent::run(this, &Browser::loadItem, dir, this ); } } -void Browser::futureFinished(QString name, const QImage* icon){ +void Browser::futureFinished(QString name, const QImage icon){ //Note: this will be called once for every item that loads //Haven't added the extra files in a directory fix, but that should be easy to do //Try to load a file with multiple videos and lots of other stuff before any other directory. It crashes for some reason //qDebug() << "Finished:" << name; QIcon *ico = new QIcon(); LFileInfo *info = new LFileInfo(name); - if(icon != nullptr && showThumbs){ - QPixmap pix = QPixmap::fromImage(*icon); + if(!icon.isNull() && showThumbs){ + QPixmap pix = QPixmap::fromImage(icon); ico->addPixmap(pix); /*}else if(info->isVideo() && showThumbs) { if(videoImages.find(name) == videoImages.end()) { @@ -132,12 +136,10 @@ void Browser::futureFinished(QString name, const QImage* icon){ ico->addPixmap(videoImages[name]); }*/ }else{ + //Standard Icon based on file type ico = loadIcon(info->iconfile()); } this->emit itemDataAvailable( ico, info); - // We are done with processing received image (copied to pixmap above) so now clean it up - delete icon; - icon = nullptr; //qDebug() << " -- done:" << name; } @@ -163,13 +165,16 @@ void Browser::loadDirectory(QString dir, bool force){ if(dir.isEmpty()){ return; } //nothing to do - nothing previously loaded updateList.clear(); //qDebug() << "Load Directory" << dir; + if(dir.endsWith("/")){ dir.chop(1); } bool dirupdate = true; if(currentDir != dir){ //let the main widget know to clear all current items (completely different dir) + //qDebug() << " - different Directory"; //videoImages.clear(); oldFiles.clear(); lastcheck = QDateTime(); //null time emit clearItems(); dirupdate = false; + QCoreApplication::processEvents(); } currentDir = dir; //save this for later QDateTime now = QDateTime::currentDateTime(); @@ -185,7 +190,7 @@ void Browser::loadDirectory(QString dir, bool force){ 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); } if(dirupdate || old.isEmpty()){ emit itemsLoading(files.length()); } - //qDebug() << "Files Found:" << files.length(); + //qDebug() << "Files Found:" << files.length() << currentDir; for(int i=0; i<files.length(); i++){ watcher->addPath(directory.absoluteFilePath(files[i])); QString path = directory.absoluteFilePath(files[i]); @@ -195,12 +200,15 @@ void Browser::loadDirectory(QString dir, bool force){ //reloaditem = true; if(old.contains(path)){ old.removeAll(path); } //still in existance //if(showThumbs && imageFormats.contains(path.section(".",-1).toLower())){ - //qDebug() << "Future Starting:" << files[i]; - if(reloaditem){ QtConcurrent::run(this, &Browser::loadItem, path, this); } - /*}else{ - //No special icon loading - just skip the file read step - futureFinished(path, QImage()); //loadItem(path, this); - }*/ + //qDebug() << "Future Starting:" << path; + if(reloaditem){ + if(imageFormats.contains(path.section(".",-1).toLower()) ){ + QtConcurrent::run(this, &Browser::loadItem, path, this); + }else{ + //No special icon loading - just skip the loadItem function + futureFinished(path, QImage()); + } + } } watcher->addPath(directory.absolutePath()); if(!old.isEmpty()){ diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.h b/src-qt5/desktop-utils/lumina-fm/Browser.h index 4eb9b6fb..dcd10275 100644 --- a/src-qt5/desktop-utils/lumina-fm/Browser.h +++ b/src-qt5/desktop-utils/lumina-fm/Browser.h @@ -20,6 +20,7 @@ #include <LVideoLabel.h> #include <LuminaXDG.h> #include <LFileInfo.h> +#include <QMutex> class Browser : public QObject{ Q_OBJECT @@ -43,14 +44,15 @@ private: QStringList imageFormats, videoFormats, oldFiles, updateList; QHash<QString, QIcon> mimeIcons; //cache for quickly re-using QIcons QTimer *updateTimer; + QMutex hashMutex; - void loadItem(QString info, Browser *obj); //this is the main loader class - multiple instances each run in a separate thread + void loadItem(const 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 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, const QImage* ); + void futureFinished(const QString, const QImage ); void updateRequested(); public slots: @@ -66,7 +68,7 @@ signals: void itemsLoading(int); //number of items which are getting loaded //Internal signal for the alternate threads - void threadDone(QString, const QImage*); + void threadDone(const QString, const QImage); }; #endif diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp index 6fa9da94..65dbdb16 100644 --- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp +++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp @@ -53,6 +53,7 @@ void BrowserWidget::stop(){ } void BrowserWidget::changeDirectory(QString dir){ + //qDebug() << "Change Dir:" << dir; if(USE_VIDEO_LABEL){ QStringList vids = videoMap.keys(); for(int i=0; i<vids.length(); i++){ videoMap.take(vids[i]).second->deleteLater(); } @@ -219,7 +220,7 @@ QStringList BrowserWidget::currentSelection(){ //qDebug() << "Selection number:" << sel.length(); //if(sel.isEmpty() && listWidget->currentItem()!=0){ sel << listWidget->currentItem(); } //qDebug() << "Selection number:" << sel.length(); - for(int i=0; i<sel.length(); i++){ out << sel[i]->whatsThis(); qDebug() << "Selection:" << sel[i]->text() << sel[i]->whatsThis(); } + for(int i=0; i<sel.length(); i++){ out << sel[i]->whatsThis(); } }else if(treeWidget!=0){ QList<QTreeWidgetItem*> sel = treeWidget->selectedItems(); //if(sel.isEmpty() && treeWidget->currentItem()!=0){ sel << treeWidget->currentItem(); } @@ -321,11 +322,13 @@ void BrowserWidget::itemRemoved(QString item){ } void BrowserWidget::itemDataAvailable(const QIcon* ico, LFileInfo *info){ + //qDebug() << "itemDataAvailable"; if(info==0){ return; } + if(info->absolutePath() != BROWSER->currentDirectory()){ return; } //leftover item from a previous load + widgetMutex.lock(); if(listWidget!=0){ listWidget->setWhatsThis( BROWSER->currentDirectory() ); } if(treeWidget!=0){ treeWidget->setWhatsThis(BROWSER->currentDirectory() ); } - if(info->absolutePath() != BROWSER->currentDirectory()){ return; } //leftover item from a previous load - //qDebug() << "Item Data Available:" << info->fileName(); + //if(info->absolutePath().contains("/.zfs/")){ qDebug() << "Item Data Available:" << info->fileName(); } int num = 0; if(listWidget!=0){ //LIST WIDGET - name and icon only @@ -356,11 +359,10 @@ void BrowserWidget::itemDataAvailable(const QIcon* ico, LFileInfo *info){ //Now update the information for the item if(info->isDesktopFile() && info->XDG()->isValid()){ it->setText(info->XDG()->name); - it->setIcon(*ico); }else{ - it->setIcon(*ico); it->setText(info->fileName()); } + if(ico!=0){ it->setIcon(*ico); } }else if(treeWidget!=0){ QTreeWidgetItem *it = 0; @@ -397,7 +399,9 @@ void BrowserWidget::itemDataAvailable(const QIcon* ico, LFileInfo *info){ } } //Now set/update all the data - if(!info->isVideo() || !hasThumbnails() || !USE_VIDEO_LABEL){ it->setIcon(0, *ico); } + if(!info->isVideo() || !hasThumbnails() || !USE_VIDEO_LABEL){ + if(ico!=0){ it->setIcon(0, *ico); } + } it->setText(1, info->isDir() ? "" : LUtils::BytesToDisplaySize(info->size()) ); //size (1) it->setText(2, info->mimetype() ); //type (2) it->setText(3, DTtoString(info->lastModified() )); //modification date (3) @@ -410,7 +414,7 @@ void BrowserWidget::itemDataAvailable(const QIcon* ico, LFileInfo *info){ } if(num < numItems){ //Still loading items - this->setEnabled(false); + //this->setEnabled(false); }else{ //qDebug() << "Got Items Loaded:" << num << numItems; if(freshload && treeWidget!=0){ @@ -423,9 +427,11 @@ void BrowserWidget::itemDataAvailable(const QIcon* ico, LFileInfo *info){ QtConcurrent::run(this, &BrowserWidget::loadStatistics, this); //QTimer::singleShot(0, this, SLOT(loadStatistics())); //Done loading items - this->setEnabled(true); + //this->setEnabled(true); }//end check for finished loading items + widgetMutex.unlock(); + //qDebug() << " - Done with itemDataAvailable"; } void BrowserWidget::itemsLoading(int total){ diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h index 46165242..f6d918e3 100644 --- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h +++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h @@ -29,6 +29,7 @@ private: QMap<QString,QPair<QTreeWidgetItem*, LVideoWidget*>> videoMap; bool freshload; int treeSortColumn; + QMutex widgetMutex; //The drag and drop brower widgets DDListWidget *listWidget; @@ -61,7 +62,7 @@ public: QStringList history(); void setShowActive(bool show); //used for accenting if the widget is "active" - + void setTreeWidgetSortColumn(int col, bool now = false); QString status(){ return statustip; } diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp index 44930511..f9f62427 100644 --- a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp +++ b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp @@ -832,6 +832,7 @@ void DirWidget::removeFiles(){ } void DirWidget::runFiles(){ + //qDebug() << "Run Files"; QStringList sel = currentBrowser()->currentSelection(); if(sel.isEmpty()){ return; } QStringList dirs; @@ -842,6 +843,7 @@ void DirWidget::runFiles(){ QProcess::startDetached("lumina-open \""+sel[i]+"\""); } } + //qDebug() << " - got Dirs:" << dirs; if(!dirs.isEmpty()){ currentBrowser()->changeDirectory( dirs.takeFirst()); //load the first directory in this widget } |