dev.stuconnolly.com / svn / safaritabs

  1. /*
  2.  *  $Id: STSafariPluginHandler.m 207 2010-01-31 00:08:34Z stuart $
  3.  *
  4.  *  SafariTabs
  5.  *  http://stuconnolly.com/projects/safaritabs/
  6.  *
  7.  *  Copyright (c) 2010 Stuart Connolly. All rights reserved.
  8.  *
  9.  *  This program is free software: you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation, either version 3 of the License, or
  12.  *  (at your option) any later version.
  13.  *
  14.  *  This program is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17.  *  GNU General Public License for more details.
  18.  *
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with this program. If not, see <http://www.gnu.org/licenses/>.
  21.  */
  22.  
  23. #import <WebKit/WebKit.h>
  24.  
  25. #import "STSafariPluginHandler.h"
  26. #import "STSessionHandler.h"
  27. #import "STSessionRestoreController.h"
  28.  
  29. #import "BrowserDocument.h"
  30. #import "STBrowserWindowController.h"
  31.  
  32. #import "STUpdater.h"
  33. #import "STUpdaterDialogs.h"
  34. #import "STConstants.h"
  35.  
  36. @implementation STSafariPluginHandler
  37.  
  38. /*!
  39.  * Returns the application's shared instance of the SafariTabs plugin.
  40.  *
  41.  * @return The application's shared instance of the SafariTabs plugin.
  42.  */
  43. + (STSafariPluginHandler *)sharedInstance
  44. {
  45.     // Singleton instance
  46.     static STSafariPluginHandler *_sharedPluginHandler = nil;
  47.    
  48.     // Returns a single static instance of the plugin handler
  49.     if (_sharedPluginHandler == nil) {
  50.         _sharedPluginHandler = [[STSafariPluginHandler alloc] init];
  51.     }
  52.    
  53.     return _sharedPluginHandler;
  54. }
  55.  
  56. /*!
  57.  * Returns SafariTabs' main instance of its updater.
  58.  *
  59.  * @return SafariTabs' updater
  60.  */
  61. - (STUpdater *)safariTabsUpdater
  62. {
  63.     if (!_updater) {
  64.         _updater = [[STUpdater alloc] init];
  65.     }
  66.    
  67.     return _updater;
  68. }
  69.  
  70. /*!
  71.  * Returns SafariTabs' main instance of its session handler.
  72.  *
  73.  * @return SafariTabs' session handler
  74.  */
  75. - (STSessionHandler *)sessionHandler
  76. {
  77.     if (!_sessionHandler) {
  78.         _sessionHandler = [[STSessionHandler alloc] init];
  79.     }
  80.    
  81.     return _sessionHandler;
  82. }
  83.  
  84. /*!
  85.  * Returns SafariTabs' main instance of its session restore controller.
  86.  *
  87.  * @return SafariTabs' session restore controller
  88.  */
  89. - (STSessionRestoreController *)sessionRestoreController
  90. {
  91.     if (!_sessionRestoreController) {
  92.         _sessionRestoreController = [[STSessionRestoreController alloc] initWithDelegate:self];
  93.     }
  94.    
  95.     return _sessionRestoreController;
  96. }
  97.  
  98. #pragma mark -
  99. #pragma mark Updater Delegate Methods
  100.  
  101. - (void)updater:(STUpdater *)updater newVersionAvailable:(NSString *)version
  102. {
  103.     NSAlert *alert = STGetNewVersionAvailableDialog(version, YES);
  104.    
  105.     if ([alert runModal] == NSAlertDefaultReturn) {
  106.         [_updater downloadUpdate];
  107.     }
  108.    
  109.     if ([[alert suppressionButton] state] == NSOnState) {      
  110.         [[NSUserDefaults standardUserDefaults] setBool:NO forKey:STCheckForUpdates];
  111.     }
  112. }
  113.  
  114. - (void)updaterDownloadUpdateError:(STUpdater *)updater
  115. {
  116.     // Do nothing becuase we are checking in the background
  117. }
  118.  
  119. - (void)updaterDownloadComplete:(STUpdater *)updater
  120. {
  121.     STDisplayDownloadCompleteDialog();
  122. }
  123.  
  124. - (void)updaterNoNewVersionAvailable:(STUpdater *)updater
  125. {
  126.     // Do nothing becuase we are checking in the background
  127. }
  128.  
  129. - (void)updaterCheckForUpdateError:(STUpdater *)updater
  130. {
  131.     // Do nothing becuase we are checking in the background
  132. }
  133.  
  134. #pragma mark -
  135.  
  136. /*!
  137.  * @brief Dealloc
  138.  */
  139. - (void)dealloc
  140. {
  141.     [_updater release], _updater = nil;
  142.     [_sessionRestoreController release], _sessionRestoreController = nil;
  143.    
  144.     [super dealloc];
  145. }
  146.  
  147. @end
  148.