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.
17 #import "AIPreferenceController.h"
18 #import "CPFVersionChecker.h"
19 #import "ESVersionCheckerWindowController.h"
20 #import <AIUtilities/ESDateFormatterAdditions.h>
22 #define ADIUM_UPDATE_URL @"http://download.adiumx.com/"
23 #define ADIUM_UPDATE_BETA_URL @"http://beta.adiumx.com/"
24 #define UPDATE_PROMPT AILocalizedString(@"Adium was updated on %@. Your copy is %@ old. Would you like to update?", nil)
26 #define VERSION_AVAILABLE_NIB @"VersionAvailable"
27 #define VERSION_UPTODATE_NIB @"VersionUpToDate"
28 #define CONNECT_ERROR_NIB @"VersionCannotConnect"
30 @interface ESVersionCheckerWindowController (PRIVATE)
31 - (void)localizeUpToDateWindow;
32 - (void)showWindowFromBuild:(NSDate *)currentDate toBuild:(NSDate *)newestDate;
36 * @class ESVersionCheckerWindowController
37 * @brief A window that notifies the user of new Adium releases
39 * This window can either notify the user of a new Adium release, or that their current release is the newest
42 @implementation ESVersionCheckerWindowController
44 static ESVersionCheckerWindowController *sharedVersionCheckerInstance = nil;
47 * @brief Display the 'Up to date' panel
49 * This panel tells the user that their release of Adium is the newest available
51 + (void)showUpToDateWindow
53 if(sharedVersionCheckerInstance) [sharedVersionCheckerInstance release];
54 sharedVersionCheckerInstance = [[self alloc] initWithWindowNibName:VERSION_UPTODATE_NIB];
55 [sharedVersionCheckerInstance localizeUpToDateWindow];
56 [sharedVersionCheckerInstance showWindowFromBuild:nil toBuild:nil];
60 * @brief Display the 'Update available' panel
62 * This panel tells the user that a newer release of Adium is available.
63 * @param currentBuildDate Date of the release they're running
64 * @param latestBuildDate Date of the newest release
66 + (void)showUpdateWindowFromBuild:(NSDate *)currentBuildDate toBuild:(NSDate *)latestBuildDate
68 if(sharedVersionCheckerInstance) [sharedVersionCheckerInstance release];
69 sharedVersionCheckerInstance = [[self alloc] initWithWindowNibName:VERSION_AVAILABLE_NIB];
70 [sharedVersionCheckerInstance showWindowFromBuild:currentBuildDate toBuild:latestBuildDate];
74 * @brief Display the 'Connection error' panel
76 * This panel tells the user that we were unable to retrieve version information
78 + (void)showCannotConnectWindow
80 if(sharedVersionCheckerInstance) [sharedVersionCheckerInstance release];
81 sharedVersionCheckerInstance = [[self alloc] initWithWindowNibName:CONNECT_ERROR_NIB];
82 [sharedVersionCheckerInstance showWindowFromBuild:nil toBuild:nil];
86 * @brief Configure the window
90 [super windowDidLoad];
92 //Disable the 'check automatically' button if we are in a beta build
94 [checkBox_checkAutomatically setState:YES];
95 [checkBox_checkAutomatically setEnabled:NO];
98 [checkBox_checkAutomatically setLocalizedString:AILocalizedString(@"Check for updates automatically", nil)];
102 * @brief Called as the window closes, release the shared window controller
104 - (void)windowWillClose:(id)sender
106 [super windowWillClose:sender];
108 [sharedVersionCheckerInstance autorelease];
109 sharedVersionCheckerInstance = nil;
113 //Window Display -------------------------------------------------------------------------------------------------------
114 #pragma mark Window display
116 * @brief Display the new version available window for the passed build dates
118 * Displays a panel that tells the user that a newer release of Adium is available. Build dates aren't required for
119 * up-to-date and error window nibs.
120 * @param currentDate Date of the release they're running
121 * @param newestDate Date of the newest release
123 - (void)showWindowFromBuild:(NSDate *)currentDate toBuild:(NSDate *)newestDate
125 //Ensure the window is loaded
126 [[self window] center];
128 //'Check automatically' checkbox
129 [checkBox_checkAutomatically setState:[[[adium preferenceController] preferenceForKey:KEY_CHECK_AUTOMATICALLY
130 group:PREF_GROUP_UPDATING] boolValue]];
131 //Set our panel to display the build date and age of the running copy
132 if(currentDate && newestDate){
133 NSDateFormatter *dateFormatter;
134 NSString *newestDateString;
137 dateFormatter = [NSDateFormatter localizedDateFormatter];
138 newestDateString = [dateFormatter stringForObjectValue:newestDate];
140 //Time since last update (contains a trailing space)
141 interval = [NSDateFormatter stringForApproximateTimeIntervalBetweenDate:newestDate
142 andDate:currentDate];
143 [textField_updateAvailable setStringValue:[NSString stringWithFormat:UPDATE_PROMPT, newestDateString, interval]];
146 [self showWindow:nil];
150 * @brief Update to the new release of Adium
152 * Called when the user presses the download button, this method opens the Adium download site.
154 - (IBAction)update:(id)sender
156 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:(BETA_RELEASE ? ADIUM_UPDATE_BETA_URL : ADIUM_UPDATE_URL)]];
157 [self closeWindow:nil];
161 * @brief Invoked when a preference is changed
163 * Toggle auto-checking for new releases. This option is unavailable for beta releases.
165 - (IBAction)changePreference:(id)sender
167 if(sender == checkBox_checkAutomatically){
168 [[adium preferenceController] setPreference:[NSNumber numberWithBool:[sender state]]
169 forKey:KEY_CHECK_AUTOMATICALLY
170 group:PREF_GROUP_UPDATING];
175 * @brief Localize the strings in the up to date window
177 - (void)localizeUpToDateWindow
179 //Make sure the window loads before attempting to localize
182 [textField_isUpToDateTitle setStringValue:AILocalizedString(@"Your Adium is up to date",nil)];
183 [textField_isUpToDateExplanation setStringValue:AILocalizedString(@"No updates are available. Please try again later.",nil)];
184 [button_okay setLocalizedString:AILocalizedString(@"OK",nil)];