Add code to the AppDelegate to record if a user has ever used an unstable VersionCast...
[macgdbp.git] / Source / AppDelegate.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "AppDelegate.h"
18
19 #import <Sparkle/Sparkle.h>
20
21 @implementation AppDelegate
22
23 @synthesize debugger;
24 @synthesize breakpoint;
25 @synthesize loggingController = loggingController_;
26
27 /**
28 * Initialize method that is called before all other messages. This will set the default
29 * preference values.
30 */
31 + (void)load
32 {
33 NSAutoreleasePool* pool = [NSAutoreleasePool new];
34
35 NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys:
36 [NSNumber numberWithInt:9000], @"Port",
37 [NSNumber numberWithBool:YES], @"BreakpointsWindowVisible",
38 [NSNumber numberWithBool:YES], @"InspectorWindowVisible",
39 [NSMutableArray array], @"PathReplacements",
40 [NSNumber numberWithBool:YES], @"BreakOnFirstLine",
41 [NSNumber numberWithBool:YES], @"DebuggerAttached",
42 nil
43 ];
44
45 [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
46
47 [dict release];
48
49 [pool release];
50 }
51
52 + (AppDelegate*)instance
53 {
54 return (AppDelegate*)[NSApp delegate];
55 }
56
57 - (void)applicationDidFinishLaunching:(NSNotification*)notification
58 {
59 // Record whether this user ever used the beta VersionCast feed. In the
60 // future, we will use this bit to query for unstable releases after the user
61 // has upgraded to a stable version.
62 NSString* const kUsesUnstableVersionCast = @"UnstableVersionCast";
63 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
64
65 BOOL usesUnstable = [defaults boolForKey:kUsesUnstableVersionCast];
66 NSURL* feedURL = [[SUUpdater sharedUpdater] feedURL];
67 usesUnstable = usesUnstable ||
68 [[feedURL absoluteString] rangeOfString:@"?unstable"].location != NSNotFound;
69 NSLog(@"usesUnstable = %d", usesUnstable);
70 [defaults setBool:usesUnstable forKey:kUsesUnstableVersionCast];
71 }
72
73 - (void)applicationWillTerminate:(NSNotification*)notification
74 {
75 [[NSUserDefaults standardUserDefaults] setBool:self.debugger.connection.attached
76 forKey:@"DebuggerAttached"];
77 }
78
79 /**
80 * Shows the debugger window
81 */
82 - (IBAction)showDebuggerWindow:(id)sender
83 {
84 [[debugger window] makeKeyAndOrderFront:self];
85 NSLog(@"logg %@", [loggingController_ window]);
86 }
87
88 /**
89 * Shows the breakpoints window
90 */
91 - (IBAction)showBreakpointWindow:(id)sender
92 {
93 if (![[breakpoint window] isVisible] || ![[breakpoint window] isKeyWindow])
94 [[breakpoint window] makeKeyAndOrderFront:sender];
95 else
96 [[breakpoint window] orderOut:sender];
97 }
98
99 /**
100 * Shows the preferences window. Lazily loads the PreferencesController.
101 */
102 - (IBAction)showPreferences:(id)sender
103 {
104 if (!prefs)
105 prefs = [[PreferencesController alloc] init];
106
107 [prefs showPreferencesWindow];
108 }
109
110 /**
111 * Opens the URL to the help page
112 */
113 - (IBAction)openHelpPage:(id)sender
114 {
115 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.bluestatic.org/software/macgdbp/help.php"]];
116 }
117
118 @end