public
Description: A Mac OS X photo uploader program for my photo album.
Homepage: http://bleu.west.spy.net/~dustin/projects/photoupload/
Clone URL: git://github.com/dustin/photoupload.git
photoupload / BatchController.m
100644 99 lines (84 sloc) 2.72 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// arch-tag: 421A4542-9196-11D8-ABDD-000A957659CC
 
#import "BatchController.h"
 
@implementation BatchController
 
- (void)alert:(id)title message:(id)msg
{
    NSRunAlertPanel(title, msg, @"OK", nil, nil);
}
 
- (IBAction)addPhotos:(id)sender
{
    NSLog(@"addPhotos called.\n");
}
 
- (IBAction)dateToToday:(id)sender
{
    NSDate *today = [NSDate date];
    NSString *datestr=
        [today descriptionWithCalendarFormat:
                        @"%Y/%m/%d" timeZone: nil
                                      locale: nil];
 
    [taken setStringValue:datestr];
}
 
- (IBAction)saveBatch:(id)sender
{
    NSLog(@"saveBatch called.\n");
 
    // Get the location to save the file.
    NSSavePanel *sp;
    int runResult;
    sp = [NSSavePanel savePanel];
    /* set up new attributes */
    // [sp setAccessoryView:newView];
    [sp setRequiredFileType:@"pbatch"];
    runResult = [sp runModal];
    if (runResult == NSOKButton) {
        NSDate *date=[NSCalendarDate dateWithString: [taken stringValue]
                                 calendarFormat: @"%Y/%m/%d"];
        NSString *k=[keywords stringValue];
        if([k length] == 0) {
            [self alert:_str(@"A.T.NoKeywords")
                message:_str(@"A.B.NoKeywords")];
            return;
        }
        NSString *d=[description stringValue];
        if([d length] == 0) {
            [self alert:_str(@"A.T.NoDescription")
                message:_str(@"A.B.NoDescription")];
            return;
        }
        NSString *cat=[category stringValue];
 
        NSArray *files=[imgMatrix files];
        Batch *batch=[[Batch alloc] init];
        [batch setKeywords: k];
        [batch setDescription: d];
        [batch setCategory: cat];
        [batch setTaken: date];
        [batch setFiles: files];
 
        // Save it to the selected file.
        BOOL result = [NSKeyedArchiver archiveRootObject:batch
                                              toFile:[sp filename]];
        NSLog(@"Wrote %d\n", result);
        [batch release];
    } else {
        NSLog(@"Not saving.\n");
    }
}
 
-(DumpMatrix *)imgMatrix
{
    return (imgMatrix);
}
 
-(void)awakeFromNib
{
    NSLog(@"BatchController awaking from nib.\n");
    [imgMatrix clear];
    [imgMatrix registerForDraggedTypes:[NSArray arrayWithObjects:
        NSFilenamesPboardType, nil]];
    [self dateToToday: nil];
 
    id defaults=[NSUserDefaults standardUserDefaults];
    id catList=[defaults objectForKey:@"categories"];
    if(catList == nil) {
        catList=[NSArray arrayWithObjects: @"Public", @"Private", nil];
    }
    // Initialize the batch category list from the user defaults
    [category removeAllItems];
    [category addItemsWithObjectValues: catList];
}
 
@end