Skip to content

Commit 1be530e

Browse files
authored
Merge pull request #76 from rodlie/6.1-perf
6.1 fixes
2 parents 03136e5 + 2e839cf commit 1be530e

File tree

5 files changed

+83
-25
lines changed

5 files changed

+83
-25
lines changed

ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
6.1.4 23-November 2018
1+
6.1.4 26-November 2018
22
- fix potential config corruption. Thanks to @slackuser0xae34 for the patch
33
- fix segfault on thumbnail update (view may have changed since loading thumbnails)
44
- don't cut file(s) if moving to same directory in bookmarks
55
- verify reply from udisks (avoid crash)
66
- populate view if not watched
77
- fix refresh view
8+
- improved performance
89

910
6.1.3 07-October 2018
1011
- update grid on paste/remove

fm/src/mainwindow.cpp

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ MainWindow::MainWindow()
127127
// Create filesystem model
128128
bool realMime = settings->value("realMimeTypes", true).toBool();
129129
modelList = new myModel(realMime, mimeUtils);
130-
connect(modelList, SIGNAL(reloadDir()), this, SLOT(dirLoaded()));
130+
connect(modelList, SIGNAL(reloadDir(QString)), this, SLOT(handleReloadDir(QString)));
131131

132132
dockTree = new QDockWidget(tr("Tree"),this,Qt::SubWindow);
133133
dockTree->setObjectName("treeDock");
@@ -243,6 +243,7 @@ MainWindow::MainWindow()
243243
show();
244244

245245
trashDir = Common::trashDir();
246+
ignoreReload = false;
246247

247248
QTimer::singleShot(0, this, SLOT(lateStart()));
248249
}
@@ -378,8 +379,8 @@ void MainWindow::lateStart() {
378379
connect(detailTree, SIGNAL(pressed(QModelIndex)),
379380
this, SLOT(listItemPressed(QModelIndex)));
380381

381-
connect(modelList, SIGNAL(thumbUpdate()),
382-
this, SLOT(thumbUpdate()));
382+
connect(modelList, SIGNAL(thumbUpdate(QString)),
383+
this, SLOT(thumbUpdate(QString)));
383384

384385
qApp->setKeyboardInputInterval(1000);
385386

@@ -667,19 +668,20 @@ void MainWindow::treeSelectionChanged(QModelIndex current, QModelIndex previous)
667668

668669
listSelectionModel->blockSignals(0);
669670
updateGrid();
671+
qDebug() << "trigger dirloaded on tree selection changed";
670672
QTimer::singleShot(30,this,SLOT(dirLoaded()));
671673
}
672674

673675
//---------------------------------------------------------------------------
674-
void MainWindow::dirLoaded()
676+
void MainWindow::dirLoaded(bool thumbs)
675677
{
676678

677679
if (backIndex.isValid()) {
678680
backIndex = QModelIndex();
679681
return;
680682
}
681683

682-
qDebug() << "dirLoaded";
684+
qDebug() << "dirLoaded triggered, thumbs?" << thumbs;
683685
qint64 bytes = 0;
684686
QModelIndexList items;
685687
bool includeHidden = hiddenAct->isChecked();
@@ -704,12 +706,32 @@ void MainWindow::dirLoaded()
704706
statusSize->setText(QString("%1 items").arg(items.count()));
705707
statusDate->setText(QString("%1").arg(total));
706708

707-
if (thumbsAct->isChecked()) { QtConcurrent::run(modelList,&myModel::loadThumbs,items); }
709+
if (thumbsAct->isChecked() && thumbs) { QtConcurrent::run(modelList,&myModel::loadThumbs,items); }
708710
updateGrid();
709711
}
710712

711-
void MainWindow::thumbUpdate()
713+
void MainWindow::updateDir()
712714
{
715+
dirLoaded(false /* dont refresh thumb*/);
716+
}
717+
718+
void MainWindow::handleReloadDir(const QString &path)
719+
{
720+
if (ignoreReload) {
721+
qDebug() << "ignore reload";
722+
return;
723+
}
724+
ignoreReload = true;
725+
qDebug() << "handle reload dir" << path << modelList->getRootPath();
726+
if (path != modelList->getRootPath()) { return; }
727+
dirLoaded();
728+
QTimer::singleShot(500, this, SLOT(enableReload()));
729+
}
730+
731+
void MainWindow::thumbUpdate(const QString &path)
732+
{
733+
qDebug() << "thumbupdate" << path << modelList->getRootPath();
734+
if (path != modelList->getRootPath()) { return; }
713735
refresh(false, false);
714736
}
715737

@@ -1534,12 +1556,21 @@ void MainWindow::refresh(bool modelRefresh, bool loadDir)
15341556
qDebug() << "refresh";
15351557
if (modelRefresh) {
15361558
modelList->refreshItems();
1537-
modelList->update();
1559+
modelList->forceRefresh();
15381560
}
15391561
QModelIndex baseIndex = modelView->mapFromSource(modelList->index(pathEdit->currentText()));
15401562
if (currentView == 2) { detailTree->setRootIndex(baseIndex); }
15411563
else { list->setRootIndex(baseIndex); }
1542-
if (loadDir) { dirLoaded(); }
1564+
if (loadDir) {
1565+
qDebug() << "trigger dirloaded from refresh";
1566+
dirLoaded();
1567+
}
1568+
}
1569+
1570+
void MainWindow::enableReload()
1571+
{
1572+
qDebug() << "enable reload";
1573+
ignoreReload = false;
15431574
}
15441575
//---------------------------------------------------------------------------
15451576

@@ -1840,6 +1871,7 @@ void MainWindow::actionMapper(QString cmd)
18401871
//---------------------------------------------------------------------------------
18411872
void MainWindow::clearCutItems()
18421873
{
1874+
qDebug() << "clearCutItems";
18431875
//this refreshes existing items, sizes etc but doesn't re-sort
18441876
modelList->clearCutItems();
18451877
modelList->update();
@@ -1848,8 +1880,9 @@ void MainWindow::clearCutItems()
18481880

18491881
if (currentView == 2) { detailTree->setRootIndex(baseIndex); }
18501882
else { list->setRootIndex(baseIndex); }
1851-
QTimer::singleShot(50,this,SLOT(dirLoaded()));
1852-
return;
1883+
1884+
qDebug() << "trigger updateDir from clearCutItems";
1885+
QTimer::singleShot(50,this,SLOT(updateDir()));
18531886
}
18541887

18551888
//---------------------------------------------------------------------------------

fm/src/mainwindow.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ public slots:
276276
void focusAction();
277277
void openFolderAction();
278278
void exitAction();
279-
void dirLoaded();
280-
void thumbUpdate();
279+
void dirLoaded(bool thumbs = true);
280+
void updateDir();
281+
void handleReloadDir(const QString &path);
282+
void thumbUpdate(const QString &path);
281283
void addressChanged(int,int);
282284
void loadSettings(bool wState = true, bool hState = true, bool tabState = true, bool thumbState = true);
283285
void firstRunBookmarks(bool isFirstRun);
@@ -313,6 +315,7 @@ private slots:
313315
void handlePathRequested(QString path);
314316
void slowPathEdit();
315317
void refresh(bool modelRefresh = true, bool loadDir = true);
318+
void enableReload();
316319
private:
317320
void createActions();
318321
void createActionIcons();
@@ -451,6 +454,8 @@ private slots:
451454
QString copyXof;
452455
// custom timestamp for copy of
453456
QString copyXofTS;
457+
458+
bool ignoreReload;
454459
};
455460

456461
//---------------------------------------------------------------------------------

fm/src/mymodel.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ void myModel::clearIconCache() {
108108
QFile(QString("%1/folder.cache").arg(Common::configDir())).remove();
109109
QFile(QString("%1/file.cache").arg(Common::configDir())).remove();
110110
}
111+
112+
void myModel::forceRefresh()
113+
{
114+
qDebug() << "force refresh model view";
115+
beginResetModel();
116+
endResetModel();
117+
}
111118
//---------------------------------------------------------------------------
112119

113120
/**
@@ -272,7 +279,7 @@ void myModel::notifyChange()
272279
}
273280

274281
notifier->setEnabled(1);
275-
emit reloadDir();
282+
//if (!lastEventFilename.isEmpty()) { emit reloadDir(); }
276283
}
277284

278285
//---------------------------------------------------------------------------------------
@@ -286,19 +293,21 @@ void myModel::eventTimeout()
286293
void myModel::notifyProcess(int eventID, QString fileName)
287294
{
288295
qDebug() << "notifyProcess" << eventID << fileName;
289-
if(watchers.contains(eventID)) {
296+
QString folderChanged;
297+
if (watchers.contains(eventID)) {
290298
myModelItem *parent = rootItem->matchPath(watchers.value(eventID).split(SEPARATOR));
291-
if(parent) {
299+
if (parent) {
292300
parent->dirty = 1;
293301
QDir dir(parent->absoluteFilePath());
302+
folderChanged = dir.absolutePath();
294303
QFileInfoList all = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
295304
foreach(myModelItem * child, parent->children()) {
296-
if(all.contains(child->fileInfo())) {
305+
if (all.contains(child->fileInfo())) {
297306
//just remove known items
298307
all.removeOne(child->fileInfo());
299308
} else {
300-
//must of been deleted, remove from model
301-
if(child->fileInfo().isDir()) {
309+
//must have been deleted, remove from model
310+
if (child->fileInfo().isDir()) {
302311
int wd = watchers.key(child->absoluteFilePath());
303312
inotify_rm_watch(inotifyFD,wd);
304313
watchers.remove(wd);
@@ -321,7 +330,10 @@ void myModel::notifyProcess(int eventID, QString fileName)
321330
if (!fileName.isEmpty() && showThumbs) {
322331
lastEventFilename = fileName;
323332
}
324-
emit reloadDir();
333+
if (!folderChanged.isEmpty()) {
334+
qDebug() << "folder modified" << folderChanged;
335+
emit reloadDir(folderChanged);
336+
}
325337
}
326338

327339
//---------------------------------------------------------------------------------
@@ -442,6 +454,7 @@ void myModel::refreshItems()
442454
{
443455
myModelItem *item = rootItem->matchPath(currentRootPath.split(SEPARATOR));
444456
if (item == NULL) { return; }
457+
qDebug() << "refresh items";
445458
item->clearAll();
446459
populateItem(item);
447460
}
@@ -607,6 +620,7 @@ void myModel::loadThumbs(QModelIndexList indexes) {
607620

608621
// Loads thumbnails from cache
609622
if (files.count()) {
623+
QFileInfo pathInfo (files.at(0));
610624
if (thumbs->count() == 0) {
611625
qDebug() << "thumbs are empty, try to load cache ...";
612626
QFile fileIcons(QString("%1/thumbs.cache").arg(Common::configDir()));
@@ -619,8 +633,11 @@ void myModel::loadThumbs(QModelIndexList indexes) {
619633
thumbCount = thumbs->count();
620634
qDebug() << "thumbcount" << thumbCount;
621635
}
636+
622637
foreach (QString item, files) {
623-
if (!thumbs->contains(item) || (item.split("/").takeLast() == lastEventFilename && !lastEventFilename.isEmpty())) {
638+
if (!thumbs->contains(item) ||
639+
(item.split("/").takeLast() == lastEventFilename && !lastEventFilename.isEmpty()))
640+
{
624641
qDebug() << "gen new thumb" << item;
625642
thumbs->insert(item, getThumb(item));
626643
if (item.split("/").takeLast() == lastEventFilename) {
@@ -639,7 +656,7 @@ void myModel::loadThumbs(QModelIndexList indexes) {
639656
}
640657
}
641658
}
642-
emit thumbUpdate();
659+
emit thumbUpdate(pathInfo.absolutePath());
643660
}
644661
}
645662

@@ -910,6 +927,7 @@ QVariant myModel::findMimeIcon(myModelItem *item) const {
910927
mimeIcons->insert(mime, theIcon);
911928
return theIcon;
912929
}
930+
913931
//---------------------------------------------------------------------------
914932

915933
bool myModel::setData(const QModelIndex & index, const QVariant & value, int role)

fm/src/mymodel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ public slots:
8686
void addWatcher(myModelItem* path);
8787
void clearCutItems();
8888
void clearIconCache();
89+
void forceRefresh();
8990
signals:
9091
void dragDropPaste(const QMimeData *data, QString newPath,
9192
Common::DragMode mode = Common::DM_UNKNOWN);
92-
void thumbUpdate();
93-
void reloadDir();
93+
void thumbUpdate(const QString &path);
94+
void reloadDir(const QString &path);
9495
protected:
9596
QVariant data(const QModelIndex & index, int role) const;
9697
QVariant headerData(int section, Qt::Orientation orientation, int role) const;

0 commit comments

Comments
 (0)