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
dustin (author)
Mon Oct 29 22:12:08 -0700 2007
commit  3645951ef6d97a1f99754d83550e44b768a9e680
tree    d779d45f73bc18c3acbd7b17eb5640c8655a38b1
parent  63f39e4d4d6371aeb1b7afb5ef375f57cea456f5
photoupload / BatchUploadController.m
100644 130 lines (106 sloc) 3.099 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// arch-tag: 44DFAAB1-9196-11D8-A436-000A957659CC
 
#import "BatchUploadController.h"
#import "Batch.h"
#import "UploadParams.h";
#import "Uploadthread.h";
 
@implementation BatchUploadController
 
- (void)alert:(id)title message:(id)msg
{
    NSRunAlertPanel(title, msg, @"OK", nil, nil);
}
 
- (IBAction)stopUpload:(id)sender
{
}
 
-(void)upload: (Batch *)batch
{
    // Set the current file info
    _numFiles=[[batch files] count];
    _currentFile=1;
    [fileProgressBar setMinValue: 0];
    [fileProgressBar setMaxValue: _numFiles];
    [fileProgressBar setDoubleValue: 0];
    
    UploadParams *params=[[UploadParams alloc] init];
 
    [batch setUrl: _url];
    [batch setUsername: _username];
    [batch setPassword: _password];
 
    [params setController: self];
    [params setUploadErrorMethod: @selector(uploadError:)];
    [params setUploadedFileMethod: @selector(uploadedFile)];
    [params setUploadCompleteMethod: @selector(uploadComplete)];
 
    UploadThread *ut=[[UploadThread alloc] init];
    [ut setBatch: batch];
    [NSThread detachNewThreadSelector: @selector(run:)
                             toTarget:ut withObject: params];
    
    [params release];
}
 
-(void)processFiles:(NSArray *)files
{
    [self showWindow:self];
    _batchSize=[files count];
    _currentBatch=0;
    [batchProgressBar setMinValue: 0];
    [batchProgressBar setMaxValue: _batchSize];
    [batchProgressBar setDoubleValue: 0];
    
    NSEnumerator *e=[files objectEnumerator];
    id filename=nil;
    while(filename = [e nextObject]) {
        NSLog(@"Processing batch %@\n", filename);
 
        // Get the batch
        id batch = [NSKeyedUnarchiver unarchiveObjectWithFile:
            filename];
        
        // Process batch
        [self upload: batch];
        _currentBatch++;
    }
}
 
- (void)updateProgressText
{
    if(_currentFile <= _numFiles)
    {
        NSString *msg=[NSString stringWithFormat:@"Uploading file %d of %d",
            _currentFile, _numFiles];
        [fileText setStringValue: msg];
        [fileText displayIfNeeded];
    }
}
 
-(void)uploadError: (id)msg
{
    [self alert:_str(@"Upload Error") message: msg];
}
 
-(void)uploadedFile
{
    // NSLog(@"Uploaded a file.\n");
    _currentFile++;
    [self updateProgressText];
    [fileProgressBar incrementBy: 1];
    [fileProgressBar displayIfNeeded];
}
 
-(void)uploadComplete
{
    NSLog(@"Batch upload is complete.\n");
    [fileProgressBar setMinValue: 0];
    [fileProgressBar setMaxValue: 0];
    [fileProgressBar setDoubleValue: 0];
    [fileProgressBar displayIfNeeded];
 
    // Update the batch progress bar
    [batchProgressBar incrementBy: 1];
    [batchProgressBar displayIfNeeded];
    NSString *msg=[NSString stringWithFormat:@"Uploading batch %d of %d",
        _currentBatch+1, _batchSize];
    [batchText setStringValue: msg];
    [batchText displayIfNeeded];
    [[self window] orderOut: self];
}
 
-(void)setUrl: (NSString *)url
{
    _url=url;
}
 
-(void)setUsername: (NSString *)username
{
    _username=username;
}
 
-(void)setPassword: (NSString *)password
{
    _password=password;
}
 
@end