[Pkg-owncloud-commits] [owncloud-client] 254/332: MocOverlays: Handle the UPDATE_VIEW socket notification correctly.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:07:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 86acdf69d993b3055dceb27e8f7a625755f68d15
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Jul 11 11:31:04 2014 +0200

    MocOverlays: Handle the UPDATE_VIEW socket notification correctly.
    
    With UPDATE_VIEW the plugin gets notified to update the overlays.
    It invalidates the entries in the file icon cache for the path
    that comes with the UPDATE_VIEW and than refreshes the view.
---
 .../MacOSX/LiferayNativityFinder/ContentManager.h  |  1 +
 .../MacOSX/LiferayNativityFinder/ContentManager.m  | 29 ++++++++-
 .../LiferayNativityFinder/IconOverlayHandlers.m    |  2 +-
 .../MacOSX/LiferayNativityFinder/RequestManager.m  | 72 ++++++++++++----------
 4 files changed, 68 insertions(+), 36 deletions(-)

diff --git a/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.h b/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.h
index 454672d..878a3df 100644
--- a/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.h
+++ b/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.h
@@ -28,5 +28,6 @@
 - (void)removeIcons:(NSArray*)paths;
 - (void)setIcons:(NSDictionary*)iconDictionary filterByFolder:(NSString*)filterFolder;
 - (void)setResultForPath:(NSString*)path result:(NSString*)result;
+- (void)clearFileNameCacheForPath:(NSString*)path;
 
 @end
\ No newline at end of file
diff --git a/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.m b/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.m
index 3a4ae1a..f05f929 100644
--- a/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.m
+++ b/shell_integration/MacOSX/LiferayNativityFinder/ContentManager.m
@@ -77,7 +77,7 @@ static ContentManager* sharedInstance = nil;
 	int res = 0; // NOP
 	if( [result isEqualToString:@"OK"] ) {
 		res = 1;
-	} else if( [result isEqualToString:@"NEED_SYNC"]) {
+	} else if( [result isEqualToString:@"SYNC"] || [result isEqualToString:@"NEW"] ) {
 		res = 2;
 	} else if( [result isEqualToString:@"IGNORE"]) {
 		res = 3;
@@ -112,7 +112,7 @@ static ContentManager* sharedInstance = nil;
 	NSString* normalizedPath = [path decomposedStringWithCanonicalMapping];
 	
 	NSNumber* result = [_fileNamesCache objectForKey:normalizedPath];
-	NSLog(@"XXXXXXX Asking for icon for path %@ = %d",path, [result intValue]);
+	// NSLog(@"XXXXXXX Asking for icon for path %@ = %d",path, [result intValue]);
 	
 	if( result == nil ) {
 		// start the async call
@@ -126,11 +126,34 @@ static ContentManager* sharedInstance = nil;
 	} else {
 		// there is a proper icon index
 	}
-    NSLog(@"iconByPath return value %d", [result intValue]);
+    // NSLog(@"iconByPath return value %d", [result intValue]);
 	
 	return result;
 }
 
+// called as a result of an UPDATE_VIEW message.
+// it clears the entries from the hash to make it call again home to mirall.
+- (void)clearFileNameCacheForPath:(NSString*)path
+{
+	NSMutableArray *keysToDelete = [NSMutableArray array];
+	NSLog(@"Clearing the cache for %@", path);
+	
+	for (id path in [_fileNamesCache keyEnumerator]) {
+		//do stuff with obj
+		if ( [path hasPrefix:path] ) {
+			[keysToDelete addObject:path];
+		}
+	}
+	
+	if( [keysToDelete count] > 0 ) {
+		NSLog( @"Entries to delete: %d", [keysToDelete count]);
+		[_fileNamesCache removeObjectsForKeys:keysToDelete];
+	
+		[self repaintAllWindows];
+
+	}
+}
+
 - (void)removeAllIcons
 {
 	[_fileNamesCache removeAllObjects];
diff --git a/shell_integration/MacOSX/LiferayNativityFinder/IconOverlayHandlers.m b/shell_integration/MacOSX/LiferayNativityFinder/IconOverlayHandlers.m
index 7f39eab..d18d803 100644
--- a/shell_integration/MacOSX/LiferayNativityFinder/IconOverlayHandlers.m
+++ b/shell_integration/MacOSX/LiferayNativityFinder/IconOverlayHandlers.m
@@ -78,7 +78,7 @@
     }
 	
 	NSNumber* imageIndex = [[ContentManager sharedInstance] iconByPath:[url path] isDirectory:isDir];
-	NSLog(@"2 The icon index is %d", [imageIndex intValue]);
+	// NSLog(@"2 The icon index is %d", [imageIndex intValue]);
 
 	if ([imageIndex intValue] > 0)
 	{
diff --git a/shell_integration/MacOSX/LiferayNativityFinder/RequestManager.m b/shell_integration/MacOSX/LiferayNativityFinder/RequestManager.m
index 05afb68..fa3c773 100644
--- a/shell_integration/MacOSX/LiferayNativityFinder/RequestManager.m
+++ b/shell_integration/MacOSX/LiferayNativityFinder/RequestManager.m
@@ -92,10 +92,43 @@ static RequestManager* sharedInstance = nil;
 }
 
 
+- (void)socket:(GCDAsyncSocket*)socket didReadData:(NSData*)data withTag:(long)tag
+{
+	NSArray *chunks;
+	NSString *answer = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+	if (answer != nil && [answer length] > 0) {
+		// cut a trailing newline
+		answer = [answer substringToIndex:[answer length] - 1];
+		chunks = [answer componentsSeparatedByString: @":"];
+	}
+	NSLog(@"READ from socket (%ld): <%@>", tag, answer);
+	ContentManager *contentman = [ContentManager sharedInstance];
+
+	if( [chunks count] > 0 && tag == READ_TAG ) {
+		if( [[chunks objectAtIndex:0] isEqualToString:@"STATUS"] ) {
+			[contentman setResultForPath:[chunks objectAtIndex:2] result:[chunks objectAtIndex:1]];
+		} else if( [[chunks objectAtIndex:0] isEqualToString:@"UPDATE_VIEW"] ) {
+			[contentman clearFileNameCacheForPath:[chunks objectAtIndex:1]]; // Fixme: index1 can be empty
+		} else {
+			NSLog(@"Unknown command %@", [chunks objectAtIndex:0]);
+		}
+	} else {
+		NSLog(@"Received unknown tag %ld", tag);
+	}
+	// Read on and on
+	NSData* stop = [@"\n" dataUsingEncoding:NSUTF8StringEncoding];
+	[_socket readDataToData:stop withTimeout:-1 tag:READ_TAG];
+
+}
+
+- (NSTimeInterval)socket:(GCDAsyncSocket*)socket shouldTimeoutReadWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length
+{
+	// Called if a read operation has reached its timeout without completing.
+	return 0.0;
+}
+
 - (void)socket:(GCDAsyncSocket*)socket didConnectToHost:(NSString*)host port:(UInt16)port
 {
-	// [socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];
-	
 	NSLog( @"Connected to host successfully!");
 	_isConnected = YES;
 	
@@ -105,41 +138,17 @@ static RequestManager* sharedInstance = nil;
 			[self askOnSocket:path];
 		}
 	}
-}
-
-
-- (void)socket:(GCDAsyncSocket*)socket didReadData:(NSData*)data withTag:(long)tag
-{
 	
-	if( tag == READ_TAG) {
-		NSString *answer = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-		
-		// Cut the trailing newline.
-		if ([answer length] > 0) {
-			answer = [answer substringToIndex:[answer length] - 1];
-		}
-		
-		NSLog(@"READ from socket (%ld): <%@>", tag, answer);
+	// Read for the UPDATE_VIEW requests
+	NSData* stop = [@"\n" dataUsingEncoding:NSUTF8StringEncoding];
+	[_socket readDataToData:stop withTimeout:-1 tag:READ_TAG];
 	
-		if( answer != nil ) {
-			NSArray *chunks = [answer componentsSeparatedByString: @":"];
-			
-			if( [chunks count] > 0 && [[chunks objectAtIndex:0] isEqualToString:@"STATUS"] ) {
-				ContentManager *contentman = [ContentManager sharedInstance];
-				[contentman setResultForPath:[chunks objectAtIndex:2] result:[chunks objectAtIndex:1]];
-			}
-		}
-	}
-}
-
-- (NSTimeInterval)socket:(GCDAsyncSocket*)socket shouldTimeoutReadWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length
-{
-	// Called if a read operation has reached its timeout without completing.
-	return 0.0;
 }
 
 - (void)socketDidDisconnect:(GCDAsyncSocket*)socket withError:(NSError*)err
 {
+	NSLog(@"Socket DISconnected!");
+
 	if ([_connectedListenSockets containsObject:socket])
 	{
 		[_connectedListenSockets removeObject:socket];
@@ -165,7 +174,6 @@ static RequestManager* sharedInstance = nil;
 			// If there was an error, it's likely something like "already connected" or "no delegate set"
 			NSLog(@"I goofed: %@", err);
 		}
-		NSLog(@"Socket Connected!");
 		
 		 _isRunning = YES;
 	}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list