/*
* $Id: STPreferenceController.m 225 2011-08-13 21:16:20Z stuart $
*
* SafariTabs
* http://stuconnolly.com/projects/safaritabs/
*
* Copyright (c) 2010 Stuart Connolly. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#import "STPreferenceController.h"
#import "STSafariPlugin.h"
#import "STUpdaterDialogs.h"
#import "STSafariPluginHandler.h"
#import "STUpdater.h"
#import "STUtilities.h"
#import "STConstants.h"
@interface STPreferenceController ()
- (void)_toggleCheckForUpdatesButton;
@end
@implementation STPreferenceController
/*!
* This method is called automatically and is part of the NSNibAwaking protocol. It basically prepares the shared
* instance of this class after it is loaded from a NIB archive.
*/
- (void)awakeFromNib
{
[self toggleTabRestoreOptions:nil];
[authorTextField setStringValue
:[NSString stringWithFormat
:STLocalizedString
(@"Copyright"), STPluginVersion
(), STBundleVersion
(),
[[NSDate date
] descriptionWithCalendarFormat
:@"%Y" timeZone
:nil locale
:nil]]];
}
/*!
* Returns the preference pane image associated with the supplied name.
*
* @param name The name of the preference associated with the required image
*
* @return The toolbar image to be used in the preference window
*/
{
if (!image) {
NSString *imagePath
= [STPluginBundle
() pathForImageResource
:name
];
if (!imagePath) {
NSLog(@"SafariTabs Error: image path for %@ is nil", name);
return nil;
}
image
= [[[NSImage alloc
] initByReferencingFile
:imagePath
] autorelease
];
if (!image) {
NSLog(@"SafariTabs Error: image for %@ is nil", name);
return nil;
}
[image setName:name];
}
return image;
}
/*!
* Returns SafariTabs' preferences Nib name.
*
* @return SafariTabs' preferences Nib name
*/
{
return STPreferencesNibName;
}
/*!
* Indicates whether the preference view is resizable
*
* @return A boolean value
*/
- (BOOL)isResizable
{
return NO;
}
#pragma mark -
#pragma mark IB Action Methods
/*!
* Toggles (enable/disables) the tab restore option.
*
* @param sender The object calling the method
*/
- (IBAction)toggleTabRestoreOptions:(id)sender
{
[launchActionMatrix setEnabled:![_defaults integerForKey:STTabRestoreQuitAction]];
[tabWindowOptionsMatrix setEnabled:![_defaults integerForKey:STTabRestoreQuitAction]];
}
/*!
* Checks for available updates.
*
* @param sender The object calling the method
*/
- (IBAction)checkForUpdates:(id)sender
{
[updateCheckProgressIndicator startAnimation:self];
[self _toggleCheckForUpdatesButton];
[[[STSafariPluginHandler sharedInstance] safariTabsUpdater] checkForUpdatesUsingDelegate:self inBackground:NO];
}
#pragma mark -
#pragma mark Updater Delegate Methods
- (void)updater
:(STUpdater
*)updater newVersionAvailable
:(NSString *)version
{
[updateCheckProgressIndicator stopAnimation:self];
[self _toggleCheckForUpdatesButton];
if ([STGetNewVersionAvailableDialog(version, NO) runModal] == NSAlertDefaultReturn) {
[[[STSafariPluginHandler sharedInstance] safariTabsUpdater] downloadUpdate];
}
}
- (void)updaterNoNewVersionAvailable:(STUpdater *)updater
{
[updateCheckProgressIndicator stopAnimation:self];
[self _toggleCheckForUpdatesButton];
STDisplayNoNewVersionAvailableDialog();
}
- (void)updaterCheckForUpdateError:(STUpdater *)updater
{
[updateCheckProgressIndicator stopAnimation:self];
[self _toggleCheckForUpdatesButton];
STDisplayCheckForUpdateErrorDialog();
}
- (void)updaterDownloadUpdateError:(STUpdater *)updater
{
[updateCheckProgressIndicator stopAnimation:self];
[self _toggleCheckForUpdatesButton];
STDisplayDownloadUpdateErrorDialog();
}
- (void)updaterDownloadComplete:(STUpdater *)updater
{
STDisplayDownloadCompleteDialog();
}
/*!
* Toggles (enables/disables) the title and state of the 'Check For Updates' button.
*/
- (void)_toggleCheckForUpdatesButton
{
[checkForUpdatesButton setTitle:([[checkForUpdatesButton title] isEqualToString:STLocalizedString(@"Check Now")]) ? STLocalizedString(@"Checking...") : STLocalizedString(@"Check Now")];
[checkForUpdatesButton setEnabled:![checkForUpdatesButton isEnabled]];
}
@end