]> git.sesse.net Git - vlc/commitdiff
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 9d1ee5d3c2c0f5fe95fdecd045e488ce365fe3f2..1ca3e85c9183eb3c509920c4957bc268e1cb945d 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 072aca2293fab390e2878a1d5e0180f645e3e69d..a047cb101674b86a2c11ad2f53b72e2b1d5f7d15 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 de6aa359131a64250285cc86e510c029657d6eb6..a02e27a34a74b88b44202eb2f4d106e646642fb4 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 4a60444472dafb48a8693d647ddc0cd08cfeb7d8..0be05fc0ead85003366b5a53a063d4d17affd52b 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 a4eb52c15c5949504ae36b251ee778a166396c97..56ee5e4f2e578e54630e31588d0314f42d186677 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 1db80f7d6aa5da5609db07d816576776cdd3e983..7d64de6684f8e0e60d79b5cfeb7829d007dc6184 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];
 
                 }