-
Notifications
You must be signed in to change notification settings - Fork 52
/
IMBFlickrNode.m
632 lines (512 loc) · 22.8 KB
/
IMBFlickrNode.m
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/*
iMedia Browser Framework <http://karelia.com/imedia/>
Copyright (c) 2005-2012 by Karelia Software et al.
iMedia Browser is based on code originally developed by Jason Terhorst,
further developed for Sandvox by Greg Hulands, Dan Wood, and Terrence Talbot.
The new architecture for version 2.0 was developed by Peter Baumgartner.
Contributions have also been made by Matt Gough, Martin Wennerberg and others
as indicated in source files.
The iMedia Browser Framework is licensed under the following terms:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in all or substantial portions of the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following
conditions:
Redistributions of source code must retain the original terms stated here,
including this list of conditions, the disclaimer noted below, and the
following copyright notice: Copyright (c) 2005-2012 by Karelia Software et al.
Redistributions in binary form must include, in an end-user-visible manner,
e.g., About window, Acknowledgments window, or similar, either a) the original
terms stated here, including this list of conditions, the disclaimer noted
below, and the aforementioned copyright notice, or b) the aforementioned
copyright notice and a link to karelia.com/imedia.
Neither the name of Karelia Software, nor Sandvox, nor the names of
contributors to iMedia Browser may be used to endorse or promote products
derived from the Software without prior and express written permission from
Karelia Software or individual contributors, as appropriate.
Disclaimer: THE SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH, THE
SOFTWARE OR THE USE OF, OR OTHER DEALINGS IN, THE SOFTWARE.
*/
// Author: Christoph Priebe
//----------------------------------------------------------------------------------------------------------------------
// iMedia
#import "IMBFlickrNode.h"
#import "IMBFlickrObject.h"
#import "IMBFlickrParser.h"
#import "IMBLibraryController.h"
#import "IMBLoadMoreObject.h"
#import "NSString+iMedia.h"
#import "IMBNodeViewController.h"
#import "IMBFlickrHeaderViewController.h"
//----------------------------------------------------------------------------------------------------------------------
@interface IMBFlickrNode ()
// Utilities:
+ (NSString*) identifierWithMethod: (NSInteger) method query: (NSString*) query;
@end
#pragma mark -
//----------------------------------------------------------------------------------------------------------------------
// Some additions to the iMB node useful for Flickr handling:
@implementation IMBFlickrNode
NSString* const IMBFlickrNodeProperty_License = @"license";
NSString* const IMBFlickrNodeProperty_Method = @"method";
NSString* const IMBFlickrNodeProperty_Query = @"query";
NSString* const IMBFlickrNodeProperty_SortOrder = @"sortOrder";
NSString* const IMBFlickrNodeProperty_UUID = @"uuid";
#pragma mark
#pragma mark Construction
- (id) init {
if (self = [super init]) {
self.license = IMBFlickrNodeLicense_Undefined;
self.method = IMBFlickrNodeMethod_TextSearch;
self.sortOrder = IMBFlickrNodeSortOrder_InterestingnessDesc;
}
return self;
}
- (id) copyWithZone: (NSZone*) inZone {
IMBFlickrNode* copy = [super copyWithZone:inZone];
copy.customNode = self.customNode;
copy.flickrResponse = self.flickrResponse;
copy.license = self.license;
copy.method = self.method;
copy.query = self.query;
copy.page = self.page;
copy.sortOrder = self.sortOrder;
return copy;
}
+ (IMBFlickrNode*) genericFlickrNodeForRoot: (IMBFlickrNode*) root
parser: (IMBParser*) parser {
IMBFlickrNode* node = [[[IMBFlickrNode alloc] init] autorelease];
node.attributes = [NSMutableDictionary dictionary];
node.leaf = YES;
//node.parentNode = root;
node.parser = parser;
// Leaving subNodes and objects nil, will trigger a populateNode:options:error:
// as soon as the root node is opened.
node.subNodes = nil;
node.objects = nil;
node.badgeTypeNormal = kIMBBadgeTypeReload;
node.badgeTarget = self;
node.badgeSelector = @selector (reloadNode:);
return node;
}
+ (IMBFlickrNode*) flickrNodeForInterestingPhotosForRoot: (IMBFlickrNode*) root
parser: (IMBParser*) parser {
IMBFlickrNode* node = [self genericFlickrNodeForRoot:root parser:parser];
node.icon = [NSImage imageNamed:NSImageNameFolderSmart];
[node.icon setScalesWhenResized:YES];
[node.icon setSize:NSMakeSize(16.0, 16.0)];
node.identifier = [self identifierWithMethod:IMBFlickrNodeMethod_MostInteresting query:@"30"];
node.mediaSource = node.identifier;
node.method = IMBFlickrNodeMethod_MostInteresting;
node.name = NSLocalizedStringWithDefaultValue(@"IMBFlickrParser.node.mostinteresting",nil,IMBBundle(),@"Most Interesting",@"Flickr parser standard node name.");
node.sortOrder = IMBFlickrNodeSortOrder_DatePostedDesc;
return node;
}
+ (IMBFlickrNode*) flickrNodeForRecentPhotosForRoot: (IMBFlickrNode*) root
parser: (IMBParser*) parser {
IMBFlickrNode* node = [self genericFlickrNodeForRoot:root parser:parser];
node.icon = [NSImage imageNamed:NSImageNameFolderSmart];
[node.icon setScalesWhenResized:YES];
[node.icon setSize:NSMakeSize(16.0, 16.0)];
node.identifier = [self identifierWithMethod:IMBFlickrNodeMethod_Recent query:@"30"];
node.mediaSource = node.identifier;
node.method = IMBFlickrNodeMethod_Recent;
node.name = NSLocalizedStringWithDefaultValue(@"IMBFlickrParser.node.recent",nil,IMBBundle(),@"Recent",@"Flickr parser standard node name.");
node.sortOrder = IMBFlickrNodeSortOrder_DatePostedDesc;
return node;
}
+ (IMBFlickrNode*) flickrNodeForRoot: (IMBFlickrNode*) root
parser: (IMBParser*) parser {
// iMB general...
IMBFlickrNode* node = [[[IMBFlickrNode alloc] init] autorelease];
//node.parentNode = root;
node.parser = parser;
node.leaf = YES;
node.attributes = [NSMutableDictionary dictionary];
// Leaving subNodes and objects nil, will trigger a populateNode:options:error:
// as soon as the root node is opened.
node.subNodes = nil;
node.objects = nil;
node.badgeTypeNormal = kIMBBadgeTypeReload;
node.badgeTarget = self;
node.badgeSelector = @selector (reloadNode:);
return node;
}
+ (IMBFlickrNode*) flickrNodeFromDictionary: (NSDictionary*) dictionary
rootNode: (IMBFlickrNode*) root
parser: (IMBParser*) parser {
IMBFlickrNode* node = [IMBFlickrNode flickrNodeForRoot:root parser:parser];
[node readPropertiesFromDictionary:dictionary];
return node;
}
+ (void) sendSelectNodeNotificationForDict:(NSDictionary*) dict {
if (dict) {
NSString* identifier = [IMBFlickrNode identifierWithQueryParams:dict];
[IMBNodeViewController selectNodeWithIdentifier:identifier];
}
}
- (void) dealloc {
IMBRelease (_query);
IMBRelease (_flickrResponse);
[super dealloc];
}
#pragma mark
#pragma mark Flickr Response Handling
- (void) clearFlickrResponse {
self.flickrResponse = nil;
}
- (BOOL) hasFlickrResponse {
return _flickrResponse != nil;
}
// What about original size?
- (NSString *)flickrSizeFromFlickrSizeSpecifier:(IMBFlickrSizeSpecifier)flickrSizeSpecifier
{
NSAssert(flickrSizeSpecifier >= kIMBFlickrSizeSpecifierOriginal && flickrSizeSpecifier <= kIMBFlickrSizeSpecifierLarge, @"Illegal size for flickr");
NSString *sizeLookup[] = { @"o", OFFlickrSmallSize, OFFlickrMediumSize, OFFlickrLargeSize };
// Note: medium is nil, so we can't put in a dictionary. Original not specified in objective-flickr
return sizeLookup[flickrSizeSpecifier];
}
- (NSURL *)imageURLForDesiredSize:(IMBFlickrSizeSpecifier)size fromPhotoDict:(NSDictionary *)photoDict context:(OFFlickrAPIContext*) context;
{
NSURL* imageURL = nil;
if (!imageURL && kIMBFlickrSizeSpecifierOriginal == size)
{
if ([photoDict objectForKey:@"url_o"])
{
imageURL = [NSURL URLWithString:[photoDict objectForKey:@"url_o"]];
}
else
{
size = kIMBFlickrSizeSpecifierLarge; // downgrade to requesting large if no original
}
}
if (!imageURL && kIMBFlickrSizeSpecifierLarge == size)
{
if ([photoDict objectForKey:@"url_l"])
{
imageURL = [NSURL URLWithString:[photoDict objectForKey:@"url_l"]];
}
else
{
size = kIMBFlickrSizeSpecifierMedium; // downgrade to requesting medium if no large
}
}
if (!imageURL && kIMBFlickrSizeSpecifierMedium == size)
{
if ([photoDict objectForKey:@"url_m"])
{
imageURL = [NSURL URLWithString:[photoDict objectForKey:@"url_m"]];
}
else
{
size = kIMBFlickrSizeSpecifierSmall; // downgrade to requesting medium if no large
}
}
if (!imageURL && kIMBFlickrSizeSpecifierSmall == size)
{
if ([photoDict objectForKey:@"url_s"])
{
imageURL = [NSURL URLWithString:[photoDict objectForKey:@"url_s"]];
}
}
// Fallback. Really we should have it by now! But search for Edward & Bella Icon has no medium size!
if (!imageURL)
{
// build up URL programatically
NSString *flickrSize = [self flickrSizeFromFlickrSizeSpecifier:size];
imageURL = [context photoSourceURLFromDictionary:photoDict size:flickrSize];
}
return imageURL;
}
- (NSArray*) extractPhotosFromFlickrResponse: (NSDictionary*) response context: (OFFlickrAPIContext*) context {
IMBFlickrParser* parser = (IMBFlickrParser*) self.parser;
NSArray* photos = [response valueForKeyPath:@"photos.photo"];
NSMutableArray* objects = [NSMutableArray arrayWithCapacity:photos.count];
self.displayedObjectCount = 0;
for (NSDictionary* photoDict in photos) {
IMBFlickrObject* obj = [[IMBFlickrObject alloc] init];
// Only store a location if we are allowed to download
BOOL canDownload = [[photoDict objectForKey:@"can_download"] boolValue];
if (canDownload)
{
obj.location = [self imageURLForDesiredSize:parser.desiredSize fromPhotoDict:photoDict context:context];
}
obj.shouldDisableTitle = !canDownload;
obj.name = [photoDict objectForKey:@"title"];
// A lot of the metadata comes from the "extras" key we request
NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
[metadata addEntriesFromDictionary:photoDict]; // give metaData the whole thing!
NSURL *webPageURL = [context photoWebPageURLFromDictionary:photoDict];
[metadata setObject:[webPageURL absoluteString] forKey:@"webPageURL"];
NSURL *quickLookURL = [self imageURLForDesiredSize:kIMBFlickrSizeSpecifierMedium fromPhotoDict:photoDict context:context];
[metadata setObject:[quickLookURL absoluteString] forKey:@"quickLookURL"];
// But give it a better 'description' without the nested item
NSString *descHTML = [[photoDict objectForKey:@"description"] objectForKey:@"_text"];
if (descHTML)
{
NSData *HTMLData = [descHTML dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:NSUTF8StringEncoding] forKey:NSCharacterEncodingDocumentOption];
NSAttributedString *descAttributed = [[[NSAttributedString alloc] initWithHTML:HTMLData options:options documentAttributes:nil] autorelease];
if (descAttributed)
{
NSString *desc = [descAttributed string];
if (nil != desc) [metadata setObject:desc forKey:@"comment"];
}
#ifdef DEBUG
else NSLog(@"Unable to make attributed string out of %@", descHTML);
#endif
}
NSString *can_download = [photoDict objectForKey:@"can_download"];
NSString *license = [photoDict objectForKey:@"license"];
NSString *ownerName = [photoDict objectForKey:@"ownername"];
NSString *photoID = [photoDict objectForKey:@"id"];
id width = [metadata objectForKey:@"width_o"];
if (width == nil) width = [metadata objectForKey:@"width_l"];
if (width == nil) width = [metadata objectForKey:@"width_m"];
if (width == nil) width = [metadata objectForKey:@"width_s"];
id height = [metadata objectForKey:@"height_o"];
if (height == nil) height = [metadata objectForKey:@"height_l"];
if (height == nil) height = [metadata objectForKey:@"height_m"];
if (height == nil) height = [metadata objectForKey:@"height_s"];
if (nil != can_download) [metadata setObject:can_download forKey:@"can_download"];
if (nil != license) [metadata setObject:license forKey:@"license"];
if (nil != ownerName) [metadata setObject:ownerName forKey:@"ownername"];
if (nil != photoID) [metadata setObject:photoID forKey:@"id"];
if (nil != width) [metadata setObject:width forKey:@"width"];
if (nil != height) [metadata setObject:height forKey:@"height"];
obj.preliminaryMetadata = [NSDictionary dictionaryWithDictionary:metadata];
obj.parser = self.parser;
NSURL* thumbnailURL = [context photoSourceURLFromDictionary:photoDict size:OFFlickrThumbnailSize];
obj.imageLocation = thumbnailURL;
obj.imageRepresentationType = IKImageBrowserCGImageRepresentationType;
obj.imageRepresentation = nil; // Build lazily when needed
[objects addObject:obj];
[obj release];
self.displayedObjectCount++;
}
return objects;
}
- (void) processResponseForContext: (OFFlickrAPIContext*) context {
if (!self.hasFlickrResponse) return;
// TODO: Instead of inserting the "load more" object at the end of the
// array, we should probably associate a sort descriptor with the image view.
NSMutableArray* oldImages = [self.objects mutableCopy];
IMBLoadMoreObject* loadMoreObject = nil;
for (id object in oldImages) {
if ([object isKindOfClass:[IMBLoadMoreObject class]]) {
loadMoreObject = object;
break;
}
}
if (loadMoreObject) {
[oldImages removeObject:loadMoreObject];
}
NSMutableArray* newImages = [[self extractPhotosFromFlickrResponse:[self flickrResponse] context:context] mutableCopy];
[newImages removeObjectsInArray:oldImages]; // ensure that we have no doubles
if ( [oldImages count] ) {
[newImages insertObjects:oldImages atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, oldImages.count)]];
}
// add 'load more' button...
IMBLoadMoreObject* loadMoreButton = ((IMBFlickrParser*) self.parser).loadMoreButton;
loadMoreButton.nodeIdentifier = self.identifier;
[newImages addObject:loadMoreButton];
self.objects = newImages;
[newImages release];
[oldImages release];
}
#pragma mark
#pragma mark Properties
@synthesize customNode = _customNode;
@synthesize flickrResponse = _flickrResponse;
@synthesize license = _license;
@synthesize method = _method;
@synthesize page = _page;
@synthesize query = _query;
@synthesize sortOrder = _sortOrder;
#pragma mark
#pragma mark Utilities
/// License kinds and ids as found under
/// http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
typedef enum {
IMBFlickrNodeFlickrLicenseID_Undefined = 0,
IMBFlickrNodeFlickrLicenseID_AttributionNonCommercialShareAlike = 1,
IMBFlickrNodeFlickrLicenseID_AttributionNonCommercial = 2,
IMBFlickrNodeFlickrLicenseID_AttributionNonCommercialNoDerivs = 3,
IMBFlickrNodeFlickrLicenseID_Attribution = 4,
IMBFlickrNodeFlickrLicenseID_AttributionShareAlike = 5,
IMBFlickrNodeFlickrLicenseID_AttributionNoDerivs = 6,
IMBFlickrNodeFlickrLicenseID_NoKnownCopyrightRestrictions = 7
} IMBFlickrNodeFlickrLicenseID;
/// Make the properties of the receiver into a dictionary with keys and values
/// that can be directly passed to the Flick method call.
/// Have a look at http://www.flickr.com/services/api/flickr.photos.search.html
/// for details and arguments of a search query.
- (NSDictionary*) argumentsForFlickrCall {
NSMutableDictionary* arguments = [NSMutableDictionary dictionary];
// build query arguments based on method...
if (self.query) {
if (self.method == IMBFlickrNodeMethod_TagSearch) {
[arguments setObject:self.query forKey:@"tags"];
[arguments setObject:@"all" forKey:@"tag_mode"];
} else if (self.method == IMBFlickrNodeMethod_TextSearch) {
[arguments setObject:self.query forKey:@"text"];
}
}
// translate our user kinds into Flickr license kind ids...
if (self.license == IMBFlickrNodeLicense_CreativeCommons) {
[arguments setObject:[NSString stringWithFormat:@"%d", IMBFlickrNodeFlickrLicenseID_Attribution] forKey:@"license"];
} else if (self.license == IMBFlickrNodeLicense_DerivativeWorks) {
[arguments setObject:[NSString stringWithFormat:@"%d", self.license] forKey:@"license"];
} else if (self.license == IMBFlickrNodeLicense_CommercialUse) {
[arguments setObject:[NSString stringWithFormat:@"%d", IMBFlickrNodeFlickrLicenseID_NoKnownCopyrightRestrictions] forKey:@"license"];
}
// determine sort order...
NSString* sortOrder = nil;
if (self.sortOrder == IMBFlickrNodeSortOrder_DatePostedDesc) {
sortOrder = @"date-posted-desc";
} else if (self.sortOrder == IMBFlickrNodeSortOrder_DatePostedAsc) {
sortOrder = @"date-posted-asc";
} else if (self.sortOrder == IMBFlickrNodeSortOrder_DateTakenAsc) {
sortOrder = @"date-taken-asc";
} else if (self.sortOrder == IMBFlickrNodeSortOrder_DateTakenDesc) {
sortOrder = @"date-taken-desc";
} else if (self.sortOrder == IMBFlickrNodeSortOrder_InterestingnessDesc) {
sortOrder = @"interestingness-desc";
} else if (self.sortOrder == IMBFlickrNodeSortOrder_InterestingnessAsc) {
sortOrder = @"interestingness-asc";
} else if (self.sortOrder == IMBFlickrNodeSortOrder_Relevance) {
sortOrder = @"relevance";
}
if (sortOrder) {
[arguments setObject:sortOrder forKey:@"sort"];
}
// limit the search to a specific number of items...
[arguments setObject:@"30" forKey:@"per_page"];
// We are only doing photos. Maybe later we want to do videos?
[arguments setObject:@"photos" forKey:@"media"];
// Extra metadata needed
// http://www.flickr.com/services/api/flickr.photos.search.html
[arguments setObject:@"description,license,owner_name,original_format,geo,tags,o_dims,url_o,url_l,url_m,url_s,usage" forKey:@"extras"];
// Useful keys we can get from this:
// description -> array with ... description
// original_format -> originalformat, orignalsecret
// url_o,l, m, s ... URL to get the various sizes. (url_l is not really documented, but works if needed.)
// usage: can_download (& others)
// Example of a photo that can't be downloaded: THE DECEIVING title.
// load the specified page...
NSString* page = [NSString stringWithFormat:@"%ld", (long)(self.page + 1)];
[arguments setObject:page forKey:@"page"];
return arguments;
}
// From http://gist.github.com/101674
+ (NSString *)base58EncodedValue:(long long)num {
NSString *alphabet = @"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
NSInteger baseCount = [alphabet length];
NSString *encoded = @"";
while(num >= baseCount) {
double div = num/baseCount;
long long mod = (num - (baseCount * (long long)div));
NSString *alphabetChar = [alphabet substringWithRange: NSMakeRange(mod, 1)];
encoded = [NSString stringWithFormat: @"%@%@", alphabetChar, encoded];
num = (long long)div;
}
if(num) {
encoded = [NSString stringWithFormat: @"%@%@", [alphabet substringWithRange: NSMakeRange(num, 1)], encoded];
}
return encoded;
}
+ (NSString*) descriptionOfLicense: (NSInteger) aLicenseNumber {
NSString* result = nil;
switch (aLicenseNumber)
{
case IMBFlickrNodeFlickrLicenseID_AttributionNonCommercialShareAlike:
result = @"Attribution-NonCommercial-ShareAlike License";
break;
case IMBFlickrNodeFlickrLicenseID_AttributionNonCommercial:
result = @"Attribution-NonCommercial License";
break;
case IMBFlickrNodeFlickrLicenseID_AttributionNonCommercialNoDerivs:
result = @"Attribution-NonCommercial-NoDerivs License";
break;
case IMBFlickrNodeFlickrLicenseID_Attribution:
result = @"Attribution License";
break;
case IMBFlickrNodeFlickrLicenseID_AttributionShareAlike:
result = @"Attribution-ShareAlike License";
break;
case IMBFlickrNodeFlickrLicenseID_AttributionNoDerivs:
result = @"Attribution-NoDerivs License";
break;
}
if (result)
{
result = [@"Creative Commons: " stringByAppendingString:result];
}
return result;
}
/// We construct here something like:
/// IMBFlickrParser://flickr.photos.search/tag/macintosh,apple
///
/// TOOD: Maybe it's a better idea to just go with
/// [NSString uuid]
/// and create something like:
/// IMBFlickrParser://12345678-12345-12345-12345678
+ (NSString*) identifierWithMethod: (NSInteger) method query: (NSString*) query {
#if 0
// EXPERIMENTAL...
NSString* parserClassName = NSStringFromClass ([IMBFlickrParser class]);
return [NSString stringWithFormat:@"%@:/%@", parserClassName, [NSString uuid]];
// ...EXPERIMENTAL
#else
NSString* flickrMethod = [IMBFlickrParser flickrMethodForMethodCode:method];
if (method == IMBFlickrNodeMethod_TagSearch) {
flickrMethod = [flickrMethod stringByAppendingString:@"/tag"];
} else if (method == IMBFlickrNodeMethod_TextSearch) {
flickrMethod = [flickrMethod stringByAppendingString:@"/text"];
} else if (method == IMBFlickrNodeMethod_Recent) {
flickrMethod = [flickrMethod stringByAppendingString:@"/recent"];
} else if (method == IMBFlickrNodeMethod_MostInteresting) {
flickrMethod = [flickrMethod stringByAppendingString:@"/interesting"];
}
NSString* albumPath = [NSString stringWithFormat:@"/%@/%@", flickrMethod, query];
NSString* parserClassName = NSStringFromClass ([IMBFlickrParser class]);
return [NSString stringWithFormat:@"%@:/%@", parserClassName, albumPath];
#endif
}
+ (NSString*) identifierWithQueryParams: (NSDictionary*) inQueryParams {
NSString* parserClassName = NSStringFromClass ([IMBFlickrParser class]);
NSString* uuid = [inQueryParams objectForKey:IMBFlickrNodeProperty_UUID];
if (uuid == nil) uuid = [inQueryParams objectForKey:IMBFlickrNodeProperty_Query];
return [NSString stringWithFormat:@"%@:/%@",parserClassName,uuid];
}
- (void) readPropertiesFromDictionary: (NSDictionary*) dictionary {
if (!dictionary) return;
// extract node data from preferences dictionary...
NSInteger method = [[dictionary objectForKey:IMBFlickrNodeProperty_Method] intValue];
NSString* query = [dictionary objectForKey:IMBFlickrNodeProperty_Query];
NSString* title = query;
if (!query || !title) {
NSLog (@"Invalid Flickr parser user node dictionary.");
return;
}
// Flickr stuff...
self.customNode = YES;
self.icon = [NSImage imageNamed:NSImageNameFolderSmart];
[self.icon setScalesWhenResized:YES];
[self.icon setSize:NSMakeSize(16.0, 16.0)];
self.identifier = [IMBFlickrNode identifierWithQueryParams:dictionary];
self.license = [[dictionary objectForKey:IMBFlickrNodeProperty_License] intValue];
self.mediaSource = self.identifier;
self.method = method;
self.name = title;
self.query = query;
self.sortOrder = [[dictionary objectForKey:IMBFlickrNodeProperty_SortOrder] intValue];
}
@end