French updates
[adiumx.git] / Source / LNAboutBoxController.m
blob1de27d8afddaa78d14ca3924b1c22e844df3300f
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/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;
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 //Dealloc
61 - (void)dealloc
62 {    
63     [buildNumber release];
64     [buildDate release];
65     
66     [super dealloc];
69 //Prepare the about box window
70 - (void)windowDidLoad
72     NSAttributedString          *creditsString;
73     
74     //Load our build information and avatar list
75     [self _loadBuildInformation];
77     //Credits
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];
82     
83     //Start scrolling    
84     scrollLocation = 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)
88                                                                                                         target:self
89                                                                                                   selector:@selector(scrollTimer:)
90                                                                                                   userInfo:nil
91                                                                                                    repeats:YES] retain];
92         eventLoopScrollTimer = [[NSTimer timerWithTimeInterval:(1.0/ABOUT_SCROLL_FPS)
93                                                                                                    target:self
94                                                                                                  selector:@selector(scrollTimer:)
95                                                                                                  userInfo:nil
96                                                                                                   repeats:YES] retain];
97     [[NSRunLoop currentRunLoop] addTimer:eventLoopScrollTimer forMode:NSEventTrackingRunLoopMode];
98         
99     //Setup the build date / version
100     [button_buildButton setTitle:buildDate];
101     [textField_version setStringValue:[self _applicationVersion]];
102     
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];
115         
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
130 //Scroll the credits
131 - (void)scrollTimer:(NSTimer *)scrollTimer
132 {    
133         scrollLocation += scrollRate;
134         
135         if(scrollLocation > maxScroll) scrollLocation = 0;    
136         if(scrollLocation < 0) scrollLocation = maxScroll;
137         
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]){
147         scrollRate = 0;
148     }else{
149         scrollRate = ABOUT_SCROLL_RATE;   
150     }
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];
161     }else{
162                 [button_buildButton setTitle:buildNumber];
163     }
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])
179     {
180         FILE *f = fopen(path, "r");
181         fscanf(f, "%s | %s | %s", num, unixDate, whoami);
182         fclose(f);
183                 
184         if(*num){
185             buildNumber = [[NSString stringWithFormat:@"%s", num] retain];
186                 }
187                 
188                 if(*unixDate){
189                         NSDateFormatter *dateFormatter = [NSDateFormatter localizedDateFormatter];
191                         NSDate      *date;
192                         
193                         date = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithCString:unixDate] doubleValue]];
194             buildDate = [[dateFormatter stringForObjectValue:date] retain];
195                 }
196     }
197         
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]];
211         
212         [NSApp beginSheet:panel_licenseSheet
213            modalForWindow:[self window]
214                 modalDelegate:nil
215            didEndSelector:nil
216                   contextInfo:nil];
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"];
237         }else{
238                 [[adium soundController] playSoundNamed:@"/Adium.AdiumSoundset/Quack.aif"];
239         }
240         
244 @end