From 2f34b046d096a44616ea995c78c308e344cf24d3 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 27 Aug 2014 19:05:26 +0200 Subject: [PATCH] Overlay Icons: Improve OS X version, improve general feedback Now the update phase of the syncing algorithm pushes stuff the notification socket too. --- .../MacOSX/OwnCloudFinder/ContentManager.h | 1 + .../MacOSX/OwnCloudFinder/ContentManager.m | 32 ++++++++++++++----- .../MacOSX/OwnCloudFinder/RequestManager.m | 3 -- src/mirall/folder.cpp | 6 ++++ src/mirall/folder.h | 1 + src/mirall/progressdispatcher.h | 2 ++ src/mirall/socketapi.cpp | 24 ++++++++++++-- src/mirall/socketapi.h | 1 + 8 files changed, 56 insertions(+), 14 deletions(-) diff --git a/shell_integration/MacOSX/OwnCloudFinder/ContentManager.h b/shell_integration/MacOSX/OwnCloudFinder/ContentManager.h index 9ac2c3ac2..7ee3172cb 100644 --- a/shell_integration/MacOSX/OwnCloudFinder/ContentManager.h +++ b/shell_integration/MacOSX/OwnCloudFinder/ContentManager.h @@ -18,6 +18,7 @@ { NSMutableDictionary* _fileNamesCache; BOOL _fileIconsEnabled; + BOOL _hasChangedContent; NSNumber *_icnOk; NSNumber *_icnSync; diff --git a/shell_integration/MacOSX/OwnCloudFinder/ContentManager.m b/shell_integration/MacOSX/OwnCloudFinder/ContentManager.m index 8ca237088..1a69f6315 100644 --- a/shell_integration/MacOSX/OwnCloudFinder/ContentManager.m +++ b/shell_integration/MacOSX/OwnCloudFinder/ContentManager.m @@ -31,6 +31,7 @@ static ContentManager* sharedInstance = nil; { _fileNamesCache = [[NSMutableDictionary alloc] init]; _fileIconsEnabled = TRUE; + _hasChangedContent = TRUE; NSString *base = @"/Applications/owncloud.app/Contents/Resources/icons/"; @@ -107,14 +108,18 @@ static ContentManager* sharedInstance = nil; } NSString* normalizedPath = [path decomposedStringWithCanonicalMapping]; - [_fileNamesCache setObject:res forKey:normalizedPath]; - // NSLog(@"SET value %d", [res intValue]); - - [self repaintAllWindows]; + + if (![_fileNamesCache objectForKey:normalizedPath] || ![[_fileNamesCache objectForKey:normalizedPath] isEqualToString:res]) { + [_fileNamesCache setObject:res forKey:normalizedPath]; + // NSLog(@"SET value %d", [res intValue]); + _hasChangedContent = YES; + [self performSelector:@selector(repaintAllWindowsIfNeeded) withObject:0 afterDelay:1.0]; // 1 sec + } } - (NSNumber*)iconByPath:(NSString*)path isDirectory:(BOOL)isDir { + //NSLog(@"%@ %@", NSStringFromSelector(_cmd), path); if (!_fileIconsEnabled) { NSLog(@"Icons are NOT ENABLED!"); @@ -151,6 +156,7 @@ static ContentManager* sharedInstance = nil; // it clears the entries from the hash to make it call again home to mirall. - (void)clearFileNameCacheForPath:(NSString*)path { + NSLog(@"%@", NSStringFromSelector(_cmd)); NSMutableArray *keysToDelete = [NSMutableArray array]; if( path != nil ) { @@ -170,9 +176,6 @@ static ContentManager* sharedInstance = nil; if( [keysToDelete count] > 0 ) { NSLog( @"Entries to delete: %d", [keysToDelete count]); [_fileNamesCache removeObjectsForKeys:keysToDelete]; - - [self repaintAllWindows]; - } } @@ -195,8 +198,20 @@ static ContentManager* sharedInstance = nil; [self repaintAllWindows]; } +- (void)repaintAllWindowsIfNeeded +{ + if (!_hasChangedContent) { + NSLog(@"%@ Repaint scheduled but not needed", NSStringFromSelector(_cmd)); + return; + } + + _hasChangedContent = NO; + [self repaintAllWindows]; +} + - (void)repaintAllWindows { + NSLog(@"%@", NSStringFromSelector(_cmd)); NSArray* windows = [[NSApplication sharedApplication] windows]; for (int i = 0; i < [windows count]; i++) @@ -286,7 +301,7 @@ static ContentManager* sharedInstance = nil; } else { - NSLog(@"LiferayNativityFinder: refreshing icon badges failed"); + NSLog(@"OwnCloudFinder: refreshing icon badges failed"); return; } @@ -297,6 +312,7 @@ static ContentManager* sharedInstance = nil; - (void)setIcons:(NSDictionary*)iconDictionary filterByFolder:(NSString*)filterFolder { + NSLog(@"%@", NSStringFromSelector(_cmd)); for (NSString* path in iconDictionary) { if (filterFolder && ![path hasPrefix:filterFolder]) diff --git a/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m b/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m index e4393be43..f4ab9cc13 100644 --- a/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m +++ b/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m @@ -136,9 +136,6 @@ static RequestManager* sharedInstance = nil; [contentman setResultForPath:[chunks objectAtIndex:2] result:[chunks objectAtIndex:1]]; } else if( [[chunks objectAtIndex:0] isEqualToString:@"UPDATE_VIEW"] ) { NSString *path = [chunks objectAtIndex:1]; - [contentman clearFileNameCacheForPath:path]; - - [contentman repaintAllWindows]; } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"REGISTER_PATH"] ) { NSNumber *one = [NSNumber numberWithInt:1]; NSString *path = [chunks objectAtIndex:1]; diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 81bd84bdf..c3edd1390 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -600,6 +600,7 @@ void Folder::startSync(const QStringList &pathList) connect(_engine.data(), SIGNAL(folderDiscovered(bool,QString)), this, SLOT(slotFolderDiscovered(bool,QString))); connect(_engine.data(), SIGNAL(transmissionProgress(Progress::Info)), this, SLOT(slotTransmissionProgress(Progress::Info))); connect(_engine.data(), SIGNAL(jobCompleted(SyncFileItem)), this, SLOT(slotJobCompleted(SyncFileItem))); + connect(_engine.data(), SIGNAL(syncItemDiscovered(SyncFileItem)), this, SLOT(slotSyncItemDiscovered(SyncFileItem))); setDirtyNetworkLimits(); _engine->setSelectiveSyncBlackList(selectiveSyncBlackList()); @@ -725,6 +726,11 @@ void Folder::slotJobCompleted(const SyncFileItem &item) emit ProgressDispatcher::instance()->jobCompleted(alias(), item); } +void Folder::slotSyncItemDiscovered(const SyncFileItem & item) +{ + emit ProgressDispatcher::instance()->syncItemDiscovered(alias(), item); +} + void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction, bool *cancel) { diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 62a9e1db9..b5eff8e59 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -164,6 +164,7 @@ private slots: void slotFolderDiscovered(bool local, QString folderName); void slotTransmissionProgress(const Progress::Info& pi); void slotJobCompleted(const SyncFileItem&); + void slotSyncItemDiscovered(const SyncFileItem & item); void slotPollTimerTimeout(); void etagRetreived(const QString &); diff --git a/src/mirall/progressdispatcher.h b/src/mirall/progressdispatcher.h index 54b6d3338..66a8e411f 100644 --- a/src/mirall/progressdispatcher.h +++ b/src/mirall/progressdispatcher.h @@ -201,6 +201,8 @@ signals: */ void jobCompleted(const QString &folder, const SyncFileItem & item); + void syncItemDiscovered(const QString &folder, const SyncFileItem & item); + protected: void setProgressInfo(const QString& folder, const Progress::Info& progress); diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp index 22922aed1..b6efc7038 100644 --- a/src/mirall/socketapi.cpp +++ b/src/mirall/socketapi.cpp @@ -199,6 +199,8 @@ SocketApi::SocketApi(QObject* parent) connect(FolderMan::instance(), SIGNAL(folderSyncStateChange(QString)), this, SLOT(slotUpdateFolderView(QString))); connect(ProgressDispatcher::instance(), SIGNAL(jobCompleted(QString,SyncFileItem)), SLOT(slotJobCompleted(QString,SyncFileItem))); + connect(ProgressDispatcher::instance(), SIGNAL(syncItemDiscovered(QString,SyncFileItem)), + this, SLOT(slotSyncItemDiscovered(QString,SyncFileItem))); } SocketApi::~SocketApi() @@ -318,8 +320,9 @@ void SocketApi::slotUpdateFolderView(const QString& alias) void SocketApi::slotJobCompleted(const QString &folder, const SyncFileItem &item) { Folder *f = FolderMan::instance()->folder(folder); - if (!f) + if (!f) { return; + } const QString path = f->path() + item.destination(); @@ -327,9 +330,24 @@ void SocketApi::slotJobCompleted(const QString &folder, const SyncFileItem &item if (Progress::isWarningKind(item._status)) { command = QLatin1String("ERROR"); } - if( Utility::isLinux() ) { - broadcastMessage(QLatin1String("BROADCAST"), path, command); + broadcastMessage(QLatin1String("STATUS"), path, command); +} + +void SocketApi::slotSyncItemDiscovered(const QString &folder, const SyncFileItem &item) +{ + if (item._instruction == CSYNC_INSTRUCTION_NONE) { + return; } + + Folder *f = FolderMan::instance()->folder(folder); + if (!f) { + return; + } + + const QString path = f->path() + item.destination(); + + const QString command = QLatin1String("SYNC"); + broadcastMessage(QLatin1String("STATUS"), path, command); } diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h index bfd3d12fe..c90922357 100644 --- a/src/mirall/socketapi.h +++ b/src/mirall/socketapi.h @@ -51,6 +51,7 @@ private slots: void onLostConnection(); void slotReadSocket(); void slotJobCompleted(const QString &, const SyncFileItem &); + void slotSyncItemDiscovered(const QString &, const SyncFileItem &); private: void sendMessage(QTcpSocket* socket, const QString& message, bool doWait = false);