Просмотр исходного кода

OS X: Overlay Icons: Load from bundle-specific path

The client (in this case mirall) tells the Finder plugin where to get the icons.
This enables installation in different locations and in branded clients.
Markus Goetz 11 лет назад
Родитель
Сommit
2fddf05515

+ 2 - 0
shell_integration/MacOSX/OwnCloudFinder/ContentManager.h

@@ -42,4 +42,6 @@
 - (void)reFetchFileNameCacheForPath:(NSString*)path;
 - (void)repaintAllWindows;
 
+- (void)loadIconResourcePath:(NSString*)path;
+
 @end

+ 20 - 13
shell_integration/MacOSX/OwnCloudFinder/ContentManager.m

@@ -32,19 +32,6 @@ static ContentManager* sharedInstance = nil;
 		_fileNamesCache = [[NSMutableDictionary alloc] init];
 		_fileIconsEnabled = TRUE;
 		_hasChangedContent = TRUE;
-
-		NSString *base = @"/Applications/owncloud.app/Contents/Resources/icons/";
-		
-		_icnOk   = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"ok.icns"]];
-		_icnSync = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"sync.icns"]];
-		_icnWarn = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"warning.icns"]];
-		_icnErr  = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"error.icns"]];
-		_icnOkSwm   = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"ok_swm.icns"]];
-		_icnSyncSwm = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"sync_swm.icns"]];
-		_icnWarnSwm = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"warning_swm.icns"]];
-		_icnErrSwm  = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"error_swm.icns"]];
-		
-		NSLog(@"Icon ok identifier: %d", [_icnOk intValue]);
 	}
 
 	return self;
@@ -72,6 +59,22 @@ static ContentManager* sharedInstance = nil;
 	return sharedInstance;
 }
 
+- (void)loadIconResourcePath:(NSString*)path
+{
+	NSString *base = path;
+
+	_icnOk   = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"ok.icns"]];
+	_icnSync = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"sync.icns"]];
+	_icnWarn = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"warning.icns"]];
+	_icnErr  = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"error.icns"]];
+	_icnOkSwm   = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"ok_swm.icns"]];
+	_icnSyncSwm = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"sync_swm.icns"]];
+	_icnWarnSwm = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"warning_swm.icns"]];
+	_icnErrSwm  = [[IconCache sharedInstance] registerIcon:[base stringByAppendingString:@"error_swm.icns"]];
+
+	NSLog(@"Icon ok identifier: %d from %@", [_icnOk intValue], [base stringByAppendingString:@"ok.icns"]);
+}
+
 - (void)enableFileIcons:(BOOL)enable
 {
 	_fileIconsEnabled = enable;
@@ -81,6 +84,10 @@ static ContentManager* sharedInstance = nil;
 
 - (void)setResultForPath:(NSString*)path result:(NSString*)result
 {
+	if (_icnOk == nil) {
+		// no icon resource path registered yet
+		return;
+	}
 
 	NSNumber *res;
 	res = [NSNumber numberWithInt:0];

+ 3 - 0
shell_integration/MacOSX/OwnCloudFinder/RequestManager.m

@@ -149,6 +149,9 @@ static RequestManager* sharedInstance = nil;
 			[_registeredPathes removeObjectForKey:path];
 
 			[contentman repaintAllWindows];
+		} else if( [[chunks objectAtIndex:0 ] isEqualToString:@"ICON_PATH"] ) {
+			NSString *path = [chunks objectAtIndex:1];
+			[[ContentManager sharedInstance] loadIconResourcePath:path];
 		} else {
 			NSLog(@"Unknown command %@", [chunks objectAtIndex:0]);
 		}

+ 11 - 0
src/mirall/socketapi.cpp

@@ -246,6 +246,17 @@ void SocketApi::slotNewConnection()
 
     _listeners.append(socket);
 
+#ifdef Q_OS_MAC
+    // We want to tell our location so it can load the icons
+    // e.g. "/Users/guruz/woboq/owncloud/client/buildmirall/owncloud.app/Contents/MacOS/"
+    QString iconPath = qApp->applicationDirPath() + "/../Resources/icons/";
+    if (!QDir(iconPath).exists()) {
+        DEBUG << "Icon path " << iconPath << " does not exist, did you forget make install?";
+    }
+    broadcastMessage(QLatin1String("ICON_PATH"), iconPath );
+#endif
+
+
     foreach( QString alias, FolderMan::instance()->map().keys() ) {
        slotRegisterPath(alias);
     }