aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2016-09-27 14:24:25 -0400
committerKen Moore <ken@pcbsd.org>2016-09-27 14:24:25 -0400
commit9fe8cb1f455f5c0c029a1340076cb2cae4e2716d (patch)
tree2407de242a7dab5e7fc1ddd458a2704dcf671fd4 /src-qt5/desktop-utils
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-9fe8cb1f455f5c0c029a1340076cb2cae4e2716d.tar.gz
lumina-9fe8cb1f455f5c0c029a1340076cb2cae4e2716d.tar.bz2
lumina-9fe8cb1f455f5c0c029a1340076cb2cae4e2716d.zip
Get the new backend functional.
This is still disabled for the moment, but the initial tests seem to indicate that the new backend is faster and more stable than the current system.
Diffstat (limited to 'src-qt5/desktop-utils')
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.cpp86
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.h28
-rw-r--r--src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp44
-rw-r--r--src-qt5/desktop-utils/lumina-fm/BrowserWidget.h16
-rw-r--r--src-qt5/desktop-utils/lumina-fm/lumina-fm.pro8
-rw-r--r--src-qt5/desktop-utils/lumina-fm/main.cpp12
6 files changed, 157 insertions, 37 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.cpp b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
index b207604c..1312aca0 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
@@ -6,11 +6,20 @@
//===========================================
#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(){
@@ -30,20 +39,30 @@ bool Browser::showingHiddenFiles(){
}
// 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
@@ -57,24 +76,53 @@ void Browser::dirChanged(QString dir){
else if(dir.startsWith(currentDir)){ emit itemUpdated(dir); }
}
+void Browser::futureFinished(QString name, QByteArray icon){
+ //Note: this will be called once for every item that loads
+ qDebug() << "Future Finished" << name;
+ //for(int i=0; i<fwatchers.length(); i++){
+ //if(fwatchers[i]->isFinished()){
+ //FileItem FI = fwatchers[i]->result();
+ //qDebug() << "Found finished:" << FI.name << i;
+ //disconnect(fwatchers[i]);
+ //fwatchers.takeAt(i)->deleteLater();
+ //fwatchers.removeAt(i);
+ 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()){ ico = LXDG::findIcon( info.mimetype(), "unknown" ); }
+ this->emit itemDataAvailable( ico, info );
+ qDebug() << "- done";
+ //i--;
+ //return;
+ //}
+ //}
+}
+
// 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
//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();
// 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); }
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]);
+ QtConcurrent::run(this, &Browser::loadItem, path );
}
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 ccc10c02..870e9fe1 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.h
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.h
@@ -9,6 +9,22 @@
#ifndef _LUMINA_FM_BROWSE_BACKEND_H
#define _LUMINA_FM_BROWSE_BACKEND_H
+#include <QObject>
+#include <QString>
+#include <QFileSystemWatcher>
+#include <QIcon>
+#include <QFutureWatcher>
+
+#include <LuminaXDG.h>
+class FileItem{
+public:
+ QString name;
+ QByteArray icon;
+
+ FileItem(){}
+ ~FileItem(){};
+};
+
class Browser : public QObject{
Q_OBJECT
public:
@@ -19,19 +35,25 @@ public:
void showHiddenFiles(bool);
bool showingHiddenFiles();
+ //FileItem loadItem(QString info); //this is the main loader class - multiple instances each run in a separate thread
+
private:
QString currentDir;
QFileSystemWatcher *watcher;
+ QList< QFutureWatcher<FileItem>* > fwatchers;
bool showHidden;
+ QStringList imageFormats;
- void loadItem(QFileInfo info); //this is the main loader class - multiple instances each run in a separate thread
+ void loadItem(QString info); //this is the main loader class - multiple instances each run in a separate thread
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);
+
public slots:
- QString loadDirectory(QString dir = "");
+ void loadDirectory(QString dir = "");
signals:
//Main Signals
@@ -42,6 +64,8 @@ signals:
//Start/Stop signals for loading of data
void itemsLoading(int); //number of items which are getting loaded
+ //Internal signal for the alternate threads
+ void threadDone(QString, QByteArray);
};
#endif
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
index 12fd36fe..e6017e77 100644
--- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
@@ -5,17 +5,21 @@
// See the LICENSE file for full details
//===========================================
#include "BrowserWidget.h"
+
+#include <QVBoxLayout>
+#include <QTimer>
+
BrowserWidget::BrowserWidget(QString objID, QWidget *parent) : QWidget(parent){
//Setup the Widget/UI
this->setLayout( new QVBoxLayout(this) );
-
+ this->setWhatsThis(objID);
//Setup the backend browser object
BROWSER = new Browser(this);
connect(BROWSER, SIGNAL(clearItems()), this, SLOT(clearItems()) );
connect(BROWSER, SIGNAL(itemUpdated(QString)), this, SLOT(itemUpdated(QString)) );
- connect(BROWSER, SIGNAL(itemUpdated(QString)), this, SLOT(itemUpdated(QString)) );
- connect(BROWSER, SIGNAL(itemUpdated(QString)), this, SLOT(itemUpdated(QString)) );
-
+ connect(BROWSER, SIGNAL(itemDataAvailable(QIcon, LFileInfo)), this, SLOT(itemDataAvailable(QIcon, LFileInfo)) );
+ connect(BROWSER, SIGNAL(itemsLoading(int)), this, SLOT(itemsLoading(int)) );
+ connect(this, SIGNAL(dirChange(QString)), BROWSER, SLOT(loadDirectory(QString)) );
listWidget = 0;
treeWidget = 0;
}
@@ -26,7 +30,33 @@ BrowserWidget::~BrowserWidget(){
void BrowserWidget::changeDirectory(QString dir){
if(BROWSER->currentDirectory()==dir){ return; } //already on this directory
- BROWSER->loadDirectory(dir);
+ emit dirChange(dir);
+}
+
+void BrowserWidget::showDetails(bool show){
+ //Clean up widgets first
+ if(show && listWidget!=0){
+ //Clean up list widget
+ listWidget->deleteLater();
+ listWidget = 0;
+ }else if(!show && treeWidget!=0){
+ treeWidget->deleteLater();
+ treeWidget = 0;
+ }
+ //Now create any new widgets
+ if(show && treeWidget == 0){
+ treeWidget = new DDTreeWidget(this);
+ this->layout()->addWidget(treeWidget);
+ if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
+ }else if(!show && listWidget==0){
+ listWidget = new DDListWidget(this);
+ this->layout()->addWidget(listWidget);
+ if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
+ }
+}
+
+bool BrowserWidget::hasDetails(){
+ return (treeWidget!=0);
}
// =================
@@ -43,11 +73,12 @@ void BrowserWidget::itemUpdated(QString item){
qDebug() << "item updated" << item;
QList<QTreeWidgetItem*> found = treeWidget->findItems(item.section("/",-1), Qt::MatchExactly, 0); //look for exact name match
if(found.isEmpty()){ return; } //no match
- QTreeWidgetItem *it = found[0]; //onlyp update the first match (should only ever be one - duplicate file names are disallowed)
+ QTreeWidgetItem *it = found[0]; //only update the first match (should only ever be one - duplicate file names are disallowed)
//it->setText(
}
void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
+ qDebug() << "Item Data Available:" << info.fileName();
int num = 0;
if(listWidget!=0){
listWidget->addItem( new QListWidgetItem(ico, info.fileName(), listWidget) );
@@ -67,4 +98,3 @@ void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
void BrowserWidget::itemsLoading(int total){
numItems = total; //save this for later
}
-
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h
index a0dc535a..e438c4dc 100644
--- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h
+++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h
@@ -8,14 +8,16 @@
#ifndef _LUMINA_FM_BROWSE_FRONTEND_H
#define _LUMINA_FM_BROWSE_FRONTEND_H
+#include <QString>
+#include <QWidget>
+
#include "Browser.h"
#include "widgets/DDListWidgets.h"
class BrowserWidget : public QWidget{
Q_OBJECT
private:
- Browser *DIR:
- QString ID;
+ Browser *BROWSER;
int numItems; //used for checking if all the items have loaded yet
bool details; //show details or not
@@ -27,7 +29,7 @@ public:
BrowserWidget(QString objID, QWidget *parent = 0);
~BrowserWidget();
- QString id(){ return ID; }
+ QString id(){ return this->whatsThis(); }
void changeDirectory(QString dir);
@@ -37,7 +39,7 @@ public:
public slots:
private slots:
- //Brower connections
+ //Browser connections
void clearItems();
void itemUpdated(QString);
void itemDataAvailable(QIcon, LFileInfo);
@@ -45,7 +47,7 @@ private slots:
signals:
//void activated(QString); //current dir path
- void dirChanged(QString); //current dir path
+ void dirChange(QString); //current dir path
};
@@ -56,7 +58,7 @@ signals:
* On this class, we overwrite the function operator<.
*/
-class CQTreeWidgetItem : public QTreeWidgetItem {
+/*class CQTreeWidgetItem : public QTreeWidgetItem {
public:
CQTreeWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
CQTreeWidgetItem(const QStringList & strings, int type = Type) : QTreeWidgetItem(strings, type) {}
@@ -93,5 +95,5 @@ public:
// In other cases, we trust base class implementation
return QTreeWidgetItem::operator<(tmp);
}
-};
+};*/
#endif
diff --git a/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro b/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro
index 91e2952c..487a6421 100644
--- a/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro
+++ b/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro
@@ -17,7 +17,9 @@ SOURCES += main.cpp \
widgets/SlideshowWidget.cpp \
widgets/DirWidget.cpp \
gitCompat.cpp \
- gitWizard.cpp
+ gitWizard.cpp \
+ Browser.cpp \
+ BrowserWidget.cpp
HEADERS += MainUI.h \
FODialog.h \
@@ -29,7 +31,9 @@ HEADERS += MainUI.h \
widgets/SlideshowWidget.h \
widgets/DirWidget.h \
gitCompat.h \
- gitWizard.h
+ gitWizard.h \
+ Browser.h \
+ BrowserWidget.h
FORMS += MainUI.ui \
FODialog.ui \
diff --git a/src-qt5/desktop-utils/lumina-fm/main.cpp b/src-qt5/desktop-utils/lumina-fm/main.cpp
index b05c4016..eaaf182c 100644
--- a/src-qt5/desktop-utils/lumina-fm/main.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/main.cpp
@@ -9,6 +9,8 @@
#include <LuminaUtils.h>
#include <LuminaSingleApplication.h>
+#include "BrowserWidget.h"
+
int main(int argc, char ** argv)
{
LTHEME::LoadCustomEnvSettings();
@@ -28,6 +30,16 @@ int main(int argc, char ** argv)
w.OpenDirs(in);
w.show();
+ // TESTING CODE FOR NEW BACKEND
+ /*QMainWindow W;
+ BrowserWidget B("",&W);
+ W.setCentralWidget( &B);
+ B.showDetails(false);
+ B.changeDirectory(in.first());
+ qDebug() << "Show Window";
+ W.show();
+ */
+
int retCode = a.exec();
return retCode;
}
bgstack15