From 7325abf2d0a7aaf7adec65c6bd1e125887355039 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 25 Oct 2011 16:41:33 +0300 Subject: [PATCH] Sync folder can be selected in the preferences. Improvements in handling of user properties. --- pithos-macos.xcodeproj/project.pbxproj | 6 + pithos-macos/DirPathFileURLTransformer.h | 39 +++ pithos-macos/DirPathFileURLTransformer.m | 66 ++++ pithos-macos/PithosActivityFacility.m | 1 - pithos-macos/PithosPreferencesController.h | 2 - pithos-macos/PithosPreferencesController.m | 9 +- pithos-macos/PithosPreferencesController.xib | 234 ++++++-------- pithos-macos/PithosSyncDaemon.h | 1 + pithos-macos/PithosSyncDaemon.m | 2 +- pithos-macos/en.lproj/MainMenu.xib | 435 ++++++++++++++++++++++++-- pithos-macos/pithos-macos-Info.plist | 4 +- pithos-macos/pithos_macosAppDelegate.h | 8 +- pithos-macos/pithos_macosAppDelegate.m | 41 ++- 13 files changed, 663 insertions(+), 185 deletions(-) create mode 100644 pithos-macos/DirPathFileURLTransformer.h create mode 100644 pithos-macos/DirPathFileURLTransformer.m diff --git a/pithos-macos.xcodeproj/project.pbxproj b/pithos-macos.xcodeproj/project.pbxproj index d33e610..c59a1b1 100644 --- a/pithos-macos.xcodeproj/project.pbxproj +++ b/pithos-macos.xcodeproj/project.pbxproj @@ -52,6 +52,7 @@ 6154BF4B145554D600EE353A /* pithos-logo-small.png in Resources */ = {isa = PBXBuildFile; fileRef = 6154BF4A145554D600EE353A /* pithos-logo-small.png */; }; 6154BF4D145558E300EE353A /* pithos.icns in Resources */ = {isa = PBXBuildFile; fileRef = 6154BF4C145558E300EE353A /* pithos.icns */; }; 6154BF501456A83200EE353A /* UsingSizeTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6154BF4F1456A83100EE353A /* UsingSizeTransformer.m */; }; + 6154BF531456EE4900EE353A /* DirPathFileURLTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6154BF521456EE4700EE353A /* DirPathFileURLTransformer.m */; }; 615615DD140CECDB00017BD4 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 615615DC140CECDB00017BD4 /* libz.dylib */; }; 615A444E140F8A5700308614 /* MetadataKeyTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 615A444D140F8A5700308614 /* MetadataKeyTransformer.m */; }; 615A4451140F8A7F00308614 /* MetadataKeyFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 615A4450140F8A7F00308614 /* MetadataKeyFormatter.m */; }; @@ -167,6 +168,8 @@ 6154BF4C145558E300EE353A /* pithos.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = pithos.icns; path = ../pithos.icns; sourceTree = ""; }; 6154BF4E1456A83100EE353A /* UsingSizeTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UsingSizeTransformer.h; path = "pithos-macos/UsingSizeTransformer.h"; sourceTree = ""; }; 6154BF4F1456A83100EE353A /* UsingSizeTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UsingSizeTransformer.m; path = "pithos-macos/UsingSizeTransformer.m"; sourceTree = ""; }; + 6154BF511456EE4600EE353A /* DirPathFileURLTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DirPathFileURLTransformer.h; path = "pithos-macos/DirPathFileURLTransformer.h"; sourceTree = ""; }; + 6154BF521456EE4700EE353A /* DirPathFileURLTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DirPathFileURLTransformer.m; path = "pithos-macos/DirPathFileURLTransformer.m"; sourceTree = ""; }; 615615DC140CECDB00017BD4 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 615A444C140F8A5700308614 /* MetadataKeyTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MetadataKeyTransformer.h; path = "pithos-macos/MetadataKeyTransformer.h"; sourceTree = ""; }; 615A444D140F8A5700308614 /* MetadataKeyTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MetadataKeyTransformer.m; path = "pithos-macos/MetadataKeyTransformer.m"; sourceTree = ""; }; @@ -424,6 +427,8 @@ 6164B2DC1450E55C00D4C1AB /* LastCompletedSyncTransformer.m */, 6154BF4E1456A83100EE353A /* UsingSizeTransformer.h */, 6154BF4F1456A83100EE353A /* UsingSizeTransformer.m */, + 6154BF511456EE4600EE353A /* DirPathFileURLTransformer.h */, + 6154BF521456EE4700EE353A /* DirPathFileURLTransformer.m */, ); name = "Value Transformers"; sourceTree = ""; @@ -636,6 +641,7 @@ 61F04133144DB97600A0C788 /* PithosSyncDaemon.m in Sources */, 6164B2DD1450E55C00D4C1AB /* LastCompletedSyncTransformer.m in Sources */, 6154BF501456A83200EE353A /* UsingSizeTransformer.m in Sources */, + 6154BF531456EE4900EE353A /* DirPathFileURLTransformer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/pithos-macos/DirPathFileURLTransformer.h b/pithos-macos/DirPathFileURLTransformer.h new file mode 100644 index 0000000..ba458c5 --- /dev/null +++ b/pithos-macos/DirPathFileURLTransformer.h @@ -0,0 +1,39 @@ +// +// DirPathFileURLTransformer.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 DirPathFileURLTransformer : NSValueTransformer +@end diff --git a/pithos-macos/DirPathFileURLTransformer.m b/pithos-macos/DirPathFileURLTransformer.m new file mode 100644 index 0000000..b8e4cab --- /dev/null +++ b/pithos-macos/DirPathFileURLTransformer.m @@ -0,0 +1,66 @@ +// +// DirPathFileURLTransformer.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 "DirPathFileURLTransformer.h" + +@implementation DirPathFileURLTransformer + ++ (Class)transformedValueClass { + return [NSURL class]; +} + ++ (BOOL)allowsReverseTransformation { + return YES; +} + +- (id)transformedValue:(id)value { + if (value == nil) + return nil; + return [NSURL fileURLWithPath:(NSString *)value]; +} + +- (id)reverseTransformedValue:(id)value { + if (value == nil) + return nil; + return [(NSURL *)value path]; +} + ++ (void)initialize { + [[NSValueTransformer class] setValueTransformer:[self new] forName:@"DirPathFileURLTransformer"]; +} + +@end diff --git a/pithos-macos/PithosActivityFacility.m b/pithos-macos/PithosActivityFacility.m index a11ab79..ae692cf 100644 --- a/pithos-macos/PithosActivityFacility.m +++ b/pithos-macos/PithosActivityFacility.m @@ -178,7 +178,6 @@ static PithosActivityFacility *defaultPithosActivityFacility = nil; [info setObject:[NSNumber numberWithUnsignedInteger:totalDownloadBytes] forKey:@"totalDownloadBytes"]; [info setObject:[NSNumber numberWithUnsignedInteger:currentDownloadBytes] forKey:@"currentDownloadBytes"]; [activity release]; - NSLog(@"PithosActivityFacility update: %@", info); } if (delegate) { [delegate activityUpdate:info]; diff --git a/pithos-macos/PithosPreferencesController.h b/pithos-macos/PithosPreferencesController.h index cdb35c4..4017bbc 100644 --- a/pithos-macos/PithosPreferencesController.h +++ b/pithos-macos/PithosPreferencesController.h @@ -39,7 +39,6 @@ @class PithosBrowserController; @interface PithosPreferencesController : NSWindowController { - NSUserDefaultsController *userDefaultsController; PithosBrowserController *pithosBrowserController; NSTextField *authenticationUserTextField; @@ -50,7 +49,6 @@ NSDictionaryController *selectedGroupMembersDictionaryController; } -@property (nonatomic, assign) IBOutlet NSUserDefaultsController *userDefaultsController; @property (nonatomic, assign) IBOutlet PithosBrowserController *pithosBrowserController; @property (nonatomic, assign) IBOutlet NSTextField *authenticationUserTextField; diff --git a/pithos-macos/PithosPreferencesController.m b/pithos-macos/PithosPreferencesController.m index 43f6d2b..3dc3635 100644 --- a/pithos-macos/PithosPreferencesController.m +++ b/pithos-macos/PithosPreferencesController.m @@ -41,7 +41,7 @@ #import "pithos_macosAppDelegate.h" @implementation PithosPreferencesController -@synthesize userDefaultsController, pithosBrowserController; +@synthesize pithosBrowserController; @synthesize authenticationUserTextField, authenticationTokenTextField, authenticationRenewCheckBox; @synthesize groupsDictionaryController, selectedGroupMembersDictionaryController; @@ -72,9 +72,7 @@ - (void)windowWillClose:(NSNotification *)notification { [[self window] makeFirstResponder:nil]; - NSString *authUser = [[userDefaultsController values] valueForKey:@"authUser"]; - NSString *authToken = [[userDefaultsController values] valueForKey:@"authToken"]; - [(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] authenticateWithAuthUser:authUser authToken:authToken]; + [(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] authenticate]; } - (IBAction)toolbarItemSelected:(id)sender { @@ -84,7 +82,6 @@ #pragma Authentication - (IBAction)authenticationLogin:(id)sender { - // XXX hardcoded for now NSProcessInfo *processInfo = [NSProcessInfo processInfo]; NSString *loginURL = [NSString stringWithFormat:@"%@?next=pithos://%@_%d", ((pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate]).loginURLPrefix, @@ -94,8 +91,6 @@ loginURL = [loginURL stringByAppendingString:@"&renew="]; NSLog(@"loginURL: %@", loginURL); [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:loginURL]]; - // XXX Should we wait for results or do something else? - // XXX check the case where this happens for the first time } #pragma mark - diff --git a/pithos-macos/PithosPreferencesController.xib b/pithos-macos/PithosPreferencesController.xib index 84c1d7b..d0e200f 100644 --- a/pithos-macos/PithosPreferencesController.xib +++ b/pithos-macos/PithosPreferencesController.xib @@ -12,9 +12,7 @@ YES - NSTabView - NSMenuItem - NSMenu + NSPathCell NSToolbarItem NSButton NSCustomObject @@ -26,15 +24,15 @@ NSTableColumn NSBox NSView - NSPopUpButtonCell NSDictionaryController NSToolbar NSScrollView NSTabViewItem NSUserDefaultsController + NSPathControl NSScroller NSTableHeaderView - NSPopUpButton + NSTabView YES @@ -155,13 +153,13 @@ 12 {265, 159} - + YES 0 - + 274 YES @@ -170,7 +168,7 @@ 268 {{12, 116}, {83, 14}} - + YES 68288064 @@ -338,6 +336,7 @@ 289 {{188, 2}, {72, 28}} + YES -2080244224 @@ -427,81 +426,66 @@ 25 - + 268 - {{97, 111}, {161, 22}} + + YES + + YES + Apple URL pasteboard type + NSFilenamesPboardType + + + {{97, 110}, {161, 22}} YES - - -2076049856 - 133120 - - - 109199615 - 129 - - - 400 - 75 - - - Item 1 - - 1048576 - 2147483647 - 1 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState + + 337772033 + 131072 + + + + file://localhost/ - _popUpItemAction: - - YES - - OtherViews - - YES - - - - Item 2 - - 1048576 - 2147483647 - - - _popUpItemAction: - + + + + YES + + 67239488 + 1024 + karvouni4 + + + + + + file://localhost// - - - Item 3 - - 1048576 - 2147483647 - - - _popUpItemAction: - + + + 67239488 + 1024 + Macintosh HD + + + + + + file://localhost// - - 1 - YES - YES - 2 + 2 + {265, 159} + General @@ -511,7 +495,7 @@ 1 - + 274 YES @@ -966,7 +950,6 @@ {265, 159} - Groups @@ -974,14 +957,14 @@ - + 6 YES YES YES - + @@ -1498,6 +1481,35 @@ 465 + + + value: values.pithosSyncDirectoryPath + + + + + + value: values.pithosSyncDirectoryPath + value + values.pithosSyncDirectoryPath + + YES + + YES + NSValidatesImmediately + NSValueTransformerName + + + YES + + DirPathFileURLTransformer + + + 2 + + + 477 + @@ -1590,7 +1602,7 @@ - + @@ -1915,50 +1927,6 @@ - 367 - - - YES - - - - - - 368 - - - YES - - - - - - 369 - - - YES - - - - - - - - 370 - - - - - 371 - - - - - 372 - - - - 382 @@ -2026,6 +1994,20 @@ + + 470 + + + YES + + + + + + 471 + + + @@ -2089,12 +2071,6 @@ 341.IBPluginDependency 343.IBPluginDependency 344.IBPluginDependency - 367.IBPluginDependency - 368.IBPluginDependency - 369.IBPluginDependency - 370.IBPluginDependency - 371.IBPluginDependency - 372.IBPluginDependency 382.IBPluginDependency 383.IBPluginDependency 384.IBPluginDependency @@ -2106,6 +2082,8 @@ 4.IBPluginDependency 433.IBPluginDependency 449.IBPluginDependency + 470.IBPluginDependency + 471.IBPluginDependency 5.IBPluginDependency 6.IBPluginDependency @@ -2183,10 +2161,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin @@ -2201,7 +2175,7 @@ - 465 + 477 0 @@ -2218,8 +2192,6 @@ YES NSAddTemplate NSEveryone - NSMenuCheckmark - NSMenuMixedState NSPreferencesGeneral NSRemoveTemplate NSSwitch @@ -2228,8 +2200,6 @@ YES {8, 8} {32, 32} - {9, 8} - {7, 2} {32, 32} {8, 8} {15, 15} diff --git a/pithos-macos/PithosSyncDaemon.h b/pithos-macos/PithosSyncDaemon.h index caec13f..dfd3d77 100644 --- a/pithos-macos/PithosSyncDaemon.h +++ b/pithos-macos/PithosSyncDaemon.h @@ -75,6 +75,7 @@ @property (nonatomic, retain) NSMutableDictionary *storedLocalObjectStates; @property (nonatomic, retain) NSMutableDictionary *currentLocalObjectStates; +@property (nonatomic, readonly) NSString *directoryPath; @property (nonatomic, readonly) NSString *containerDirectoryPath; @property (nonatomic, readonly) NSString *pithosStateFilePath; @property (nonatomic, readonly) NSString *tempDownloadsDirPath; diff --git a/pithos-macos/PithosSyncDaemon.m b/pithos-macos/PithosSyncDaemon.m index 15d5a0e..5ecb9c6 100644 --- a/pithos-macos/PithosSyncDaemon.m +++ b/pithos-macos/PithosSyncDaemon.m @@ -69,7 +69,7 @@ @implementation PithosSyncDaemon @synthesize blockHash, blockSize, lastModified, lastCompletedSync, remoteObjects, storedLocalObjectStates, currentLocalObjectStates; -@synthesize containerDirectoryPath, pithosStateFilePath, tempDownloadsDirPath, tempTrashDirPath; +@synthesize directoryPath, containerDirectoryPath, pithosStateFilePath, tempDownloadsDirPath, tempTrashDirPath; #pragma mark - #pragma Object Lifecycle diff --git a/pithos-macos/en.lproj/MainMenu.xib b/pithos-macos/en.lproj/MainMenu.xib index 5cb878b..a507cf2 100644 --- a/pithos-macos/en.lproj/MainMenu.xib +++ b/pithos-macos/en.lproj/MainMenu.xib @@ -12,7 +12,6 @@ YES - NSUserDefaultsController NSMenu NSMenuItem NSCustomObject @@ -1421,9 +1420,6 @@ - - YES - @@ -2158,14 +2154,6 @@ - userDefaultsController - - - - 558 - - - pithosBrowserController @@ -3359,11 +3347,6 @@ PithosPreferencesController - - 557 - - - @@ -3518,7 +3501,6 @@ 544.IBPluginDependency 545.IBPluginDependency 546.IBPluginDependency - 557.IBPluginDependency 56.IBPluginDependency 57.IBPluginDependency 58.IBPluginDependency @@ -3700,7 +3682,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin @@ -3717,7 +3698,421 @@ 575 - + + + YES + + NSDocument + + YES + + YES + printDocument: + revertDocumentToSaved: + runPageLayout: + saveDocument: + saveDocumentAs: + saveDocumentTo: + + + YES + id + id + id + id + id + id + + + + YES + + YES + printDocument: + revertDocumentToSaved: + runPageLayout: + saveDocument: + saveDocumentAs: + saveDocumentTo: + + + YES + + printDocument: + id + + + revertDocumentToSaved: + id + + + runPageLayout: + id + + + saveDocument: + id + + + saveDocumentAs: + id + + + saveDocumentTo: + id + + + + + IBProjectSource + ./Classes/NSDocument.h + + + + PithosBrowserController + NSWindowController + + YES + + YES + forceRefresh: + refresh: + + + YES + id + id + + + + YES + + YES + forceRefresh: + refresh: + + + YES + + forceRefresh: + id + + + refresh: + id + + + + + YES + + YES + activityProgressIndicator + activityTextField + browser + browserMenu + horizontalSplitView + leftBottomView + leftTopView + outlineView + outlineViewMenu + verticalSplitView + + + YES + NSProgressIndicator + NSTextField + NSBrowser + NSMenu + NSSplitView + NSView + NSView + NSOutlineView + NSMenu + NSSplitView + + + + YES + + YES + activityProgressIndicator + activityTextField + browser + browserMenu + horizontalSplitView + leftBottomView + leftTopView + outlineView + outlineViewMenu + verticalSplitView + + + YES + + activityProgressIndicator + NSProgressIndicator + + + activityTextField + NSTextField + + + browser + NSBrowser + + + browserMenu + NSMenu + + + horizontalSplitView + NSSplitView + + + leftBottomView + NSView + + + leftTopView + NSView + + + outlineView + NSOutlineView + + + outlineViewMenu + NSMenu + + + verticalSplitView + NSSplitView + + + + + IBProjectSource + ./Classes/PithosBrowserController.h + + + + PithosPreferencesController + NSWindowController + + YES + + YES + authenticationLogin: + toolbarItemSelected: + + + YES + id + id + + + + YES + + YES + authenticationLogin: + toolbarItemSelected: + + + YES + + authenticationLogin: + id + + + toolbarItemSelected: + id + + + + + YES + + YES + authenticationRenewCheckBox + authenticationTokenTextField + authenticationUserTextField + groupsDictionaryController + pithosBrowserController + selectedGroupMembersDictionaryController + userDefaultsController + + + YES + NSButton + NSTextField + NSTextField + NSDictionaryController + PithosBrowserController + NSDictionaryController + NSUserDefaultsController + + + + YES + + YES + authenticationRenewCheckBox + authenticationTokenTextField + authenticationUserTextField + groupsDictionaryController + pithosBrowserController + selectedGroupMembersDictionaryController + userDefaultsController + + + YES + + authenticationRenewCheckBox + NSButton + + + authenticationTokenTextField + NSTextField + + + authenticationUserTextField + NSTextField + + + groupsDictionaryController + NSDictionaryController + + + pithosBrowserController + PithosBrowserController + + + selectedGroupMembersDictionaryController + NSDictionaryController + + + userDefaultsController + NSUserDefaultsController + + + + + IBProjectSource + ./Classes/PithosPreferencesController.h + + + + PithosSyncDaemon + NSObject + + IBProjectSource + ./Classes/PithosSyncDaemon.h + + + + pithos_macosAppDelegate + NSObject + + YES + + YES + aboutPithos: + showPithosBrowser: + showPithosPreferences: + syncNow: + + + YES + id + id + id + id + + + + YES + + YES + aboutPithos: + showPithosBrowser: + showPithosPreferences: + syncNow: + + + YES + + aboutPithos: + id + + + showPithosBrowser: + id + + + showPithosPreferences: + id + + + syncNow: + id + + + + + YES + + YES + pithosBrowserController + pithosPreferencesController + pithosSyncDaemon + statusMenu + + + YES + PithosBrowserController + PithosPreferencesController + PithosSyncDaemon + NSMenu + + + + YES + + YES + pithosBrowserController + pithosPreferencesController + pithosSyncDaemon + statusMenu + + + YES + + pithosBrowserController + PithosBrowserController + + + pithosPreferencesController + PithosPreferencesController + + + pithosSyncDaemon + PithosSyncDaemon + + + statusMenu + NSMenu + + + + + IBProjectSource + ./Classes/pithos_macosAppDelegate.h + + + + 0 IBCocoaFramework diff --git a/pithos-macos/pithos-macos-Info.plist b/pithos-macos/pithos-macos-Info.plist index c67f429..7ba208d 100644 --- a/pithos-macos/pithos-macos-Info.plist +++ b/pithos-macos/pithos-macos-Info.plist @@ -24,7 +24,7 @@ CFBundleURLName - Pithos' URL + Pithos' URL CFBundleURLSchemes pithos @@ -49,8 +49,6 @@ https://pithos.dev.grnet.gr/v1 PithosSyncContainerName pithos - PithosSyncDirectoryPath - PithosSyncTimeInterval 180 diff --git a/pithos-macos/pithos_macosAppDelegate.h b/pithos-macos/pithos_macosAppDelegate.h index b5d50c2..326616d 100644 --- a/pithos-macos/pithos_macosAppDelegate.h +++ b/pithos-macos/pithos_macosAppDelegate.h @@ -44,20 +44,17 @@ IBOutlet PithosBrowserController *pithosBrowserController; IBOutlet PithosPreferencesController *pithosPreferencesController; - IBOutlet PithosSyncDaemon *pithosSyncDaemon; + PithosSyncDaemon *pithosSyncDaemon; BOOL alwaysNo; IBOutlet NSMenu *statusMenu; NSStatusItem *statusItem; - IBOutlet NSUserDefaultsController *userDefaultsController; - NSString *storageURLPrefix; NSString *publicURLPrefix; NSString *loginURLPrefix; NSString *aboutURL; - NSString *syncDirectoryPath; NSString *syncContainerName; NSTimeInterval syncTimeInterval; } @@ -68,14 +65,13 @@ - (IBAction)aboutPithos:(id)sender; - (IBAction)syncNow:(id)sender; -- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken; +- (void)authenticate; - (void)startSyncWithDirectoryPath:(NSString *)directoryPath containerName:(NSString *)containerName; @property (nonatomic, readonly) NSString *storageURLPrefix; @property (nonatomic, readonly) NSString *publicURLPrefix; @property (nonatomic, readonly) NSString *loginURLPrefix; @property (nonatomic, readonly) NSString *aboutURL; -@property (nonatomic, readonly) NSString *syncDirectoryPath; @property (nonatomic, readonly) NSString *syncContainerName; @property (nonatomic, assign) NSTimeInterval syncTimeInterval; diff --git a/pithos-macos/pithos_macosAppDelegate.m b/pithos-macos/pithos_macosAppDelegate.m index 47260f1..d9b51f2 100644 --- a/pithos-macos/pithos_macosAppDelegate.m +++ b/pithos-macos/pithos_macosAppDelegate.m @@ -44,7 +44,7 @@ @implementation pithos_macosAppDelegate @synthesize storageURLPrefix, publicURLPrefix, loginURLPrefix, aboutURL; -@synthesize syncDirectoryPath, syncContainerName, syncTimeInterval, pithosBrowserController, pithosSyncDaemon, alwaysNo; +@synthesize syncContainerName, syncTimeInterval, pithosBrowserController, pithosSyncDaemon, alwaysNo; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSURL *testURL; @@ -88,15 +88,22 @@ } [aboutURL retain]; - syncDirectoryPath = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncDirectoryPath"]; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + NSString *syncDirectoryPath = [userDefaults stringForKey:@"pithosSyncDirectoryPath"]; if (!syncDirectoryPath || ![syncDirectoryPath length]) { syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"]; } else { + NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL isDirectory; - if ([[NSFileManager defaultManager] fileExistsAtPath:syncDirectoryPath isDirectory:&isDirectory] && !isDirectory) + BOOL fileExists = [fileManager fileExistsAtPath:syncDirectoryPath isDirectory:&isDirectory]; + NSError *error = nil; + if ((fileExists && !isDirectory) || + (!fileExists && (![fileManager createDirectoryAtPath:syncDirectoryPath withIntermediateDirectories:YES attributes:nil error:&error] || error))) { syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"]; + } } - [syncDirectoryPath retain]; + [userDefaults setObject:syncDirectoryPath forKey:@"pithosSyncDirectoryPath"]; + [userDefaults synchronize]; syncContainerName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncContainerName"]; if (!syncContainerName || ![syncContainerName length] || [syncContainerName isEqualToString:@"trash"]) { @@ -115,8 +122,7 @@ andEventID:kAEGetURL]; [self showPithosBrowser:self]; - [self authenticateWithAuthUser:[[userDefaultsController values] valueForKey:@"authUser"] - authToken:[[userDefaultsController values] valueForKey:@"authToken"]]; + [self authenticate]; } // Based on: http://cocoatutorial.grapewave.com/2010/01/creating-a-status-bar-application/ @@ -181,10 +187,12 @@ NSLog(@"query authUser: '%@', authToken: '%@'", authUser, authToken); if ([authUser length] && [authToken length]) { - [[userDefaultsController values] setValue:authUser forKey:@"authUser"]; - [[userDefaultsController values] setValue:authToken forKey:@"authToken"]; - - [self authenticateWithAuthUser:authUser authToken:authToken]; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setObject:authUser forKey:@"authUser"]; + [userDefaults setObject:authToken forKey:@"authToken"]; + [userDefaults synchronize]; + + [self authenticate]; } // XXX else maybe show an error message? } @@ -217,7 +225,11 @@ #pragma mark - #pragma Authentication -- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken { +- (void)authenticate { + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + NSString *authUser = [userDefaults stringForKey:@"authUser"]; + NSString *authToken = [userDefaults stringForKey:@"authToken"]; + NSString *syncDirectoryPath = [userDefaults stringForKey:@"pithosSyncDirectoryPath"]; NSLog(@"Authentication - storageURLPrefix:%@, authUser:%@, authToken:%@", storageURLPrefix, authUser, authToken); if ([authUser length] && [authToken length] && (![[ASIPithosRequest authUser] isEqualToString:authUser] || ![[ASIPithosRequest authToken] isEqualToString:authToken])) { @@ -233,12 +245,15 @@ [self startSyncWithDirectoryPath:syncDirectoryPath containerName:syncContainerName]; [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAuthenticationCredentialsUpdated" object:self]; + return; } + if (![pithosSyncDaemon.directoryPath isEqualToString:syncDirectoryPath]) + [self startSyncWithDirectoryPath:syncDirectoryPath containerName:syncContainerName]; } - (void)startSyncWithDirectoryPath:(NSString *)directoryPath containerName:(NSString *)containerName { - self.pithosSyncDaemon = [[[PithosSyncDaemon alloc] initWithDirectoryPath:syncDirectoryPath - containerName:syncContainerName + self.pithosSyncDaemon = [[[PithosSyncDaemon alloc] initWithDirectoryPath:directoryPath + containerName:containerName timeInterval:syncTimeInterval] autorelease]; } -- 1.7.10.4