Commit 0c9b2d28 authored by Rafaël Carré's avatar Rafaël Carré

fix update code in macosx gui

parent 234bf661
{ <?xml version="1.0" encoding="UTF-8"?>
IBClasses = ( <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, <plist version="1.0">
{ <dict>
ACTIONS = {changeCheckUpdateOnStartup = id; download = id; okay = id; }; <key>IBClasses</key>
CLASS = VLCUpdate; <array>
LANGUAGE = ObjC; <dict>
OUTLETS = { <key>CLASS</key>
"o_bar_checking" = id; <string>FirstResponder</string>
"o_btn_DownloadNow" = id; <key>LANGUAGE</key>
"o_btn_okay" = id; <string>ObjC</string>
"o_chk_updateOnStartup" = id; <key>SUPERCLASS</key>
"o_fld_currentVersionAndSize" = id; <string>NSObject</string>
"o_fld_releaseNote" = id; </dict>
"o_fld_status" = id; <dict>
"o_update_window" = id; <key>ACTIONS</key>
}; <dict>
SUPERCLASS = NSObject; <key>changeCheckUpdateOnStartup</key>
} <string>id</string>
); <key>download</key>
IBVersion = 1; <string>id</string>
} <key>okay</key>
\ No newline at end of file <string>id</string>
</dict>
<key>CLASS</key>
<string>VLCUpdate</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>o_bar_checking</key>
<string>id</string>
<key>o_btn_DownloadNow</key>
<string>id</string>
<key>o_btn_okay</key>
<string>id</string>
<key>o_chk_updateOnStartup</key>
<string>id</string>
<key>o_fld_currentVersion</key>
<string>id</string>
<key>o_fld_releaseNote</key>
<string>id</string>
<key>o_fld_status</key>
<string>id</string>
<key>o_update_window</key>
<string>id</string>
</dict>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
</array>
<key>IBVersion</key>
<string>1</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>IBDocumentLocation</key>
<string>16 51 356 240 0 0 1280 778 </string>
<key>IBFramework Version</key> <key>IBFramework Version</key>
<string>446.1</string> <string>629</string>
<key>IBOldestOS</key>
<integer>5</integer>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
<integer>5</integer> <integer>5</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>8P2137</string> <string>9C31</string>
<key>targetFramework</key>
<string>IBCocoaFramework</string>
</dict> </dict>
</plist> </plist>
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
#include <string.h> #include <string.h>
#include <vlc_keys.h> #include <vlc_keys.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#import "intf.h" #import "intf.h"
#import "fspanel.h" #import "fspanel.h"
#import "vout.h" #import "vout.h"
...@@ -420,7 +424,7 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -420,7 +424,7 @@ static VLCMain *_o_sharedMainInstance = nil;
o_interaction_list = [[VLCInteractionList alloc] init]; o_interaction_list = [[VLCInteractionList alloc] init];
o_sfilters = nil; o_sfilters = nil;
#ifdef UPDATE_CHECK #ifdef UPDATE_CHECK
//FIXME o_update = [[VLCUpdate alloc] init]; o_update = [[VLCUpdate alloc] init];
#endif #endif
i_lastShownVolume = -1; i_lastShownVolume = -1;
...@@ -865,9 +869,8 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -865,9 +869,8 @@ static VLCMain *_o_sharedMainInstance = nil;
if( !nib_update_loaded ) if( !nib_update_loaded )
nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self]; nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
// FIXME if([o_update shouldCheckForUpdate])
//if([o_update shouldCheckForUpdate]) [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
// [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
#endif #endif
/* Handle sleep notification */ /* Handle sleep notification */
...@@ -2019,8 +2022,9 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -2019,8 +2022,9 @@ static VLCMain *_o_sharedMainInstance = nil;
#ifdef UPDATE_CHECK #ifdef UPDATE_CHECK
if( !nib_update_loaded ) if( !nib_update_loaded )
nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self]; nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
[o_update showUpdateWindow]; [o_update showUpdateWindow];
#else
msg_Err( VLCIntf, "Updates checking was not enabled in this build" );
#endif #endif
} }
......
/***************************************************************************** /*****************************************************************************
* update.h: MacOS X Check-For-Update window * update.h: MacOS X Check-For-Update window
***************************************************************************** *****************************************************************************
* Copyright (C) 2005-2007 the VideoLAN team * Copyright © 2005-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Felix Kühne <fkuehne@users.sf.net> * Authors: Felix Kühne <fkuehne@users.sf.net>
* Rafaël Carré <funman@videolanorg>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -21,6 +22,10 @@ ...@@ -21,6 +22,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef UPDATE_CHECK #ifdef UPDATE_CHECK
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <vlc_update.h> #import <vlc_update.h>
...@@ -30,16 +35,14 @@ ...@@ -30,16 +35,14 @@
IBOutlet id o_btn_DownloadNow; IBOutlet id o_btn_DownloadNow;
IBOutlet id o_btn_okay; IBOutlet id o_btn_okay;
IBOutlet id o_fld_releaseNote; IBOutlet id o_fld_releaseNote;
IBOutlet id o_fld_source; IBOutlet id o_fld_currentVersion;
IBOutlet id o_fld_currentVersionAndSize;
IBOutlet id o_fld_status; IBOutlet id o_fld_status;
IBOutlet id o_update_window; IBOutlet id o_update_window;
IBOutlet id o_bar_checking; IBOutlet id o_bar_checking;
IBOutlet id o_chk_updateOnStartup; IBOutlet id o_chk_updateOnStartup;
NSString * o_urlOfBinary;
update_t * p_u; update_t * p_u;
intf_thread_t * p_intf; vlc_bool_t b_checked;
} }
- (IBAction)download:(id)sender; - (IBAction)download:(id)sender;
...@@ -49,8 +52,8 @@ ...@@ -49,8 +52,8 @@
- (BOOL)shouldCheckForUpdate; - (BOOL)shouldCheckForUpdate;
- (void)showUpdateWindow; - (void)showUpdateWindow;
- (void)initInterface;
- (void)checkForUpdate; - (void)checkForUpdate;
- (void)updateManagement: (vlc_bool_t) b_success;
- (void)performDownload:(NSString *)path; - (void)performDownload:(NSString *)path;
+ (VLCUpdate *)sharedInstance; + (VLCUpdate *)sharedInstance;
......
/***************************************************************************** /*****************************************************************************
* update.m: MacOS X Check-For-Update window * update.m: MacOS X Check-For-Update window
***************************************************************************** *****************************************************************************
* Copyright (C) 2005-2007 the VideoLAN team * Copyright © 2005-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Felix Kühne <fkuehne@users.sf.net> * Authors: Felix Kühne <fkuehne@users.sf.net>
* Rafaël Carré <funman@videolanorg>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -21,11 +22,9 @@ ...@@ -21,11 +22,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifdef HAVE_CONFIG_H
/***************************************************************************** # include "config.h"
* Note: the code used to communicate with VLC's core was inspired by #endif
* ../wxwidgets/dialogs/updatevlc.cpp, written by Antoine Cellerier.
*****************************************************************************/
#ifdef UPDATE_CHECK #ifdef UPDATE_CHECK
...@@ -57,39 +56,25 @@ static VLCUpdate *_o_sharedInstance = nil; ...@@ -57,39 +56,25 @@ static VLCUpdate *_o_sharedInstance = nil;
[self dealloc]; [self dealloc];
} else { } else {
_o_sharedInstance = [super init]; _o_sharedInstance = [super init];
} b_checked = VLC_FALSE;
return _o_sharedInstance;
}
- (void)awakeFromNib
{
/* get up */
p_intf = VLCIntf;
/* clean the interface */ /* clean the interface */
[o_fld_releaseNote setString: @""]; [o_fld_releaseNote setString: @""];
[o_fld_currentVersion setString: @""];
[self initInterface];
}
- (void)dealloc
{
if( o_urlOfBinary )
[o_urlOfBinary release];
[super dealloc];
}
- (void)initInterface
{
/* translate strings to the user's language */ /* translate strings to the user's language */
[o_update_window setTitle: _NS("Check for Updates")]; [o_update_window setTitle: _NS("Check for Updates")];
[o_btn_DownloadNow setTitle: _NS("Download now")]; [o_btn_DownloadNow setTitle: _NS("Download now")];
[o_btn_okay setTitle: _NS("OK")]; [o_btn_okay setTitle: _NS("OK")];
[o_chk_updateOnStartup setTitle: _NS("Automatically check for updates")]; [o_chk_updateOnStartup setTitle: _NS("Automatically check for updates")];
/* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want the Alert }
* panel to pop up at this time */
return _o_sharedInstance;
}
- (void)awakeFromNib
{
/* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want
* the Alert panel to pop up at this time */
[o_chk_updateOnStartup setState: [[NSUserDefaults standardUserDefaults] boolForKey: kPrefUpdateOnStartup]]; [o_chk_updateOnStartup setState: [[NSUserDefaults standardUserDefaults] boolForKey: kPrefUpdateOnStartup]];
} }
...@@ -129,17 +114,17 @@ static VLCUpdate *_o_sharedInstance = nil; ...@@ -129,17 +114,17 @@ static VLCUpdate *_o_sharedInstance = nil;
- (void)showUpdateWindow - (void)showUpdateWindow
{ {
/* show the window and check for a potential update */ /* show the window and check for a potential update */
[o_fld_status setStringValue: _NS("Checking for Updates...")];
[o_fld_currentVersionAndSize setStringValue: @""];
[o_fld_releaseNote setString: @""];
[o_update_window center]; [o_update_window center];
[o_update_window displayIfNeeded]; [o_update_window displayIfNeeded];
[o_update_window makeKeyAndOrderFront:nil]; [o_update_window makeKeyAndOrderFront:nil];
if( !b_checked )
{
[o_bar_checking startAnimation: self]; [o_bar_checking startAnimation: self];
[self checkForUpdate]; [self checkForUpdate];
b_checked = VLC_TRUE;
[o_bar_checking stopAnimation: self]; [o_bar_checking stopAnimation: self];
}
} }
- (IBAction)download:(id)sender - (IBAction)download:(id)sender
...@@ -152,7 +137,7 @@ static VLCUpdate *_o_sharedInstance = nil; ...@@ -152,7 +137,7 @@ static VLCUpdate *_o_sharedInstance = nil;
[saveFilePanel setCanSelectHiddenExtension: YES]; [saveFilePanel setCanSelectHiddenExtension: YES];
[saveFilePanel setCanCreateDirectories: YES]; [saveFilePanel setCanCreateDirectories: YES];
[saveFilePanel beginSheetForDirectory:nil file: [saveFilePanel beginSheetForDirectory:nil file:
[[o_urlOfBinary componentsSeparatedByString:@"/"] lastObject] [[[NSString stringWithUTF8String: p_u->release.psz_url] componentsSeparatedByString:@"/"] lastObject]
modalForWindow: o_update_window modalForWindow: o_update_window
modalDelegate:self modalDelegate:self
didEndSelector:sel didEndSelector:sel
...@@ -173,8 +158,8 @@ static VLCUpdate *_o_sharedInstance = nil; ...@@ -173,8 +158,8 @@ static VLCUpdate *_o_sharedInstance = nil;
- (IBAction)okay:(id)sender - (IBAction)okay:(id)sender
{ {
/* just close the window */ /* just hides the window */
[o_update_window close]; [o_update_window orderOut: self];
} }
- (IBAction)changeCheckUpdateOnStartup:(id)sender - (IBAction)changeCheckUpdateOnStartup:(id)sender
...@@ -182,173 +167,54 @@ static VLCUpdate *_o_sharedInstance = nil; ...@@ -182,173 +167,54 @@ static VLCUpdate *_o_sharedInstance = nil;
[self setShouldCheckUpdate: [sender state]]; [self setShouldCheckUpdate: [sender state]];
} }
- (void)checkForUpdate - (void)updateManagement:(vlc_bool_t)b_success
{ {
/* We may not run on first thread */
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 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 );
BOOL releaseChecked = NO;
BOOL gettingReleaseNote = NO;
int x = 0;
NSString * pathToReleaseNote;
pathToReleaseNote = [NSString stringWithFormat:
@"/tmp/vlc_releasenote_%d.tmp", mdate()];
[[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked]; if( !b_success ||
update_CompareReleaseToCurrent( p_u ) != UpdateReleaseStatusNewer )
if( p_uit )
{ {
p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER; [o_fld_status setStringValue: _NS("This version of VLC is the latest available.")];
p_uit->i_t = UPDATE_FILE_TYPE_ALL; [o_btn_DownloadNow setEnabled: NO];
update_iterator_Action( p_uit, UPDATE_MIRROR );
while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL )
{
msg_Dbg( p_intf, "parsing available updates, run %i", x );
/* if the announced item is of the type "binary", keep it and display
* its details to the user. Do similar stuff on "info". Do both
* only if the file is announced as stable */
if( p_uit->release.i_type == UPDATE_RELEASE_TYPE_STABLE )
{
if( p_uit->file.i_type == UPDATE_FILE_TYPE_INFO )
{
msg_Dbg( p_intf, "release note found, desc = %s",
p_uit->file.psz_description );
[o_fld_releaseNote setString:
[NSString stringWithUTF8String:
(p_uit->file.psz_description)]];
/* download our release note
* We will read the temp file after this loop */
update_download( p_uit, (char *)[pathToReleaseNote UTF8String] );
gettingReleaseNote = YES;
}
else if( p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY )
{
msg_Dbg( p_intf, "binary found, version = %s, "
"url=%s, size=%i MB", p_uit->release.psz_version,
p_uit->file.psz_url,
(int)((p_uit->file.l_size / 1024) / 1024) );
[o_fld_currentVersionAndSize setStringValue:
[NSString stringWithFormat:
_NS("The latest VLC media player release "
"is %s (%i MB to download)."),
p_uit->release.psz_version, ((p_uit->file.l_size
/ 1024) / 1024)]];
if( o_urlOfBinary )
[o_urlOfBinary release];
o_urlOfBinary = [[NSString alloc] initWithUTF8String:
p_uit->file.psz_url];
} }
if( p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER && else
!releaseChecked )
{ {
/* our version is outdated, let the user download the new [o_fld_releaseNote setString: [NSString stringWithUTF8String: (p_u->release.psz_desc)]];
* release */ [o_fld_status setStringValue: _NS("This version of VLC is outdated.")];
[o_fld_status setStringValue: _NS("This version of VLC " [o_fld_currentVersion setStringValue: [NSString stringWithFormat:
"is outdated.")]; _NS("The current release is %d.%d.%d%c."), p_u->release.i_major,
p_u->release.i_minor, p_u->release.i_revision, p_u->release.extra]];
[o_btn_DownloadNow setEnabled: YES]; [o_btn_DownloadNow setEnabled: YES];
msg_Dbg( p_intf, "this version of VLC is outdated" );
/* put the mirror information */
msg_Dbg( p_intf, "used mirror: %s, %s [%s]",
p_uit->mirror.psz_name, p_uit->mirror.psz_location,\
p_uit->mirror.psz_type );
/* make sure that we perform this check only once */
releaseChecked = YES;
/* Make sure the update window is showed in case we have something */ /* Make sure the update window is showed in case we have something */
[o_update_window center]; [o_update_window center];
[o_update_window displayIfNeeded]; [o_update_window displayIfNeeded];
[o_update_window makeKeyAndOrderFront: self]; [o_update_window makeKeyAndOrderFront: self];
}
else if(! releaseChecked )
{
[o_fld_status setStringValue: _NS("This version of VLC "
"is the latest available.")];
[o_btn_DownloadNow setEnabled: NO];
msg_Dbg( p_intf, "current version is up-to-date" );
releaseChecked = YES;
}
} }
x += 1;
}
update_iterator_Delete( p_uit );
/* wait for our release notes if necessary, since the download is done
* by another thread -- this does usually take 300000 to 500000 ms */
if( gettingReleaseNote )
{
int i = 0;
while( [[NSFileManager defaultManager] fileExistsAtPath: pathToReleaseNote] == NO )
{
msleep( 100000 );
i += 1;
if( i == 150 )
{
/* if this takes more than 15 sec, exit */
msg_Warn( p_intf, "download took more than 15 sec, exiting" );
break;
}
}
msg_Dbg( p_intf, "waited %i ms for the release notes", (i * 100000) );
msleep( 500000 );
/* let's open our cached release note and display it
* we can't use NSString stringWithContentsOfFile:encoding:error:
* since it is Tiger only */
NSString * releaseNote = [[NSString alloc] initWithData:
[NSData dataWithContentsOfFile: pathToReleaseNote]
encoding: NSISOLatin1StringEncoding];
if( releaseNote )
[o_fld_releaseNote setString: releaseNote];
/* delete the file since it isn't needed anymore */
BOOL myBOOL = NO;
myBOOL = [[NSFileManager defaultManager] removeFileAtPath:
pathToReleaseNote handler: nil];
}
else
{
/* don't confuse the user, but make her happy */
[o_fld_status setStringValue: _NS("This version of VLC "
"is the latest available.")];
[o_btn_DownloadNow setEnabled: NO];
msg_Dbg( p_intf, "current version is up-to-date" );
}
}
[pool release]; [pool release];
} }
- (void)performDownload:(NSString *)path static void updateCallback( void * p_data, vlc_bool_t b_success )
{ {
update_iterator_t *p_uit = update_iterator_New( p_u ); [(id)p_data updateManagement: b_success];
if( p_uit ) }
{
update_iterator_Action( p_uit, UPDATE_MIRROR );
while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL )
{
if( p_uit->release.i_type == UPDATE_RELEASE_TYPE_STABLE &&
p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER &&
p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY )
{
/* put the mirror information */
msg_Dbg( p_intf, "used mirror: %s, %s [%s]",
p_uit->mirror.psz_name, p_uit->mirror.psz_location,
p_uit->mirror.psz_type );
/* that's our binary */ - (void)checkForUpdate
update_download( p_uit, (char *)[path UTF8String] ); {
} p_u = update_New( VLCIntf );
} if( !p_u )
return;
update_Check( p_u, updateCallback, self );
update_iterator_Delete( p_uit ); [[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked];
} }
[o_update_window close]; - (void)performDownload:(NSString *)path
{
update_Download( p_u, (char*)[path UTF8String] );
[o_btn_DownloadNow setEnabled: NO];
[o_update_window orderOut: self];
update_Delete( p_u );
} }
@end @end
......
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