Permalink
Browse files

Add some much nicer UI for icon setting. Now includes a select button…

…, drag/drop and paste
  • Loading branch information...
1 parent 0cddf55 commit 240aeb124a12ad006aaaa15d78f9770f15f3dee8 Michael Gorbach committed Mar 21, 2008
@@ -0,0 +1,18 @@
+//
+// MFAdvancedViewController.h
+// MacFusion2
+//
+// Created by Michael Gorbach on 3/20/08.
+// Copyright 2008 Michael Gorbach. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@class MFIconSettingImageView;
+@interface MFAdvancedViewController : NSViewController {
+ IBOutlet MFIconSettingImageView* iconView;
+}
+
+- (IBAction)chooseIcon:(id)sender;
+
+@end
@@ -0,0 +1,33 @@
+//
+// MFAdvancedViewController.m
+// MacFusion2
+//
+// Created by Michael Gorbach on 3/20/08.
+// Copyright 2008 Michael Gorbach. All rights reserved.
+//
+
+#import "MFAdvancedViewController.h"
+#import "MFClientFS.h"
+
+@implementation MFAdvancedViewController
+- (void)awakeFromNib
+{
+ [iconView bind:@"fs" toObject:self withKeyPath:@"representedObject" options:nil];
+}
+
+- (IBAction)chooseIcon:(id)sender
+{
+ NSOpenPanel* panel = [NSOpenPanel openPanel];
+ [panel setAllowsMultipleSelection: NO];
+ [panel setAllowedFileTypes: [NSArray arrayWithObject: @"icns"]];
+ NSInteger returnValue = [panel runModalForTypes: [NSArray arrayWithObject: @"icns"]];
+ if (returnValue == NSOKButton && [[panel filenames] count] > 0)
+ {
+ NSString* filename = [[panel filenames] objectAtIndex: 0];
+ NSImage* iconImage = [[NSImage alloc] initWithContentsOfFile: filename];
+ if (iconImage)
+ [(MFClientFS*)[self representedObject] setIconImage: iconImage];
+ }
+}
+
+@end
View
@@ -49,6 +49,7 @@
// UI
- (NSDictionary*)configurationViewControllers;
+- (void)setIconImage:(NSImage*)image;
@property(readwrite, assign) NSInteger displayOrder;
@property(readwrite, retain) id<MFClientFSDelegateProtocol> clientFSDelegate;
View
@@ -19,6 +19,10 @@
#import "MFClientPlugin.h"
#import "MFServerFSProtocol.h"
#import "MFSecurity.h"
+#import "IconFamily.h"
+#import "MFAdvancedViewController.h"
+#import "MGNSImage.h"
+#import <QuartzCore/QuartzCore.h>
@interface MFClientFS (PrivateAPI)
- (void)fillInitialData;
@@ -42,7 +46,8 @@ + (MFClientFS*)clientFSWithRemoteFS:(id)remoteFS
+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key
{
- if ([key isEqualToString: @"displayDictionary"])
+ if ([key isEqualToString: @"displayDictionary"] ||
+ [key isEqualToString: @"imagePath"])
return [NSSet setWithObjects:
KMFStatusDict, kMFParameterDict, nil];
else
@@ -242,7 +247,7 @@ - (void)setPauseTimeout:(BOOL)p
- (NSDictionary*)configurationViewControllers
{
NSMutableDictionary* myControllers = [NSMutableDictionary dictionary];
- NSViewController* macfusionAdvancedController = [[NSViewController alloc] initWithNibName: @"macfusionAdvancedView"
+ NSViewController* macfusionAdvancedController = [[MFAdvancedViewController alloc] initWithNibName: @"macfusionAdvancedView"
bundle: [NSBundle bundleForClass: [self class]]];
[myControllers setObject: macfusionAdvancedController forKey:kMFUIMacfusionAdvancedViewKey];
NSDictionary* delegateControllers = [delegate configurationViewControllers];
@@ -255,5 +260,79 @@ - (NSDictionary*)configurationViewControllers
return [myControllers copy];
}
+- (void)setIconImage:(NSImage*)image
+{
+ if (image == nil)
+ {
+ [self willChangeValueForKey:@"parameters"];
+ [parameters removeObjectForKey: kMFFSVolumeIconPathParameter];
+ [parameters removeObjectForKey: kMFFSVolumeImagePathParameter];
+ [self didChangeValueForKey:@"parameters"];
+ return;
+ }
+
+ // MFLogS(self, @"Writing image %@", image);
+ BOOL isDir;
+ NSString* iconDirPath = [@"~/Library/Application Support/Macfusion/Icons" stringByExpandingTildeInPath];
+
+ // Make Icons Directory if needed
+ if (![[NSFileManager defaultManager] fileExistsAtPath:iconDirPath isDirectory:&isDir] || !isDir)
+ {
+ NSError* dirCreateError;
+ BOOL ok = [[NSFileManager defaultManager] createDirectoryAtPath:iconDirPath
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&dirCreateError];
+ if (!ok)
+ {
+ MFLogS(self, @"Directory create for icon storage failed. Error %@", dirCreateError);
+ return;
+ }
+ }
+
+ // Write Icon
+ NSString* fullIconPath = [iconDirPath stringByAppendingPathComponent:
+ [NSString stringWithFormat:@"%@.icns", self.uuid]];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:fullIconPath])
+ [[NSFileManager defaultManager] removeFileAtPath:fullIconPath handler:nil];
+
+ IconFamily* icon = [[IconFamily alloc] initWithThumbnailsOfImage: image];
+ BOOL writeOK = [icon writeToFile: fullIconPath];
+ if (!writeOK)
+ {
+ MFLogS(self, @"Failed to write to file icon %@", icon);
+ return;
+ }
+
+ // Write Black and White image
+ NSString* fullBWImagePath = [iconDirPath stringByAppendingPathComponent:
+ [NSString stringWithFormat:@"%@.tiff", self.uuid]];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:fullBWImagePath])
+ [[NSFileManager defaultManager] removeFileAtPath: fullBWImagePath handler:nil];
+
+
+ CIFilter* bwFilter = [CIFilter filterWithName:@"CIColorControls"];
+ [bwFilter setDefaults];
+ [bwFilter setValue: [image ciImageRepresentation] forKey: @"inputImage"];
+ [bwFilter setValue: [NSNumber numberWithFloat:0.0] forKey: @"inputSaturation"];
+ CIImage* bwCIImage = [bwFilter valueForKey:@"outputImage"];
+
+ NSData* tiffData = [[bwCIImage nsImageRepresentation] TIFFRepresentation];
+ writeOK = [tiffData writeToFile:fullBWImagePath atomically:YES];
+ if(!writeOK)
+ {
+ MFLogS(self, @"Failed to write BW tiff file at path %@", fullBWImagePath);
+ return;
+ }
+
+ // Set the data and cause updates
+ [self willChangeValueForKey:@"parameters"];
+ [parameters setObject:fullIconPath
+ forKey:kMFFSVolumeIconPathParameter];
+ [parameters setObject:fullBWImagePath
+ forKey:kMFFSVolumeImagePathParameter];
+ [self didChangeValueForKey:@"parameters"];
+}
+
@synthesize displayOrder, clientFSDelegate;
@end
View
@@ -165,6 +165,7 @@ - (NSArray*)parameterList
[parameterList addObject: kMFFSVolumeIconPathParameter ];
[parameterList addObject: kMFFSFilePathParameter ];
[parameterList addObject: kMFFSPersistentParameter ];
+ [parameterList addObject: kMFFSVolumeImagePathParameter ];
return [parameterList copy];
}
@@ -205,11 +206,13 @@ - (NSMutableDictionary*)parametersWithImpliedValues
- (NSString*)iconPath
{
- return [self valueForParameterNamed: kMFFSVolumeIconPathParameter ];
+ NSString* iconPath = [self valueForParameterNamed: kMFFSVolumeIconPathParameter ];
+ return iconPath;
}
- (NSString*)imagePath
{
+ // NSLog(@"Calc imagePath parammeter %@ implied %@", parameters, [self parametersWithImpliedValues]);
return [self valueForParameterNamed: kMFFSVolumeImagePathParameter ];
}
View
@@ -275,6 +275,7 @@ - (NSDictionary*)taskEnvironment
- (NSArray*)taskArguments
{
NSArray* delegateArgs;
+ // MFLogS(self, @"Parameters in server are %@, implied are %@", parameters, [self parametersWithImpliedValues]);
if ([delegate respondsToSelector:@selector(taskArgumentsForParameters:)])
{
delegateArgs = [delegate taskArgumentsForParameters: [self parametersWithImpliedValues]];
@@ -123,6 +123,14 @@
D4E51FE80CE03AC3009B1A30 /* MFFilesystem.h in Headers */ = {isa = PBXBuildFile; fileRef = D42E14540CDFCF9000C81814 /* MFFilesystem.h */; };
D4E51FEA0CE03ACA009B1A30 /* MFPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E141C0CDFC99A00C81814 /* MFPlugin.m */; };
D4E51FEB0CE03ACA009B1A30 /* MFFilesystem.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E14550CDFCF9000C81814 /* MFFilesystem.m */; };
+ D4E6CCA20D9202AA0022763F /* MFIconSettingImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CCA00D9202AA0022763F /* MFIconSettingImageView.h */; };
+ D4E6CCA30D9202AA0022763F /* MFIconSettingImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CCA10D9202AA0022763F /* MFIconSettingImageView.m */; };
+ D4E6CEFC0D9223770022763F /* IconFamily.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CEF80D9223770022763F /* IconFamily.h */; };
+ D4E6CEFD0D9223770022763F /* IconFamily.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CEF90D9223770022763F /* IconFamily.m */; };
+ D4E6CEFE0D9223770022763F /* NSString+CarbonFSRefCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CEFA0D9223770022763F /* NSString+CarbonFSRefCreation.m */; };
+ D4E6CEFF0D9223770022763F /* NSString+CarbonFSRefCreation.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CEFB0D9223770022763F /* NSString+CarbonFSRefCreation.h */; };
+ D4E6CF3E0D9224DB0022763F /* MFAdvancedViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CF3C0D9224DB0022763F /* MFAdvancedViewController.h */; };
+ D4E6CF3F0D9224DB0022763F /* MFAdvancedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CF3D0D9224DB0022763F /* MFAdvancedViewController.m */; };
D4E983450D7223CE0058AF73 /* MGNSImage.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E983440D7223CE0058AF73 /* MGNSImage.m */; };
D4E983470D7223D70058AF73 /* MGNSImage.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E983460D7223D70058AF73 /* MGNSImage.h */; };
D4EA61570D8B30ED006D8885 /* MFMainController.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E13E50CDFC69500C81814 /* MFMainController.m */; };
@@ -399,6 +407,14 @@
D4DF34CD0D80FC73005C9402 /* topView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = topView.xib; sourceTree = "<group>"; };
D4DF353A0D812AA7005C9402 /* MGSmoothingImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGSmoothingImageView.h; sourceTree = "<group>"; };
D4DF353B0D812AA7005C9402 /* MGSmoothingImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGSmoothingImageView.m; sourceTree = "<group>"; };
+ D4E6CCA00D9202AA0022763F /* MFIconSettingImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MFIconSettingImageView.h; path = Settings/MFIconSettingImageView.h; sourceTree = "<group>"; };
+ D4E6CCA10D9202AA0022763F /* MFIconSettingImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MFIconSettingImageView.m; path = Settings/MFIconSettingImageView.m; sourceTree = "<group>"; };
+ D4E6CEF80D9223770022763F /* IconFamily.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconFamily.h; sourceTree = "<group>"; };
+ D4E6CEF90D9223770022763F /* IconFamily.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IconFamily.m; sourceTree = "<group>"; };
+ D4E6CEFA0D9223770022763F /* NSString+CarbonFSRefCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+CarbonFSRefCreation.m"; sourceTree = "<group>"; };
+ D4E6CEFB0D9223770022763F /* NSString+CarbonFSRefCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+CarbonFSRefCreation.h"; sourceTree = "<group>"; };
+ D4E6CF3C0D9224DB0022763F /* MFAdvancedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFAdvancedViewController.h; sourceTree = "<group>"; };
+ D4E6CF3D0D9224DB0022763F /* MFAdvancedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFAdvancedViewController.m; sourceTree = "<group>"; };
D4E983440D7223CE0058AF73 /* MGNSImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGNSImage.m; sourceTree = "<group>"; };
D4E983460D7223D70058AF73 /* MGNSImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGNSImage.h; sourceTree = "<group>"; };
D4EA61500D8B30DA006D8885 /* macfusionAgent.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = macfusionAgent.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -541,12 +557,9 @@
D413146B0D7F224900F55B9B /* Shared */ = {
isa = PBXGroup;
children = (
- D413146D0D7F225E00F55B9B /* MGTransitioningTabView.h */,
- D413146E0D7F225E00F55B9B /* MGTransitioningTabView.m */,
- D4DF353A0D812AA7005C9402 /* MGSmoothingImageView.h */,
- D4DF353B0D812AA7005C9402 /* MGSmoothingImageView.m */,
- D41E24280D897F0B00F46F50 /* MFPreferencesController.h */,
- D41E24290D897F0B00F46F50 /* MFPreferencesController.m */,
+ D4E6CF3B0D9224C70022763F /* Other */,
+ D4E6CF3A0D9224AE0022763F /* Controllers */,
+ D4E6CF380D92249F0022763F /* Views */,
);
name = Shared;
sourceTree = "<group>";
@@ -815,6 +828,41 @@
path = SSHFS;
sourceTree = "<group>";
};
+ D4E6CF380D92249F0022763F /* Views */ = {
+ isa = PBXGroup;
+ children = (
+ D4E6CCA00D9202AA0022763F /* MFIconSettingImageView.h */,
+ D4E6CCA10D9202AA0022763F /* MFIconSettingImageView.m */,
+ D413146D0D7F225E00F55B9B /* MGTransitioningTabView.h */,
+ D413146E0D7F225E00F55B9B /* MGTransitioningTabView.m */,
+ D4DF353A0D812AA7005C9402 /* MGSmoothingImageView.h */,
+ D4DF353B0D812AA7005C9402 /* MGSmoothingImageView.m */,
+ );
+ name = Views;
+ sourceTree = "<group>";
+ };
+ D4E6CF3A0D9224AE0022763F /* Controllers */ = {
+ isa = PBXGroup;
+ children = (
+ D41E24280D897F0B00F46F50 /* MFPreferencesController.h */,
+ D41E24290D897F0B00F46F50 /* MFPreferencesController.m */,
+ D4E6CF3C0D9224DB0022763F /* MFAdvancedViewController.h */,
+ D4E6CF3D0D9224DB0022763F /* MFAdvancedViewController.m */,
+ );
+ name = Controllers;
+ sourceTree = "<group>";
+ };
+ D4E6CF3B0D9224C70022763F /* Other */ = {
+ isa = PBXGroup;
+ children = (
+ D4E6CEF80D9223770022763F /* IconFamily.h */,
+ D4E6CEF90D9223770022763F /* IconFamily.m */,
+ D4E6CEFA0D9223770022763F /* NSString+CarbonFSRefCreation.m */,
+ D4E6CEFB0D9223770022763F /* NSString+CarbonFSRefCreation.h */,
+ );
+ name = Other;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -844,6 +892,10 @@
D41E1DA30D87557900F46F50 /* MFCore.h in Headers */,
D41E242A0D897F0C00F46F50 /* MFPreferencesController.h in Headers */,
D4CF0E460D8C75B30065A2C3 /* MFPreferences.h in Headers */,
+ D4E6CCA20D9202AA0022763F /* MFIconSettingImageView.h in Headers */,
+ D4E6CEFC0D9223770022763F /* IconFamily.h in Headers */,
+ D4E6CEFF0D9223770022763F /* NSString+CarbonFSRefCreation.h in Headers */,
+ D4E6CF3E0D9224DB0022763F /* MFAdvancedViewController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1133,6 +1185,10 @@
D41E1DA40D87557900F46F50 /* MFCore.m in Sources */,
D41E242B0D897F0C00F46F50 /* MFPreferencesController.m in Sources */,
D4CF0E470D8C75B30065A2C3 /* MFPreferences.m in Sources */,
+ D4E6CCA30D9202AA0022763F /* MFIconSettingImageView.m in Sources */,
+ D4E6CEFD0D9223770022763F /* IconFamily.m in Sources */,
+ D4E6CEFE0D9223770022763F /* NSString+CarbonFSRefCreation.m in Sources */,
+ D4E6CF3F0D9224DB0022763F /* MFAdvancedViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,25 @@
+/*
+ Copyright (c) 2001-2006 Troy N. Stephens
+
+ Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#import <Foundation/Foundation.h>
+#import <Carbon/Carbon.h>
+
+@interface NSString (CarbonFSRefCreation)
+
+// Fills in the given FSRef struct so it specifies the file whose path is in this string.
+// If the file doesn't exist, and "createFile" is YES, this method will attempt to create
+// an empty file with the specified path. (The caller should insure that the directory
+// the file is to be placed in already exists.)
+
+- (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile;
+
+@end
@@ -0,0 +1,58 @@
+/*
+ Copyright (c) 2001-2006 Troy N. Stephens
+
+ Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#import "NSString+CarbonFSRefCreation.h"
+
+@implementation NSString (CarbonFSRefCreation)
+
+- (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile
+{
+ NSFileManager* fileManager = [NSFileManager defaultManager];
+ CFURLRef urlRef;
+ Boolean gotFSRef;
+
+ // Check whether the file exists already. If not, create an empty file if requested.
+ if (![fileManager fileExistsAtPath:self]) {
+ if (createFile) {
+ if (![@"" writeToFile:self atomically:YES]) {
+ return NO;
+ }
+ } else {
+ return NO;
+ }
+ }
+
+ // Create a CFURL with the specified POSIX path.
+ urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
+ (CFStringRef) self,
+ kCFURLPOSIXPathStyle,
+ FALSE /* isDirectory */ );
+ if (urlRef == NULL) {
+// printf( "** Couldn't make a CFURLRef for the file.\n" );
+ return NO;
+ }
+
+ // Try to create an FSRef from the URL. (If the specified file doesn't exist, this
+ // function will return false, but if we've reached this code we've already insured
+ // that the file exists.)
+ gotFSRef = CFURLGetFSRef( urlRef, fsRef );
+ CFRelease( urlRef );
+
+ if (!gotFSRef) {
+// printf( "** Couldn't get an FSRef for the file.\n" );
+ return NO;
+ }
+
+ return YES;
+}
+
+@end
Oops, something went wrong.

0 comments on commit 240aeb1

Please sign in to comment.