Commit fc5f7efa authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

Mac OS X gui: Ask the user if she wants to check update on startup. And if so,...

Mac OS X gui: Ask the user if she wants to check update on startup. And if so, check for update only every two days.
parent 3bf0dec4
......@@ -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;
......
......@@ -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>
......@@ -742,6 +742,8 @@ static VLCMain *_o_sharedMainInstance = nil;
/* Check for update silently on startup */
if ( !nib_update_loaded )
nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
if([o_update shouldCheckForUpdate])
[NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
}
......
......@@ -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;
......@@ -42,9 +43,12 @@
- (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;
......
......@@ -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];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment