forked from joshholt/QSTwitter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
QSTwitterPrefPane.m
62 lines (54 loc) · 1.61 KB
/
QSTwitterPrefPane.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
//
// QSTwitterPrefPane.m
// QSTwitter
//
// Created by Patrick Robertson on 23/03/2013.
//
//
#import "QSTwitterPrefPane.h"
#import "ConsumerKey.h"
#import "QSTwitterDefines.h"
#import "QSTwitterUtil.h"
#import "GTMOAuthAuthentication.h"
@implementation QSTwitterPrefPane
-(NSView *)loadMainView {
NSView *view = [super loadMainView];
[[QSTwitterUtil sharedInstance] setPrefPane:self];
[ind setHidden:NO];
[ind startAnimation:self];
[self updateUI];
return view;
}
-(IBAction)authenticate:(id)sender {
QSTwitterUtil *tu = [QSTwitterUtil sharedInstance];
if ([tu isSignedIn]) {
[tu signOut];
[self updateUI];
} else {
[ind setHidden:NO];
[ind startAnimation:sender];
[tu signInToCustomService];
}
}
-(void)updateCredentials:(NSDictionary *)credentials {
NSString *name = nil;
if (credentials) {
name = [NSString stringWithFormat:@"%@%@",[credentials objectForKey:@"name"],[credentials objectForKey:@"screen_name"] ? [NSString stringWithFormat:@" (@%@)",[credentials objectForKey:@"screen_name"]] : @""];
}
[usr setStringValue:(name != nil ? name : @"")];
[signInOutButton setTitle:[[QSTwitterUtil sharedInstance] isSignedIn] ? @"Sign Out" :@"Sign In"];
[ind setHidden:YES];
}
-(void)updateUI {
QSTwitterUtil *tu = [QSTwitterUtil sharedInstance];
if ([tu isSignedIn]) {
[usr setStringValue:@"Loading..."];
[tu getCredentials];
} else {
// signed out
[usr setStringValue:@"-Not signed in-"];
[signInOutButton setTitle:@"Sign In"];
[ind setHidden:YES];
}
}
@end