forked from ViennaRSS/vienna-rss
/
SyncPreferences.m
108 lines (88 loc) · 2.79 KB
/
SyncPreferences.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
//
// SyncPreferences.m
// Vienna
//
// Created by Adam Hartford on 7/7/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "SyncPreferences.h"
#import "GoogleReader.h"
#import "Preferences.h"
#import "SyncMerge.h"
@implementation SyncPreferences
@synthesize syncButton, mergeButton, createButton;
-(id)init
{
return [super initWithWindowNibName:@"SyncPreferences"];
}
-(id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
// Initialization code here.
merge = [[SyncMerge alloc] init];
[merge retain];
}
return self;
}
-(void)windowWillClose:(NSNotification *)notification
{
Preferences *prefs = [Preferences standardPreferences];
[prefs setSyncGoogleReader:([syncButton state] == NSOnState)];
[prefs savePreferences];
}
-(IBAction)changeSyncGoogleReader:(id)sender
{
BOOL sync = [sender state] == NSOnState;
[[Preferences standardPreferences] setSyncGoogleReader:sync];
if (sync) {
[[GoogleReader sharedManager] authenticate];
[[GoogleReader sharedManager] loadSubscriptions:nil];
}
}
-(IBAction)mergeSubscriptions:(id)sender
{
//TOFIX
/*
modalSession = [[NSApplication sharedApplication] beginModalSessionForWindow:[merge window]];
[merge setSession:modalSession];
[merge beginMerge];
*/
}
- (IBAction)createGoogleAccount:(id)sender
{
NSURL * url = [NSURL URLWithString:@"https://www.google.com/accounts/NewAccount"];
[[NSWorkspace sharedWorkspace] openURL:url];
}
- (void)windowDidLoad
{
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleGoogleAuthFailed:) name:@"MA_Notify_GoogleAuthFailed" object:nil];
Preferences * prefs = [Preferences standardPreferences];
[syncButton setState:[prefs syncGoogleReader] ? NSOnState : NSOffState];
}
-(void)handleGoogleAuthFailed:(NSNotification *)nc
{
if ([merge running])
{
[merge close];
[[NSApplication sharedApplication] endModalSession:modalSession];
/*NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:@"Google Authentication Failed"];
[alert setInformativeText:@"Please check your Google username and password in Vienna's preferences."];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:nil contextInfo:nil];*/
}
}
-(void)dealloc
{
[syncButton release];
[mergeButton release];
[createButton release];
[merge release];
[super dealloc];
}
@end