Skip to content

Commit

Permalink
performance fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Nov 23, 2018
1 parent 03136e5 commit e88be93
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
40 changes: 30 additions & 10 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 @@ -378,8 +378,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 +667,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 +705,26 @@ 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)
{
qDebug() << "handle reload dir" << path << modelList->getRootPath();
if (path != modelList->getRootPath()) { return; }
dirLoaded();
}

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

Expand Down Expand Up @@ -1539,7 +1554,10 @@ void MainWindow::refresh(bool modelRefresh, bool loadDir)
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();
}
}
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -1840,6 +1858,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 +1867,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
6 changes: 4 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
40 changes: 31 additions & 9 deletions fm/src/mymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ myModel::myModel(bool realMime, MimeUtils *mimeUtils) {
thumbs = new QHash<QString,QByteArray>;
icons = new QCache<QString,QIcon>;
icons->setMaxCost(500);
lockNotify = false;

// Loads cached mime icons
QFile fileIcons(QString("%1/file.cache").arg(Common::configDir()));
Expand Down Expand Up @@ -272,7 +273,7 @@ void myModel::notifyChange()
}

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

//---------------------------------------------------------------------------------------
Expand All @@ -286,19 +287,26 @@ void myModel::eventTimeout()
void myModel::notifyProcess(int eventID, QString fileName)
{
qDebug() << "notifyProcess" << eventID << fileName;
if(watchers.contains(eventID)) {
if (lockNotify) {
qDebug() << "ignore notify";
return;
}
lockNotify = true;
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 +329,11 @@ 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);
}
QTimer::singleShot(500, this, SLOT(unlockNotify()));
}

//---------------------------------------------------------------------------------
Expand Down Expand Up @@ -607,6 +619,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 +632,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 +655,7 @@ void myModel::loadThumbs(QModelIndexList indexes) {
}
}
}
emit thumbUpdate();
emit thumbUpdate(pathInfo.absolutePath());
}
}

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

void myModel::unlockNotify()
{
qDebug() << "unlock notify";
lockNotify = false;
}
//---------------------------------------------------------------------------

bool myModel::setData(const QModelIndex & index, const QVariant & value, int role)
Expand Down
8 changes: 6 additions & 2 deletions fm/src/mymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public slots:
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 All @@ -104,6 +104,7 @@ public slots:
bool realMimeTypes;
bool showThumbs;
int thumbCount;
bool lockNotify;

QPalette colors;
QStringList cutItems;
Expand All @@ -122,6 +123,9 @@ public slots:
QTimer eventTimer;
int lastEventID;
QString lastEventFilename;

private slots:
void unlockNotify();
};

#endif // MYMODEL_H

0 comments on commit e88be93

Please sign in to comment.