Mac OS X gui: Ask the user if she wants to check update on startup. And if so, check...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 1 Apr 2007 17:41:51 +0000 (17:41 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 1 Apr 2007 17:41:51 +0000 (17:41 +0000)
extras/MacOSX/Resources/English.lproj/Update.nib/classes.nib
extras/MacOSX/Resources/English.lproj/Update.nib/info.nib
extras/MacOSX/Resources/English.lproj/Update.nib/keyedobjects.nib
modules/gui/macosx/intf.m
modules/gui/macosx/update.h
modules/gui/macosx/update.m

index 9d1ee5d..1ca3e85 100644 (file)
@@ -2,13 +2,14 @@
     IBClasses = (
         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
         {
-            ACTIONS = {download = id; okay = id; }; 
+            ACTIONS = {changeCheckUpdateOnStartup = id; download = id; okay = id; }; 
             CLASS = VLCUpdate; 
             LANGUAGE = ObjC; 
             OUTLETS = {
                 "o_bar_checking" = id; 
                 "o_btn_DownloadNow" = id; 
                 "o_btn_okay" = id; 
+                "o_chk_updateOnStartup" = id; 
                 "o_fld_currentVersionAndSize" = id; 
                 "o_fld_releaseNote" = id; 
                 "o_fld_status" = id; 
index 072aca2..a047cb1 100644 (file)
@@ -3,14 +3,14 @@
 <plist version="1.0">
 <dict>
        <key>IBDocumentLocation</key>
-       <string>19 61 356 240 0 0 1440 878 </string>
+       <string>23 75 356 240 0 0 1680 1028 </string>
        <key>IBFramework Version</key>
-       <string>443.0</string>
+       <string>446.1</string>
        <key>IBOpenObjects</key>
        <array>
                <integer>5</integer>
        </array>
        <key>IBSystem Version</key>
-       <string>8H14</string>
+       <string>8P2137</string>
 </dict>
 </plist>
index de6aa35..a02e27a 100644 (file)
Binary files a/extras/MacOSX/Resources/English.lproj/Update.nib/keyedobjects.nib and b/extras/MacOSX/Resources/English.lproj/Update.nib/keyedobjects.nib differ
index 4a60444..0be05fc 100644 (file)
@@ -742,7 +742,9 @@ static VLCMain *_o_sharedMainInstance = nil;
     /* Check for update silently on startup */
     if ( !nib_update_loaded )
         nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
-    [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
+
+    if([o_update shouldCheckForUpdate])
+        [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
 }
 
 /* Listen to the remote in exclusive mode, only when VLC is the active
index a4eb52c..56ee5e4 100644 (file)
@@ -34,6 +34,7 @@
     IBOutlet id o_fld_status;
     IBOutlet id o_update_window;
     IBOutlet id o_bar_checking;
+    IBOutlet id o_chk_updateOnStartup;
 
     NSString * o_urlOfBinary;
     update_t * p_u;
 
 - (IBAction)download:(id)sender;
 - (IBAction)okay:(id)sender;
+- (IBAction)changeCheckUpdateOnStartup:(id)sender;
+
+- (BOOL)shouldCheckForUpdate;
 
 - (void)showUpdateWindow;
-- (void)initStrings;
+- (void)initInterface;
 - (void)checkForUpdate;
 - (void)performDownload:(NSString *)path;
 
index 1db80f7..7d64de6 100644 (file)
@@ -34,6 +34,8 @@
 #import "update.h"
 #import "intf.h"
 
+static NSString * kPrefUpdateOnStartup = @"UpdateOnStartup";
+static NSString * kPrefUpdateLastTimeChecked = @"UpdateLastTimeChecked";
 
 /*****************************************************************************
  * VLCExtended implementation
@@ -67,7 +69,7 @@ static VLCUpdate *_o_sharedInstance = nil;
     /* clean the interface */
     [o_fld_releaseNote setString: @""];
     
-    [self initStrings];
+    [self initInterface];
 }
 
 - (void)dealloc
@@ -78,12 +80,49 @@ static VLCUpdate *_o_sharedInstance = nil;
     [super dealloc];
 }
 
-- (void)initStrings
+- (void)initInterface
 {
     /* translate strings to the user's language */
     [o_update_window setTitle: _NS("Check for Updates")];
     [o_btn_DownloadNow setTitle: _NS("Download now")];
     [o_btn_okay setTitle: _NS("OK")];
+    [o_chk_updateOnStartup setTitle: _NS("Check for update when VLC is launched")];
+    /* we don't use - (BOOL)shouldCheckUpdateOnStartup beccause we don't want the Alert
+     * panel to pop up at this time */
+    [o_chk_updateOnStartup setState: [[NSUserDefaults standardUserDefaults] boolForKey: kPrefUpdateOnStartup]];
+}
+
+- (void)setShouldCheckUpdate: (BOOL)check
+{
+    [[NSUserDefaults standardUserDefaults] setBool: check forKey: kPrefUpdateOnStartup];
+    [o_chk_updateOnStartup setState: check];
+}
+
+- (BOOL)shouldCheckForUpdate
+{
+    NSDate *o_last_update;
+    NSDate *o_next_update;
+    
+    if(![[NSUserDefaults standardUserDefaults] objectForKey: kPrefUpdateOnStartup])
+    {
+        /* We don't have any preferences stored, ask the user. */
+        int res = NSRunInformationalAlertPanel( _NS("Do you want VLC to check for update automatically?"),
+              _NS("You can change this option later in the VLC update window."), _NS("Yes"), _NS("No"), nil );
+        [self setShouldCheckUpdate: res];
+    }
+
+    if( ![[NSUserDefaults standardUserDefaults] boolForKey: kPrefUpdateOnStartup] )
+        return NO;
+
+    o_last_update = [[NSUserDefaults standardUserDefaults] objectForKey: kPrefUpdateLastTimeChecked];
+    if( !o_last_update )
+        return YES;
+
+    o_next_update = [[[NSDate alloc] initWithTimeInterval: 60*60*24*2 /* every two days */ sinceDate: o_last_update] autorelease];
+    if( !o_next_update )
+        return YES;
+
+    return [o_next_update compare: [NSDate date]] == NSOrderedAscending;
 }
 
 - (void)showUpdateWindow
@@ -134,11 +173,15 @@ static VLCUpdate *_o_sharedInstance = nil;
     [o_update_window close];
 }
 
+- (IBAction)changeCheckUpdateOnStartup:(id)sender
+{
+    [self setShouldCheckUpdate: [sender state]];
+}
+
 - (void)checkForUpdate
 {
     /* We may not run on first thread */
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
     p_u = update_New( p_intf );
     update_Check( p_u, VLC_FALSE );
     update_iterator_t *p_uit = update_iterator_New( p_u );
@@ -149,6 +192,8 @@ static VLCUpdate *_o_sharedInstance = nil;
     pathToReleaseNote = [NSString stringWithFormat: \
         @"/tmp/vlc_releasenote_%d.tmp", mdate()];
 
+    [[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked];
+
     if( p_uit )
     {
         p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
@@ -210,6 +255,7 @@ static VLCUpdate *_o_sharedInstance = nil;
                     releaseChecked = YES;
                     /* Make sure the update window is showed in case we have something */
                     [o_update_window center];
+                    [o_update_window displayIfNeeded];
                     [o_update_window makeKeyAndOrderFront: self];
 
                 }