Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / LNAboutBoxController.m
blob56e2fd17fb567afbbb31854bceaac82c7a563bba
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
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 License,
7  * 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 even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 //$Id$
19 #import "AISoundController.h"
20 #import "LNAboutBoxController.h"
21 #import <AIUtilities/AIEventAdditions.h>
22 #import <AIUtilities/AIWindowAdditions.h>
23 #import <AIUtilities/AIApplicationAdditions.h>
24 #import <AIUtilities/AIDateFormatterAdditions.h>
26 #define ABOUT_BOX_NIB           @"AboutBox"
27 #define ADIUM_SITE_LINK         AILocalizedString(@"http://www.adiumx.com/","Adium homepage. Only localize if a translated version of the page exists.")
29 #define ABOUT_SCROLL_FPS        30.0
30 #define ABOUT_SCROLL_RATE       1.0
32 @interface LNAboutBoxController (PRIVATE)
33 - (id)initWithWindowNibName:(NSString *)windowNibName;
34 - (NSString *)_applicationVersion;
35 - (NSString *)_applicationDate;
36 @end
38 @implementation LNAboutBoxController
40 //Returns the shared about box instance
41 LNAboutBoxController *sharedAboutBoxInstance = nil;
42 + (LNAboutBoxController *)aboutBoxController
44     if (!sharedAboutBoxInstance) {
45         sharedAboutBoxInstance = [[self alloc] initWithWindowNibName:ABOUT_BOX_NIB];
46     }
47     return sharedAboutBoxInstance;
50 //Init
51 - (id)initWithWindowNibName:(NSString *)windowNibName
53     if ((self = [super initWithWindowNibName:windowNibName])) {
54                 numberOfDuckClicks = -1;
55         }
57         return self;
60 //Prepare the about box window
61 - (void)windowDidLoad
63     NSAttributedString          *creditsString;
64     
65     //Credits
66     creditsString = [[[NSAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]
67                                                                                    documentAttributes:nil] autorelease];
68     [[textView_credits textStorage] setAttributedString:creditsString];
69     [[textView_credits enclosingScrollView] setLineScroll:0.0];
70     [[textView_credits enclosingScrollView] setPageScroll:0.0];
71         [[textView_credits enclosingScrollView] setVerticalScroller:nil];
72     
73     //Start scrolling    
74     scrollLocation = 0; 
75     scrollRate = ABOUT_SCROLL_RATE;
76     maxScroll = [[textView_credits textStorage] size].height - [[textView_credits enclosingScrollView] documentVisibleRect].size.height;
77     scrollTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0/ABOUT_SCROLL_FPS)
78                                                                                                         target:self
79                                                                                                   selector:@selector(scrollTimer:)
80                                                                                                   userInfo:nil
81                                                                                                    repeats:YES] retain];
82         eventLoopScrollTimer = [[NSTimer timerWithTimeInterval:(1.0/ABOUT_SCROLL_FPS)
83                                                                                                    target:self
84                                                                                                  selector:@selector(scrollTimer:)
85                                                                                                  userInfo:nil
86                                                                                                   repeats:YES] retain];
87     [[NSRunLoop currentRunLoop] addTimer:eventLoopScrollTimer forMode:NSEventTrackingRunLoopMode];
88         
89     //Setup the build date / version
90     [button_buildButton setTitle:[self _applicationDate]];
91     [textField_version setStringValue:[self _applicationVersion]];
92     
93         //Set the localized values
94         [button_homepage setLocalizedString:AILocalizedString(@"Adium Homepage",nil)];
95         [button_license setLocalizedString:AILocalizedString(@"License",nil)];
97     [[self window] betterCenter];
100 //Cleanup as the window is closing
101 - (void)windowWillClose:(id)sender
103         [super windowWillClose:sender];
104         
105     [sharedAboutBoxInstance autorelease]; sharedAboutBoxInstance = nil;
106     [scrollTimer invalidate]; [scrollTimer release]; scrollTimer = nil;
107         [eventLoopScrollTimer invalidate]; [eventLoopScrollTimer release]; eventLoopScrollTimer = nil;
110 //Visit the Adium homepage
111 - (IBAction)visitHomepage:(id)sender
113     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.adiumx.com"]];
117 //Scrolling Credits ----------------------------------------------------------------------------------------------------
118 #pragma mark Scrolling Credits
119 //Scroll the credits
120 - (void)scrollTimer:(NSTimer *)scrollTimer
121 {    
122         scrollLocation += scrollRate;
123         
124         if (scrollLocation > maxScroll) scrollLocation = 0;    
125         if (scrollLocation < 0) scrollLocation = maxScroll;
126         
127         [textView_credits scrollPoint:NSMakePoint(0, scrollLocation)];
130 //Receive the flags changed event for reversing the scroll direction via option
131 - (void)flagsChanged:(NSEvent *)theEvent
133     if ([theEvent optionKey]) {
134         scrollRate = -ABOUT_SCROLL_RATE;
135     } else if ([theEvent controlKey]) {
136         scrollRate = 0;
137     } else {
138         scrollRate = ABOUT_SCROLL_RATE;   
139     }
143 //Build Information ----------------------------------------------------------------------------------------------------
144 #pragma mark Build Information
145 //Toggle build date/number display
146 - (IBAction)buildFieldClicked:(id)sender
148     if ((++numberOfBuildFieldClicks) % 2 == 0) {
149         [button_buildButton setTitle:[self _applicationDate]];
150     } else {
151                 [button_buildButton setTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"AIBuildIdentifier"]];
152     }
155 //Returns the current version of Adium
156 - (NSString *)_applicationVersion
158     NSString    *version = [NSApp applicationVersion];
159     return [NSString stringWithFormat:@"Adium X %@",(version ? version : @"")];
162 //Returns the formatted build date of Adium
163 - (NSString *)_applicationDate
165         NSTimeInterval date = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"AIBuildDate"] doubleValue];
167         return [[NSDateFormatter localizedDateFormatter] stringFromDate:[NSDate dateWithTimeIntervalSince1970:date]];
171 //Software License -----------------------------------------------------------------------------------------------------
172 #pragma mark Software License
173 //Display the software license sheet
174 - (IBAction)showLicense:(id)sender
176         NSString        *licensePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"License" ofType:@"txt"];
177         [textView_license setString:[NSString stringWithContentsOfFile:licensePath]];
178         
179         [NSApp beginSheet:panel_licenseSheet
180            modalForWindow:[self window]
181                 modalDelegate:nil
182            didEndSelector:nil
183                   contextInfo:nil];
186 //Close the software license sheet
187 - (IBAction)hideLicense:(id)sender
189     [panel_licenseSheet orderOut:nil];
190     [NSApp endSheet:panel_licenseSheet returnCode:0];
194 //Sillyness ----------------------------------------------------------------------------------------------------
195 #pragma mark Sillyness
196 //Flap the duck when clicked
197 - (IBAction)adiumDuckClicked:(id)sender
199     numberOfDuckClicks++;
200         
201 #define PATH_TO_SOUNDS          [NSString pathWithComponents:[NSArray arrayWithObjects:[[NSBundle mainBundle] bundlePath], @"Contents", @"Resources", @"Sounds", @"Adium.AdiumSoundset", nil]]
203         if (numberOfDuckClicks == 10) {
204                 numberOfDuckClicks = -1;            
205                 [[adium soundController] playSoundAtPath:[PATH_TO_SOUNDS stringByAppendingPathComponent:@"Feather Ruffle.aif"]];
206         } else {
207                 [[adium soundController] playSoundAtPath:[PATH_TO_SOUNDS stringByAppendingPathComponent:@"Quack.aif"]];
208         }
209         
212 @end