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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
/*
* PushrPhotoProperties.m
* ----------------------
*
* Author: Chris Lee <clee@mg8.org>
* License: GPL v2 <http://www.opensource.org/licenses/gpl-license.php>
*/
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIView.h>
#import <UIKit/UIView-Geometry.h>
#import <UIKit/UINavigationBar.h>
#import <UIKit/UITransitionView.h>
#import <UIKit/UIPreferencesTable.h>
#import <UIKit/UIPreferencesTextTableCell.h>
#import <UIKit/UIPreferencesControlTableCell.h>
#import <UIKit/UIPreferencesTableCell.h>
#import <UIKit/UISegmentedControl.h>
#import <UIKit/UISwitchControl.h>
#import <UIKit/UITextLabel.h>
#import <UIKit/UIAlertSheet.h>
#import <UIKit/UIWindow.h>
#import "PushrPhotoProperties.h"
#import "ExtendedAttributes.h"
#import "Flickr.h"
#import "MobilePushr.h"
@implementation PushrPhotoTags
- (void)show
{
struct CGRect settingsRect = [UIHardware fullScreenApplicationContentRect];
settingsRect.origin.x = 0.0f; // */ settingsRect.size.width;
settingsRect.origin.y = 0.0f;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
Flickr *flickr = [[Flickr alloc] initWithPushr: _pushr];
_availableTags = [[flickr tags] retain];
_tagsView = [[UIView alloc] initWithFrame: settingsRect];
_navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, settingsRect.size.width, 44.0f)];
[_navBar setBarStyle: 1];
[_navBar setDelegate: self];
[_navBar showLeftButton: nil withStyle: 0 rightButton: @"Done" withStyle: 0];
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle: @"Tags"];
[_navBar pushNavigationItem: title];
[title release];
[_tagsView addSubview: _navBar];
_tagsTable = [[UIPreferencesTable alloc] initWithFrame: CGRectMake(0.0f, 44.0f, settingsRect.size.width, settingsRect.size.height - 44.0f)];
[_tagsTable setDataSource: self];
[_tagsTable setDelegate: self];
[_tagsTable reloadData];
[_tagsView addSubview: _tagsTable];
UITransitionView *transitionView = [[UITransitionView alloc] initWithFrame: settingsRect];
[_mainWindow setContentView: transitionView];
[transitionView transition: 0 toView: _prefView];
[transitionView transition: 1 fromView: _prefView toView: _tagsView];
[transitionView release];
}
- (id)initFromWindow: (UIWindow *)window withPushr: (MobilePushr *)pushr withView: (UIView *)view withTable: (UIPreferencesTable *)table atPath: (NSString *)path
{
if (![super init])
return nil;
_photoPath = [path retain];
_pushr = [pushr retain];
_mainWindow = window;
_prefView = view;
_prefTable = table;
[self show];
return self;
}
- (void)dealloc
{
[_photoPath release];
[_availableTags release];
[_navBar release];
[_prefView release];
[_prefTable release];
[_tagsView release];
[_tagsTable release];
[_mainWindow release];
[_pushr release];
[super dealloc];
}
#pragma mark PushrGlobalTags delegates
- (int)numberOfGroupsInPreferencesTable: (id)preferencesTable
{
return 1;
}
- (int)preferencesTable: (UIPreferencesTable *)preferencesTable numberOfRowsInGroup: (int)group
{
return [_availableTags count];
}
- (id)preferencesTable: (UIPreferencesTable *)preferencesTable titleForGroup: (int)group
{
return @"Default tags for photos";
}
- (float)preferencesTable: (id)preferencesTable heightForRow:(int)row inGroup: (int)group withProposedHeight: (float)proposedHeight
{
return 48.0f;
}
- (id)preferencesTable: (id)preferencesTable cellForRow: (int)row inGroup: (int)group
{
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
UIPreferencesTableCell *thisCell = [[UIPreferencesTableCell alloc] initWithFrame: CGRectMake(0.0f, 0.0f, rect.size.width, 48.0f)];
[thisCell setTitle: [_availableTags objectAtIndex: row]];
if ([[ExtendedAttributes allKeysAtPath: _photoPath] containsObject: TAGS_ATTRIBUTE])
[thisCell setChecked: [[ExtendedAttributes objectForKey: TAGS_ATTRIBUTE atPath: _photoPath] containsObject: [_availableTags objectAtIndex: row]]];
else
[thisCell setChecked: [[defaults arrayForKey: @"defaultTags"] containsObject: [_availableTags objectAtIndex: row]]];
return [thisCell autorelease];
}
- (void)tableRowSelected: (NSNotification *)notification
{
id row = [_tagsTable cellAtRow: [_tagsTable selectedRow] column: 0];
[row setChecked: ![row isChecked]];
}
- (void)navigationBar: (UINavigationBar *)navBar buttonClicked: (int)button
{
struct CGRect settingsRect = [UIHardware fullScreenApplicationContentRect];
UITransitionView *transitionView = [[UITransitionView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, settingsRect.size.width, settingsRect.size.height)];
[_mainWindow setContentView: transitionView];
[transitionView transition: 0 toView: _tagsView];
NSMutableArray *checkedTags = [NSMutableArray array];
for (int tagIndex = 0; tagIndex < [_availableTags count]; tagIndex++)
if ([[_tagsTable cellAtRow: tagIndex + 1 column: 0] isChecked])
[checkedTags addObject: [_availableTags objectAtIndex: tagIndex]];
[ExtendedAttributes setObject: checkedTags forKey: TAGS_ATTRIBUTE atPath: _photoPath];
[transitionView transition: 2 fromView: _tagsView toView: _prefView];
[_prefTable reloadData];
[_prefTable selectRow: -1 byExtendingSelection: NO];
[transitionView release];
}
@end
@implementation PushrPhotoPrivacy
- (void)show
{
struct CGRect settingsRect = [UIHardware fullScreenApplicationContentRect];
settingsRect.origin.x = 0.0f; // */ settingsRect.size.width;
settingsRect.origin.y = 0.0f;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
_privacyView = [[UIView alloc] initWithFrame: settingsRect];
_navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, settingsRect.size.width, 44.0f)];
[_navBar setBarStyle: 1];
[_navBar setDelegate: self];
[_navBar showLeftButton: nil withStyle: 0 rightButton: @"Done" withStyle: 0];
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle: @"Privacy"];
[_navBar pushNavigationItem: title];
[title release];
[_privacyView addSubview: _navBar];
_privacyTable = [[UIPreferencesTable alloc] initWithFrame: CGRectMake(0.0f, 44.0f, settingsRect.size.width, settingsRect.size.height - 44.0f)];
[_privacyTable setDataSource: self];
[_privacyTable setDelegate: self];
[_privacyTable reloadData];
[_privacyView addSubview: _privacyTable];
UITransitionView *transitionView = [[UITransitionView alloc] initWithFrame: settingsRect];
[_mainWindow setContentView: transitionView];
[transitionView transition: 0 toView: _prefView];
[transitionView transition: 1 fromView: _prefView toView: _privacyView];
[transitionView release];
}
- (id)initFromWindow: (UIWindow *)window withPushr: (MobilePushr *)pushr withView: (UIView *)view withTable: (UIPreferencesTable *)table atPath: (NSString *)path
{
if (![super init])
return nil;
_photoPath = [path retain];
_pushr = [pushr retain];
_mainWindow = window;
_prefView = view;
_prefTable = table;
_availablePrivacy = [[NSArray arrayWithObjects: @"Private", @"Friends", @"Family", @"Public", nil] retain];
[self show];
return self;
}
- (void)dealloc
{
[_photoPath release];
[_availablePrivacy release];
[_navBar release];
[_prefView release];
[_prefTable release];
[_privacyTable release];
[_privacyView release];
[_mainWindow release];
[_pushr release];
[super dealloc];
}
#pragma mark PushrGlobalPrivacy delegates
- (int)numberOfGroupsInPreferencesTable: (id)preferencesTable
{
return 1;
}
- (int)preferencesTable: (UIPreferencesTable *)preferencesTable numberOfRowsInGroup: (int)group
{
return [_availablePrivacy count];
}
- (id)preferencesTable: (UIPreferencesTable *)preferencesTable titleForGroup: (int)group
{
return @"Default privacy for photos";
}
- (float)preferencesTable: (id)preferencesTable heightForRow:(int)row inGroup: (int)group withProposedHeight: (float)proposedHeight
{
return 48.0f;
}
- (BOOL)table: (id)table shouldIndentRow: (int)row
{
if (row == 1 || row == 2)
return YES;
return NO;
}
- (id)preferencesTable: (id)preferencesTable cellForRow: (int)row inGroup: (int)group
{
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
UIPreferencesTableCell *thisCell = [[UIPreferencesTableCell alloc] initWithFrame: CGRectMake(0.0f, 0.0f, rect.size.width, 48.0f)];
// Ugly, ugly hack. If shouldIndentRow just worked properly this would be unnecessary.
if (row == 1 || row == 2)
[thisCell setTitle: [NSString stringWithFormat: @" %@", [_availablePrivacy objectAtIndex: row]]];
else
[thisCell setTitle: [_availablePrivacy objectAtIndex: row]];
if ([[ExtendedAttributes allKeysAtPath: _photoPath] containsObject: PRIVACY_ATTRIBUTE])
[thisCell setChecked: [[ExtendedAttributes objectForKey: PRIVACY_ATTRIBUTE atPath: _photoPath] containsObject: [_availablePrivacy objectAtIndex: row]]];
else
[thisCell setChecked: [[defaults arrayForKey: PRIVACY_ATTRIBUTE] containsObject: [_availablePrivacy objectAtIndex: row]]];
return [thisCell autorelease];
}
/*
* This is a little tricky, it turns out! There are invalid combinations of privacy settings -
* for example, 'Friends' + 'Public' simply wouldn't make sense.
* This code allows the user to toggle friends/family rows, but prevents invalid combinations.
*/
- (void)tableRowSelected: (NSNotification *)notification
{
id row = [_privacyTable cellAtRow: [_privacyTable selectedRow] column: 0];
switch ([_privacyTable selectedRow]) {
case 1:
case 2:
case 3: {
[row setChecked: ![row isChecked]];
[[_privacyTable cellAtRow: 1 column: 0] setChecked: YES];
[[_privacyTable cellAtRow: 4 column: 0] setChecked: NO];
break;
}
case 4: {
for (int currentRow = 1; currentRow < 4; currentRow++) {
[[_privacyTable cellAtRow: currentRow column: 0] setChecked: NO];
}
[row setChecked: YES];
}
}
}
- (void)navigationBar: (UINavigationBar *)navBar buttonClicked: (int)button
{
struct CGRect settingsRect = [UIHardware fullScreenApplicationContentRect];
UITransitionView *transitionView = [[UITransitionView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, settingsRect.size.width, settingsRect.size.height)];
[_mainWindow setContentView: transitionView];
[transitionView transition: 0 toView: _privacyView];
NSMutableArray *checkedPrivacySettings = [NSMutableArray array];
for (int settingIndex = 0; settingIndex < [_availablePrivacy count]; settingIndex++)
if ([[_privacyTable cellAtRow: settingIndex + 1 column: 0] isChecked])
[checkedPrivacySettings addObject: [_availablePrivacy objectAtIndex: settingIndex]];
[ExtendedAttributes setObject: checkedPrivacySettings forKey: PRIVACY_ATTRIBUTE atPath: _photoPath];
[transitionView transition: 2 fromView: _privacyView toView: _prefView];
[_prefTable reloadData];
[_prefTable selectRow: -1 byExtendingSelection: NO];
[transitionView release];
}
@end
@implementation PushrPhotoProperties
- (id)initFromWindow: (UIWindow *)window withPushr: (MobilePushr *)pushr forPhoto: (NSString *)photo
{
if (![super init])
return nil;
_photoPath = [photo retain];
_pushr = [pushr retain];
_mainWindow = window;
[self show];
return self;
}
- (void)dealloc
{
[_photoPath release];
[_navBar release];
[_prefView release];
[_prefTable release];
[_photoView release];
[_mainWindow release];
[_pushr release];
[super dealloc];
}
- (void)show
{
struct CGRect settingsRect = [UIHardware fullScreenApplicationContentRect];
settingsRect.origin.x = 0.0f; // */ settingsRect.size.width;
settingsRect.origin.y = 0.0f;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
_prefView = [[UIView alloc] initWithFrame: settingsRect];
UITransitionView *transitionView = [[UITransitionView alloc] initWithFrame: settingsRect];
_navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, settingsRect.size.width, 44.0f)];
[_navBar setBarStyle: 1];
[_navBar setDelegate: self];
[_navBar showLeftButton: nil withStyle: 0 rightButton: @"Done" withStyle: 1];
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle: @"Properties"];
[_navBar pushNavigationItem: title];
[title release];
[_prefView addSubview: _navBar];
_prefTable = [[UIPreferencesTable alloc] initWithFrame: CGRectMake(0.0f, 44.0f, settingsRect.size.width, settingsRect.size.height - 44.0f)];
[_prefTable setDataSource: self];
[_prefTable setDelegate: self];
[_prefTable reloadData];
[_prefView addSubview: _prefTable];
_photoView = [[_mainWindow contentView] retain];
// This doesn't seem like the right way to do this but it seems to work...
[_mainWindow setContentView: transitionView];
[transitionView transition: 0 toView: _photoView];
[transitionView transition: 1 fromView: _photoView toView: _prefView];
[transitionView release];
}
#pragma mark PushrSettings delegates
- (void)navigationBar: (UINavigationBar *)navBar buttonClicked: (int)button
{
struct CGRect settingsRect = [UIHardware fullScreenApplicationContentRect];
UITransitionView *transitionView = [[UITransitionView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, settingsRect.size.width, settingsRect.size.height)];
[_mainWindow setContentView: transitionView];
[transitionView transition: 0 toView: _prefView];
id cell = [_prefTable cellAtRow: 1 column: 0];
if ([[cell value] length] > 0)
[ExtendedAttributes setString: [cell value] forKey: NAME_ATTRIBUTE atPath: _photoPath];
cell = [_prefTable cellAtRow: 2 column: 0];
if ([[cell value] length] > 0)
[ExtendedAttributes setString: [cell value] forKey: DESCRIPTION_ATTRIBUTE atPath: _photoPath];
switch (button) {
default: {
[transitionView transition: 2 fromView: _prefView toView: _photoView];
}
}
[transitionView release];
}
- (int)numberOfGroupsInPreferencesTable:(id)preferencesTable { return 1; }
- (int)preferencesTable: (UIPreferencesTable *)preferencesTable numberOfRowsInGroup: (int)group
{
switch (group) {
default: {
return 4;
}
}
}
- (id)preferencesTable: (UIPreferencesTable *)preferencesTable cellForRow: (int)row inGroup: (int)group
{
if (group > 0)
return nil;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
switch (row) {
case 0: {
id nameCell = [[UIPreferencesTextTableCell alloc] initWithFrame: CGRectMake(0.0f, 0.0f, rect.size.width, 48.0f)];
[nameCell setTitle: @"Name"];
if ([[ExtendedAttributes allKeysAtPath: _photoPath] containsObject: NAME_ATTRIBUTE])
[nameCell setValue: [ExtendedAttributes stringForKey: NAME_ATTRIBUTE atPath: _photoPath]];
else
[nameCell setPlaceHolderValue: [_photoPath lastPathComponent]];
return [nameCell autorelease];
}
case 1: {
id descCell = [[UIPreferencesTextTableCell alloc] initWithFrame: CGRectMake(0.0f, 0.0f, rect.size.width, 48.0f)];
[descCell setTitle: @"Description"];
if ([[ExtendedAttributes allKeysAtPath: _photoPath] containsObject: DESCRIPTION_ATTRIBUTE])
[descCell setValue: [ExtendedAttributes stringForKey: DESCRIPTION_ATTRIBUTE atPath: _photoPath]];
else
[descCell setPlaceHolderValue: @"Optional description"];
return [descCell autorelease];
}
case 2: {
id tagsCell = [[UIPreferencesTableCell alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
[tagsCell setTitle: @"Tags"];
if ([[ExtendedAttributes allKeysAtPath: _photoPath] containsObject: TAGS_ATTRIBUTE])
[tagsCell setValue: [[ExtendedAttributes objectForKey: TAGS_ATTRIBUTE atPath: _photoPath] componentsJoinedByString: @", "]];
else
[tagsCell setValue: [[defaults arrayForKey: @"defaultTags"] componentsJoinedByString: @", "]];
[tagsCell setShowDisclosure: YES];
return [tagsCell autorelease];
}
case 3: {
id privacyCell = [[UIPreferencesTableCell alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
[privacyCell setTitle: @"Privacy"];
if ([[ExtendedAttributes allKeysAtPath: _photoPath] containsObject: PRIVACY_ATTRIBUTE])
[privacyCell setValue: [[ExtendedAttributes objectForKey: PRIVACY_ATTRIBUTE atPath: _photoPath] componentsJoinedByString: @" + "]];
else
[privacyCell setValue: [[defaults arrayForKey: @"defaultPrivacy"] componentsJoinedByString: @" + "]];
[privacyCell setShowDisclosure: YES];
return [privacyCell autorelease];
}
default:
return nil;
}
}
- (id)preferencesTable: (UIPreferencesTable *)preferencesTable titleForGroup: (int)group
{
return [NSString stringWithFormat: @"Properties for photo %@", [_photoPath lastPathComponent]];
}
- (float)preferencesTable: (id)preferencesTable heightForRow:(int)row inGroup: (int)group withProposedHeight: (float)proposedHeight
{
return 48.0f;
}
- (void)tableRowSelected:(NSNotification *)notification
{
int i = [_prefTable selectedRow];
NSLog(@"Selected row %d", i);
id cell = [_prefTable cellAtRow: 1 column: 0];
if ([[cell value] length] > 0)
[ExtendedAttributes setString: [cell value] forKey: NAME_ATTRIBUTE atPath: _photoPath];
cell = [_prefTable cellAtRow: 2 column: 0];
if ([[cell value] length] > 0)
[ExtendedAttributes setString: [cell value] forKey: DESCRIPTION_ATTRIBUTE atPath: _photoPath];
switch (i) {
case 3: {
[[PushrPhotoTags alloc] initFromWindow: _mainWindow withPushr: _pushr withView: _prefView withTable: _prefTable atPath: _photoPath];
break;
}
case 4: {
[[PushrPhotoPrivacy alloc] initFromWindow: _mainWindow withPushr: _pushr withView: _prefView withTable: _prefTable atPath: _photoPath];
break;
}
}
}
@end
|