From: Michael J. Rubinsky Date: Tue, 3 Feb 2009 16:53:40 +0000 (-0500) Subject: Start adding the ability to set a default server. This adds and X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dc7703b07b8ff1395e71bc0d2298a86a7feedf2e;p=horde.git Start adding the ability to set a default server. This adds and hooks up some outlets and UI elements, stops autoconnected to the first listed server, adds "None" as the first option in the popup, but nothing is remembered (yet). --- diff --git a/iPhoto2Ansel/AnselExportController.h b/iPhoto2Ansel/AnselExportController.h index 93da3acea..14c885225 100644 --- a/iPhoto2Ansel/AnselExportController.h +++ b/iPhoto2Ansel/AnselExportController.h @@ -16,6 +16,7 @@ // User defaults keys extern NSString * const TURAnselServersKey; extern NSString * const TURAnselExportSize; +extern NSString * const TURAnselDefaultServerKey; // Server property keys extern NSString * const TURAnselServerNickKey; @@ -48,6 +49,7 @@ extern NSString * const TURAnselServerPasswordKey; IBOutlet NSTextField *mServerSheetUsername; IBOutlet NSSecureTextField *mServerSheetPassword; IBOutlet NSTextField *mServerSheetServerNickName; + IBOutlet NSButton *mMakeNewServerDefault; // Server list IBOutlet NSPanel *serverListPanel; @@ -71,6 +73,10 @@ extern NSString * const TURAnselServerPasswordKey; TURAnsel *anselController; TURAnselGallery *currentGallery; int currentImageCount; + + // Remembers the selected server before it changes. Used to reselect the + // proper server if necessary when server panels are closed. + int mIndexOfPreviouslySelectedServer; } @property (readwrite, retain) TURAnselGallery *currentGallery; @@ -93,4 +99,5 @@ extern NSString * const TURAnselServerPasswordKey; - (void)awakeFromNib; - (void)dealloc; + @end diff --git a/iPhoto2Ansel/AnselExportController.m b/iPhoto2Ansel/AnselExportController.m index 749dd3530..fd61810e4 100644 --- a/iPhoto2Ansel/AnselExportController.m +++ b/iPhoto2Ansel/AnselExportController.m @@ -30,6 +30,7 @@ // User default keys NSString * const TURAnselServersKey = @"AnselServers"; NSString * const TURAnselExportSize = @"AnselExportSize"; +NSString * const TURAnselDefaultServerKey = @"AnselDefaultServer"; // Server property keys NSString * const TURAnselServerNickKey = @"nickname"; @@ -51,7 +52,12 @@ NSString * const TURAnselServerPasswordKey = @"password"; NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary]; [defaultValues setObject: [NSNumber numberWithInt: 2] forKey: TURAnselExportSize]; + [defaultValues setObject: [[NSMutableArray alloc] init] forKey: TURAnselServersKey]; + + [defaultValues setObject: @"" + forKey: TURAnselDefaultServerKey]; + NSUserDefaults *userPrefs = [NSUserDefaults standardUserDefaults]; [userPrefs registerDefaults: defaultValues]; @@ -129,7 +135,10 @@ NSString * const TURAnselServerPasswordKey = @"password"; // Action sent by the server pop up menu - (IBAction)clickServer: (id)sender { - if ([mServersPopUp indexOfSelectedItem] == [mServersPopUp numberOfItems] - 1) { + // Are we set to "none" now? + if ([mServersPopUp indexOfSelectedItem] == 0) { + [self disconnect]; + } else if ([mServersPopUp indexOfSelectedItem] == [mServersPopUp numberOfItems] - 1) { // Server list [self showServerListPanel]; } else if ([mServersPopUp indexOfSelectedItem] == [mServersPopUp numberOfItems] - 2) { @@ -166,9 +175,10 @@ NSString * const TURAnselServerPasswordKey = @"password"; [anselServers addObject: newServer]; [NSApp endSheet: newServerSheet]; [newServerSheet orderOut: nil]; - currentServer = [newServer retain]; [self doConnect]; + int butState = [mMakeNewServerDefault state]; + // Make the new server the default? // Save it to the userdefaults NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; @@ -350,6 +360,7 @@ NSString * const TURAnselServerPasswordKey = @"password"; - (void)updateServersPopupMenu { [mServersPopUp removeAllItems]; + [mServersPopUp addItemWithTitle:@"(None)"]; for (NSDictionary *server in anselServers) { NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: [server objectForKey: TURAnselServerNickKey] action: nil @@ -357,9 +368,6 @@ NSString * const TURAnselServerPasswordKey = @"password"; [menuItem setRepresentedObject: server]; [[mServersPopUp menu] addItem: menuItem]; } - if ([anselServers count] == 0) { - [mServersPopUp addItemWithTitle:@"(None)"]; - } // add separator [[mServersPopUp menu] addItem:[NSMenuItem separatorItem]]; @@ -623,29 +631,17 @@ NSString * const TURAnselServerPasswordKey = @"password"; } #pragma mark comboBoxDelegate -// Probably should have a seperate controller for each combobox, but this is -// pretty small stuff... - (void)comboBoxSelectionDidChange:(NSNotification *)notification { - // Yes, I'm comparing the pointers here on purpose - //if ([notification object] == galleryCombo) { - int row = [galleryCombo indexOfSelectedItem]; - [currentGallery setDelegate:nil]; - [currentGallery autorelease]; - currentGallery = [[anselController getGalleryByIndex:row] retain]; - [currentGallery setDelegate: self]; - NSImage *theImage = [[NSImage alloc] initWithContentsOfURL: [currentGallery galleryDefaultImageURL]]; - [defaultImageView setImage: theImage]; - [theImage release]; - [self canExport]; - //} -} - - -#pragma mark NSTableView Notifications -- (void)tableViewSelectionDidChange:(NSNotification *)aNotification -{ - NSLog(@"%@", aNotification); + int row = [galleryCombo indexOfSelectedItem]; + [currentGallery setDelegate:nil]; + [currentGallery autorelease]; + currentGallery = [[anselController getGalleryByIndex:row] retain]; + [currentGallery setDelegate: self]; + NSImage *theImage = [[NSImage alloc] initWithContentsOfURL: [currentGallery galleryDefaultImageURL]]; + [defaultImageView setImage: theImage]; + [theImage release]; + [self canExport]; } #pragma mark TURAnselGalleryPanel Notifications @@ -664,13 +660,20 @@ NSString * const TURAnselServerPasswordKey = @"password"; name: NSWindowDidBecomeKeyNotification object: nil]; [self updateServersPopupMenu]; + + // Register for notifications + [[NSNotificationCenter defaultCenter] addObserver: self + selector: @selector(NSPopUpWillPopUp:) + name:@"NSPopUpButtonWillPopUpNotification" + object: nil]; + if ([anselServers count] == 0) { [self showNewServerSheet]; } else { // Autoconnect to default server. For now, just make it the first one. // TODO: Fix this so it uses a default pref, not just the first in the list - currentServer = [[mServersPopUp selectedItem] representedObject]; - [self doConnect]; + //currentServer = [[mServersPopUp selectedItem] representedObject]; + //[self doConnect]; } } - (void)sizeChoiceWillChange: (NSNotification *)notification @@ -681,6 +684,15 @@ NSString * const TURAnselServerPasswordKey = @"password"; [userPrefs synchronize]; } +#pragma mark NSPopUpButton Notification Handlers +- (void) NSPopUpWillPopUp:(id)theButton +{ + // Remember the previous selection before it changes. + // The 'clickServer' action will handle what to do with the selection. + mIndexOfPreviouslySelectedServer = [mServersPopUp indexOfSelectedItem]; +} + + #pragma mark NSTableView Datasource - (int)numberOfRowsInTableView:(NSTableView *)aTableView { diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib b/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib index 6ca2fb904..d0c4a590f 100644 --- a/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib +++ b/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib @@ -8,8 +8,8 @@ 353.00 YES - - + + YES @@ -676,7 +676,7 @@ {3.40282e+38, 3.40282e+38} - + 256 YES @@ -868,9 +868,9 @@ YES - -2080244224 + 67239424 0 - Default Server + Make Default 1211912703 @@ -890,6 +890,7 @@ {455, 195} + {{0, 0}, {1920, 1178}} {3.40282e+38, 3.40282e+38} @@ -904,21 +905,21 @@ {3.40282e+38, 3.40282e+38} - + 256 YES 268 - {{569, 12}, {96, 32}} + {{568, 28}, {96, 28}} YES 67239424 - 134217728 + 134348800 Done - + -2038284033 129 @@ -1123,14 +1124,14 @@ 268 - {{14, 12}, {96, 32}} + {{15, 28}, {96, 28}} YES 67239424 - 134217728 + 134348800 Remove - + -2038284033 129 @@ -1140,9 +1141,28 @@ 25 + + + 268 + {{109, 28}, {123, 28}} + + YES + + 67239424 + 134348800 + Make Default + + + -2038284033 + 129 + + + 200 + 25 + + {679, 358} - {{0, 0}, {1920, 1178}} {3.40282e+38, 3.40282e+38} @@ -1351,6 +1371,46 @@ 526 + + + mMakeNewServerDefault + + + + 529 + + + + mServerSheetServerNickName + + + + 530 + + + + mServerSheetHostURL + + + + 531 + + + + mServerSheetUsername + + + + 532 + + + + mServerSheetPassword + + + + 533 + @@ -1899,9 +1959,10 @@ YES - + + @@ -2013,6 +2074,20 @@ + + 527 + + + YES + + + + + + 528 + + + @@ -2121,6 +2196,8 @@ 515.IBPluginDependency 521.IBPluginDependency 522.IBPluginDependency + 527.IBPluginDependency + 528.IBPluginDependency 6.IBPluginDependency 6.ImportedFromIB2 7.CustomClassName @@ -2167,9 +2244,9 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{42, 910}, {455, 195}} + {{419, 246}, {455, 195}} com.apple.InterfaceBuilder.CocoaPlugin - {{42, 910}, {455, 195}} + {{419, 246}, {455, 195}} com.apple.InterfaceBuilder.CocoaPlugin @@ -2234,6 +2311,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin AnselExportPluginBox com.apple.InterfaceBuilder.CocoaPlugin @@ -2262,7 +2341,7 @@ - 526 + 533 @@ -2297,45 +2376,47 @@ YES YES - anselHostURL defaultImageView firstView galleryCombo mCancelConnect mExportMgr + mMakeNewServerDefault + mNewGalleryButton + mServerSheetHostURL + mServerSheetPassword + mServerSheetServerNickName + mServerSheetUsername mServersPopUp mSettingsBox mSizePopUp - newGalleryButton newServerSheet - password serverListPanel - serverNickName serverTable spinner statusLabel - username YES - NSTextField NSImageView NSControl NSComboBox NSButton id + NSButton + NSButton + NSTextField + NSSecureTextField + NSTextField + NSTextField NSPopUpButton NSBox NSPopUpButton - NSButton NSWindow - NSSecureTextField NSPanel - NSTextField NSTableView NSProgressIndicator NSTextField - NSTextField diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib index 48c956029..dddf7b5b7 100644 Binary files a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib and b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib differ