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:11:24 -0700 2007
commit  63f39e4d4d6371aeb1b7afb5ef375f57cea456f5
tree    0a10805d736d82caf73478bf79514ffc794c559f
parent  3725f3fbb6f13fb33293b37303d88c1e48b95ef1
photoupload / UploadThread.m
100644 115 lines (91 sloc) 2.842 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
//
// UploadThread.m
// PhotoUpload
// arch-tag: 53F4E420-9196-11D8-9294-000A957659CC
//
// Created by Dustin Sallings on Wed Sep 25 2002.
// Copyright (c) 2002 __MyCompanyName__. All rights reserved.
//
 
#import <CoreServices/CoreServices.h>
 
#import "UploadThread.h"
#import "PUImage.h"
 
@implementation UploadThread
 
-(void)setBatch:(Batch *)to
{
  id tmp=to;
  _batch=to;
  [_batch retain];
  if(tmp != nil) {
    [tmp release];
  }
}
 
-(void)run: (id)object
{
  // Create the autorelease pool.
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
  // Retain the parameters
    params=object;
  [params retain];
 
  // Dictionary for the arguments
    NSMutableDictionary *dict=[[NSMutableDictionary alloc] initWithCapacity:10];
 
  // The arguments that are always the same
    [dict setObject:[_batch username] forKey:@"username"];
    [dict setObject:[_batch password] forKey:@"password"];
    [dict setObject:[_batch keywords] forKey:@"keywords"];
    [dict setObject:[_batch description] forKey:@"info"];
    [dict setObject:[_batch taken] forKey:@"taken"];
    [dict setObject:[_batch category] forKey:@"category"];
 
  // URL for uploading
    NSURL *url=[[NSURL alloc] initWithString: [_batch url]];
    
  NSEnumerator *en=[[_batch files] objectEnumerator];
  id f=nil;
    while( (f = [en nextObject]) && (! [params finished])) {
    // Create an inner autorelease pool to deal with the garbage the
    // upload produces
      NSAutoreleasePool *ipool = [[NSAutoreleasePool alloc] init];
 
        NSLog(@"Uploading %@.", f);
 
        // Get the file data
        NSData *myData = [[NSData alloc] initWithContentsOfFile:[f filename]];
        [dict setObject:myData forKey:@"image"];
 
    NSDictionary *argDict=[NSDictionary dictionaryWithObject:dict
      forKey:@"args"];
 
    WSMethodInvocationRef rpcCall=WSMethodInvocationCreate(
   (CFURLRef)url, (CFStringRef)@"addImage.addImage",
         kWSXMLRPCProtocol);
 
    WSMethodInvocationSetParameters(rpcCall, (CFDictionaryRef)argDict, nil);
 
    NSDictionary *result =
      (NSDictionary *)WSMethodInvocationInvoke(rpcCall);
 
    NSLog(@"Result: %@", result);
 
    if(WSMethodResultIsFault((CFDictionaryRef)result)) {
      [params uploadError:
        [result objectForKey: (NSString *)kWSFaultString]];
    } else {
      id rv=[result objectForKey: (NSString *)kWSMethodInvocationResult];
      NSLog(@"Uploaded image %@", rv);
    }
 
    // Release the XML-RPC specific stuff.
    CFRelease(rpcCall);
    [result release];
 
        [myData release];
        [params uploadedFile];
    [ipool release];
    }
    NSLog(@"Finished, thread will join.\n");
    [params uploadComplete];
 
    [url release];
    [dict release];
    [pool release];
}
 
-(void)dealloc
{
  if(_batch!=nil) {
    [_batch release];
    _batch=nil;
  }
  if(params!=nil) {
    [params release];
    params=nil;
  }
  [super dealloc];
}
 
@end