Before we can update the user interface, we need to update the source. We know from the MetaWeblog API that we will need the following data:
So, in MetaWeblogPlugIn.h lets add the following:
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import "ApertureExportManager.h"
#import "ApertureExportPlugIn.h"
@interface MetaWeblogPlugIn : NSObject <ApertureExportPlugIn>
{
id _apiManager;
NSObject<ApertureExportManager, PROAPIObject> *_exportManager;
NSLock *_progressLock;
NSArray *_topLevelNibObjects;
ApertureExportProgress exportProgress;
IBOutlet NSView *settingsView;
IBOutlet NSView *firstView;
IBOutlet NSView *lastView;
IBOutlet NSTextField *blogAccessPointTextField; IBOutlet NSTextField *blogUserNameTextField; IBOutlet NSSecureTextField *blogPasswordTextField; IBOutlet NSTextField *blogIdTextField;
}
We added both NSString and IBOutlet fields for each piece of data we need to connect to the MetaWeblog API. In the MetaWeblogPlugIn.m, we will add methods to deal with changes to the various UI elements. For example, if the text blogAccesPointTextField changes, then we will update the underlying _blogAccessPoint field.
#import "MetaWeblogPlugIn.h"
@implementation MetaWeblogPlugIn
- (id)initWithAPIManager:(id<PROAPIAccessing>)apiManager
{
if (self = [super init])
{
_apiManager = apiManager;
_exportManager = [[_apiManager apiForProtocol:@protocol(ApertureExportManager)] retain];
if (!_exportManager)
return nil;
_progressLock = [[NSLock alloc] init];
}
return self;
}
- (void)dealloc
{
[_topLevelNibObjects makeObjectsPerformSelector:@selector(release)];
[_topLevelNibObjects release];
[_progressLock release];
[_exportManager release];
[super dealloc];
}
#pragma mark -
// UI Methods
#pragma mark UI Methods
- (NSView *)settingsView
{
if (nil == settingsView)
{
// Load the nib using NSNib, and retain the array of top-level objects so we can release
// them properly in dealloc
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSNib *myNib = [[NSNib alloc] initWithNibNamed:"MetaWeblogPlugIn"Â bundle:myBundle];
if ([myNib instantiateNibWithOwner:self topLevelObjects:&_topLevelNibObjects])
{
[_topLevelNibObjects retain];
}
[myNib release];
}
return settingsView;
}
- (NSView *)firstView
{
return firstView;
}
- (NSView *)lastView
{
return lastView;
}
- (void)willBeActivated
{
}
- (void)willBeDeactivated
{
}
#pragma mark
// Aperture UI Controls
#pragma mark Aperture UI Controls
- (BOOL)allowsOnlyPlugInPresets
{
return TRUE;
}
- (BOOL)allowsMasterExport
{
return FALSE;
}
- (BOOL)allowsVersionExport
{
return TRUE;
}
- (BOOL)wantsFileNamingControls
{
return FALSE;
}
- (void)exportManagerExportTypeDidChange
{
}
#pragma mark -
// Save Path Methods
#pragma mark Save/Path Methods
- (BOOL)wantsDestinationPathPrompt
{
return FALSE;
}
- (NSString *)destinationPath
{
return nil;
}
- (NSString *)defaultDirectory
{
return nil;
}
#pragma mark -
// Export Process Methods
#pragma mark Export Process Methods
- (void)exportManagerShouldBeginExport
{
NSString* blogAccessPoint = [blogAccessPointTextField stringValue];
NSString* blogId = [blogIdTextField stringValue];
NSString* blogUserName = [blogUserNameTextField stringValue];
NSString* blogpassword = [blogPasswordTextField stringValue];
NSLog("blogAccessPoint: %", blogAccessPoint);
NSLog("blogId: %", blogId);
NSLog("blogUserName: %", blogUserName);
NSLog("blogPassword: ********");
[_exportManager shouldBeginExport];
}
- (void)exportManagerWillBeginExportToPath:(NSString *)path
{
}
- (BOOL)exportManagerShouldExportImageAtIndex:(unsigned)index
{
return TRUE;
}
- (void)exportManagerWillExportImageAtIndex:(unsigned)index
{
}
- (BOOL)exportManagerShouldWriteImageData:(NSData *)imageData toRelativePath:(NSString *)path forImageAtIndex:(unsigned)index
{
return TRUE;
}
- (void)exportManagerDidWriteImageDataToRelativePath:(NSString *)relativePath forImageAtIndex:(unsigned)index
{
}
- (void)exportManagerDidFinishExport
{
[_exportManager shouldFinishExport];
}
- (void)exportManagerShouldCancelExport
{
[_exportManager shouldCancelExport];
}
#pragma mark -
// Progress Methods
#pragma mark Progress Methods
- (ApertureExportProgress *)progress
{
return &exportProgress;
}
- (void)lockProgress
{
if (!_progressLock)
_progressLock = [[NSLock alloc] init];
[_progressLock lock];
}
- (void)unlockProgress
{
[_progressLock unlock];
}
@end
Now that we have the foundations in place, modify the UI. To do that, open MetaWeblogPlugIn.nib. The settings window will be visible. Delete the "Build Your UI Here"Âlabel.

Now add a simple box, three text fields and one secure text fields. Add four labels and organize them such that they look as follows:

The endpoint, blog id and user name are all text fields. The password is the secure text field. Now lets connect the fields accordingly with each instance of IBOutlet we created in the MetaWeblogPlugIn class. First, select the "File's owner"Â.

Select Tools then Connections Inspector.

Using your mouse, select the open circle of the settings view and connect it to the settings view.

Connect the blogAccessPointTextView to the first text field, blogIdTextField to the second text field, the blogPasswordTextField to the last text field and blogUserTextField with the third text field.

In order to test whether all of this was correctly done, run the plug-in by starting Aperture, then selecting File, Export and then Blog. Enter some values and select Export.

Check the debugger console and you'll see the values entered in the UI.

Comments