aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-10-09 16:06:38 -0400
committerKen Moore <ken@ixsystems.com>2017-10-09 16:06:38 -0400
commit860d2ca1863f3838b5575c6efc2151a7270b0d79 (patch)
tree7af4a5d589f37065c359b3f24f6a1d243ebb5da5 /src-qt5/desktop-utils
parentAdd a few test QML files which work to the src-qml directory. (diff)
downloadlumina-860d2ca1863f3838b5575c6efc2151a7270b0d79.tar.gz
lumina-860d2ca1863f3838b5575c6efc2151a7270b0d79.tar.bz2
lumina-860d2ca1863f3838b5575c6efc2151a7270b0d79.zip
Clean up how the backend of the file manager handles atomic updates to changes in the current directory. This speeds up sequential re-scans considerably.
Diffstat (limited to 'src-qt5/desktop-utils')
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.cpp43
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.h10
-rw-r--r--src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp10
-rw-r--r--src-qt5/desktop-utils/lumina-fm/BrowserWidget.h2
-rw-r--r--src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp2
5 files changed, 42 insertions, 25 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.cpp b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
index e0e79d04..4665ccc4 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
@@ -35,6 +35,7 @@ QString Browser::currentDirectory(){ return currentDir; }
void Browser::showHiddenFiles(bool show){
if(show !=showHidden){
showHidden = show;
+ lastcheck = QDateTime(); //reset this timestamp - need to reload all
if(!currentDir.isEmpty()){ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); }
}
}
@@ -45,6 +46,7 @@ bool Browser::showingHiddenFiles(){
void Browser::showThumbnails(bool show){
if(show != showThumbs){
showThumbs = show;
+ lastcheck = QDateTime(); //reset this timestamp - need to reload all
if(!currentDir.isEmpty()){ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); }
}
}
@@ -69,7 +71,7 @@ void Browser::loadItem(QString info, Browser *obj){
}else if(videoFormats.contains(info.section(".",-1).toLower()) ){
videoList.push_back(info);
}
- qDebug() << " - done with item:" << info;
+ //qDebug() << " - done with item:" << info;
obj->emit threadDone(info, pix);
}
@@ -84,15 +86,19 @@ QIcon* Browser::loadIcon(QString icon){
// PRIVATE SLOTS
void Browser::fileChanged(QString file){
- if(file.startsWith(currentDir+"/") ){
+ //qDebug() << "Got File Changed:" << file;
+ if(file.section("/",0,-2) == 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()) ); }
+ else if(oldFiles.contains(file) ){
+ oldFiles.removeAll(file);
+ emit itemRemoved(file);
+ }
+ }//else if(file==currentDir){ QTimer::singleShot(0, this, SLOT(loadDirectory()) ); }
}
void Browser::dirChanged(QString dir){
-
- if(dir==currentDir){ QTimer::singleShot(500, this, SLOT(loadDirectory()) ); }
+ //qDebug() << "Got Dir Changed:" << dir;
+ if(dir==currentDir){ QTimer::singleShot(10, this, SLOT(loadDirectory()) ); }
else if(dir.startsWith(currentDir)){ QtConcurrent::run(this, &Browser::loadItem, dir, this ); }
}
@@ -109,7 +115,7 @@ void Browser::captureFrame(QPixmap pix, QIcon *ico) {
static int received = 0;
//qDebug() << "grabbing frame" << received+1;
*ico = pix/*.scaledToHeight(64)*/;
- if(++received == videoList.size()) {
+ if(++received == videoList.size()) {
emit frameChanged();
received = 0;
}
@@ -145,7 +151,7 @@ void Browser::futureFinished(QString name, QImage icon){
player->play();
player->pause();
- //qDebug() << "Started loop";
+ //qDebug() << "Started loop";
loadingTime.start();
QTimer timeout;
timeout.setSingleShot(true);
@@ -154,7 +160,7 @@ void Browser::futureFinished(QString name, QImage icon){
connect(this, SIGNAL(frameChanged()), &loop, SLOT(quit()), Qt::DirectConnection);
connect(&timeout, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.exec();
- //qDebug() << "Exited loop";
+ //qDebug() << "Exited loop";
qDebug() << loadingTime.elapsed();
delete player;
@@ -168,16 +174,21 @@ void Browser::futureFinished(QString name, QImage icon){
}
// PUBLIC SLOTS
-void Browser::loadDirectory(QString dir){
+void Browser::loadDirectory(QString dir, bool force){
+ if(force){ lastcheck = QDateTime(); } //reset check time to force reloads
videoList.clear();
if(dir.isEmpty()){ dir = currentDir; } //reload current directory
if(dir.isEmpty()){ return; } //nothing to do - nothing previously loaded
//qDebug() << "Load Directory" << dir;
+ bool dirupdate = true;
if(currentDir != dir){ //let the main widget know to clear all current items (completely different dir)
oldFiles.clear();
+ lastcheck = QDateTime(); //null time
emit clearItems();
+ dirupdate = false;
}
currentDir = dir; //save this for later
+ QDateTime now = QDateTime::currentDateTime();
//clean up the watcher first
QStringList watched; watched << watcher->files() << watcher->directories();
if(!watched.isEmpty()){ watcher->removePaths(watched); }
@@ -189,15 +200,18 @@ void Browser::loadDirectory(QString dir){
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());
+ if(dirupdate){ emit itemsLoading(files.length()); }
for(int i=0; i<files.length(); 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
+ bool reloaditem = !dirupdate || lastcheck.isNull() || (QFileInfo(path).lastModified() > lastcheck || QFileInfo(path).created() > lastcheck);
+ //if(dirupdate){ qDebug() << "Reload Item:" << reloaditem << path.section("/",-1); }
+ //reloaditem = true;
+ if(old.contains(path)){ old.removeAll(path); } //still in existance
//if(showThumbs && imageFormats.contains(path.section(".",-1).toLower())){
- QtConcurrent::run(this, &Browser::loadItem, path, this);
+ //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);
@@ -213,4 +227,5 @@ void Browser::loadDirectory(QString dir){
}else{
emit itemsLoading(0); //nothing to load
}
+ lastcheck = now; // save this for later
}
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.h b/src-qt5/desktop-utils/lumina-fm/Browser.h
index 004bf046..3254db54 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.h
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.h
@@ -44,8 +44,9 @@ public:
private:
QString currentDir;
+ QDateTime lastcheck;
QFileSystemWatcher *watcher;
- QList<QString> videoList;
+ QList<QString> videoList;
bool showHidden, showThumbs;
QStringList imageFormats, videoFormats, oldFiles;
QHash<QString, QIcon> mimeIcons; //cache for quickly re-using QIcons
@@ -56,12 +57,13 @@ private:
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 captureFrame(QPixmap, QIcon*);
- void stopVideo(QMediaPlayer*, QMediaPlayer::MediaStatus);
+ void captureFrame(QPixmap, QIcon*);
+ void stopVideo(QMediaPlayer*, QMediaPlayer::MediaStatus);
void futureFinished(QString, QImage);
public slots:
- void loadDirectory(QString dir = "");
+ void loadDirectory(QString dir = "", bool force = false);
+
signals:
//Main Signals
void itemRemoved(QString item); //emitted if a file was removed from the underlying
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
index d5f219bb..d2c07648 100644
--- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
@@ -24,7 +24,7 @@ BrowserWidget::BrowserWidget(QString objID, QWidget *parent) : QWidget(parent){
connect(BROWSER, SIGNAL(itemRemoved(QString)), this, SLOT(itemRemoved(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)) );
+ connect(this, SIGNAL(dirChange(QString, bool)), BROWSER, SLOT(loadDirectory(QString, bool)) );
listWidget = 0;
treeWidget = 0;
readDateFormat();
@@ -50,7 +50,7 @@ void BrowserWidget::changeDirectory(QString dir){
if( (historyList.isEmpty() || historyList.last()!=cleaned) && !cleaned.isEmpty() ){ historyList << cleaned; }
}
//qDebug() << "History:" << historyList;
- emit dirChange(dir);
+ emit dirChange(dir, false);
}
void BrowserWidget::showDetails(bool show){
@@ -81,7 +81,7 @@ void BrowserWidget::showDetails(bool show){
connect(treeWidget, SIGNAL(GotFocus()), this, SLOT(selectionChanged()) );
retranslate();
treeWidget->sortItems(0, Qt::AscendingOrder);
- if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
+ if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange("", true); }
}else if(!show && listWidget==0){
listWidget = new DDListWidget(this);
listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -91,7 +91,7 @@ void BrowserWidget::showDetails(bool show){
connect(listWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SIGNAL(contextMenuRequested()) );
connect(listWidget, SIGNAL(DataDropped(QString, QStringList)), this, SIGNAL(DataDropped(QString, QStringList)) );
connect(listWidget, SIGNAL(GotFocus()), this, SLOT(selectionChanged()) );
- if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
+ if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange("",true); }
}
//qDebug() << " Done making widget";
}
@@ -127,7 +127,7 @@ void BrowserWidget::setThumbnailSize(int px){
}
//qDebug() << "Changing Icon Size:" << px << larger;
if(BROWSER->currentDirectory().isEmpty() || !larger ){ return; } //don't need to reload icons unless the new size is larger
- emit dirChange("");
+ emit dirChange("", larger);
}
int BrowserWidget::thumbnailSize(){
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h
index fafb3746..a9e58bf3 100644
--- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h
+++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.h
@@ -88,7 +88,7 @@ signals:
void hasFocus(QString); //ID output
//Internal signal
- void dirChange(QString); //current dir path
+ void dirChange(QString, bool); //current dir path, force
};
#endif
diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp
index 8273d09c..1b00343d 100644
--- a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp
@@ -59,7 +59,7 @@ DirWidget::DirWidget(QString objID, QSettings *settings, QWidget *parent) : QWid
RCBW = 0; //right column browser is unavailable initially
BW = new BrowserWidget("", this);
ui->browser_layout->addWidget(BW);
- connect(BW, SIGNAL(dirChange(QString)), this, SLOT(currentDirectoryChanged()) );
+ connect(BW, SIGNAL(dirChange(QString, bool)), this, SLOT(currentDirectoryChanged()) );
connect(BW, SIGNAL(itemsActivated()), this, SLOT(runFiles()) );
connect(BW, SIGNAL(DataDropped(QString, QStringList)), this, SIGNAL(PasteFiles(QString, QStringList)) );
connect(BW, SIGNAL(contextMenuRequested()), this, SLOT(OpenContextMenu()) );
bgstack15