From 589a14ca2a08aa5dcde3754f249704598f4272ee Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Sun, 14 Aug 2011 20:20:00 +0300 Subject: [PATCH] Created status bar icon with menu. Initial implementation of preferences window. Moved authentication to app delegate and preferences. --- pithos-macos.xcodeproj/project.pbxproj | 10 + pithos-macos/PithosBrowserController.h | 16 - pithos-macos/PithosBrowserController.m | 91 +-- pithos-macos/PithosBrowserController.xib | 683 +---------------- pithos-macos/PithosPreferencesController.h | 53 ++ pithos-macos/PithosPreferencesController.m | 116 +++ pithos-macos/PithosPreferencesController.xib | 1012 ++++++++++++++++++++++++++ pithos-macos/en.lproj/MainMenu.xib | 569 +++++++-------- pithos-macos/pithos_macosAppDelegate.h | 17 +- pithos-macos/pithos_macosAppDelegate.m | 71 +- 10 files changed, 1558 insertions(+), 1080 deletions(-) create mode 100644 pithos-macos/PithosPreferencesController.h create mode 100644 pithos-macos/PithosPreferencesController.m create mode 100644 pithos-macos/PithosPreferencesController.xib diff --git a/pithos-macos.xcodeproj/project.pbxproj b/pithos-macos.xcodeproj/project.pbxproj index 5980bf2..829205d 100644 --- a/pithos-macos.xcodeproj/project.pbxproj +++ b/pithos-macos.xcodeproj/project.pbxproj @@ -42,6 +42,8 @@ 611FFCB313EBF40900E43E18 /* ImageAndTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 611FFCB213EBF40900E43E18 /* ImageAndTextCell.m */; }; 6121250913F033F500063041 /* PithosBrowserPreviewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6121250813F033F400063041 /* PithosBrowserPreviewController.xib */; }; 6139837113EFEECC004CE444 /* FileSystemBrowserCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6139837013EFEECC004CE444 /* FileSystemBrowserCell.m */; }; + 619B85D513F8077800C9371F /* PithosPreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 619B85D313F8077100C9371F /* PithosPreferencesController.m */; }; + 619B85D613F8077800C9371F /* PithosPreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 619B85D413F8077300C9371F /* PithosPreferencesController.xib */; }; 61E99D9413EC348500E48DA5 /* 145-persondot.png in Resources */ = {isa = PBXBuildFile; fileRef = 61E99D9313EC348500E48DA5 /* 145-persondot.png */; }; /* End PBXBuildFile section */ @@ -115,6 +117,9 @@ 6121250813F033F400063041 /* PithosBrowserPreviewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PithosBrowserPreviewController.xib; sourceTree = ""; }; 6139836F13EFEECC004CE444 /* FileSystemBrowserCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileSystemBrowserCell.h; path = "pithos-macos/FileSystemBrowserCell.h"; sourceTree = ""; }; 6139837013EFEECC004CE444 /* FileSystemBrowserCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileSystemBrowserCell.m; path = "pithos-macos/FileSystemBrowserCell.m"; sourceTree = ""; }; + 619B85D213F8076F00C9371F /* PithosPreferencesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PithosPreferencesController.h; sourceTree = ""; }; + 619B85D313F8077100C9371F /* PithosPreferencesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PithosPreferencesController.m; sourceTree = ""; }; + 619B85D413F8077300C9371F /* PithosPreferencesController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PithosPreferencesController.xib; sourceTree = ""; }; 61E99D9313EC348500E48DA5 /* 145-persondot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "145-persondot.png"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -185,6 +190,9 @@ 610DD34D13E6BEF400ED982F /* PithosBrowserController.m */, 610DD34F13E6C00E00ED982F /* PithosBrowserController.xib */, 6121250813F033F400063041 /* PithosBrowserPreviewController.xib */, + 619B85D213F8076F00C9371F /* PithosPreferencesController.h */, + 619B85D313F8077100C9371F /* PithosPreferencesController.m */, + 619B85D413F8077300C9371F /* PithosPreferencesController.xib */, 610DD35713E6C3D100ED982F /* PithosNode.h */, 610DD35813E6C3D100ED982F /* PithosNode.m */, 610DD36213E6E2E400ED982F /* PithosAccountNode.h */, @@ -340,6 +348,7 @@ 610DD49D13EAE03400ED982F /* container.png in Resources */, 61E99D9413EC348500E48DA5 /* 145-persondot.png in Resources */, 6121250913F033F500063041 /* PithosBrowserPreviewController.xib in Resources */, + 619B85D613F8077800C9371F /* PithosPreferencesController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -374,6 +383,7 @@ 611FFCAF13EBF0B900E43E18 /* PithosEmptyNode.m in Sources */, 611FFCB313EBF40900E43E18 /* ImageAndTextCell.m in Sources */, 6139837113EFEECC004CE444 /* FileSystemBrowserCell.m in Sources */, + 619B85D513F8077800C9371F /* PithosPreferencesController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/pithos-macos/PithosBrowserController.h b/pithos-macos/PithosBrowserController.h index 38e6ec1..0ff6617 100644 --- a/pithos-macos/PithosBrowserController.h +++ b/pithos-macos/PithosBrowserController.h @@ -46,28 +46,12 @@ NSViewController *sharedPreviewController; } -@property (nonatomic, retain) IBOutlet NSUserDefaultsController *userDefaultsController; - @property (nonatomic, retain) NSMutableArray *outlineViewDataSourceArray; @property (nonatomic, retain) IBOutlet NSSplitView *splitView; @property (nonatomic, retain) IBOutlet NSOutlineView *outlineView; @property (nonatomic, retain) IBOutlet NSBrowser *browser; -@property (nonatomic, retain) IBOutlet NSPanel *authenticationPanel; -@property (nonatomic, retain) IBOutlet NSTextField *authenticationUserTextField; -@property (nonatomic, retain) IBOutlet NSTextField *authenticationTokenTextField; -@property (nonatomic, retain) IBOutlet NSButton *authenticationRenewCheckBox; -@property (nonatomic, retain) IBOutlet NSButton *authenticationCancelPushButton; -@property (nonatomic, retain) IBOutlet NSButton *authenticationManualPushButton; -@property (nonatomic, retain) IBOutlet NSButton *authenticationLoginPushButton; - - (IBAction)refresh:(id)sender; -- (void)authenticateFromURLWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken; -- (IBAction)authenticationSelect:(id)sender; -- (IBAction)authenticationLogin:(id)sender; -- (IBAction)authenticationCancel:(id)sender; -- (IBAction)authenticationManual:(id)sender; - @end diff --git a/pithos-macos/PithosBrowserController.m b/pithos-macos/PithosBrowserController.m index d76e31f..b79e3c4 100644 --- a/pithos-macos/PithosBrowserController.m +++ b/pithos-macos/PithosBrowserController.m @@ -1,4 +1,4 @@ - // +// // PithosBrowserController.m // pithos-macos // @@ -90,14 +90,11 @@ @end @interface PithosBrowserController (Private) {} -- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken; - (void)resetContainers; @end @implementation PithosBrowserController -@synthesize userDefaultsController, outlineViewDataSourceArray, splitView, outlineView, browser; -@synthesize authenticationPanel, authenticationUserTextField, authenticationTokenTextField, authenticationRenewCheckBox, - authenticationCancelPushButton, authenticationManualPushButton, authenticationLoginPushButton; +@synthesize outlineViewDataSourceArray, splitView, outlineView, browser; #pragma mark - #pragma Object Lifecycle @@ -111,17 +108,9 @@ [sharedPreviewController release]; [outlineViewDataSourceArray release]; [rootNode release]; - [authenticationLoginPushButton release]; - [authenticationManualPushButton release]; - [authenticationCancelPushButton release]; - [authenticationRenewCheckBox release]; - [authenticationTokenTextField release]; - [authenticationUserTextField release]; - [authenticationPanel release]; [browser release]; [splitView release]; [outlineView release]; - [userDefaultsController release]; [super dealloc]; } @@ -174,8 +163,6 @@ } - (void)windowDidLoad { -// [userDefaultsController setAppliesImmediately:NO]; - [[[outlineView tableColumns] objectAtIndex:0] setDataCell:[[[PithosOutlineViewCell alloc] init] autorelease]]; // Register for updates @@ -187,8 +174,10 @@ selector:@selector(pithosNodeChildrenUpdated:) name:@"PithosSubdirNodeChildrenUpdated" object:nil]; - - [self authenticateWithAuthUser:[authenticationUserTextField stringValue] authToken:[authenticationTokenTextField stringValue]]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(resetContainers) + name:@"PithosAuthenticationCredentialsUpdated" + object:nil]; } #pragma mark - @@ -221,74 +210,6 @@ } #pragma mark - -#pragma Authentication - -- (void)authenticateFromURLWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken { - if ([authUser length] && [authToken length]) { - [authenticationUserTextField setStringValue:authUser]; - [authenticationTokenTextField setStringValue:authToken]; - [userDefaultsController save:self]; - [self authenticateWithAuthUser:authUser authToken:authToken]; - } - // XXX else maybe an error message? -} - -- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken { - // XXX hardcoded for now - NSString *storageURLPrefix = @"https://pithos.dev.grnet.gr/v1/"; - - NSLog(@"Authentication - storageURLPrefix:%@, authUser:%@, authToken:%@", storageURLPrefix, authUser, authToken); - if ([authUser length] && [authToken length]) { - [ASIPithosRequest setStorageURL:[storageURLPrefix stringByAppendingString:[authUser stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; - [ASIPithosRequest setAuthToken:authToken]; - [self resetContainers]; - } else { - [self authenticationSelect:nil]; - } -} - -- (IBAction)authenticationSelect:(id)sender { - [self.window makeFirstResponder:nil]; - [NSApp beginSheet:authenticationPanel - modalForWindow:self.window - modalDelegate:self - didEndSelector:NULL - contextInfo:nil]; -} - -- (IBAction)authenticationLogin:(id)sender { - [NSApp endSheet:authenticationPanel]; - [authenticationPanel orderOut:self]; - // XXX hardcoded for now - NSProcessInfo *processInfo = [NSProcessInfo processInfo]; - NSString *loginURL = [NSString stringWithFormat:@"https://pithos.dev.grnet.gr/login?next=pithos://%@_%d", - [processInfo processName], [processInfo processIdentifier]]; - if ([authenticationRenewCheckBox state] == NSOnState) - 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 - // XXX maybe don't remove the Panel, and let the handler do it -} - -- (IBAction)authenticationCancel:(id)sender { - [NSApp endSheet:authenticationPanel]; - [authenticationPanel orderOut:self]; - [userDefaultsController revert:sender]; -} - -- (IBAction)authenticationManual:(id)sender { - [NSApp endSheet:authenticationPanel]; - [authenticationPanel orderOut:self]; - [userDefaultsController save:sender]; - // Because of delayed saves of the userDefaultsController, we use the TextField values directly, instead of - //NSString *authUser = [[userDefaultsController values] valueForKey:@"authUser"]; - //NSString *authToken = [[userDefaultsController values] valueForKey:@"authToken"]; - [self authenticateWithAuthUser:[authenticationUserTextField stringValue] authToken:[authenticationTokenTextField stringValue]]; -} - -#pragma mark - #pragma NSBrowserDelegate - (id)rootItemForBrowser:(NSBrowser *)browser { diff --git a/pithos-macos/PithosBrowserController.xib b/pithos-macos/PithosBrowserController.xib index 7477f57..5c7ed16 100644 --- a/pithos-macos/PithosBrowserController.xib +++ b/pithos-macos/PithosBrowserController.xib @@ -18,7 +18,6 @@ NSCustomObject NSSplitView NSCustomView - NSTextField NSToolbarSeparatorItem NSWindowTemplate NSTextFieldCell @@ -95,9 +94,10 @@ Authorization - + 268 {{23, 14}, {36, 25}} + YES 67239424 @@ -140,9 +140,10 @@ Refresh - + 268 {{6, 14}, {36, 25}} + YES 67239424 @@ -291,11 +292,10 @@ - + YES - YES @@ -379,12 +379,12 @@ 6 System controlBackgroundColor - + 3 MC42NjY2NjY2NjY3AA - + 6 System controlTextColor @@ -538,235 +538,6 @@ YES - - 73 - 2 - {{169, 105}, {320, 135}} - -1267203072 - Authentication - NSPanel - - {320, 135} - - - 256 - - YES - - - 270 - {{62, 95}, {248, 22}} - - - - YES - - -1804468671 - 272630784 - User - - - YES - - 6 - System - textBackgroundColor - - 3 - MQA - - - - 6 - System - textColor - - - - - - - 268 - {{9, 98}, {48, 17}} - - - - YES - - 68288064 - 71304192 - User: - - - - 6 - System - controlColor - - - - - - - - 270 - {{62, 70}, {248, 22}} - - - - YES - - -1804468671 - 272630784 - Token - - - YES - - - - - - - 268 - {{9, 73}, {48, 17}} - - - - YES - - 68288064 - 71304192 - Token: - - - - - - - - - 268 - {{9, 48}, {48, 17}} - - - - YES - - 68288064 - 71304192 - Renew - - - - - - - - - 289 - {{218, 12}, {96, 32}} - - - - YES - - 67239424 - 134217728 - Login - - - -2038284033 - 129 - - DQ - 200 - 25 - - - - - 292 - {{6, 12}, {96, 32}} - - - - YES - - 67239424 - 134217728 - Cancel - - - -2038284033 - 129 - - Gw - 200 - 25 - - - - - 293 - {{112, 12}, {96, 32}} - - - - YES - - 67239424 - 134217728 - Manual - - - -2038284033 - 129 - - Gw - 200 - 25 - - - - - 268 - {{60, 47}, {63, 18}} - - - - YES - - 67239424 - 0 - - - - 1211912703 - 2 - - NSImage - NSSwitch - - - NSSwitch - - - - 200 - 25 - - - - {{7, 11}, {320, 135}} - - - - - {{0, 0}, {1280, 778}} - {320, 157} - {1e+13, 1e+13} - YES @@ -885,134 +656,6 @@ 46 - - - value: values.authToken - - - - - - value: values.authToken - value - values.authToken - 2 - - - 111 - - - - userDefaultsController - - - - 120 - - - - authenticationPanel - - - - 122 - - - - authenticationCancel: - - - - 123 - - - - authenticationSelect: - - - - 125 - - - - value: values.authUser - - - - - - value: values.authUser - value - values.authUser - 2 - - - 128 - - - - authenticationCancelPushButton - - - - 136 - - - - authenticationLoginPushButton - - - - 137 - - - - authenticationManualPushButton - - - - 138 - - - - authenticationRenewCheckBox - - - - 139 - - - - authenticationTokenTextField - - - - 140 - - - - authenticationUserTextField - - - - 141 - - - - authenticationManual: - - - - 142 - - - - authenticationLogin: - - - - 143 - @@ -1200,121 +843,6 @@ - 39 - - - - - 47 - - - YES - - - - - - 48 - - - YES - - - - - - - - - - - - - - 62 - - - YES - - - - - - 63 - - - - - 64 - - - YES - - - - - - 65 - - - - - 83 - - - YES - - - - - - 85 - - - YES - - - - - - 86 - - - - - 88 - - - - - 91 - - - YES - - - - - - 92 - - - - - 93 - - - YES - - - - - - 94 - - - - 113 @@ -1339,46 +867,9 @@ - 129 - - - YES - - - - - - 130 - - - - - 131 - - - YES - - - - - - 132 - - - - - 133 - - - YES - - - - - - 134 - - + 39 + + @@ -1397,13 +888,7 @@ 11.IBPluginDependency 114.IBPluginDependency 115.IBPluginDependency - 129.IBPluginDependency 13.IBPluginDependency - 130.IBPluginDependency - 131.IBPluginDependency - 132.IBPluginDependency - 133.IBPluginDependency - 134.IBPluginDependency 14.IBPluginDependency 15.IBPluginDependency 18.IBPluginDependency @@ -1418,22 +903,7 @@ 30.IBPluginDependency 31.IBPluginDependency 38.IBPluginDependency - 47.IBPluginDependency - 47.NSWindowTemplate.visibleAtLaunch - 48.IBPluginDependency - 62.IBPluginDependency - 63.IBPluginDependency - 64.IBPluginDependency - 65.IBPluginDependency 8.IBPluginDependency - 83.IBPluginDependency - 85.IBPluginDependency - 86.IBPluginDependency - 88.IBPluginDependency - 91.IBPluginDependency - 92.IBPluginDependency - 93.IBPluginDependency - 94.IBPluginDependency YES @@ -1464,27 +934,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 - 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 - 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 - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin @@ -1508,136 +957,42 @@ PithosBrowserController NSWindowController - YES - - YES - authenticationCancel: - authenticationLogin: - authenticationManual: - authenticationSelect: - refresh: - - - YES - id - id - id - id - id - + refresh: + id - YES - - YES - authenticationCancel: - authenticationLogin: - authenticationManual: - authenticationSelect: - refresh: - - - YES - - authenticationCancel: - id - - - authenticationLogin: - id - - - authenticationManual: - id - - - authenticationSelect: - id - - - refresh: - id - + refresh: + + refresh: + id YES YES - authenticationCancelPushButton - authenticationLoginPushButton - authenticationManualPushButton - authenticationPanel - authenticationRenewCheckBox - authenticationTokenTextField - authenticationUserTextField browser outlineView splitView - userDefaultsController YES - NSButton - NSButton - NSButton - NSPanel - NSButton - NSTextField - NSTextField NSBrowser NSOutlineView NSSplitView - NSUserDefaultsController YES YES - authenticationCancelPushButton - authenticationLoginPushButton - authenticationManualPushButton - authenticationPanel - authenticationRenewCheckBox - authenticationTokenTextField - authenticationUserTextField browser outlineView splitView - userDefaultsController YES - authenticationCancelPushButton - NSButton - - - authenticationLoginPushButton - NSButton - - - authenticationManualPushButton - NSButton - - - authenticationPanel - NSPanel - - - authenticationRenewCheckBox - NSButton - - - authenticationTokenTextField - NSTextField - - - authenticationUserTextField - NSTextField - - browser NSBrowser @@ -1649,10 +1004,6 @@ splitView NSSplitView - - userDefaultsController - NSUserDefaultsController - @@ -1678,7 +1029,6 @@ 145-persondot NSMenuCheckmark NSMenuMixedState - NSSwitch NSToolbarCustomizeToolbarItemImage @@ -1687,7 +1037,6 @@ {24, 26} {9, 8} {7, 2} - {15, 15} {32, 32} diff --git a/pithos-macos/PithosPreferencesController.h b/pithos-macos/PithosPreferencesController.h new file mode 100644 index 0000000..33f1181 --- /dev/null +++ b/pithos-macos/PithosPreferencesController.h @@ -0,0 +1,53 @@ +// +// PithosPreferencesController.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. + +#import + +@interface PithosPreferencesController : NSWindowController + +@property (nonatomic, retain) IBOutlet NSUserDefaultsController *userDefaultsController; + +@property (nonatomic, retain) IBOutlet NSTextField *authenticationUserTextField; +@property (nonatomic, retain) IBOutlet NSTextField *authenticationTokenTextField; +@property (nonatomic, retain) IBOutlet NSButton *authenticationRenewCheckBox; + +- (IBAction)toolbarItemSelected:(id)sender; + +- (IBAction)authenticationLogin:(id)sender; +- (IBAction)authenticationManual:(id)sender; + +@end diff --git a/pithos-macos/PithosPreferencesController.m b/pithos-macos/PithosPreferencesController.m new file mode 100644 index 0000000..4d4c1f7 --- /dev/null +++ b/pithos-macos/PithosPreferencesController.m @@ -0,0 +1,116 @@ +// +// PithosPreferencesController.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 "PithosPreferencesController.h" +#import "pithos_macosAppDelegate.h" + +@implementation PithosPreferencesController +@synthesize userDefaultsController; +@synthesize authenticationUserTextField, authenticationTokenTextField, authenticationRenewCheckBox; + +- (id)init { + return [super initWithWindowNibName:@"PithosPreferencesController"]; +} + +- (void)dealloc { + [authenticationRenewCheckBox release]; + [authenticationTokenTextField release]; + [authenticationUserTextField release]; + [userDefaultsController release]; + [super dealloc]; +} + +- (void)windowDidLoad { + [super windowDidLoad]; + + NSWindow *window = [self window]; + [window setHidesOnDeactivate:NO]; + [window setExcludedFromWindowsMenu:YES]; + + // Select the first tab when the window is loaded for the first time. + [[window valueForKeyPath:@"toolbar"] setSelectedItemIdentifier:@"0"]; + +// // Monitor changes. +// [userDefaultsController addObserver:self +// forKeyPath:@"values.authUser" +// options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) +// context:NULL]; +// [userDefaultsController addObserver:self +// forKeyPath:@"values.authToken" +// options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) +// context:NULL]; +} + +// We do this to catch the case where the user enters a value into one of +// the text fields but closes the window without hitting enter or tab. +// TODO: Does not seem to work. +- (BOOL)windowShouldClose:(NSWindow *)window { + return [window makeFirstResponder:nil]; +} + +- (IBAction)toolbarItemSelected:(id)sender { +} + +//- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { +// NSLog(@"observeValueForKeyPath: %@ %@", keyPath, [userDefaultsController valueForKeyPath:keyPath]); +//} + +#pragma mark - +#pragma Authentication + +- (IBAction)authenticationLogin:(id)sender { + // XXX hardcoded for now + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + NSString *loginURL = [NSString stringWithFormat:@"https://pithos.dev.grnet.gr/login?next=pithos://%@_%d", + [processInfo processName], [processInfo processIdentifier]]; + if ([authenticationRenewCheckBox state] == NSOnState) + 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 +} + +- (IBAction)authenticationManual:(id)sender { + [userDefaultsController save:sender]; + // Because of delayed saves of the userDefaultsController, we use the TextField values directly, instead of + //NSString *authUser = [[userDefaultsController values] valueForKey:@"authUser"]; + //NSString *authToken = [[userDefaultsController values] valueForKey:@"authToken"]; + [(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] authenticateWithAuthUser:[authenticationUserTextField stringValue] authToken:[authenticationTokenTextField stringValue]]; +} + +@end diff --git a/pithos-macos/PithosPreferencesController.xib b/pithos-macos/PithosPreferencesController.xib new file mode 100644 index 0000000..bd03e83 --- /dev/null +++ b/pithos-macos/PithosPreferencesController.xib @@ -0,0 +1,1012 @@ + + + + 1070 + 11A511 + 1617 + 1138 + 566.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 1617 + + + YES + NSUserDefaultsController + NSToolbar + NSButton + NSButtonCell + NSTextFieldCell + NSTabView + NSCustomObject + NSTabViewItem + NSView + NSWindowTemplate + NSTextField + NSToolbarItem + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + + + YES + + PithosPreferencesController + + + FirstResponder + + + NSApplication + + + 3 + 2 + {{403, 468}, {338, 135}} + 1954022400 + Pithos Preferences + NSWindow + + + E03AA9E7-49CC-4B42-AFD8-98034E482341 + + + YES + YES + NO + NO + 1 + 1 + + YES + + YES + 16C40F9F-7895-4E0A-9FAE-C1854DDC3902 + 39E17C0B-AF3B-4277-B1E2-E65416307BF2 + + + YES + + + 16C40F9F-7895-4E0A-9FAE-C1854DDC3902 + + General + General + + + + NSImage + NSPreferencesGeneral + + + + {0, 0} + {0, 0} + YES + YES + -1 + YES + 0 + + + + 39E17C0B-AF3B-4277-B1E2-E65416307BF2 + + Authentication + Authentication + + + + NSImage + NSUser + + + + {0, 0} + {0, 0} + YES + YES + -1 + YES + 0 + + + + + YES + + + + + YES + + + + + + + {338, 135} + {338, 135} + + + 274 + + YES + + + 12 + {338, 135} + + + + YES + + 0 + + + 274 + + YES + + + 268 + {{17, 96}, {48, 17}} + + + YES + + 68288064 + 71304192 + Folder: + + LucidaGrande + 13 + 1044 + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + + 270 + {{70, 93}, {248, 22}} + + + YES + + -1804468671 + 272630784 + Folder + + + YES + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + textColor + + + + + + {338, 135} + + + General + + + + + 1 + + + 274 + + YES + + + 270 + {{70, 93}, {248, 22}} + + + YES + + -1804468671 + 272630784 + User + + + YES + + + + + + + 268 + {{17, 95}, {48, 17}} + + + YES + + 68288064 + 71304192 + User: + + + + + + + + + 270 + {{70, 68}, {248, 22}} + + + YES + + -1804468671 + 272630784 + Token + + + YES + + + + + + + 268 + {{17, 71}, {48, 17}} + + + YES + + 68288064 + 71304192 + Token: + + + + + + + + + 289 + {{228, 12}, {96, 32}} + + + YES + + 67239424 + 134217728 + Login + + + -2038284033 + 129 + + DQ + 200 + 25 + + + + + 293 + {{121, 12}, {96, 32}} + + + YES + + 67239424 + 134217728 + Manual + + + -2038284033 + 129 + + Gw + 200 + 25 + + + + + 268 + {{68, 46}, {63, 18}} + + + YES + + 67239424 + 0 + Renew + + + 1211912703 + 2 + + NSImage + NSSwitch + + + NSSwitch + + + + 200 + 25 + + + + {338, 135} + + + + Authentication + + + + + + + 6 + YES + YES + + YES + + + + + {338, 135} + + + + {{0, 0}, {1680, 1028}} + {338, 213} + {338, 213} + YES + + + YES + + + + + YES + + + authenticationRenewCheckBox + + + + 192 + + + + authenticationTokenTextField + + + + 193 + + + + authenticationUserTextField + + + + 194 + + + + authenticationLogin: + + + + 196 + + + + authenticationManual: + + + + 197 + + + + window + + + + 198 + + + + value: values.authUser + + + + + + value: values.authUser + value + values.authUser + 2 + + + 204 + + + + value: values.authToken + + + + + + value: values.authToken + value + values.authToken + 2 + + + 206 + + + + selectedIndex: window.toolbar.selectedItemIdentifier + + + + + + selectedIndex: window.toolbar.selectedItemIdentifier + selectedIndex + window.toolbar.selectedItemIdentifier + 2 + + + 208 + + + + toolbarItemSelected: + + + + 209 + + + + toolbarItemSelected: + + + + 210 + + + + userDefaultsController + + + + 211 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 3 + + + YES + + + + + + + 4 + + + YES + + + + + + + 5 + + + YES + + + + + + 6 + + + YES + + + + + + + 10 + + + YES + + + + + + 11 + + + YES + + + + + + 12 + + + YES + + + + + + + 63 + + + YES + + + + + + + + + + + + 167 + + + + + 168 + + + + + 169 + + + + + 179 + + + YES + + + + + + 180 + + + YES + + + + + + 178 + + + YES + + + + + + 177 + + + YES + + + + + + 173 + + + YES + + + + + + 172 + + + YES + + + + + + 175 + + + YES + + + + + + 186 + + + + + 189 + + + + + 188 + + + + + 184 + + + + + 183 + + + + + 181 + + + + + 182 + + + + + 199 + + + YES + + + + + + 200 + + + YES + + + + + + 201 + + + + + 202 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 10.IBPluginDependency + 11.IBPluginDependency + 12.IBPluginDependency + 167.IBPluginDependency + 167.designableToolbarItemIdentifier + 167.toolbarItem.selectable + 168.IBPluginDependency + 168.designableToolbarItemIdentifier + 168.toolbarItem.selectable + 169.IBPluginDependency + 172.IBPluginDependency + 173.IBPluginDependency + 175.IBPluginDependency + 177.IBPluginDependency + 178.IBPluginDependency + 179.IBPluginDependency + 180.IBPluginDependency + 181.IBPluginDependency + 182.IBPluginDependency + 183.IBPluginDependency + 184.IBPluginDependency + 186.IBPluginDependency + 188.IBPluginDependency + 189.IBPluginDependency + 199.IBPluginDependency + 200.IBPluginDependency + 201.IBPluginDependency + 202.IBPluginDependency + 3.IBPluginDependency + 3.IBWindowTemplateEditedContentRect + 3.NSWindowTemplate.visibleAtLaunch + 4.IBPluginDependency + 5.IBPluginDependency + 6.IBPluginDependency + 63.IBPluginDependency + + + YES + 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 + 1 + + com.apple.InterfaceBuilder.CocoaPlugin + 0 + + 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 + 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 + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{438, 560}, {520, 345}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 211 + + + + YES + + PithosPreferencesController + NSWindowController + + YES + + YES + authenticationLogin: + authenticationManual: + toolbarItemSelected: + + + YES + id + id + id + + + + YES + + YES + authenticationLogin: + authenticationManual: + toolbarItemSelected: + + + YES + + authenticationLogin: + id + + + authenticationManual: + id + + + toolbarItemSelected: + id + + + + + YES + + YES + authenticationRenewCheckBox + authenticationTokenTextField + authenticationUserTextField + userDefaultsController + + + YES + NSButton + NSTextField + NSTextField + NSUserDefaultsController + + + + YES + + YES + authenticationRenewCheckBox + authenticationTokenTextField + authenticationUserTextField + userDefaultsController + + + YES + + authenticationRenewCheckBox + NSButton + + + authenticationTokenTextField + NSTextField + + + authenticationUserTextField + NSTextField + + + userDefaultsController + NSUserDefaultsController + + + + + IBProjectSource + ./Classes/PithosPreferencesController.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + YES + + YES + NSPreferencesGeneral + NSSwitch + NSUser + + + YES + {32, 32} + {15, 15} + {32, 32} + + + + diff --git a/pithos-macos/en.lproj/MainMenu.xib b/pithos-macos/en.lproj/MainMenu.xib index 60f03ba..0a8b869 100644 --- a/pithos-macos/en.lproj/MainMenu.xib +++ b/pithos-macos/en.lproj/MainMenu.xib @@ -12,6 +12,7 @@ YES + NSUserDefaultsController NSMenu NSMenuItem NSCustomObject @@ -1323,6 +1324,106 @@ PithosBrowserController + + PithosPreferencesController + + + Status Menu + + YES + + + YES + Using 300MB of 50GB + + 2147483647 + + + + + + Browse Pithos + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + YES + Last Sync: Today, 3:30PM + + 2147483647 + + + + + + Sync Now + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + About Pithos + + 2147483647 + + + + + + Preferences... + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Quit Pithos + + 2147483647 + + + + + + + YES + @@ -2007,6 +2108,62 @@ 534 + + + statusMenu + + + + 549 + + + + terminate: + + + + 552 + + + + showPithosBrowser: + + + + 553 + + + + showPithosPreferences: + + + + 554 + + + + pithosPreferencesController + + + + 555 + + + + aboutPithos: + + + + 556 + + + + userDefaultsController + + + + 558 + @@ -3040,6 +3197,85 @@ PithosBrowserController + + 535 + + + YES + + + + + + + + + + + + + + + 536 + + + + + 537 + + + + + 538 + + + + + 539 + + + + + 540 + + + + + 541 + + + + + 542 + + + + + 543 + + + + + 544 + + + + + 545 + + + + + 546 + + + PithosPreferencesController + + + 557 + + + @@ -3050,138 +3286,65 @@ -2.IBPluginDependency -3.IBPluginDependency 112.IBPluginDependency - 112.ImportedFromIB2 124.IBPluginDependency - 124.ImportedFromIB2 125.IBPluginDependency - 125.ImportedFromIB2 - 125.editorWindowContentRectSynchronizationRect 126.IBPluginDependency - 126.ImportedFromIB2 129.IBPluginDependency - 129.ImportedFromIB2 130.IBPluginDependency - 130.ImportedFromIB2 - 130.editorWindowContentRectSynchronizationRect 131.IBPluginDependency - 131.ImportedFromIB2 134.IBPluginDependency - 134.ImportedFromIB2 136.IBPluginDependency - 136.ImportedFromIB2 143.IBPluginDependency - 143.ImportedFromIB2 144.IBPluginDependency - 144.ImportedFromIB2 145.IBPluginDependency - 145.ImportedFromIB2 149.IBPluginDependency - 149.ImportedFromIB2 150.IBPluginDependency - 150.ImportedFromIB2 19.IBPluginDependency - 19.ImportedFromIB2 195.IBPluginDependency - 195.ImportedFromIB2 196.IBPluginDependency - 196.ImportedFromIB2 197.IBPluginDependency - 197.ImportedFromIB2 198.IBPluginDependency - 198.ImportedFromIB2 199.IBPluginDependency - 199.ImportedFromIB2 - 200.IBEditorWindowLastContentRect 200.IBPluginDependency - 200.ImportedFromIB2 - 200.editorWindowContentRectSynchronizationRect 201.IBPluginDependency - 201.ImportedFromIB2 202.IBPluginDependency - 202.ImportedFromIB2 203.IBPluginDependency - 203.ImportedFromIB2 204.IBPluginDependency - 204.ImportedFromIB2 - 205.IBEditorWindowLastContentRect 205.IBPluginDependency - 205.ImportedFromIB2 - 205.editorWindowContentRectSynchronizationRect 206.IBPluginDependency - 206.ImportedFromIB2 207.IBPluginDependency - 207.ImportedFromIB2 208.IBPluginDependency - 208.ImportedFromIB2 209.IBPluginDependency - 209.ImportedFromIB2 210.IBPluginDependency - 210.ImportedFromIB2 211.IBPluginDependency - 211.ImportedFromIB2 212.IBPluginDependency - 212.ImportedFromIB2 - 212.editorWindowContentRectSynchronizationRect 213.IBPluginDependency - 213.ImportedFromIB2 214.IBPluginDependency - 214.ImportedFromIB2 215.IBPluginDependency - 215.ImportedFromIB2 216.IBPluginDependency - 216.ImportedFromIB2 217.IBPluginDependency - 217.ImportedFromIB2 218.IBPluginDependency - 218.ImportedFromIB2 219.IBPluginDependency - 219.ImportedFromIB2 - 220.IBEditorWindowLastContentRect 220.IBPluginDependency - 220.ImportedFromIB2 - 220.editorWindowContentRectSynchronizationRect 221.IBPluginDependency - 221.ImportedFromIB2 23.IBPluginDependency - 23.ImportedFromIB2 236.IBPluginDependency - 236.ImportedFromIB2 239.IBPluginDependency - 239.ImportedFromIB2 - 24.IBEditorWindowLastContentRect 24.IBPluginDependency - 24.ImportedFromIB2 - 24.editorWindowContentRectSynchronizationRect - 29.IBEditorWindowLastContentRect 29.IBPluginDependency - 29.ImportedFromIB2 - 29.WindowOrigin - 29.editorWindowContentRectSynchronizationRect 295.IBPluginDependency - 296.IBEditorWindowLastContentRect 296.IBPluginDependency - 296.editorWindowContentRectSynchronizationRect 297.IBPluginDependency 298.IBPluginDependency 346.IBPluginDependency - 346.ImportedFromIB2 348.IBPluginDependency - 348.ImportedFromIB2 - 349.IBEditorWindowLastContentRect 349.IBPluginDependency - 349.ImportedFromIB2 - 349.editorWindowContentRectSynchronizationRect 350.IBPluginDependency - 350.ImportedFromIB2 351.IBPluginDependency - 351.ImportedFromIB2 354.IBPluginDependency - 354.ImportedFromIB2 375.IBPluginDependency - 376.IBEditorWindowLastContentRect 376.IBPluginDependency 377.IBPluginDependency - 388.IBEditorWindowLastContentRect 388.IBPluginDependency 389.IBPluginDependency 390.IBPluginDependency @@ -3216,7 +3379,6 @@ 419.IBPluginDependency 420.IBPluginDependency 450.IBPluginDependency - 451.IBEditorWindowLastContentRect 451.IBPluginDependency 452.IBPluginDependency 453.IBPluginDependency @@ -3229,17 +3391,14 @@ 466.IBPluginDependency 485.IBPluginDependency 490.IBPluginDependency - 491.IBEditorWindowLastContentRect 491.IBPluginDependency 492.IBPluginDependency 494.IBPluginDependency 496.IBPluginDependency - 497.IBEditorWindowLastContentRect 497.IBPluginDependency 498.IBPluginDependency 499.IBPluginDependency 5.IBPluginDependency - 5.ImportedFromIB2 500.IBPluginDependency 501.IBPluginDependency 502.IBPluginDependency @@ -3248,7 +3407,6 @@ 505.IBPluginDependency 506.IBPluginDependency 507.IBPluginDependency - 508.IBEditorWindowLastContentRect 508.IBPluginDependency 509.IBPluginDependency 510.IBPluginDependency @@ -3260,40 +3418,34 @@ 516.IBPluginDependency 517.IBPluginDependency 533.IBPluginDependency + 535.IBPluginDependency + 536.IBPluginDependency + 537.IBPluginDependency + 538.IBPluginDependency + 539.IBPluginDependency + 540.IBPluginDependency + 541.IBPluginDependency + 542.IBPluginDependency + 543.IBPluginDependency + 544.IBPluginDependency + 545.IBPluginDependency + 546.IBPluginDependency + 557.IBPluginDependency 56.IBPluginDependency - 56.ImportedFromIB2 - 57.IBEditorWindowLastContentRect 57.IBPluginDependency - 57.ImportedFromIB2 - 57.editorWindowContentRectSynchronizationRect 58.IBPluginDependency - 58.ImportedFromIB2 72.IBPluginDependency - 72.ImportedFromIB2 73.IBPluginDependency - 73.ImportedFromIB2 74.IBPluginDependency - 74.ImportedFromIB2 75.IBPluginDependency - 75.ImportedFromIB2 77.IBPluginDependency - 77.ImportedFromIB2 78.IBPluginDependency - 78.ImportedFromIB2 79.IBPluginDependency - 79.ImportedFromIB2 80.IBPluginDependency - 80.ImportedFromIB2 - 81.IBEditorWindowLastContentRect 81.IBPluginDependency - 81.ImportedFromIB2 - 81.editorWindowContentRectSynchronizationRect 82.IBPluginDependency - 82.ImportedFromIB2 83.IBPluginDependency - 83.ImportedFromIB2 92.IBPluginDependency - 92.ImportedFromIB2 YES @@ -3301,138 +3453,65 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{522, 812}, {146, 23}} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{436, 809}, {64, 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 - 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 - - {{753, 187}, {275, 113}} com.apple.InterfaceBuilder.CocoaPlugin - - {{608, 612}, {275, 83}} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{547, 180}, {254, 283}} com.apple.InterfaceBuilder.CocoaPlugin - - {{187, 434}, {243, 243}} 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 - - {{608, 612}, {167, 43}} 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 - - {{753, 217}, {238, 103}} com.apple.InterfaceBuilder.CocoaPlugin - - {{608, 612}, {241, 103}} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{654, 239}, {194, 73}} com.apple.InterfaceBuilder.CocoaPlugin - - {{525, 802}, {197, 73}} - {{380, 836}, {512, 20}} com.apple.InterfaceBuilder.CocoaPlugin - - {74, 862} - {{6, 978}, {478, 20}} com.apple.InterfaceBuilder.CocoaPlugin - {{604, 269}, {231, 43}} com.apple.InterfaceBuilder.CocoaPlugin - {{475, 832}, {234, 43}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{746, 287}, {220, 133}} com.apple.InterfaceBuilder.CocoaPlugin - - {{608, 612}, {215, 63}} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{591, 420}, {83, 43}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{523, 2}, {178, 283}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3467,7 +3546,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{753, 197}, {170, 63}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3480,17 +3558,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{725, 289}, {246, 23}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{674, 260}, {204, 183}} 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 @@ -3499,7 +3574,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{878, 180}, {164, 173}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3512,39 +3586,33 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - {{286, 129}, {275, 183}} com.apple.InterfaceBuilder.CocoaPlugin - - {{23, 794}, {245, 183}} 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 - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{452, 109}, {196, 203}} com.apple.InterfaceBuilder.CocoaPlugin - - {{145, 474}, {199, 203}} 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 + 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 + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -3559,118 +3627,9 @@ - 534 - - - - 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 - - browser - NSBrowser - - - browser - - browser - NSBrowser - - - - IBProjectSource - ./Classes/PithosBrowserController.h - - - - pithos_macosAppDelegate - NSObject - - pithosBrowserController - PithosBrowserController - - - pithosBrowserController - - pithosBrowserController - PithosBrowserController - - - - IBProjectSource - ./Classes/pithos_macosAppDelegate.h - - - + 558 + 0 IBCocoaFramework diff --git a/pithos-macos/pithos_macosAppDelegate.h b/pithos-macos/pithos_macosAppDelegate.h index 7c23c4a..01c26af 100644 --- a/pithos-macos/pithos_macosAppDelegate.h +++ b/pithos-macos/pithos_macosAppDelegate.h @@ -36,15 +36,24 @@ // or implied, of GRNET S.A. #import - @class PithosBrowserController; +@class PithosPreferencesController; @interface pithos_macosAppDelegate : NSObject { - PithosBrowserController *pithosBrowserController; -} + IBOutlet PithosBrowserController *pithosBrowserController; + IBOutlet PithosPreferencesController *pithosPreferencesController; -@property (assign) IBOutlet PithosBrowserController *pithosBrowserController; + IBOutlet NSMenu *statusMenu; + NSStatusItem *statusItem; + + IBOutlet NSUserDefaultsController *userDefaultsController; +} - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent; +- (IBAction)showPithosBrowser:(id)sender; +- (IBAction)showPithosPreferences:(id)sender; +- (IBAction)aboutPithos:(id)sender; + +- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken; @end diff --git a/pithos-macos/pithos_macosAppDelegate.m b/pithos-macos/pithos_macosAppDelegate.m index 42d731e..e7e1881 100644 --- a/pithos-macos/pithos_macosAppDelegate.m +++ b/pithos-macos/pithos_macosAppDelegate.m @@ -37,16 +37,39 @@ #import "pithos_macosAppDelegate.h" #import "PithosBrowserController.h" +#import "PithosPreferencesController.h" +#import "ASIPithosRequest.h" @implementation pithos_macosAppDelegate -@synthesize pithosBrowserController; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleAppleEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; - [pithosBrowserController showWindow:self]; + //[pithosBrowserController showWindow:self]; + [self showPithosBrowser:self]; + + [self authenticateWithAuthUser:[[userDefaultsController values] valueForKey:@"authUser"] + authToken:[[userDefaultsController values] valueForKey:@"authToken"]]; +} + +// Based on: http://cocoatutorial.grapewave.com/2010/01/creating-a-status-bar-application/ +// and: http://www.cocoadev.com/index.pl?ThumbnailImages +- (void)awakeFromNib { + NSImage *sourceImage = [NSImage imageNamed:NSImageNameFolder]; + + NSImage *smallImage = [[[NSImage alloc] initWithSize:NSMakeSize(18, 18)] autorelease]; + [smallImage lockFocus]; + [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; + [sourceImage setSize:NSMakeSize(18, 18)]; + [sourceImage compositeToPoint:NSZeroPoint operation:NSCompositeCopy]; + [smallImage unlockFocus]; + + statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; + [statusItem setMenu:statusMenu]; + [statusItem setImage:sourceImage]; + [statusItem setHighlightMode:YES]; } - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { @@ -88,10 +111,52 @@ authToken = [[query substringFromIndex:authTokenStartLocation] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } + NSLog(@"query authUser: '%@', authToken: '%@'", authUser, authToken); - [pithosBrowserController authenticateFromURLWithAuthUser:authUser authToken:authToken]; + if ([authUser length] && [authToken length]) { + [[userDefaultsController values] setValue:authUser forKey:@"authUser"]; + [[userDefaultsController values] setValue:authToken forKey:@"authToken"]; + + [self authenticateWithAuthUser:authUser authToken:authToken]; + } + // XXX else maybe show an error message? } // XXX else maybe show an error message? } +#pragma mark - +#pragma Actions + +- (IBAction)showPithosBrowser:(id)sender { + [pithosBrowserController showWindow:sender]; + [[pithosBrowserController window] makeKeyAndOrderFront:sender]; + [NSApp activateIgnoringOtherApps:YES]; +} + +- (IBAction)showPithosPreferences:(id)sender { + [pithosPreferencesController showWindow:sender]; + [[pithosPreferencesController window] makeKeyAndOrderFront:sender]; + [NSApp activateIgnoringOtherApps:YES]; +} + +- (IBAction)aboutPithos:(id)sender { + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://pithos.dev.grnet.gr/docs"]]; +} + +#pragma mark - +#pragma Authentication + +- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken { + // XXX hardcoded for now + NSString *storageURLPrefix = @"https://pithos.dev.grnet.gr/v1/"; + + NSLog(@"Authentication - storageURLPrefix:%@, authUser:%@, authToken:%@", storageURLPrefix, authUser, authToken); + if ([authUser length] && [authToken length]) { + [ASIPithosRequest setStorageURL:[storageURLPrefix stringByAppendingString:[authUser stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [ASIPithosRequest setAuthToken:authToken]; + + [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAuthenticationCredentialsUpdated" object:self]; + } +} + @end -- 1.7.10.4