bzr branch
/browse/mac/UpshotHelper
| Line | Revision | Contents |
| 1 | 1 | // |
| 2 | // UpshotHelperAppDelegate.m |
|
| 3 | // UpshotHelper |
|
| 4 | // |
|
| 5 | // Created by döme on 05.02.2010. |
|
| 6 | // Copyright 2010 Apple Inc. All rights reserved. |
|
| 7 | // |
|
| 8 | ||
| 9 | #import <unistd.h> |
|
| 10 | #import "UpshotHelperAppDelegate.h" |
|
| 11 | ||
| 12 | extern NSString* imgPath; |
|
| 13 | extern char **environ; |
|
| 14 | ||
| 15 | @implementation UpshotHelperAppDelegate |
|
| 16 | ||
| 17 | 4 | @synthesize window, imageName, nameField; |
| 18 | 1 | |
| 19 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification |
|
| 20 | { |
|
| 21 | NSUserDefaults* d = [NSUserDefaults standardUserDefaults]; |
|
| 22 | ||
| 23 | [d registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys: @"http://example.com/upshot/", @"wwwPath", @"user@example.com:/srv/upshot", @"serverPath", nil]]; |
|
| 24 | ||
| 25 | [self setImageName: [imgPath lastPathComponent]]; |
|
| 26 | [NSApp activateIgnoringOtherApps: YES]; |
|
| 27 | 2 | [window center]; |
| 28 | 4 | [window makeKeyAndOrderFront: self]; |
| 29 | |
|
| 30 | NSText* editor = [nameField currentEditor]; |
|
| 31 | [editor setSelectedRange: NSMakeRange(0, [[self imageName] length] - 4)]; |
|
| 32 | ||
| 33 | 1 | [NSApp runModalForWindow: window]; |
| 34 | |
|
| 35 | } |
|
| 36 | ||
| 37 | - (id) image |
|
| 38 | { |
|
| 39 | return [[NSImage alloc] initWithContentsOfFile: imgPath]; |
|
| 40 | } |
|
| 41 | ||
| 42 | - (id) imagePath |
|
| 43 | { |
|
| 44 | return imgPath; |
|
| 45 | } |
|
| 46 | ||
| 47 | - (void) okAction: (id) sender |
|
| 48 | { |
|
| 49 | 6 | NSUserDefaults* d = [NSUserDefaults standardUserDefaults]; |
| 50 | 1 | // const char * const argv[] = {"/usr/bin/scp", "-q", [imgPath UTF8String], [[[[NSUserDefaults standardUserDefaults] objectForKey: @"serverPath"] stringByAppendingPathComponent: [self imageName]] UTF8String],NULL}; |
| 51 | ||
| 52 | 6 | NSTask* task = [NSTask launchedTaskWithLaunchPath: @"/usr/bin/scp" arguments: [NSArray arrayWithObjects: @"-q", imgPath, [[d objectForKey: @"serverPath"] stringByAppendingPathComponent: [self imageName]], nil]]; |
| 53 | 5 | |
| 54 | [task waitUntilExit]; |
|
| 55 | ||
| 56 | 6 | printf("%s", [[[d objectForKey: @"wwwPath"] stringByAppendingPathComponent: [self imageName]] UTF8String]); |
| 57 | 1 | |
| 58 | 5 | // system([[NSString stringWithFormat: @"/usr/bin/scp -q %@ %@", imgPath, [[[NSUserDefaults standardUserDefaults] objectForKey: @"serverPath"] stringByAppendingPathComponent: [self imageName]]] UTF8String]); |
| 59 | 1 | |
| 60 | [NSApp stopModal]; |
|
| 61 | [NSApp terminate: self]; |
|
| 62 | } |
|
| 63 | - (void) cancelAction: (id) sender |
|
| 64 | { |
|
| 65 | [NSApp stopModal]; |
|
| 66 | [NSApp terminate: self]; |
|
| 67 | } |
|
| 68 | ||
| 69 | @end |
Loggerhead 1.17 is a web-based interface for Bazaar branches