]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Overlay icons: Track touched files #4730
authorChristian Kamm <mail@ckamm.de>
Thu, 14 Apr 2016 13:15:08 +0000 (15:15 +0200)
committerChristian Kamm <mail@ckamm.de>
Thu, 28 Apr 2016 05:16:49 +0000 (07:16 +0200)
This uses the file watcher to keep track of files that were modified
in order to assign them the blue icon.

This is transient state that's not persisted across restarts.

src/gui/folder.cpp
src/gui/folder.h
src/gui/folderman.cpp
src/libsync/syncfilestatustracker.cpp
src/libsync/syncfilestatustracker.h

index 6ab67cba3d65fa9b493351f9600ef92da69e2797..f64f4fdf1a94131c719fd69db82c4b95796493ec 100644 (file)
@@ -578,6 +578,7 @@ void Folder::slotWatchedPathChanged(const QString& path)
     // When no sync is running or it's in the prepare phase, we can
     // always schedule a new sync.
     if (! _engine->isSyncRunning() || _syncResult.status() == SyncResult::SyncPrepare) {
+        emit watchedFileChangedExternally(path);
         emit scheduleToSync(this);
         return;
     }
@@ -601,6 +602,7 @@ void Folder::slotWatchedPathChanged(const QString& path)
 #endif
 
     if (! ownChange) {
+        emit watchedFileChangedExternally(path);
         emit scheduleToSync(this);
     }
 }
index c0c3580c9030fa79aa3cab646d1d70de9bda072b..cf01581176dbd556a23b8e9368a457d5f7a380da 100644 (file)
@@ -204,6 +204,12 @@ signals:
     void newBigFolderDiscovered(const QString &); // A new folder bigger than the threshold was discovered
     void syncPausedChanged(Folder*, bool paused);
 
+    /**
+     * Fires for each change inside this folder that wasn't caused
+     * by sync activity.
+     */
+    void watchedFileChangedExternally(const QString& path);
+
 public slots:
 
      /**
index 8c5168171adccbafec975ba5e5adc7279af7c07c..a9021804d0991e464e7779497cc3d94d5e8a837a 100644 (file)
@@ -107,6 +107,8 @@ void FolderMan::unloadFolder( Folder *f )
                this, SLOT(slotFolderSyncPaused(Folder*,bool)));
     disconnect(&f->syncEngine().syncFileStatusTracker(), SIGNAL(fileStatusChanged(const QString &, SyncFileStatus)),
                _socketApi.data(), SLOT(slotFileStatusChanged(const QString &, SyncFileStatus)));
+    disconnect(f, SIGNAL(watchedFileChangedExternally(QString)),
+               &f->syncEngine().syncFileStatusTracker(), SLOT(slotPathTouched(QString)));
 }
 
 int FolderMan::unloadAndDeleteAllFolders()
@@ -145,6 +147,7 @@ void FolderMan::registerFolderMonitor( Folder *folder )
         // to the signal mapper which maps to the folder alias. The changed path
         // is lost this way, but we do not need it for the current implementation.
         connect(fw, SIGNAL(pathChanged(QString)), folder, SLOT(slotWatchedPathChanged(QString)));
+
         _folderWatchers.insert(folder->alias(), fw);
     }
 
@@ -795,6 +798,8 @@ Folder* FolderMan::addFolderInternal(const FolderDefinition& folderDefinition, A
     connect(folder, SIGNAL(syncPausedChanged(Folder*,bool)), SLOT(slotFolderSyncPaused(Folder*,bool)));
     connect(&folder->syncEngine().syncFileStatusTracker(), SIGNAL(fileStatusChanged(const QString &, SyncFileStatus)),
             _socketApi.data(), SLOT(slotFileStatusChanged(const QString &, SyncFileStatus)));
+    connect(folder, SIGNAL(watchedFileChangedExternally(QString)),
+            &folder->syncEngine().syncFileStatusTracker(), SLOT(slotPathTouched(QString)));
 
     registerFolderMonitor(folder);
     return folder;
index ffac9e45c57b561cdcf98b5894e157c41a8518ec..7867b140808e452d7c550d93a0ef2bf17baa9181 100644 (file)
@@ -81,6 +81,8 @@ SyncFileStatusTracker::SyncFileStatusTracker(SyncEngine *syncEngine)
               this, SLOT(slotAboutToPropagate(SyncFileItemVector&)));
     connect(syncEngine, SIGNAL(itemCompleted(const SyncFileItem&, const PropagatorJob&)),
             this, SLOT(slotItemCompleted(const SyncFileItem&)));
+    connect(syncEngine, SIGNAL(started()),
+            SLOT(slotClearDirtyPaths()));
 }
 
 SyncFileStatus SyncFileStatusTracker::rootStatus()
@@ -143,6 +145,9 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
         return SyncFileStatus(SyncFileStatus::StatusWarning);
     }
 
+    if ( _dirtyPaths.contains(fileName) )
+        return SyncFileStatus::StatusSync;
+
     SyncFileItem* item = _syncEngine->findSyncItem(fileName);
     if (item) {
         return fileStatus(*item);
@@ -157,6 +162,17 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
     return SyncFileStatus();
 }
 
+void SyncFileStatusTracker::slotPathTouched(const QString& fileName)
+{
+    QString folderPath = _syncEngine->localPath();
+    Q_ASSERT(fileName.startsWith(folderPath));
+
+    QString localPath = fileName.mid(folderPath.size());
+    _dirtyPaths.insert(localPath);
+
+    emit fileStatusChanged(fileName, SyncFileStatus::StatusSync);
+}
+
 void SyncFileStatusTracker::slotAboutToPropagate(SyncFileItemVector& items)
 {
     std::map<QString, SyncFileStatus::SyncFileStatusTag> oldProblems;
@@ -208,6 +224,13 @@ void SyncFileStatusTracker::slotItemCompleted(const SyncFileItem &item)
     emit fileStatusChanged(getSystemDestination(item), fileStatus(item));
 }
 
+void SyncFileStatusTracker::slotClearDirtyPaths()
+{
+    // We just assume that during a sync all dirty statuses will be resolved
+    // one way or the other.
+    _dirtyPaths.clear();
+}
+
 SyncFileStatus SyncFileStatusTracker::fileStatus(const SyncFileItem& item)
 {
     // Hack to know if the item was taken from the sync engine (Sync), or from the database (UpToDate)
index fe8b9b9f5759b9c87f811ba811f2fe30c102ef0a..7aa461799936b1251ac8f3d093cf14fa85c6473c 100644 (file)
@@ -19,6 +19,7 @@
 #include "syncfileitem.h"
 #include "syncfilestatus.h"
 #include <map>
+#include <QSet>
 
 namespace OCC {
 
@@ -36,12 +37,16 @@ public:
     explicit SyncFileStatusTracker(SyncEngine* syncEngine);
     SyncFileStatus fileStatus(const QString& systemFileName);
 
+public slots:
+    void slotPathTouched(const QString& fileName);
+
 signals:
     void fileStatusChanged(const QString& systemFileName, SyncFileStatus fileStatus);
 
 private slots:
     void slotAboutToPropagate(SyncFileItemVector& items);
     void slotItemCompleted(const SyncFileItem& item);
+    void slotClearDirtyPaths();
 
 private:
     SyncFileStatus fileStatus(const SyncFileItem& item);
@@ -53,6 +58,7 @@ private:
     SyncEngine* _syncEngine;
 
     std::map<QString, SyncFileStatus::SyncFileStatusTag> _syncProblems;
+    QSet<QString> _dirtyPaths;
 };
 
 }