-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPostAdaptor.m
130 lines (109 loc) · 3.01 KB
/
PostAdaptor.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
/**
* @file PostAdaptor.m
* @brief PostAdaptor class implementation.
* @author Masayuki YAMAYA
* @date 2008-03-07
*/
#import "PostAdaptor.h"
#import "DebugLog.h"
@implementation PostAdaptor
@synthesize callback = callback_;
@synthesize privated = privated_;
@synthesize queuingEnabled = queuingEnabled_;
@synthesize extractEnabled = extractEnabled_;
@synthesize options = options_;
+ (NSString *)titleForMenuItem
{
return nil;
}
+ (BOOL)enableForMenuItem:(NSString *)postType
{
#pragma unused (postType)
return YES;
}
- (id)initWithCallback:(id<PostCallback>)callback
{
if ((self = [super init]) != nil) {
callback_ = [callback retain];
privated_ = NO;
queuingEnabled_ = NO;
extractEnabled_ = YES;
}
return self;
}
- (void)dealloc
{
[callback_ release], callback_ = nil;
[options_ release], options_ = nil;
[super dealloc];
}
- (void)callbackWith:(NSString *)response
{
if (callback_ != nil) [callback_ successed:response];
}
- (void)callbackWithError:(NSError *)error
{
if (callback_ != nil) [callback_ failedWithError:error];
}
- (void)callbackWithException:(NSException *)exception
{
if (callback_ != nil) [callback_ failedWithException:exception];
}
- (void)postLink:(Anchor *)anchor description:(NSString *)description
{
#pragma unused (anchor, description)
[self doesNotRecognizeSelector:_cmd];
}
- (void)postQuote:(NSString *)quote source:(NSString *)source
{
#pragma unused (quote, source)
[self doesNotRecognizeSelector:_cmd];
}
- (void)postPhoto:(NSString *)source caption:(NSString *)caption throughURL:(NSString *)throughURL image:(NSImage *)image
{
#pragma unused (source, caption, throughURL, image)
[self doesNotRecognizeSelector:_cmd];
}
- (void)postVideo:(NSString *)embed caption:(NSString*)caption
{
#pragma unused (embed, title, caption)
[self doesNotRecognizeSelector:_cmd];
}
- (void)postEntry:(NSDictionary *)params
{
#pragma unused (params)
[self doesNotRecognizeSelector:_cmd];
}
static SEL selectorOf(PostType postType);
SEL selectorOf(PostType postType)
{
D0([NSString stringWithPostType:postType]);
switch (postType) {
case RegularPostType: break;
case LinkPostType: return @selector(postLink:description:);
case QuotePostType: return @selector(postQuote:source:);
case PhotoPostType: return @selector(postPhoto:caption:throughURL:image:);
case ConversationPostType: break;
case VideoPostType: return @selector(postVideo:caption:);
case AudioPostType: break;
case ReblogPostType: return @selector(postEntry:);
case UndefinedPostType: break;
}
return nil;
}
- (NSInvocation *)invocationWithPostType:(PostType)postType
{
NSInvocation * invocation = nil;
SEL selector = selectorOf(postType);
if (selector != nil) {
NSMethodSignature * signature = [self.class instanceMethodSignatureForSelector:selector];
invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:self];
[invocation setSelector:selector];
}
else {
D(@"unsupported invocation's post-type=%@", [NSString stringWithPostType:postType]);
}
return invocation;
}
@end