Changeset 77c834e9255cc30ff51d3107f89a6514f42ab937

Show
Ignore:
Timestamp:
18/12/07 16:51:29 (10 months ago)
Author:
Rémi Duraffort <ivoire@videolan.org>
git-committer:
Rémi Duraffort <ivoire@videolan.org> 1197993089 +0000
git-parent:

[72bef4462e04685334120e6331d861ab990648de]

git-author:
Rémi Duraffort <ivoire@videolan.org> 1197993089 +0000
Message:

Add fonctions to the update system : all is in a thread now. The rc interface doesn't use the update system for the moment and there isn't any encryption for the moment ...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_update.h

    r48c2ac8 r77c834e  
    284284VLC_EXPORT( void, update_Check, ( update_t * ) ); 
    285285VLC_EXPORT( int, update_CompareReleaseToCurrent, ( update_t * ) ); 
     286VLC_EXPORT( void, update_Download, ( update_t *, char* ) ); 
    286287 
    287288/** 
  • modules/control/rc.c

    r48c2ac8 r77c834e  
    21152115static void checkUpdates( intf_thread_t *p_intf ) 
    21162116{ 
     2117    /*TODO: - modify this to delete p_update to avoid a memory leak ! 
     2118            - complete the function wich is not working obiously ! 
    21172119    update_t *p_u = update_New( p_intf ); 
    2118     if( p_u == NULL ) return; 
    2119  
    2120     update_Check( p_u ); 
     2120    var_AddCallback( p_intf->p_libvlc, "update-notify", updatesCallback, p_intf ); 
     2121 
    21212122    msg_rc( "\nChecking for updates" ); 
    2122  
    2123     if( update_CompareReleaseToCurrent( p_u ) == UpdateReleaseStatusNewer ) 
    2124         msg_rc( "\n+----[ VLC %i.%i.%i%s ] ", p_u->release.i_major, 
    2125                                               p_u->release.i_minor, 
    2126                                               p_u->release.i_revision, 
    2127                                               p_u->release.psz_extra ); 
    2128     else 
    2129         msg_rc( "\n+----Last version" ); 
    2130     update_Delete( p_u ); 
     2123    update_Check( p_u );*/ 
    21312124} 
    21322125#endif 
  • modules/gui/qt4/dialogs/help.cpp

    r48c2ac8 r77c834e  
    4242#include <QString> 
    4343#include <QDialogButtonBox> 
     44#include <QEvent> 
     45#include <QFileDialog> 
    4446 
    4547 
     
    166168 
    167169#ifdef UPDATE_CHECK 
     170 
     171/***************************************************************************** 
     172 * UpdateDialog 
     173 *****************************************************************************/ 
     174/* callback to get information from the core */ 
     175static int updateCallback( vlc_object_t *p_this, char const *psz_cmd, 
     176                           vlc_value_t oldval, vlc_value_t newval, void *data ) 
     177{ 
     178    UpdateDialog* UDialog = (UpdateDialog *)data; 
     179    QEvent *event = new QEvent( QEvent::User ); 
     180    QApplication::postEvent( UDialog, event ); 
     181    return VLC_SUCCESS; 
     182} 
     183 
    168184UpdateDialog *UpdateDialog::instance = NULL; 
    169185 
     
    171187{ 
    172188    setWindowTitle( qtr( "Update" ) ); 
    173     resize( 320, 120 ); 
     189    resize( 120, 80 ); 
    174190 
    175191    QGridLayout *layout = new QGridLayout( this ); 
    176192 
    177     updateBrowser = new QTextBrowser( this ); 
    178     updateBrowser->setOpenExternalLinks( true ); 
    179     updateBrowser->setHtml( qtr( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=\"utf-8\" /></head> \ 
    180                                   <body><center>Push the update button to get the updates</center></body></html>" ) ); 
    181      
    182193    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) ); 
    183     QPushButton *updateButton = new QPushButton( qtr( "&Update List" ) ); 
     194    updateButton = new QPushButton( qtr( "&Update List" ) ); 
    184195    updateButton->setDefault( true ); 
    185196    QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal ); 
     
    187198    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole ); 
    188199 
    189     layout->addWidget( updateBrowser, 0, 0 ); 
     200    updateLabel = new QLabel( qtr( "Checking for the update..." ) ); 
     201    updateLabel->setWordWrap( true ); 
     202 
     203    layout->addWidget( updateLabel, 0, 0 ); 
    190204    layout->addWidget( buttonBox, 1, 0 ); 
    191205 
    192     BUTTONACT( updateButton, updateOrUpload() ); 
     206    BUTTONACT( updateButton, UpdateOrDownload() ); 
    193207    BUTTONACT( closeButton, close() ); 
    194208 
     209    /* create the update structure and the callback */ 
    195210    p_update = update_New( _p_intf ); 
     211    var_AddCallback( _p_intf->p_libvlc, "update-notify", updateCallback, this ); 
     212    b_checked = false; 
    196213} 
    197214 
    198215UpdateDialog::~UpdateDialog() 
    199216{ 
     217    var_DelCallback( p_update->p_libvlc, "update-notify", updateCallback, this ); 
    200218    update_Delete( p_update ); 
    201219} 
     
    206224} 
    207225 
    208 void UpdateDialog::updateOrUpload() 
    209 
    210     update_Check( p_update ); 
    211  
     226/* Check for updates */ 
     227void UpdateDialog::UpdateOrDownload() 
     228
     229    if( !b_checked ) 
     230    { 
     231        updateButton->setEnabled( false ); 
     232        update_Check( p_update ); 
     233    } 
     234    else 
     235    { 
     236        updateButton->setEnabled( false ); 
     237        QString dest_dir = QFileDialog::getExistingDirectory( this, qtr( "Select a directory ..." ), 
     238                                                              qfu( p_update->p_libvlc->psz_homedir ) ); 
     239 
     240        if( dest_dir != "" ) 
     241        { 
     242            toggleVisible(); 
     243            update_Download( p_update, qtu( dest_dir ) ); 
     244        } 
     245        else 
     246            updateButton->setEnabled( true ); 
     247    } 
     248
     249 
     250/* Handle the events */ 
     251void UpdateDialog::customEvent( QEvent *event ) 
     252
     253    updateNotify(); 
     254
     255 
     256/* Notify the end of the update_Check */ 
     257void UpdateDialog::updateNotify() 
     258
    212259    if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer ) 
    213260    { 
    214         updateBrowser->setHtml( qtr( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=\"utf-8\" /></head> \ 
    215                                       <body><center><p>" ) + qtu( (QString)p_update->release.psz_desc ) + 
    216                                       qtr( "</p>You can download the latest version of VLC <a href=\"" ) + 
    217                                       qtu( (QString)p_update->release.psz_url ) + qtr( "\">here</a></center></body></html>" ) ); 
     261        b_checked = true; 
     262        updateButton->setText( "Download" ); 
     263        updateLabel->setText( qtr( "There is a new version of vlc :\n" ) + qfu( p_update->release.psz_desc )  ); 
    218264    } 
    219265    else 
    220266    { 
    221         updateBrowser->setHtml( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=\"utf-8\" /></head> \ 
    222                                  <body><center>You have the latest version of VLC.</center></body></html>" ); 
    223     } 
    224 
     267        updateLabel->setText( qtr( "You have the latest version of vlc" ) ); 
     268    } 
     269    adjustSize(); 
     270    updateButton->setEnabled( true ); 
     271
     272 
    225273 
    226274#endif 
  • modules/gui/qt4/dialogs/help.hpp

    r48c2ac8 r77c834e  
    3131class QPushButton; 
    3232class QTextBrowser; 
     33class QLabel; 
     34class QEvent; 
     35class QPushButton; 
    3336 
    3437class HelpDialog : public QVLCFrame 
     
    7275 
    7376#ifdef UPDATE_CHECK 
     77 
    7478class UpdateDialog : public QVLCFrame 
    7579{ 
     
    8387    } 
    8488    virtual ~UpdateDialog(); 
     89    void updateNotify(); 
    8590 
    8691private: 
     
    8893    static UpdateDialog *instance; 
    8994    update_t *p_update; 
    90     QTextBrowser *updateBrowser; 
     95    QPushButton *updateButton; 
     96    QLabel *updateLabel; 
     97    void customEvent( QEvent * ); 
     98    bool b_checked; 
     99 
    91100private slots: 
    92101    void close(); 
    93     void updateOrUpload(); 
     102    void UpdateOrDownload(); 
    94103}; 
    95104#endif 
  • src/misc/update.c

    r48c2ac8 r77c834e  
    8383static int CompareReleases( const struct update_release_t *p1, 
    8484                            const struct update_release_t *p2 ); 
     85static char * size_str( long int l_size ); 
     86 
    8587 
    8688/***************************************************************************** 
     
    765767    p_update->release.psz_desc = NULL; 
    766768 
     769    var_Create( p_this->p_libvlc, "update-notify", VLC_VAR_INTEGER | 
     770                VLC_VAR_ISCOMMAND ); 
     771 
    767772    return p_update; 
    768773} 
     
    779784 
    780785    vlc_mutex_destroy( &p_update->lock ); 
     786 
     787    var_Destroy( p_update->p_libvlc, "update-notify" ); 
    781788 
    782789    FREENULL( p_update->release.psz_svnrev ); 
     
    808815/** 
    809816 * Get the update file and parse it 
    810  * *p_update has to be unlocked when calling this function 
     817 * *p_update has to be locked when calling this function 
    811818 * 
    812819 * \param p_update pointer to update struct 
     
    823830    char *psz_line = NULL; 
    824831 
    825     vlc_mutex_lock( &p_update->lock ); 
    826  
    827832    p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL ); 
    828833    if( !p_stream ) 
     
    878883 
    879884    error: 
    880         vlc_mutex_unlock( &p_update->lock ); 
    881  
    882885        if( p_stream ) 
    883886            stream_Delete( p_stream ); 
    884887} 
    885888 
     889 
     890/** 
     891 * Struct to launch the check in an other thread 
     892 */ 
     893typedef struct 
     894{ 
     895    VLC_COMMON_MEMBERS 
     896    update_t *p_update; 
     897} update_check_thread_t; 
     898 
     899void update_CheckReal( update_check_thread_t *p_uct ); 
     900 
    886901/** 
    887902 * Check for updates 
     
    894909    assert( p_update ); 
    895910 
    896     EmptyRelease( p_update ); 
    897  
    898     GetUpdateFile( p_update ); 
     911    update_check_thread_t *p_uct = vlc_object_create( p_update->p_libvlc, 
     912                                            sizeof( update_check_thread_t ) ); 
     913    p_uct->p_update = p_update; 
     914 
     915    vlc_thread_create( p_uct, "check for update", update_CheckReal, 
     916                       VLC_THREAD_PRIORITY_LOW, VLC_FALSE ); 
     917
     918 
     919void update_CheckReal( update_check_thread_t *p_uct ) 
     920
     921    vlc_mutex_lock( &p_uct->p_update->lock ); 
     922 
     923    EmptyRelease( p_uct->p_update ); 
     924    GetUpdateFile( p_uct->p_update ); 
     925 
     926    vlc_mutex_unlock( &p_uct->p_update->lock ); 
     927 
     928    var_TriggerCallback( p_uct->p_update->p_libvlc, "update-notify" ); 
    899929} 
    900930 
     
    923953    } 
    924954} 
     955 
    925956/** 
    926957 * Compare two release numbers 
     
    933964                            const struct update_release_t *p2 ) 
    934965{ 
     966    /* The string musn't be NULL if we don't want a segfault with strcmp */ 
     967    if( !p1->psz_extra || !p2->psz_extra || !p1->psz_svnrev || !p2->psz_svnrev ) 
     968        return UpdateReleaseStatusEqual; 
     969 
    935970    int32_t d; 
    936971    d = ( p1->i_major << 24 ) + ( p1->i_minor << 16 ) + ( p1->i_revision << 8 ); 
     
    952987 * Compare a given release's version number to the current VLC's one 
    953988 * 
    954  * \param p a releas
     989 * \param p_update structur
    955990 * \return UpdateReleaseStatus(Older|Equal|Newer) 
    956991 */ 
     
    9771012            c.psz_extra = STRDUP( "" ); 
    9781013        c.psz_svnrev = STRDUP( VLC_Changeset() ); 
    979  
    9801014        i_result = CompareReleases( &p_update->release, &c ); 
    981  
    9821015        free( c.psz_extra ); 
    9831016        free( c.psz_svnrev ); 
    9841017    } 
     1018 
    9851019    return i_result; 
    9861020} 
    9871021 
     1022/** 
     1023 * Convert a long int size in bytes to a string 
     1024 * 
     1025 * \param l_size the size in bytes 
     1026 * \return the size as a string 
     1027 */ 
     1028static char *size_str( long int l_size ) 
     1029{ 
     1030    char *psz_tmp; 
     1031    if( l_size>> 30 ) 
     1032        asprintf( &psz_tmp, "%.1f GB", (float)l_size/(1<<30) ); 
     1033    if( l_size >> 20 ) 
     1034        asprintf( &psz_tmp, "%.1f MB", (float)l_size/(1<<20) ); 
     1035    else if( l_size >> 10 ) 
     1036        asprintf( &psz_tmp, "%.1f kB", (float)l_size/(1<<10) ); 
     1037    else 
     1038        asprintf( &psz_tmp, "%ld B", l_size ); 
     1039    return psz_tmp; 
     1040} 
     1041 
     1042 
     1043/* 
     1044 * Struct to launch the download in a thread 
     1045 */ 
     1046typedef struct 
     1047{ 
     1048    VLC_COMMON_MEMBERS 
     1049    update_t *p_update; 
     1050    char *psz_destdir; 
     1051} update_download_thread_t; 
     1052 
     1053void update_DownloadReal( update_download_thread_t *p_udt ); 
     1054 
     1055/** 
     1056 * Download the file given in the update_t 
     1057 * 
     1058 * \param p_update structure 
     1059 * \param dir to store the download file 
     1060 * \return nothing 
     1061 */ 
     1062void update_Download( update_t *p_update, char *psz_destdir ) 
     1063{ 
     1064    assert( p_update ); 
     1065 
     1066    update_download_thread_t *p_udt = vlc_object_create( p_update->p_libvlc, 
     1067                                                      sizeof( update_download_thread_t ) ); 
     1068 
     1069    p_udt->p_update = p_update; 
     1070    p_udt->psz_destdir = STRDUP( psz_destdir ); 
     1071 
     1072    vlc_thread_create( p_udt, "download update", update_DownloadReal, 
     1073                       VLC_THREAD_PRIORITY_LOW, VLC_FALSE ); 
     1074} 
     1075void update_DownloadReal( update_download_thread_t *p_udt ) 
     1076{ 
     1077    int i_progress = 0; 
     1078    long int l_size; 
     1079    long int l_downloaded = 0; 
     1080    char *psz_status; 
     1081    char *psz_downloaded; 
     1082    char *psz_size; 
     1083    char *psz_destfile; 
     1084    char *psz_tmpdestfile; 
     1085 
     1086    FILE *p_file = NULL; 
     1087    stream_t *p_stream; 
     1088    void* p_buffer; 
     1089    int i_read; 
     1090 
     1091    update_t *p_update = p_udt->p_update; 
     1092    char *psz_destdir = p_udt->psz_destdir; 
     1093 
     1094    /* Open the stream */ 
     1095    p_stream = stream_UrlNew( p_update->p_libvlc, p_update->release.psz_url ); 
     1096 
     1097    if( !p_stream ) 
     1098    { 
     1099        msg_Err( p_update->p_libvlc, "Failed to open %s for reading", p_update->release.psz_url ); 
     1100    } 
     1101    else 
     1102    { 
     1103        /* Get the stream size and open the output file */ 
     1104        l_size = stream_Size( p_stream ); 
     1105 
     1106        psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' ); 
     1107        psz_tmpdestfile++; 
     1108        asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ); 
     1109 
     1110        p_file = utf8_fopen( psz_destfile, "w" ); 
     1111        if( !p_file ) 
     1112        { 
     1113            msg_Err( p_update->p_libvlc, "Failed to open %s for writing", psz_destfile ); 
     1114        } 
     1115        else 
     1116        { 
     1117            /* Create a buffer and fill it with the downloaded file */ 
     1118            p_buffer = (void *)malloc( 1 << 10 ); 
     1119            if( p_buffer ) 
     1120            { 
     1121                psz_size = size_str( l_size ); 
     1122                asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done",  p_update->release.psz_url, psz_size, 0.0 ); 
     1123                i_progress = intf_UserProgress( p_update->p_libvlc, "Downloading ...", psz_status, 0.0, 0 ); 
     1124                free( psz_status ); 
     1125 
     1126                while( ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) && 
     1127                         !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) 
     1128                { 
     1129                    fwrite( p_buffer, i_read, 1, p_file ); 
     1130 
     1131                    l_downloaded += i_read; 
     1132                    psz_downloaded = size_str( l_downloaded ); 
     1133                    asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done", p_update->release.psz_url, 
     1134                              psz_size, psz_downloaded, 100.0*(float)l_downloaded/(float)l_size ); 
     1135                    intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 10.0, 0 ); 
     1136                    free( psz_downloaded ); 
     1137                    free( psz_status ); 
     1138                } 
     1139 
     1140                /* If the user cancelled the download */ 
     1141                if( !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) 
     1142                { 
     1143                    asprintf( &psz_status, "%s\nDone %s (100.0%%)", p_update->release.psz_url, psz_size ); 
     1144                    intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 100.0, 0 ); 
     1145                    free( psz_status ); 
     1146                } 
     1147                free( p_buffer ); 
     1148                free( psz_size ); 
     1149            } 
     1150            fclose( p_file ); 
     1151            if( intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) 
     1152                remove( psz_destfile ); 
     1153        } 
     1154        stream_Delete( p_stream ); 
     1155    } 
     1156    free( psz_destdir ); 
     1157} 
     1158 
    9881159#endif