Automatically disable the Delete button in the Xtras Manager if no item is selected...
[adiumx.git] / Source / LNAboutBoxController.m
blobb642f4bb8ed80e6dff4607b76eadaf1845f2d173
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:[AIAdium buildIdentifier]];
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         return [[NSDateFormatter localizedDateFormatter] stringForObjectValue:[AIAdium buildDate]];
169 //Software License -----------------------------------------------------------------------------------------------------
170 #pragma mark Software License
171 //Display the software license sheet
172 - (IBAction)showLicense:(id)sender
174         NSString        *licensePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"License" ofType:@"txt"];
175         [textView_license setString:[NSString stringWithContentsOfFile:licensePath]];
176         
177         [NSApp beginSheet:panel_licenseSheet
178            modalForWindow:[self window]
179                 modalDelegate:nil
180            didEndSelector:nil
181                   contextInfo:nil];
184 //Close the software license sheet
185 - (IBAction)hideLicense:(id)sender
187     [panel_licenseSheet orderOut:nil];
188     [NSApp endSheet:panel_licenseSheet returnCode:0];
192 //Sillyness ----------------------------------------------------------------------------------------------------
193 #pragma mark Sillyness
194 //Flap the duck when clicked
195 - (IBAction)adiumDuckClicked:(id)sender
197     numberOfDuckClicks++;
198         
199 #define PATH_TO_SOUNDS          [NSString pathWithComponents:[NSArray arrayWithObjects:[[NSBundle mainBundle] bundlePath], @"Contents", @"Resources", @"Sounds", @"Adium.AdiumSoundset", nil]]
201         if (numberOfDuckClicks == 10) {
202                 numberOfDuckClicks = -1;            
203                 [[adium soundController] playSoundAtPath:[PATH_TO_SOUNDS stringByAppendingPathComponent:@"Feather Ruffle.aif"]];
204         } else {
205                 [[adium soundController] playSoundAtPath:[PATH_TO_SOUNDS stringByAppendingPathComponent:@"Quack.aif"]];
206         }
207         
210 @end