diff --git a/fm/src/mainwindow.cpp b/fm/src/mainwindow.cpp index 626ac97..65bc2df 100644 --- a/fm/src/mainwindow.cpp +++ b/fm/src/mainwindow.cpp @@ -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"); @@ -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); @@ -667,11 +667,12 @@ 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()) { @@ -679,7 +680,7 @@ void MainWindow::dirLoaded() return; } - qDebug() << "dirLoaded"; + qDebug() << "dirLoaded triggered, thumbs?" << thumbs; qint64 bytes = 0; QModelIndexList items; bool includeHidden = hiddenAct->isChecked(); @@ -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); } @@ -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(); + } } //--------------------------------------------------------------------------- @@ -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(); @@ -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())); } //--------------------------------------------------------------------------------- diff --git a/fm/src/mainwindow.h b/fm/src/mainwindow.h index 3f94633..3b06c95 100644 --- a/fm/src/mainwindow.h +++ b/fm/src/mainwindow.h @@ -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); diff --git a/fm/src/mymodel.cpp b/fm/src/mymodel.cpp index f9d77c8..555a961 100644 --- a/fm/src/mymodel.cpp +++ b/fm/src/mymodel.cpp @@ -45,6 +45,7 @@ myModel::myModel(bool realMime, MimeUtils *mimeUtils) { thumbs = new QHash; icons = new QCache; icons->setMaxCost(500); + lockNotify = false; // Loads cached mime icons QFile fileIcons(QString("%1/file.cache").arg(Common::configDir())); @@ -272,7 +273,7 @@ void myModel::notifyChange() } notifier->setEnabled(1); - emit reloadDir(); + //if (!lastEventFilename.isEmpty()) { emit reloadDir(); } } //--------------------------------------------------------------------------------------- @@ -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); @@ -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())); } //--------------------------------------------------------------------------------- @@ -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())); @@ -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) { @@ -639,7 +655,7 @@ void myModel::loadThumbs(QModelIndexList indexes) { } } } - emit thumbUpdate(); + emit thumbUpdate(pathInfo.absolutePath()); } } @@ -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) diff --git a/fm/src/mymodel.h b/fm/src/mymodel.h index 01822bb..6c01369 100644 --- a/fm/src/mymodel.h +++ b/fm/src/mymodel.h @@ -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; @@ -104,6 +104,7 @@ public slots: bool realMimeTypes; bool showThumbs; int thumbCount; + bool lockNotify; QPalette colors; QStringList cutItems; @@ -122,6 +123,9 @@ public slots: QTimer eventTimer; int lastEventID; QString lastEventFilename; + +private slots: + void unlockNotify(); }; #endif // MYMODEL_H