From 705d0947aec581207d020104cb326b1a7c17c39f Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Fri, 2 Sep 2011 16:16:17 +0300 Subject: [PATCH] Sharing in the object info window can be updated. --- pithos-macos.xcodeproj/project.pbxproj | 12 ++ pithos-macos/MetadataKeyFormatter.m | 5 +- pithos-macos/PithosNodeInfoController.h | 3 + pithos-macos/PithosNodeInfoController.m | 5 + pithos-macos/PithosNodeInfoController.xib | 307 +++++++++++++++++++++++++-- pithos-macos/PithosObjectNode.m | 2 +- pithos-macos/SharingDictionaryTransformer.h | 39 ++++ pithos-macos/SharingDictionaryTransformer.m | 121 +++++++++++ pithos-macos/SharingNameFormatter.h | 39 ++++ pithos-macos/SharingNameFormatter.m | 71 +++++++ 10 files changed, 584 insertions(+), 20 deletions(-) create mode 100644 pithos-macos/SharingDictionaryTransformer.h create mode 100644 pithos-macos/SharingDictionaryTransformer.m create mode 100644 pithos-macos/SharingNameFormatter.h create mode 100644 pithos-macos/SharingNameFormatter.m diff --git a/pithos-macos.xcodeproj/project.pbxproj b/pithos-macos.xcodeproj/project.pbxproj index 6c90d2c..6de78a2 100644 --- a/pithos-macos.xcodeproj/project.pbxproj +++ b/pithos-macos.xcodeproj/project.pbxproj @@ -52,6 +52,8 @@ 619B85D513F8077800C9371F /* PithosPreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 619B85D313F8077100C9371F /* PithosPreferencesController.m */; }; 619B85D613F8077800C9371F /* PithosPreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 619B85D413F8077300C9371F /* PithosPreferencesController.xib */; }; 61C24BBB1410D350007004DC /* PublicURLTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BBA1410D350007004DC /* PublicURLTransformer.m */; }; + 61C24BBE1410E031007004DC /* SharingDictionaryTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BBD1410E031007004DC /* SharingDictionaryTransformer.m */; }; + 61C24BC114110BDB007004DC /* SharingNameFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BC014110BDB007004DC /* SharingNameFormatter.m */; }; 61E99D9413EC348500E48DA5 /* 145-persondot.png in Resources */ = {isa = PBXBuildFile; fileRef = 61E99D9313EC348500E48DA5 /* 145-persondot.png */; }; /* End PBXBuildFile section */ @@ -143,6 +145,10 @@ 619B85D413F8077300C9371F /* PithosPreferencesController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PithosPreferencesController.xib; sourceTree = ""; }; 61C24BB91410D350007004DC /* PublicURLTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PublicURLTransformer.h; path = "pithos-macos/PublicURLTransformer.h"; sourceTree = ""; }; 61C24BBA1410D350007004DC /* PublicURLTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PublicURLTransformer.m; path = "pithos-macos/PublicURLTransformer.m"; sourceTree = ""; }; + 61C24BBC1410E031007004DC /* SharingDictionaryTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharingDictionaryTransformer.h; path = "pithos-macos/SharingDictionaryTransformer.h"; sourceTree = ""; }; + 61C24BBD1410E031007004DC /* SharingDictionaryTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharingDictionaryTransformer.m; path = "pithos-macos/SharingDictionaryTransformer.m"; sourceTree = ""; }; + 61C24BBF14110BDB007004DC /* SharingNameFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharingNameFormatter.h; path = "pithos-macos/SharingNameFormatter.h"; sourceTree = ""; }; + 61C24BC014110BDB007004DC /* SharingNameFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharingNameFormatter.m; path = "pithos-macos/SharingNameFormatter.m"; sourceTree = ""; }; 61E99D9313EC348500E48DA5 /* 145-persondot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "145-persondot.png"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -320,6 +326,8 @@ children = ( 615A444F140F8A7F00308614 /* MetadataKeyFormatter.h */, 615A4450140F8A7F00308614 /* MetadataKeyFormatter.m */, + 61C24BBF14110BDB007004DC /* SharingNameFormatter.h */, + 61C24BC014110BDB007004DC /* SharingNameFormatter.m */, ); name = Formatters; sourceTree = ""; @@ -348,6 +356,8 @@ 615A444D140F8A5700308614 /* MetadataKeyTransformer.m */, 61C24BB91410D350007004DC /* PublicURLTransformer.h */, 61C24BBA1410D350007004DC /* PublicURLTransformer.m */, + 61C24BBC1410E031007004DC /* SharingDictionaryTransformer.h */, + 61C24BBD1410E031007004DC /* SharingDictionaryTransformer.m */, ); name = "Value Transformers"; sourceTree = ""; @@ -454,6 +464,8 @@ 615A444E140F8A5700308614 /* MetadataKeyTransformer.m in Sources */, 615A4451140F8A7F00308614 /* MetadataKeyFormatter.m in Sources */, 61C24BBB1410D350007004DC /* PublicURLTransformer.m in Sources */, + 61C24BBE1410E031007004DC /* SharingDictionaryTransformer.m in Sources */, + 61C24BC114110BDB007004DC /* SharingNameFormatter.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/pithos-macos/MetadataKeyFormatter.m b/pithos-macos/MetadataKeyFormatter.m index 066579c..933e75f 100644 --- a/pithos-macos/MetadataKeyFormatter.m +++ b/pithos-macos/MetadataKeyFormatter.m @@ -59,7 +59,10 @@ unichar aChar; for (int i = 0; i < [partialString length]; i++) { aChar = [partialString characterAtIndex:i]; - if (!(aChar == '_' || (aChar >= '0' && aChar <= '9') || (aChar >= 'A' && aChar <= 'Z') || (aChar >= 'a' && aChar <= 'z'))) { + if (!((aChar == '_') || + ((aChar >= '0') && (aChar <= '9')) || + ((aChar >= 'A') && (aChar <= 'Z')) || + ((aChar >= 'a') && (aChar <= 'z')))) { *newString = nil; return NO; } diff --git a/pithos-macos/PithosNodeInfoController.h b/pithos-macos/PithosNodeInfoController.h index 6c44343..94f205b 100644 --- a/pithos-macos/PithosNodeInfoController.h +++ b/pithos-macos/PithosNodeInfoController.h @@ -40,6 +40,9 @@ @interface PithosNodeInfoController : NSWindowController { PithosNode *node; + + IBOutlet NSDictionaryController *metadataDictionaryController; + IBOutlet NSDictionaryController *sharingDictionaryController; } @property(assign) PithosNode *node; diff --git a/pithos-macos/PithosNodeInfoController.m b/pithos-macos/PithosNodeInfoController.m index bd041ab..430688e 100644 --- a/pithos-macos/PithosNodeInfoController.m +++ b/pithos-macos/PithosNodeInfoController.m @@ -59,6 +59,11 @@ - (void)windowDidLoad { [super windowDidLoad]; + [metadataDictionaryController setInitialKey:@"key"]; + [metadataDictionaryController setInitialValue:@"value"]; + [sharingDictionaryController setInitialKey:@"user"]; + [sharingDictionaryController setInitialValue:@"read"]; + [[self window] setDelegate:self]; } diff --git a/pithos-macos/PithosNodeInfoController.xib b/pithos-macos/PithosNodeInfoController.xib index 8933ef8..45fb87a 100644 --- a/pithos-macos/PithosNodeInfoController.xib +++ b/pithos-macos/PithosNodeInfoController.xib @@ -17,6 +17,7 @@ NSScroller NSTableHeaderView NSButton + NSComboBoxCell NSTextFieldCell NSScrollView NSImageView @@ -846,14 +847,80 @@ - - 337772096 - 2048 - Text Cell + + 68288064 + 272761856 + - + + 2 + YES + + YES + read + write + + + + 274 + {13, 18} + + + YES + + YES + + 10 + 10 + 1000 + + 75628032 + 0 + + + LucidaGrande + 12 + 16 + + + 3 + MC4zMzMzMzI5ODU2AA + + + + + 338820672 + 1024 + + + YES + + + + 3 + YES + + + + 3 + 2 + + + 16 + tableViewAction: + -765427712 + + + + 1 + 15 + 0 + YES + 0 + + NO 3 YES @@ -1050,11 +1117,7 @@ -2080244224 134217728 Revert - - LucidaGrande - 12 - 16 - + -2038152961 164 @@ -1114,9 +1177,29 @@ key value + + YES + YES + YES + YES + + YES + + key + YES + compare: + + + YES + key + value + MetadataKeyFormatter + + SharingNameFormatter + @@ -1561,6 +1644,172 @@ 294 + + + contentDictionary: node.pithosObject.sharing + + + + + + contentDictionary: node.pithosObject.sharing + contentDictionary + node.pithosObject.sharing + + NSValueTransformerName + SharingDictionaryTransformer + + 2 + + + 298 + + + + content: arrangedObjects + + + + + + content: arrangedObjects + content + arrangedObjects + 2 + + + 299 + + + + selectionIndexes: selectionIndexes + + + + + + selectionIndexes: selectionIndexes + selectionIndexes + selectionIndexes + + 2 + + + 301 + + + + sortDescriptors: sortDescriptors + + + + + + sortDescriptors: sortDescriptors + sortDescriptors + sortDescriptors + + 2 + + + 303 + + + + value: arrangedObjects.key + + + + + + value: arrangedObjects.key + value + arrangedObjects.key + + NSValidatesImmediately + + + 2 + + + 307 + + + + value: arrangedObjects.value + + + + + + value: arrangedObjects.value + value + arrangedObjects.value + + NSValidatesImmediately + + + 2 + + + 310 + + + + add: + + + + 311 + + + + remove: + + + + 312 + + + + enabled: canRemove + + + + + + enabled: canRemove + enabled + canRemove + 2 + + + 316 + + + + metadataDictionaryController + + + + 319 + + + + sharingDictionaryController + + + + 320 + + + + formatter + + + + 322 + @@ -2053,6 +2302,7 @@ + Scroll View - Table View - Sharing 69 @@ -2112,7 +2362,7 @@ YES - + @@ -2131,11 +2381,6 @@ - 80 - - - - 81 @@ -2228,6 +2473,22 @@ + + 295 + + + Dictionary Controller (Sharing) + + + 314 + + + + + 321 + + + @@ -2265,10 +2526,14 @@ 27.IBPluginDependency 28.IBPluginDependency 29.IBPluginDependency + 295.IBPluginDependency 3.IBPluginDependency 30.IBPluginDependency 31.IBPluginDependency + 314.IBComboBoxObjectValuesKey.objectValues + 314.IBPluginDependency 32.IBPluginDependency + 321.IBPluginDependency 33.IBPluginDependency 34.IBPluginDependency 35.IBPluginDependency @@ -2313,7 +2578,6 @@ 78.IBPluginDependency 79.IBPluginDependency 8.IBPluginDependency - 80.IBPluginDependency 81.IBPluginDependency 85.IBPluginDependency 86.IBPluginDependency @@ -2360,6 +2624,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + YES + read + write + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2427,7 +2698,7 @@ - 294 + 322 0 diff --git a/pithos-macos/PithosObjectNode.m b/pithos-macos/PithosObjectNode.m index aa5481a..dd1fcdb 100644 --- a/pithos-macos/PithosObjectNode.m +++ b/pithos-macos/PithosObjectNode.m @@ -118,7 +118,7 @@ contentEncoding:nil contentDisposition:nil manifest:nil - sharing:nil + sharing:pithosObject.sharing isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse) metadata:pithosObject.metadata update:NO] retain]; diff --git a/pithos-macos/SharingDictionaryTransformer.h b/pithos-macos/SharingDictionaryTransformer.h new file mode 100644 index 0000000..39ee3f4 --- /dev/null +++ b/pithos-macos/SharingDictionaryTransformer.h @@ -0,0 +1,39 @@ +// +// SharingDictionaryTransformer.h +// pithos-macos +// +// Copyright 2011 GRNET S.A. All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and +// documentation are those of the authors and should not be +// interpreted as representing official policies, either expressed +// or implied, of GRNET S.A. + +@interface SharingDictionaryTransformer : NSValueTransformer +@end diff --git a/pithos-macos/SharingDictionaryTransformer.m b/pithos-macos/SharingDictionaryTransformer.m new file mode 100644 index 0000000..3469508 --- /dev/null +++ b/pithos-macos/SharingDictionaryTransformer.m @@ -0,0 +1,121 @@ +// +// SharingDictionaryTransformer.m +// pithos-macos +// +// Copyright 2011 GRNET S.A. All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and +// documentation are those of the authors and should not be +// interpreted as representing official policies, either expressed +// or implied, of GRNET S.A. + +#import "SharingDictionaryTransformer.h" + +@implementation SharingDictionaryTransformer + ++ (Class)transformedValueClass { + return [NSMutableDictionary class]; +} + ++ (BOOL)allowsReverseTransformation { + return YES; +} + +- (id)transformedValue:(id)value { + NSMutableDictionary *sharingDictionary = [NSMutableDictionary dictionary]; + + if (value == nil) + return sharingDictionary; + + NSRange readRange = [(NSString *)value rangeOfString:@"read=" options:NSCaseInsensitiveSearch]; + NSUInteger readStart = readRange.location + readRange.length; + NSRange writeRange = [(NSString *)value rangeOfString:@"write=" options:NSCaseInsensitiveSearch]; + NSUInteger writeStart = writeRange.location + writeRange.length; + if (writeRange.length == 0) { + if (readRange.length == 0) { + return sharingDictionary; + } + for (NSString *readUser in [[(NSString *)value substringFromIndex:readStart] componentsSeparatedByString:@","]) { + [sharingDictionary setValue:@"read" forKey:readUser]; + } + } else if (readRange.length == 0) { + for (NSString *writeUser in [[(NSString *)value substringFromIndex:writeStart] componentsSeparatedByString:@","]) { + [sharingDictionary setValue:@"write" forKey:writeUser]; + } + } else if (readRange.location < writeRange.location) { + NSRange semicolonRange = [(NSString *)value rangeOfString:@";"]; + for (NSString *readUser in [[(NSString *)value substringWithRange:NSMakeRange(readStart, semicolonRange.location - readStart)] componentsSeparatedByString:@","]) { + [sharingDictionary setValue:@"read" forKey:readUser]; + } + for (NSString *writeUser in [[(NSString *)value substringFromIndex:writeStart] componentsSeparatedByString:@","]) { + [sharingDictionary setValue:@"write" forKey:writeUser]; + } + } else { + NSRange semicolonRange = [(NSString *)value rangeOfString:@";"]; + for (NSString *readUser in [[(NSString *)value substringFromIndex:readStart] componentsSeparatedByString:@","]) { + [sharingDictionary setValue:@"read" forKey:readUser]; + } + for (NSString *writeUser in [[(NSString *)value substringWithRange:NSMakeRange(writeStart, semicolonRange.location - writeStart)] componentsSeparatedByString:@","]) { + [sharingDictionary setValue:@"write" forKey:writeUser]; + } + } + + return sharingDictionary; +} + +- (id)reverseTransformedValue:(id)value { + if (value == nil || ([(NSMutableDictionary *)value count] == 0)) + return nil; + + NSString *readSharingString = nil; + NSArray *readUsers = [(NSMutableDictionary *)value allKeysForObject:@"read"]; + if ([readUsers count]) + readSharingString = [NSString stringWithFormat:@"read=%@", [readUsers componentsJoinedByString:@","]]; + NSString *writeSharingString = nil; + + NSArray *writeUsers = [(NSMutableDictionary *)value allKeysForObject:@"write"]; + if ([writeUsers count]) + writeSharingString = [NSString stringWithFormat:@"write=%@", [writeUsers componentsJoinedByString:@","]]; + + + if (readSharingString) { + if (writeSharingString) { + return [NSString stringWithFormat:@"%@;%@", readSharingString, writeSharingString]; + } + return readSharingString; + } else { + return writeSharingString; + } +} + ++ (void)initialize { + [[NSValueTransformer class] setValueTransformer:[self new] forName:@"SharingDictionaryTransformer"]; +} + +@end diff --git a/pithos-macos/SharingNameFormatter.h b/pithos-macos/SharingNameFormatter.h new file mode 100644 index 0000000..80f025b --- /dev/null +++ b/pithos-macos/SharingNameFormatter.h @@ -0,0 +1,39 @@ +// +// SharingNameFormatter.h +// pithos-macos +// +// Copyright 2011 GRNET S.A. All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and +// documentation are those of the authors and should not be +// interpreted as representing official policies, either expressed +// or implied, of GRNET S.A. + +@interface SharingNameFormatter : NSFormatter +@end diff --git a/pithos-macos/SharingNameFormatter.m b/pithos-macos/SharingNameFormatter.m new file mode 100644 index 0000000..ed1636e --- /dev/null +++ b/pithos-macos/SharingNameFormatter.m @@ -0,0 +1,71 @@ +// +// SharingNameFormatter.m +// pithos-macos +// +// Copyright 2011 GRNET S.A. All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and +// documentation are those of the authors and should not be +// interpreted as representing official policies, either expressed +// or implied, of GRNET S.A. + +#import "SharingNameFormatter.h" + +@implementation SharingNameFormatter + +- (NSString *)stringForObjectValue:(id)anObject { + if (anObject != nil) + return [NSString stringWithString:anObject]; + return nil; +} + +- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { + *anObject = [NSString stringWithString:string]; + return YES; +} + +- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error { + if ([partialString length] == 0) { + *newString = nil; + return NO; + } + + unichar aChar; + for (int i = 0; i < [partialString length]; i++) { + aChar = [partialString characterAtIndex:i]; + if ((aChar == ' ') || (aChar == '=') || (aChar == ',') || (aChar == ';')) { + *newString = nil; + return NO; + } + } + + return YES; +} + +@end -- 1.7.10.4