Skip to content

Commit

Permalink
Merge pull request #76 from rodlie/6.1-perf
Browse files Browse the repository at this point in the history
6.1 fixes
  • Loading branch information
rodlie authored Nov 25, 2018
2 parents 03136e5 + 2e839cf commit 1be530e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 25 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
6.1.4 23-November 2018
6.1.4 26-November 2018
- fix potential config corruption. Thanks to @slackuser0xae34 for the patch
- fix segfault on thumbnail update (view may have changed since loading thumbnails)
- don't cut file(s) if moving to same directory in bookmarks
- verify reply from udisks (avoid crash)
- populate view if not watched
- fix refresh view
- improved performance

6.1.3 07-October 2018
- update grid on paste/remove
Expand Down
55 changes: 44 additions & 11 deletions fm/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ MainWindow::MainWindow()
// Create filesystem model
bool realMime = settings->value("realMimeTypes", true).toBool();
modelList = new myModel(realMime, mimeUtils);
connect(modelList, SIGNAL(reloadDir()), this, SLOT(dirLoaded()));
connect(modelList, SIGNAL(reloadDir(QString)), this, SLOT(handleReloadDir(QString)));

dockTree = new QDockWidget(tr("Tree"),this,Qt::SubWindow);
dockTree->setObjectName("treeDock");
Expand Down Expand Up @@ -243,6 +243,7 @@ MainWindow::MainWindow()
show();

trashDir = Common::trashDir();
ignoreReload = false;

QTimer::singleShot(0, this, SLOT(lateStart()));
}
Expand Down Expand Up @@ -378,8 +379,8 @@ void MainWindow::lateStart() {
connect(detailTree, SIGNAL(pressed(QModelIndex)),
this, SLOT(listItemPressed(QModelIndex)));

connect(modelList, SIGNAL(thumbUpdate()),
this, SLOT(thumbUpdate()));
connect(modelList, SIGNAL(thumbUpdate(QString)),
this, SLOT(thumbUpdate(QString)));

qApp->setKeyboardInputInterval(1000);

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

listSelectionModel->blockSignals(0);
updateGrid();
qDebug() << "trigger dirloaded on tree selection changed";
QTimer::singleShot(30,this,SLOT(dirLoaded()));
}

//---------------------------------------------------------------------------
void MainWindow::dirLoaded()
void MainWindow::dirLoaded(bool thumbs)
{

if (backIndex.isValid()) {
backIndex = QModelIndex();
return;
}

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

if (thumbsAct->isChecked()) { QtConcurrent::run(modelList,&myModel::loadThumbs,items); }
if (thumbsAct->isChecked() && thumbs) { QtConcurrent::run(modelList,&myModel::loadThumbs,items); }
updateGrid();
}

void MainWindow::thumbUpdate()
void MainWindow::updateDir()
{
dirLoaded(false /* dont refresh thumb*/);
}

void MainWindow::handleReloadDir(const QString &path)
{
if (ignoreReload) {
qDebug() << "ignore reload";
return;
}
ignoreReload = true;
qDebug() << "handle reload dir" << path << modelList->getRootPath();
if (path != modelList->getRootPath()) { return; }
dirLoaded();
QTimer::singleShot(500, this, SLOT(enableReload()));
}

void MainWindow::thumbUpdate(const QString &path)
{
qDebug() << "thumbupdate" << path << modelList->getRootPath();
if (path != modelList->getRootPath()) { return; }
refresh(false, false);
}

Expand Down Expand Up @@ -1534,12 +1556,21 @@ void MainWindow::refresh(bool modelRefresh, bool loadDir)
qDebug() << "refresh";
if (modelRefresh) {
modelList->refreshItems();
modelList->update();
modelList->forceRefresh();
}
QModelIndex baseIndex = modelView->mapFromSource(modelList->index(pathEdit->currentText()));
if (currentView == 2) { detailTree->setRootIndex(baseIndex); }
else { list->setRootIndex(baseIndex); }
if (loadDir) { dirLoaded(); }
if (loadDir) {
qDebug() << "trigger dirloaded from refresh";
dirLoaded();
}
}

void MainWindow::enableReload()
{
qDebug() << "enable reload";
ignoreReload = false;
}
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -1840,6 +1871,7 @@ void MainWindow::actionMapper(QString cmd)
//---------------------------------------------------------------------------------
void MainWindow::clearCutItems()
{
qDebug() << "clearCutItems";
//this refreshes existing items, sizes etc but doesn't re-sort
modelList->clearCutItems();
modelList->update();
Expand All @@ -1848,8 +1880,9 @@ void MainWindow::clearCutItems()

if (currentView == 2) { detailTree->setRootIndex(baseIndex); }
else { list->setRootIndex(baseIndex); }
QTimer::singleShot(50,this,SLOT(dirLoaded()));
return;

qDebug() << "trigger updateDir from clearCutItems";
QTimer::singleShot(50,this,SLOT(updateDir()));
}

//---------------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions fm/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ public slots:
void focusAction();
void openFolderAction();
void exitAction();
void dirLoaded();
void thumbUpdate();
void dirLoaded(bool thumbs = true);
void updateDir();
void handleReloadDir(const QString &path);
void thumbUpdate(const QString &path);
void addressChanged(int,int);
void loadSettings(bool wState = true, bool hState = true, bool tabState = true, bool thumbState = true);
void firstRunBookmarks(bool isFirstRun);
Expand Down Expand Up @@ -313,6 +315,7 @@ private slots:
void handlePathRequested(QString path);
void slowPathEdit();
void refresh(bool modelRefresh = true, bool loadDir = true);
void enableReload();
private:
void createActions();
void createActionIcons();
Expand Down Expand Up @@ -451,6 +454,8 @@ private slots:
QString copyXof;
// custom timestamp for copy of
QString copyXofTS;

bool ignoreReload;
};

//---------------------------------------------------------------------------------
Expand Down
36 changes: 27 additions & 9 deletions fm/src/mymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ void myModel::clearIconCache() {
QFile(QString("%1/folder.cache").arg(Common::configDir())).remove();
QFile(QString("%1/file.cache").arg(Common::configDir())).remove();
}

void myModel::forceRefresh()
{
qDebug() << "force refresh model view";
beginResetModel();
endResetModel();
}
//---------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -272,7 +279,7 @@ void myModel::notifyChange()
}

notifier->setEnabled(1);
emit reloadDir();
//if (!lastEventFilename.isEmpty()) { emit reloadDir(); }
}

//---------------------------------------------------------------------------------------
Expand All @@ -286,19 +293,21 @@ void myModel::eventTimeout()
void myModel::notifyProcess(int eventID, QString fileName)
{
qDebug() << "notifyProcess" << eventID << fileName;
if(watchers.contains(eventID)) {
QString folderChanged;
if (watchers.contains(eventID)) {
myModelItem *parent = rootItem->matchPath(watchers.value(eventID).split(SEPARATOR));
if(parent) {
if (parent) {
parent->dirty = 1;
QDir dir(parent->absoluteFilePath());
folderChanged = dir.absolutePath();
QFileInfoList all = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
foreach(myModelItem * child, parent->children()) {
if(all.contains(child->fileInfo())) {
if (all.contains(child->fileInfo())) {
//just remove known items
all.removeOne(child->fileInfo());
} else {
//must of been deleted, remove from model
if(child->fileInfo().isDir()) {
//must have been deleted, remove from model
if (child->fileInfo().isDir()) {
int wd = watchers.key(child->absoluteFilePath());
inotify_rm_watch(inotifyFD,wd);
watchers.remove(wd);
Expand All @@ -321,7 +330,10 @@ void myModel::notifyProcess(int eventID, QString fileName)
if (!fileName.isEmpty() && showThumbs) {
lastEventFilename = fileName;
}
emit reloadDir();
if (!folderChanged.isEmpty()) {
qDebug() << "folder modified" << folderChanged;
emit reloadDir(folderChanged);
}
}

//---------------------------------------------------------------------------------
Expand Down Expand Up @@ -442,6 +454,7 @@ void myModel::refreshItems()
{
myModelItem *item = rootItem->matchPath(currentRootPath.split(SEPARATOR));
if (item == NULL) { return; }
qDebug() << "refresh items";
item->clearAll();
populateItem(item);
}
Expand Down Expand Up @@ -607,6 +620,7 @@ void myModel::loadThumbs(QModelIndexList indexes) {

// Loads thumbnails from cache
if (files.count()) {
QFileInfo pathInfo (files.at(0));
if (thumbs->count() == 0) {
qDebug() << "thumbs are empty, try to load cache ...";
QFile fileIcons(QString("%1/thumbs.cache").arg(Common::configDir()));
Expand All @@ -619,8 +633,11 @@ void myModel::loadThumbs(QModelIndexList indexes) {
thumbCount = thumbs->count();
qDebug() << "thumbcount" << thumbCount;
}

foreach (QString item, files) {
if (!thumbs->contains(item) || (item.split("/").takeLast() == lastEventFilename && !lastEventFilename.isEmpty())) {
if (!thumbs->contains(item) ||
(item.split("/").takeLast() == lastEventFilename && !lastEventFilename.isEmpty()))
{
qDebug() << "gen new thumb" << item;
thumbs->insert(item, getThumb(item));
if (item.split("/").takeLast() == lastEventFilename) {
Expand All @@ -639,7 +656,7 @@ void myModel::loadThumbs(QModelIndexList indexes) {
}
}
}
emit thumbUpdate();
emit thumbUpdate(pathInfo.absolutePath());
}
}

Expand Down Expand Up @@ -910,6 +927,7 @@ QVariant myModel::findMimeIcon(myModelItem *item) const {
mimeIcons->insert(mime, theIcon);
return theIcon;
}

//---------------------------------------------------------------------------

bool myModel::setData(const QModelIndex & index, const QVariant & value, int role)
Expand Down
5 changes: 3 additions & 2 deletions fm/src/mymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ public slots:
void addWatcher(myModelItem* path);
void clearCutItems();
void clearIconCache();
void forceRefresh();
signals:
void dragDropPaste(const QMimeData *data, QString newPath,
Common::DragMode mode = Common::DM_UNKNOWN);
void thumbUpdate();
void reloadDir();
void thumbUpdate(const QString &path);
void reloadDir(const QString &path);
protected:
QVariant data(const QModelIndex & index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Expand Down

0 comments on commit 1be530e

Please sign in to comment.