Pushr (master) :  summary log tree commit diff
path: root/PushablePhotos.m blob: 2ac326e4a869e211ca7788fb45894dd59f7d31cb
1/*
2 * PushablePhotos
3 * -------------
4 * Show the user a list of photos that will be pushed - and let them remove items from that list.
5 *
6 * Author: Chris Lee <clee@mg8.org>
7 * License: GPL v2 <http://www.opensource.org/licenses/gpl-license.php>
8 */
9#import <CoreFoundation/CoreFoundation.h>
10#import <Foundation/Foundation.h>
11#import <UIKit/CDStructures.h>
12#import <GraphicsServices/GraphicsServices.h>
13#import <CoreGraphics/CGColor.h>
14#import <CoreGraphics/CGColorSpace.h>
15#import <UIKit/UIKit.h>
16
17#import "MobilePushr.h"
18#import "Flickr.h"
19#import "PushablePhotos.h"
20#import "ExtendedAttributes.h"
21#import "PushrPhotoProperties.h"
22
23@implementation PushablePhotos
24
25- (id)initWithFrame: (struct CGRect)frame application: (MobilePushr *)pushr inWindow: (UIWindow *)window;
26{
27 if (![super initWithFrame: frame])
28 return nil;
29
30 float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
31 struct CGColor *whiteColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), color);
32 [self setBackgroundColor: whiteColor];
33
34 _pushr = [pushr retain];
35 _mainWindow = window;
36
37 _table = [[PushablePhotosTable alloc] initWithFrame: CGRectMake(frame.origin.x, frame.origin.y + 44.0f, frame.size.width, frame.size.height - (96.0f + 44.0f))];
38 UITableColumn *col = [[UITableColumn alloc] initWithTitle: @"Camera Roll" identifier: @"cameraroll" width: frame.size.width];
39 [_table addTableColumn: col];
40 [_table setApp: _pushr inWindow: _mainWindow];
41 [_table setSeparatorStyle: 1];
42 [_table setPhotos: [_pushr cameraRollPhotos]];
43 [_table setDelegate: _table];
44 [_table setDataSource: _table];
45 [_table reloadData];
46
47 [self addSubview: _table];
48
49 return self;
50}
51
52- (void)dealloc
53{
54 [_table release];
55 [_pushr release];
56 [super dealloc];
57}
58
59- (void)emptyRoll
60{
61 [_table setPhotos: [NSArray array]];
62 [_table reloadData];
63}
64
65- (NSArray *)photosToPush
66{
67 return [_table pushablePhotos];
68}
69
70- (void)promptUserToEditPhotos: (NSArray *)photoList
71{
72 _photoList = [photoList retain];
73 UIAlertSheet *alertSheet = [[UIAlertSheet alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 240.0f)];
74 [alertSheet setTitle: @"Done pushing to Flickr"];
75 [alertSheet setBodyText: @"Would you like to edit the information for your Flickr photos now?"];
76 [alertSheet addButtonWithTitle: @"Edit in Safari"];
77 [alertSheet addButtonWithTitle: @"Do not edit"];
78 [alertSheet setDelegate: self];
79 [alertSheet popupAlertAnimated: YES];
80}
81
82- (void)alertSheet: (UIAlertSheet *)sheet buttonClicked: (int)button
83{
84 [sheet dismiss];
85 [sheet release];
86 [_photoList release];
87
88 switch (button) {
89 case 1: {
90 [_pushr openURL: [NSURL URLWithString: [NSString stringWithFormat: @"%@?ids=%@", FLICKR_FINISHED_URL, [_photoList componentsJoinedByString: @","]]]];
91 break;
92 }
93 default: {
94 [_pushr terminate];
95 }
96 }
97}
98
99@end
100
101@implementation PushablePhotosTable
102
103- (void)setPhotos: (NSArray *)photos
104{
105 _photos = [[NSMutableArray alloc] initWithArray: photos];
106}
107
108- (void)setApp: (MobilePushr *)pushr inWindow: (UIWindow *)window
109{
110 _pushr = [pushr retain];
111 _mainWindow = window;
112}
113
114- (int)swipe: (int)type withEvent: (struct __GSEvent *)event
115{
116 if ((4 == type) || (8 == type)) {
117 struct CGRect rect = GSEventGetLocationInWindow(event);
118 CGPoint point = CGPointMake(rect.origin.x, rect.origin.y - 44.0f);
119 CGPoint offset = _startOffset;
120
121 point.x += offset.x;
122 point.y += offset.y;
123 int row = [self rowAtPoint: point];
124
125 [[self visibleCellForRow: row column: 0] _showDeleteOrInsertion: YES withDisclosure: NO animated: YES isDelete: YES andRemoveConfirmation: NO];
126 }
127
128 return [super swipe: type withEvent: event];
129}
130
131- (void)markPhotoAsIgnored: (NSString *)pathToPhoto
132{
133 NSLog(@"Marking photo at @% with ignored=true", pathToPhoto);
134 [ExtendedAttributes setString: @"true" forKey: IGNORED_ATTRIBUTE atPath: pathToPhoto];
135}
136
137- (void)removePhoto: (RemovablePhotoCell *)photoCell
138{
139 int index = [self _rowForTableCell: photoCell];
140 [self markPhotoAsIgnored: [_photos objectAtIndex: index]];
141 [_photos removeObjectAtIndex: index];
142 [self reloadData];
143}
144
145- (NSArray *)pushablePhotos
146{
147 return [NSArray arrayWithArray: _photos];
148}
149
150- (int)numberOfRowsInTable: (UITable *)table
151{
152 return [_photos count];
153}
154
155- (float)table: (UITable *)table heightForRow: (int)row
156{
157 return 96.0f;
158}
159
160- (BOOL)table: (UITable *)table canDeleteRow: (int)row
161{
162 if (row < [_photos count])
163 return YES;
164}
165
166- (BOOL)table: (UITable *)table canSelectRow: (int)row
167{
168 return YES;
169}
170
171- (void)tableRowSelected: (NSNotification *)notification
172{
173 [[PushrPhotoProperties alloc] initFromWindow: _mainWindow withPushr: _pushr forPhoto: [_photos objectAtIndex: [self selectedRow]]];
174}
175
176- (UITableCell *)table: (UITable *)table cellForRow: (int)row column: (UITableColumn *)col
177{
178 RemovablePhotoCell *cell = [[RemovablePhotoCell alloc] init];
179 NSString *photo = [_photos objectAtIndex: row];
180 NSString *thumbnail = [[photo stringByDeletingPathExtension] stringByAppendingPathExtension: @"THM"];
181
182 [cell setPath: photo];
183 [cell setTitle: [[photo pathComponents] lastObject]];
184 [cell setImage: [UIImage imageAtPath: thumbnail]];
185 [cell setTable: self];
186
187 return cell;
188}
189
190/*
191- (BOOL)respondsToSelector: (SEL)selector
192{
193 BOOL response = [super respondsToSelector: selector];
194 NSLog(@"Called respondsToSelector: %s (returned %d)", selector, response);
195 return response;
196}
197
198- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector
199{
200 NSLog(@"methodSignatureForSelector: %s", selector);
201 return [super methodSignatureForSelector: selector];
202}
203
204- (void)forwardInvocation:(NSInvocation*)invocation
205{
206 NSLog(@"forwardInvocation: %s", [invocation selector]);
207 [super forwardInvocation: invocation];
208}
209*/
210
211- (void)dealloc
212{
213 [_photos release];
214 [super dealloc];
215}
216
217@end
218
219@implementation RemovablePhotoCell
220
221- (void)removeControlWillHideRemoveConfirmation:(id)fp8
222{
223 [self _showDeleteOrInsertion: NO withDisclosure: NO animated: YES isDelete: YES andRemoveConfirmation: NO];
224}
225
226- (void)setTable: (PushablePhotosTable *)table
227{
228 _table = table;
229}
230
231- (void)setPath: (NSString *)path
232{
233 [_path release];
234 _path = [path retain];
235}
236
237- (NSString *)path
238{
239 return _path;
240}
241
242- (void)_willBeDeleted
243{
244 [_table removePhoto: self];
245}
246
247@end
248