2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
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.
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.
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.
19 #import "AISoundController.h"
20 #import "LNAboutBoxController.h"
21 #import <AIUtilities/AIEventAdditions.h>
22 #import <AIUtilities/AIWindowAdditions.h>
23 #import <AIUtilities/CBApplicationAdditions.h>
24 #import <AIUtilities/ESDateFormatterAdditions.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 - (void)_loadBuildInformation;
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];
47 return(sharedAboutBoxInstance);
51 - (id)initWithWindowNibName:(NSString *)windowNibName
53 if((self = [super initWithWindowNibName:windowNibName])) {
54 numberOfDuckClicks = -1;
63 [buildNumber release];
69 //Prepare the about box window
72 NSAttributedString *creditsString;
74 //Load our build information and avatar list
75 [self _loadBuildInformation];
78 creditsString = [[[NSAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:@"Credits.rtf" ofType:nil] documentAttributes:nil] autorelease];
79 [[textView_credits textStorage] setAttributedString:creditsString];
80 [[textView_credits enclosingScrollView] setLineScroll:0.0];
81 [[textView_credits enclosingScrollView] setPageScroll:0.0];
85 scrollRate = ABOUT_SCROLL_RATE;
86 maxScroll = [[textView_credits textStorage] size].height - [[textView_credits enclosingScrollView] documentVisibleRect].size.height;
87 scrollTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0/ABOUT_SCROLL_FPS)
89 selector:@selector(scrollTimer:)
92 eventLoopScrollTimer = [[NSTimer timerWithTimeInterval:(1.0/ABOUT_SCROLL_FPS)
94 selector:@selector(scrollTimer:)
97 [[NSRunLoop currentRunLoop] addTimer:eventLoopScrollTimer forMode:NSEventTrackingRunLoopMode];
99 //Setup the build date / version
100 [button_buildButton setTitle:buildDate];
101 [textField_version setStringValue:[self _applicationVersion]];
103 //Set the localized values
104 [[self window] setTitle:AILocalizedString(@"About Adium","About window title")];
105 [button_homepage setLocalizedString:AILocalizedString(@"Adium Homepage",nil)];
106 [button_license setLocalizedString:AILocalizedString(@"License",nil)];
108 [[self window] betterCenter];
111 //Cleanup as the window is closing
112 - (void)windowWillClose:(id)sender
114 [super windowWillClose:sender];
116 [sharedAboutBoxInstance autorelease]; sharedAboutBoxInstance = nil;
117 [scrollTimer invalidate]; [scrollTimer release]; scrollTimer = nil;
118 [eventLoopScrollTimer invalidate]; [eventLoopScrollTimer release]; eventLoopScrollTimer = nil;
121 //Visit the Adium homepage
122 - (IBAction)visitHomepage:(id)sender
124 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.adiumx.com"]];
128 //Scrolling Credits ----------------------------------------------------------------------------------------------------
129 #pragma mark Scrolling Credits
131 - (void)scrollTimer:(NSTimer *)scrollTimer
133 scrollLocation += scrollRate;
135 if(scrollLocation > maxScroll) scrollLocation = 0;
136 if(scrollLocation < 0) scrollLocation = maxScroll;
138 [textView_credits scrollPoint:NSMakePoint(0, scrollLocation)];
141 //Receive the flags changed event for reversing the scroll direction via option
142 - (void)flagsChanged:(NSEvent *)theEvent
144 if([theEvent optionKey]) {
145 scrollRate = -ABOUT_SCROLL_RATE;
146 }else if([theEvent controlKey]){
149 scrollRate = ABOUT_SCROLL_RATE;
154 //Build Information ----------------------------------------------------------------------------------------------------
155 #pragma mark Build Information
156 //Toggle build date/number display
157 - (IBAction)buildFieldClicked:(id)sender
159 if((++numberOfBuildFieldClicks) % 2 == 0){
160 [button_buildButton setTitle:buildDate];
162 [button_buildButton setTitle:buildNumber];
166 //Returns the current version of Adium
167 - (NSString *)_applicationVersion
169 NSString *version = [NSApp applicationVersion];
170 return([NSString stringWithFormat:@"Adium X %@",(version ? version : @"")]);
173 //Load the current build date and our cryptic, non-sequential build number ;)
174 - (void)_loadBuildInformation
176 //Grab the info from our buildnum script
177 char *path, unixDate[256], num[256], whoami[256];
178 if(path = (char *)[[[NSBundle mainBundle] pathForResource:@"buildnum" ofType:nil] fileSystemRepresentation])
180 FILE *f = fopen(path, "r");
181 fscanf(f, "%s | %s | %s", num, unixDate, whoami);
185 buildNumber = [[NSString stringWithFormat:@"%s", num] retain];
189 NSDateFormatter *dateFormatter = [NSDateFormatter localizedDateFormatter];
193 date = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithCString:unixDate] doubleValue]];
194 buildDate = [[dateFormatter stringForObjectValue:date] retain];
198 //Default to empty strings if something goes wrong
199 if(!buildDate) buildDate = [@"" retain];
200 if(!buildNumber) buildNumber = [@"" retain];
204 //Software License -----------------------------------------------------------------------------------------------------
205 #pragma mark Software License
206 //Display the software license sheet
207 - (IBAction)showLicense:(id)sender
209 NSString *licensePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"License" ofType:@"txt"];
210 [textView_license setString:[NSString stringWithContentsOfFile:licensePath]];
212 [NSApp beginSheet:panel_licenseSheet
213 modalForWindow:[self window]
219 //Close the software license sheet
220 - (IBAction)hideLicense:(id)sender
222 [panel_licenseSheet orderOut:nil];
223 [NSApp endSheet:panel_licenseSheet returnCode:0];
227 //Sillyness ----------------------------------------------------------------------------------------------------
228 #pragma mark Sillyness
229 //Flap the duck when clicked
230 - (IBAction)adiumDuckClicked:(id)sender
232 numberOfDuckClicks++;
234 if(numberOfDuckClicks == 10){
235 numberOfDuckClicks = -1;
236 [[adium soundController] playSoundNamed:@"/Adium.AdiumSoundset/Feather Ruffle.aif"];
238 [[adium soundController] playSoundNamed:@"/Adium.AdiumSoundset/Quack.aif"];