Changeset 0c9b2d28611409caa44eafff14e701168785fe99

Show
Ignore:
Timestamp:
25/02/08 01:28:43 (8 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1203899323 +0000
git-parent:

[234bf661a935ad204e089486a0db7e92847ff071]

git-author:
Rafaël Carré <funman@videolan.org> 1203899323 +0000
Message:

fix update code in macosx gui

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • extras/package/macosx/Resources/English.lproj/Update.nib/classes.nib

    r2e888fd r0c9b2d2  
    1 
    2     IBClasses = ( 
    3         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },  
    4         { 
    5             ACTIONS = {changeCheckUpdateOnStartup = id; download = id; okay = id; };  
    6             CLASS = VLCUpdate;  
    7             LANGUAGE = ObjC;  
    8             OUTLETS = { 
    9                 "o_bar_checking" = id;  
    10                 "o_btn_DownloadNow" = id;  
    11                 "o_btn_okay" = id;  
    12                 "o_chk_updateOnStartup" = id;  
    13                 "o_fld_currentVersionAndSize" = id;  
    14                 "o_fld_releaseNote" = id;  
    15                 "o_fld_status" = id;  
    16                 "o_update_window" = id;  
    17             };  
    18             SUPERCLASS = NSObject;  
    19         } 
    20     );  
    21     IBVersion = 1;  
    22 
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
     3<plist version="1.0"> 
     4<dict> 
     5    <key>IBClasses</key> 
     6    <array> 
     7        <dict> 
     8            <key>CLASS</key> 
     9            <string>FirstResponder</string> 
     10            <key>LANGUAGE</key> 
     11            <string>ObjC</string> 
     12            <key>SUPERCLASS</key> 
     13            <string>NSObject</string> 
     14        </dict> 
     15        <dict> 
     16            <key>ACTIONS</key> 
     17            <dict> 
     18                <key>changeCheckUpdateOnStartup</key> 
     19                <string>id</string> 
     20                <key>download</key> 
     21                <string>id</string> 
     22                <key>okay</key> 
     23                <string>id</string> 
     24            </dict> 
     25            <key>CLASS</key> 
     26            <string>VLCUpdate</string> 
     27            <key>LANGUAGE</key> 
     28            <string>ObjC</string> 
     29            <key>OUTLETS</key> 
     30            <dict> 
     31                <key>o_bar_checking</key> 
     32                <string>id</string> 
     33                <key>o_btn_DownloadNow</key> 
     34                <string>id</string> 
     35                <key>o_btn_okay</key> 
     36                <string>id</string> 
     37                <key>o_chk_updateOnStartup</key> 
     38                <string>id</string> 
     39                <key>o_fld_currentVersion</key> 
     40                <string>id</string> 
     41                <key>o_fld_releaseNote</key> 
     42                <string>id</string> 
     43                <key>o_fld_status</key> 
     44                <string>id</string> 
     45                <key>o_update_window</key> 
     46                <string>id</string> 
     47            </dict> 
     48            <key>SUPERCLASS</key> 
     49            <string>NSObject</string> 
     50        </dict> 
     51    </array> 
     52    <key>IBVersion</key> 
     53    <string>1</string> 
     54</dict> 
     55</plist> 
  • extras/package/macosx/Resources/English.lproj/Update.nib/info.nib

    r2e888fd r0c9b2d2  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
     2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
    33<plist version="1.0"> 
    44<dict> 
    5     <key>IBDocumentLocation</key> 
    6     <string>16 51 356 240 0 0 1280 778 </string> 
    75    <key>IBFramework Version</key> 
    8     <string>446.1</string> 
     6    <string>629</string> 
     7    <key>IBOldestOS</key> 
     8    <integer>5</integer> 
    99    <key>IBOpenObjects</key> 
    1010    <array> 
     
    1212    </array> 
    1313    <key>IBSystem Version</key> 
    14     <string>8P2137</string> 
     14    <string>9C31</string> 
     15    <key>targetFramework</key> 
     16    <string>IBCocoaFramework</string> 
    1517</dict> 
    1618</plist> 
  • modules/gui/macosx/intf.m

    rf46398c r0c9b2d2  
    3232#include <string.h> 
    3333#include <vlc_keys.h> 
     34 
     35#ifdef HAVE_CONFIG_H 
     36#   include "config.h" 
     37#endif 
    3438 
    3539#import "intf.h" 
     
    421425    o_sfilters = nil; 
    422426#ifdef UPDATE_CHECK 
    423     //FIXME o_update = [[VLCUpdate alloc] init]; 
     427    o_update = [[VLCUpdate alloc] init]; 
    424428#endif 
    425429 
     
    866870        nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self]; 
    867871 
    868     // FIXME 
    869     //if([o_update shouldCheckForUpdate]) 
    870     //    [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL]; 
     872    if([o_update shouldCheckForUpdate]) 
     873        [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL]; 
    871874#endif 
    872875 
     
    20202023    if( !nib_update_loaded ) 
    20212024        nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self]; 
    2022  
    20232025    [o_update showUpdateWindow]; 
     2026#else 
     2027    msg_Err( VLCIntf, "Updates checking was not enabled in this build" ); 
    20242028#endif 
    20252029} 
  • modules/gui/macosx/update.h

    r48c2ac8 r0c9b2d2  
    22 * update.h: MacOS X Check-For-Update window 
    33 ***************************************************************************** 
    4  * Copyright (C) 2005-2007 the VideoLAN team 
     4 * Copyright © 2005-2008 the VideoLAN team 
    55 * $Id$ 
    66 * 
    77 * Authors: Felix Kühne <fkuehne@users.sf.net> 
     8 *          Rafaël Carré <funman@videolanorg> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    2223 *****************************************************************************/ 
    2324 
     25#ifdef HAVE_CONFIG_H 
     26#   include "config.h" 
     27#endif 
     28 
    2429#ifdef UPDATE_CHECK 
    2530#import <Cocoa/Cocoa.h> 
     
    3136    IBOutlet id o_btn_okay; 
    3237    IBOutlet id o_fld_releaseNote; 
    33     IBOutlet id o_fld_source; 
    34     IBOutlet id o_fld_currentVersionAndSize; 
     38    IBOutlet id o_fld_currentVersion; 
    3539    IBOutlet id o_fld_status; 
    3640    IBOutlet id o_update_window; 
     
    3842    IBOutlet id o_chk_updateOnStartup; 
    3943 
    40     NSString * o_urlOfBinary; 
    4144    update_t * p_u; 
    42     intf_thread_t * p_intf
     45    vlc_bool_t b_checked
    4346} 
    4447 
     
    5053 
    5154- (void)showUpdateWindow; 
    52 - (void)initInterface; 
    5355- (void)checkForUpdate; 
     56- (void)updateManagement: (vlc_bool_t) b_success; 
    5457- (void)performDownload:(NSString *)path; 
    5558 
  • modules/gui/macosx/update.m

    r48c2ac8 r0c9b2d2  
    22 * update.m: MacOS X Check-For-Update window 
    33 ***************************************************************************** 
    4  * Copyright (C) 2005-2007 the VideoLAN team 
     4 * Copyright © 2005-2008 the VideoLAN team 
    55 * $Id$ 
    66 * 
    77 * Authors: Felix Kühne <fkuehne@users.sf.net> 
     8 *          Rafaël Carré <funman@videolanorg> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    2223 *****************************************************************************/ 
    2324 
    24  
    25 /***************************************************************************** 
    26  * Note: the code used to communicate with VLC's core was inspired by 
    27  * ../wxwidgets/dialogs/updatevlc.cpp, written by Antoine Cellerier. 
    28  *****************************************************************************/ 
     25#ifdef HAVE_CONFIG_H 
     26#   include "config.h" 
     27#endif 
    2928 
    3029#ifdef UPDATE_CHECK 
     
    5857    } else { 
    5958        _o_sharedInstance = [super init]; 
     59        b_checked = VLC_FALSE; 
     60 
     61        /* clean the interface */ 
     62        [o_fld_releaseNote setString: @""]; 
     63        [o_fld_currentVersion setString: @""]; 
     64        /* translate strings to the user's language */ 
     65        [o_update_window setTitle: _NS("Check for Updates")]; 
     66        [o_btn_DownloadNow setTitle: _NS("Download now")]; 
     67        [o_btn_okay setTitle: _NS("OK")]; 
     68        [o_chk_updateOnStartup setTitle: _NS("Automatically check for updates")]; 
    6069    } 
    6170 
     
    6574- (void)awakeFromNib 
    6675{ 
    67     /* get up */ 
    68     p_intf = VLCIntf; 
    69  
    70     /* clean the interface */ 
    71     [o_fld_releaseNote setString: @""]; 
    72   
    73     [self initInterface]; 
    74 
    75  
    76 - (void)dealloc 
    77 
    78     if( o_urlOfBinary ) 
    79         [o_urlOfBinary release]; 
    80  
    81     [super dealloc]; 
    82 
    83  
    84 - (void)initInterface 
    85 
    86     /* translate strings to the user's language */ 
    87     [o_update_window setTitle: _NS("Check for Updates")]; 
    88     [o_btn_DownloadNow setTitle: _NS("Download now")]; 
    89     [o_btn_okay setTitle: _NS("OK")]; 
    90     [o_chk_updateOnStartup setTitle: _NS("Automatically check for updates")]; 
    91     /* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want the Alert 
    92      * panel to pop up at this time */ 
     76    /* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want 
     77     * the Alert panel to pop up at this time */ 
    9378    [o_chk_updateOnStartup setState: [[NSUserDefaults standardUserDefaults] boolForKey: kPrefUpdateOnStartup]]; 
    9479} 
     
    130115{ 
    131116    /* show the window and check for a potential update */ 
    132     [o_fld_status setStringValue: _NS("Checking for Updates...")]; 
    133     [o_fld_currentVersionAndSize setStringValue: @""]; 
    134     [o_fld_releaseNote setString: @""]; 
    135  
    136117    [o_update_window center]; 
    137118    [o_update_window displayIfNeeded]; 
    138119    [o_update_window makeKeyAndOrderFront:nil]; 
    139120 
    140     [o_bar_checking startAnimation: self]; 
    141     [self checkForUpdate]; 
    142     [o_bar_checking stopAnimation: self]; 
     121    if( !b_checked ) 
     122    { 
     123        [o_bar_checking startAnimation: self]; 
     124        [self checkForUpdate]; 
     125        b_checked = VLC_TRUE; 
     126        [o_bar_checking stopAnimation: self]; 
     127    } 
    143128} 
    144129 
     
    148133    SEL sel = @selector(getLocationForSaving:returnCode:contextInfo:); 
    149134    NSSavePanel * saveFilePanel = [[NSSavePanel alloc] init]; 
    150   
     135 
    151136    [saveFilePanel setRequiredFileType: @"dmg"]; 
    152137    [saveFilePanel setCanSelectHiddenExtension: YES]; 
    153138    [saveFilePanel setCanCreateDirectories: YES]; 
    154139    [saveFilePanel beginSheetForDirectory:nil file: 
    155         [[o_urlOfBinary componentsSeparatedByString:@"/"] lastObject] 
     140        [[[NSString stringWithUTF8String: p_u->release.psz_url] componentsSeparatedByString:@"/"] lastObject] 
    156141                           modalForWindow: o_update_window  
    157142                            modalDelegate:self 
     
    174159- (IBAction)okay:(id)sender 
    175160{ 
    176     /* just close the window */ 
    177     [o_update_window close]; 
     161    /* just hides the window */ 
     162    [o_update_window orderOut: self]; 
    178163} 
    179164 
     
    183168} 
    184169 
     170- (void)updateManagement:(vlc_bool_t)b_success 
     171{ 
     172    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     173 
     174    if( !b_success || 
     175        update_CompareReleaseToCurrent( p_u ) != UpdateReleaseStatusNewer ) 
     176    { 
     177        [o_fld_status setStringValue: _NS("This version of VLC is the latest available.")]; 
     178        [o_btn_DownloadNow setEnabled: NO]; 
     179    } 
     180    else 
     181    { 
     182        [o_fld_releaseNote setString: [NSString stringWithUTF8String: (p_u->release.psz_desc)]]; 
     183        [o_fld_status setStringValue: _NS("This version of VLC is outdated.")]; 
     184        [o_fld_currentVersion setStringValue: [NSString stringWithFormat: 
     185            _NS("The current release is %d.%d.%d%c."), p_u->release.i_major, 
     186            p_u->release.i_minor, p_u->release.i_revision, p_u->release.extra]]; 
     187        [o_btn_DownloadNow setEnabled: YES]; 
     188        /* Make sure the update window is showed in case we have something */ 
     189        [o_update_window center]; 
     190        [o_update_window displayIfNeeded]; 
     191        [o_update_window makeKeyAndOrderFront: self]; 
     192    } 
     193 
     194    [pool release]; 
     195} 
     196 
     197static void updateCallback( void * p_data, vlc_bool_t b_success ) 
     198{ 
     199    [(id)p_data updateManagement: b_success]; 
     200} 
     201 
    185202- (void)checkForUpdate 
    186203{ 
    187     /* We may not run on first thread */ 
    188     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    189     p_u = update_New( p_intf ); 
    190     update_Check( p_u, VLC_FALSE ); 
    191     update_iterator_t *p_uit = update_iterator_New( p_u ); 
    192     BOOL releaseChecked = NO; 
    193     BOOL gettingReleaseNote = NO; 
    194     int x = 0; 
    195     NSString * pathToReleaseNote; 
    196     pathToReleaseNote = [NSString stringWithFormat: 
    197         @"/tmp/vlc_releasenote_%d.tmp", mdate()]; 
     204    p_u = update_New( VLCIntf ); 
     205    if( !p_u ) 
     206        return; 
     207    update_Check( p_u, updateCallback, self ); 
    198208 
    199209    [[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked]; 
    200  
    201     if( p_uit ) 
    202     { 
    203         p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER; 
    204         p_uit->i_t = UPDATE_FILE_TYPE_ALL; 
    205         update_iterator_Action( p_uit, UPDATE_MIRROR ); 
    206   
    207         while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL ) 
    208         { 
    209             msg_Dbg( p_intf, "parsing available updates, run %i", x ); 
    210             /* if the announced item is of the type "binary", keep it and display 
    211              * its details to the user. Do similar stuff on "info". Do both 
    212              * only if the file is announced as stable */ 
    213             if( p_uit->release.i_type == UPDATE_RELEASE_TYPE_STABLE ) 
    214             { 
    215                 if( p_uit->file.i_type == UPDATE_FILE_TYPE_INFO ) 
    216                 { 
    217                     msg_Dbg( p_intf, "release note found, desc = %s", 
    218                         p_uit->file.psz_description ); 
    219                     [o_fld_releaseNote setString: 
    220                         [NSString stringWithUTF8String: 
    221                         (p_uit->file.psz_description)]]; 
    222                     /* download our release note 
    223                      * We will read the temp file after this loop */ 
    224                     update_download( p_uit, (char *)[pathToReleaseNote UTF8String] ); 
    225                     gettingReleaseNote = YES; 
    226                 } 
    227                 else if( p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY ) 
    228                 { 
    229                     msg_Dbg( p_intf, "binary found, version = %s, " 
    230                         "url=%s, size=%i MB", p_uit->release.psz_version, 
    231                         p_uit->file.psz_url, 
    232                         (int)((p_uit->file.l_size / 1024) / 1024) ); 
    233                     [o_fld_currentVersionAndSize setStringValue:  
    234                         [NSString stringWithFormat: 
    235                         _NS("The latest VLC media player release " 
    236                             "is %s (%i MB to download)."), 
    237                         p_uit->release.psz_version, ((p_uit->file.l_size 
    238                         / 1024) / 1024)]]; 
    239   
    240                     if( o_urlOfBinary ) 
    241                         [o_urlOfBinary release]; 
    242                     o_urlOfBinary = [[NSString alloc] initWithUTF8String: 
    243                         p_uit->file.psz_url]; 
    244                 } 
    245                 if( p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER && 
    246                     !releaseChecked ) 
    247                 { 
    248                     /* our version is outdated, let the user download the new 
    249                      * release */ 
    250                     [o_fld_status setStringValue: _NS("This version of VLC " 
    251                         "is outdated.")]; 
    252                     [o_btn_DownloadNow setEnabled: YES]; 
    253                     msg_Dbg( p_intf, "this version of VLC is outdated" ); 
    254                     /* put the mirror information */ 
    255                     msg_Dbg( p_intf, "used mirror: %s, %s [%s]", 
    256                             p_uit->mirror.psz_name, p_uit->mirror.psz_location,\ 
    257                             p_uit->mirror.psz_type ); 
    258                     /* make sure that we perform this check only once */ 
    259                     releaseChecked = YES; 
    260                     /* Make sure the update window is showed in case we have something */ 
    261                     [o_update_window center]; 
    262                     [o_update_window displayIfNeeded]; 
    263                     [o_update_window makeKeyAndOrderFront: self]; 
    264  
    265                 } 
    266                 else if(! releaseChecked ) 
    267                 { 
    268                     [o_fld_status setStringValue: _NS("This version of VLC " 
    269                         "is the latest available.")]; 
    270                     [o_btn_DownloadNow setEnabled: NO]; 
    271                     msg_Dbg( p_intf, "current version is up-to-date" ); 
    272                     releaseChecked = YES; 
    273                 } 
    274             } 
    275             x += 1; 
    276         } 
    277  
    278         update_iterator_Delete( p_uit ); 
    279  
    280         /* wait for our release notes if necessary, since the download is done 
    281          * by another thread -- this does usually take 300000 to 500000 ms */ 
    282         if( gettingReleaseNote ) 
    283         { 
    284             int i = 0; 
    285             while( [[NSFileManager defaultManager] fileExistsAtPath: pathToReleaseNote] == NO ) 
    286             { 
    287                 msleep( 100000 ); 
    288                 i += 1; 
    289                 if( i == 150 ) 
    290                 { 
    291                     /* if this takes more than 15 sec, exit */ 
    292                     msg_Warn( p_intf, "download took more than 15 sec, exiting" ); 
    293                     break; 
    294                 } 
    295             } 
    296             msg_Dbg( p_intf, "waited %i ms for the release notes", (i * 100000) ); 
    297             msleep( 500000 ); 
    298  
    299             /* let's open our cached release note and display it 
    300              * we can't use NSString stringWithContentsOfFile:encoding:error: 
    301              * since it is Tiger only */ 
    302             NSString * releaseNote = [[NSString alloc] initWithData: 
    303                 [NSData dataWithContentsOfFile: pathToReleaseNote] 
    304                 encoding: NSISOLatin1StringEncoding]; 
    305             if( releaseNote ) 
    306                 [o_fld_releaseNote setString: releaseNote]; 
    307   
    308             /* delete the file since it isn't needed anymore */ 
    309             BOOL myBOOL = NO; 
    310             myBOOL = [[NSFileManager defaultManager] removeFileAtPath: 
    311                 pathToReleaseNote handler: nil]; 
    312         } 
    313         else 
    314         { 
    315             /* don't confuse the user, but make her happy */ 
    316             [o_fld_status setStringValue: _NS("This version of VLC " 
    317                 "is the latest available.")]; 
    318             [o_btn_DownloadNow setEnabled: NO]; 
    319             msg_Dbg( p_intf, "current version is up-to-date" ); 
    320         } 
    321     } 
    322     [pool release]; 
    323210} 
    324211 
    325212- (void)performDownload:(NSString *)path 
    326213{ 
    327     update_iterator_t *p_uit = update_iterator_New( p_u ); 
    328     if( p_uit ) 
    329     { 
    330         update_iterator_Action( p_uit, UPDATE_MIRROR ); 
    331  
    332         while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL ) 
    333         { 
    334             if( p_uit->release.i_type == UPDATE_RELEASE_TYPE_STABLE && 
    335                 p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER && 
    336                 p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY ) 
    337             { 
    338                 /* put the mirror information */ 
    339                 msg_Dbg( p_intf, "used mirror: %s, %s [%s]", 
    340                     p_uit->mirror.psz_name, p_uit->mirror.psz_location, 
    341                     p_uit->mirror.psz_type ); 
    342  
    343                 /* that's our binary */ 
    344                 update_download( p_uit, (char *)[path UTF8String] ); 
    345             } 
    346         } 
    347   
    348         update_iterator_Delete( p_uit ); 
    349     } 
    350  
    351     [o_update_window close]; 
     214    update_Download( p_u, (char*)[path UTF8String] ); 
     215    [o_btn_DownloadNow setEnabled: NO]; 
     216    [o_update_window orderOut: self]; 
     217    update_Delete( p_u ); 
    352218} 
    353219