From: Michael J. Rubinsky Date: Sun, 7 Dec 2008 21:55:02 +0000 (-0500) Subject: Move gallery creation code out of iPhoto's controller and into X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=cb0289820cf599c4379e31548cba15513c2610b6;p=horde.git Move gallery creation code out of iPhoto's controller and into a seperate new gallery controller to make it more portable. --- diff --git a/iPhoto2Ansel/AnselExportController.h b/iPhoto2Ansel/AnselExportController.h index 8dbb5aab4..1cfb926bb 100644 --- a/iPhoto2Ansel/AnselExportController.h +++ b/iPhoto2Ansel/AnselExportController.h @@ -35,11 +35,6 @@ IBOutlet NSProgressIndicator *spinner; IBOutlet NSWindow *newGallerySheet; IBOutlet NSImageView *defaultImageView; - - // New Gallery Panel - IBOutlet NSTextField *galleryNameTextField; - IBOutlet NSTextField *gallerySlugTextField; - IBOutlet NSTextField *galleryDescTextField; // Progress struct (This one is part of the protocol, but we don't use it) ExportPluginProgress progress; @@ -47,10 +42,6 @@ // This is our real progress controller (stolen from Facebook exporter). FBProgressController *progressController; - // New Gallery dialog controller (Can't get this to work with the modal - // iPhoto plugin interface??) - //TURNewGalleryController *newGalleryController; - // Mutex lock (required for the protocol, but not used) NSRecursiveLock *progressLock; @@ -68,9 +59,7 @@ // Actions - (IBAction) doConnect: (id)sender; -- (IBAction) doNewGallery: (id)sender; - (IBAction) showNewGallery: (id)sender; -- (IBAction) cancelNewGallery: (id)sender; // overrides - (void)awakeFromNib; diff --git a/iPhoto2Ansel/AnselExportController.m b/iPhoto2Ansel/AnselExportController.m index feb307901..09fb9af56 100644 --- a/iPhoto2Ansel/AnselExportController.m +++ b/iPhoto2Ansel/AnselExportController.m @@ -8,6 +8,7 @@ #import "TURAnsel.h"; #import "TURAnselGallery.h"; #import "AnselExportController.h"; +#import "TURAnselGalleryPanelController.h"; #import "FBProgressController.h"; #import "ImageResizer.h"; @@ -17,7 +18,6 @@ - (void)privatePerformExport; - (void)runExport; - (void)canExport; -- (void)newGallery; @end @implementation AnselExportController @@ -74,49 +74,28 @@ [pool release]; } - -// Start the process of creating a new gallery. This is called from an action -// from the newGallerySheet NSPanel. -- (void)doNewGallery: (id)sender -{ - [NSApplication detachDrawingThread: @selector(newGallery) - toTarget: self - withObject:nil]; -} - // Put up the newGallerySheet NSPanel - (IBAction)showNewGallery: (id)sender { // Make sure we're not doing this for nothing if ([anselController state] == TURAnselStateConnected) { - - if (!newGallerySheet) { - - [NSBundle loadNibNamed: @"AnselGalleryPanel" - owner: self]; - - [galleryNameTextField setStringValue:@"Untitled"]; - } - - [NSApp beginSheet: newGallerySheet - modalForWindow: [self window] - modalDelegate: nil - didEndSelector: nil - contextInfo: nil]; + TURAnselGalleryPanelController *newGalleryController = [[TURAnselGalleryPanelController alloc] initWithController: anselController]; + [newGalleryController setDelegate: self]; + [newGalleryController showSheetForWindow: [self window]]; } } -- (IBAction)cancelNewGallery: (id)sender -{ - [NSApp endSheet: newGallerySheet]; - [newGallerySheet orderOut: nil]; -} +//- (IBAction)cancelNewGallery: (id)sender +//{ +// [NSApp endSheet: newGallerySheet]; +// [newGallerySheet orderOut: nil]; +//} #pragma mark ExportPluginProtocol // Initialize - (id)initWithExportImageObj:(id )obj { - if(self = [super init]) + if (self = [super init]) { mExportMgr = obj; } @@ -226,52 +205,6 @@ } #pragma mark PrivateAPI - -- (void)newGallery -{ - // Get Gallery Properties from the panel. - NSString *galleryName = [galleryNameTextField stringValue]; - NSString *gallerySlug = [gallerySlugTextField stringValue]; - NSString *galleryDescription = [galleryDescTextField stringValue]; - - if (!galleryName) { - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:@"Gallery names cannot be empty"]; - [alert setAlertStyle: NSCriticalAlertStyle]; - [alert beginSheetModalForWindow: [self window] - modalDelegate: nil - didEndSelector: nil - contextInfo: nil]; - [alert release]; - return; - } - NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: - galleryName, @"name", - gallerySlug, @"slug", - galleryDescription, @"desc", nil]; - - NSDictionary *results = [[anselController createNewGallery: params] retain]; - - [NSApp endSheet: newGallerySheet]; - [newGallerySheet orderOut: nil]; - - if ([anselController state] != TURAnselStateError) { - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText: @"Gallery successfully created."]; - [alert beginSheetModalForWindow: [self window] - modalDelegate: nil - didEndSelector: nil - contextInfo: nil]; - - // Reload the NSComboBox and autoselect the last item. - [galleryCombo reloadData]; - [galleryCombo selectItemAtIndex: [galleryCombo numberOfItems] - 1]; - [alert release]; - } - - [results release]; -} - // See if we have everything we need to export... - (void)canExport { @@ -485,4 +418,12 @@ [theImage release]; [self canExport]; } + +- (void)TURAnselGalleryPanelDidAddGallery +{ + NSLog(@"Before reload"); + // Reload the NSComboBox and autoselect the last item. + [galleryCombo reloadData]; + [galleryCombo selectItemAtIndex: [galleryCombo numberOfItems] - 1]; +} @end \ No newline at end of file diff --git a/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/designable.nib b/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/designable.nib index 52a258676..aab13b850 100644 --- a/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/designable.nib +++ b/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/designable.nib @@ -8,7 +8,7 @@ 352.00 YES - + YES @@ -17,7 +17,7 @@ YES - AnselExportController + TURAnselGalleryPanelController FirstResponder @@ -331,27 +331,19 @@ YES - gallerySlugTextField - - - - 38 - - - - galleryParentCombo + newGallerySheet - + - 39 + 43 - - galleryNameTextField + + doNewGallery: - + - 40 + 48 @@ -359,31 +351,31 @@ - 41 + 49 - newGallerySheet + galleryNameTextField - + - 43 + 50 - - doNewGallery: + + gallerySlugTextField - + - 46 + 51 cancelNewGallery: - + - 47 + 53 @@ -673,99 +665,75 @@ - 47 + 53 YES - AnselExportController + NSObject + + IBProjectSource + TURAnsel.h + + + + NSObject + + IBProjectSource + TURAnselGallery.h + + + + NSObject + + IBProjectSource + TURAnselGalleryPanelController.h + + + + NSObject + + IBProjectSource + xmlrpc-1.5.1/XMLRPCConnection.h + + + + TURAnselGalleryPanelController NSObject YES YES cancelNewGallery: - doConnect: doNewGallery: - showNewGallery: YES id id - id - id YES YES - anselHostURL - beginButton - connectedLabel - firstView - galleryCombo + delegate galleryDescTextField galleryNameTextField gallerySlugTextField - mExportMgr - mQualityPopUp - mSettingsBox - mSizePopUp - newGalleryButton newGallerySheet - password - spinner - username YES - NSTextField - NSButton - NSTextField - NSControl - NSComboBox - NSTextField + id NSTextField NSTextField - id - NSPopUpButton - NSBox - NSPopUpButton - NSButton - NSWindow - NSSecureTextField - NSProgressIndicator NSTextField + NSPanel - - IBProjectSource - AnselExportController.h - - - - NSObject - - IBProjectSource - TURAnsel.h - - - - NSObject - - IBProjectSource - TURAnselGallery.h - - - - NSObject - - IBProjectSource - xmlrpc-1.5.1/XMLRPCConnection.h - + diff --git a/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/keyedobjects.nib b/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/keyedobjects.nib index c850b23d8..b318b79b4 100644 Binary files a/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/keyedobjects.nib and b/iPhoto2Ansel/English.lproj/AnselGalleryPanel.nib/keyedobjects.nib differ diff --git a/iPhoto2Ansel/TURAnselGalleryPanelController.h b/iPhoto2Ansel/TURAnselGalleryPanelController.h new file mode 100644 index 000000000..d423ca66c --- /dev/null +++ b/iPhoto2Ansel/TURAnselGalleryPanelController.h @@ -0,0 +1,34 @@ +// +// TURAnselGalleryPanelController.h +// iPhoto2Ansel +// +// Created by Michael Rubinsky on 12/7/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import +#import "TURAnsel.h" + +@interface NSObject (TURAnselGalleryPaneControllerDelegate) +-(void)TURAnselGalleryPanelDidAddGallery; +@end + +@interface TURAnselGalleryPanelController : NSObject { + // Outlets + IBOutlet NSTextField *galleryNameTextField; + IBOutlet NSTextField *gallerySlugTextField; + IBOutlet NSTextField *galleryDescTextField; + IBOutlet NSPanel *newGallerySheet; + + TURAnsel *anselController; + NSWindow *controllerWindow; + id delegate; +} + +// Actions +- (IBAction)doNewGallery: (id)sender; +- (IBAction)cancelNewGallery: (id)sender; +- (id)initWithController: (TURAnsel *)theController; +- (void)showSheetForWindow: (NSWindow *)theWindow; +- (void)setDelegate: (id)theDelegate; +@end diff --git a/iPhoto2Ansel/TURAnselGalleryPanelController.m b/iPhoto2Ansel/TURAnselGalleryPanelController.m new file mode 100644 index 000000000..419ebeef1 --- /dev/null +++ b/iPhoto2Ansel/TURAnselGalleryPanelController.m @@ -0,0 +1,102 @@ +// +// TURAnselGalleryPanelController.m +// iPhoto2Ansel +// +// Created by Michael Rubinsky on 12/7/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "TURAnselGalleryPanelController.h" + +@implementation TURAnselGalleryPanelController + +#pragma mark IBActions +- (IBAction)cancelNewGallery: (id)sender +{ + [NSApp endSheet: newGallerySheet]; + [newGallerySheet orderOut: nil]; +} + +- (IBAction)doNewGallery: (id)sender +{ + // Get Gallery Properties from the panel. + NSString *galleryName = [galleryNameTextField stringValue]; + NSString *gallerySlug = [gallerySlugTextField stringValue]; + NSString *galleryDescription = [galleryDescTextField stringValue]; + + if (!galleryName) { + + [NSApp endSheet: newGallerySheet]; + [newGallerySheet orderOut: nil]; + + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Gallery names cannot be empty"]; + [alert setAlertStyle: NSCriticalAlertStyle]; + [alert beginSheetModalForWindow: controllerWindow + modalDelegate: nil + didEndSelector: nil + contextInfo: nil]; + [alert release]; + return; + } + NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: + galleryName, @"name", + gallerySlug, @"slug", + galleryDescription, @"desc", nil]; + + NSDictionary *results = [[anselController createNewGallery: params] retain]; + + [NSApp endSheet: newGallerySheet]; + [newGallerySheet orderOut: nil]; + + if ([anselController state] != TURAnselStateError) { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText: @"Gallery successfully created."]; + [alert beginSheetModalForWindow: controllerWindow + modalDelegate: nil + didEndSelector: nil + contextInfo: nil]; + [alert release]; + if ([delegate respondsToSelector:@selector(TURAnselGalleryPanelDidAddGallery)]) { + [delegate TURAnselGalleryPanelDidAddGallery]; + } + } + + [results release]; +} + +-(id)initWithController: (TURAnsel *)theController +{ + [super init]; + anselController = [theController retain]; + [NSBundle loadNibNamed: @"AnselGalleryPanel" + owner: self]; + + return self; +} + +- (void)setDelegate: (id)theDelegate +{ + delegate = theDelegate; // weak +} + + +- (void)showSheetForWindow: (NSWindow *)theWindow +{ + [controllerWindow release]; + controllerWindow = [theWindow retain]; + [NSApp beginSheet: newGallerySheet + modalForWindow: theWindow + modalDelegate: nil + didEndSelector: nil + contextInfo: nil]; +} + +- (void)dealloc +{ + [anselController release]; + [controllerWindow release]; + [super dealloc]; +} + +@end diff --git a/iPhoto2Ansel/iPhoto2Ansel.xcodeproj/project.pbxproj b/iPhoto2Ansel/iPhoto2Ansel.xcodeproj/project.pbxproj index a525ad8cd..18aedf3dc 100644 --- a/iPhoto2Ansel/iPhoto2Ansel.xcodeproj/project.pbxproj +++ b/iPhoto2Ansel/iPhoto2Ansel.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ B0BFBCAA0ED5B32B006581A5 /* XMLRPCResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = B0BFBC960ED5B32B006581A5 /* XMLRPCResponse.m */; }; B0C888490ED85DEA000E19FB /* ProgressSheet.nib in Resources */ = {isa = PBXBuildFile; fileRef = B0C888480ED85DEA000E19FB /* ProgressSheet.nib */; }; B0C8884E0ED85E02000E19FB /* FBProgressController.m in Sources */ = {isa = PBXBuildFile; fileRef = B0C8884D0ED85E02000E19FB /* FBProgressController.m */; }; + B0CCED420EEC6E810012D3D3 /* TURAnselGalleryPanelController.m in Sources */ = {isa = PBXBuildFile; fileRef = B0CCED410EEC6E810012D3D3 /* TURAnselGalleryPanelController.m */; }; B0DF843C0EE9E6EB000DAA9E /* QuickTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B0DF843B0EE9E6EB000DAA9E /* QuickTime.framework */; }; /* End PBXBuildFile section */ @@ -114,6 +115,8 @@ B0C888480ED85DEA000E19FB /* ProgressSheet.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = ProgressSheet.nib; sourceTree = ""; }; B0C8884C0ED85E02000E19FB /* FBProgressController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBProgressController.h; sourceTree = ""; }; B0C8884D0ED85E02000E19FB /* FBProgressController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBProgressController.m; sourceTree = ""; }; + B0CCED400EEC6E810012D3D3 /* TURAnselGalleryPanelController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TURAnselGalleryPanelController.h; sourceTree = ""; }; + B0CCED410EEC6E810012D3D3 /* TURAnselGalleryPanelController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TURAnselGalleryPanelController.m; sourceTree = ""; }; B0DF843B0EE9E6EB000DAA9E /* QuickTime.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickTime.framework; path = /System/Library/Frameworks/QuickTime.framework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -238,6 +241,8 @@ B00076DE0EBA573900A95FC0 /* AnselToolkit */ = { isa = PBXGroup; children = ( + B0CCED400EEC6E810012D3D3 /* TURAnselGalleryPanelController.h */, + B0CCED410EEC6E810012D3D3 /* TURAnselGalleryPanelController.m */, B07D426C0EC230B100B59765 /* TURAnsel.h */, B07D426D0EC230B100B59765 /* TURAnsel.m */, B07D426E0EC230B100B59765 /* TURAnselGallery.h */, @@ -403,6 +408,7 @@ B07D44F70EC2AEC700B59765 /* TURXMLConnection.m in Sources */, B0C8884E0ED85E02000E19FB /* FBProgressController.m in Sources */, B05C4A060EE9E001005B4B28 /* ImageResizer.m in Sources */, + B0CCED420EEC6E810012D3D3 /* TURAnselGalleryPanelController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };