Changeset 77c834e9255cc30ff51d3107f89a6514f42ab937
- Timestamp:
- 18/12/07 16:51:29 (10 months ago)
- git-parent:
- Files:
-
- include/vlc_update.h (modified) (1 diff)
- modules/control/rc.c (modified) (1 diff)
- modules/gui/qt4/dialogs/help.cpp (modified) (5 diffs)
- modules/gui/qt4/dialogs/help.hpp (modified) (4 diffs)
- src/misc/update.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/vlc_update.h
r48c2ac8 r77c834e 284 284 VLC_EXPORT( void, update_Check, ( update_t * ) ); 285 285 VLC_EXPORT( int, update_CompareReleaseToCurrent, ( update_t * ) ); 286 VLC_EXPORT( void, update_Download, ( update_t *, char* ) ); 286 287 287 288 /** modules/control/rc.c
r48c2ac8 r77c834e 2115 2115 static void checkUpdates( intf_thread_t *p_intf ) 2116 2116 { 2117 /*TODO: - modify this to delete p_update to avoid a memory leak ! 2118 - complete the function wich is not working obiously ! 2117 2119 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 2121 2122 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 );*/ 2131 2124 } 2132 2125 #endif modules/gui/qt4/dialogs/help.cpp
r48c2ac8 r77c834e 42 42 #include <QString> 43 43 #include <QDialogButtonBox> 44 #include <QEvent> 45 #include <QFileDialog> 44 46 45 47 … … 166 168 167 169 #ifdef UPDATE_CHECK 170 171 /***************************************************************************** 172 * UpdateDialog 173 *****************************************************************************/ 174 /* callback to get information from the core */ 175 static 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 168 184 UpdateDialog *UpdateDialog::instance = NULL; 169 185 … … 171 187 { 172 188 setWindowTitle( qtr( "Update" ) ); 173 resize( 320, 120 );189 resize( 120, 80 ); 174 190 175 191 QGridLayout *layout = new QGridLayout( this ); 176 192 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 182 193 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) ); 183 QPushButton *updateButton = new QPushButton( qtr( "&Update List" ) );194 updateButton = new QPushButton( qtr( "&Update List" ) ); 184 195 updateButton->setDefault( true ); 185 196 QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal ); … … 187 198 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole ); 188 199 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 ); 190 204 layout->addWidget( buttonBox, 1, 0 ); 191 205 192 BUTTONACT( updateButton, updateOrUpload() );206 BUTTONACT( updateButton, UpdateOrDownload() ); 193 207 BUTTONACT( closeButton, close() ); 194 208 209 /* create the update structure and the callback */ 195 210 p_update = update_New( _p_intf ); 211 var_AddCallback( _p_intf->p_libvlc, "update-notify", updateCallback, this ); 212 b_checked = false; 196 213 } 197 214 198 215 UpdateDialog::~UpdateDialog() 199 216 { 217 var_DelCallback( p_update->p_libvlc, "update-notify", updateCallback, this ); 200 218 update_Delete( p_update ); 201 219 } … … 206 224 } 207 225 208 void UpdateDialog::updateOrUpload() 209 { 210 update_Check( p_update ); 211 226 /* Check for updates */ 227 void 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 */ 251 void UpdateDialog::customEvent( QEvent *event ) 252 { 253 updateNotify(); 254 } 255 256 /* Notify the end of the update_Check */ 257 void UpdateDialog::updateNotify() 258 { 212 259 if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer ) 213 260 { 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 ) ); 218 264 } 219 265 else 220 266 { 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 225 273 226 274 #endif modules/gui/qt4/dialogs/help.hpp
r48c2ac8 r77c834e 31 31 class QPushButton; 32 32 class QTextBrowser; 33 class QLabel; 34 class QEvent; 35 class QPushButton; 33 36 34 37 class HelpDialog : public QVLCFrame … … 72 75 73 76 #ifdef UPDATE_CHECK 77 74 78 class UpdateDialog : public QVLCFrame 75 79 { … … 83 87 } 84 88 virtual ~UpdateDialog(); 89 void updateNotify(); 85 90 86 91 private: … … 88 93 static UpdateDialog *instance; 89 94 update_t *p_update; 90 QTextBrowser *updateBrowser; 95 QPushButton *updateButton; 96 QLabel *updateLabel; 97 void customEvent( QEvent * ); 98 bool b_checked; 99 91 100 private slots: 92 101 void close(); 93 void updateOrUpload();102 void UpdateOrDownload(); 94 103 }; 95 104 #endif src/misc/update.c
r48c2ac8 r77c834e 83 83 static int CompareReleases( const struct update_release_t *p1, 84 84 const struct update_release_t *p2 ); 85 static char * size_str( long int l_size ); 86 85 87 86 88 /***************************************************************************** … … 765 767 p_update->release.psz_desc = NULL; 766 768 769 var_Create( p_this->p_libvlc, "update-notify", VLC_VAR_INTEGER | 770 VLC_VAR_ISCOMMAND ); 771 767 772 return p_update; 768 773 } … … 779 784 780 785 vlc_mutex_destroy( &p_update->lock ); 786 787 var_Destroy( p_update->p_libvlc, "update-notify" ); 781 788 782 789 FREENULL( p_update->release.psz_svnrev ); … … 808 815 /** 809 816 * Get the update file and parse it 810 * *p_update has to be unlocked when calling this function817 * *p_update has to be locked when calling this function 811 818 * 812 819 * \param p_update pointer to update struct … … 823 830 char *psz_line = NULL; 824 831 825 vlc_mutex_lock( &p_update->lock );826 827 832 p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL ); 828 833 if( !p_stream ) … … 878 883 879 884 error: 880 vlc_mutex_unlock( &p_update->lock );881 882 885 if( p_stream ) 883 886 stream_Delete( p_stream ); 884 887 } 885 888 889 890 /** 891 * Struct to launch the check in an other thread 892 */ 893 typedef struct 894 { 895 VLC_COMMON_MEMBERS 896 update_t *p_update; 897 } update_check_thread_t; 898 899 void update_CheckReal( update_check_thread_t *p_uct ); 900 886 901 /** 887 902 * Check for updates … … 894 909 assert( p_update ); 895 910 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 919 void 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" ); 899 929 } 900 930 … … 923 953 } 924 954 } 955 925 956 /** 926 957 * Compare two release numbers … … 933 964 const struct update_release_t *p2 ) 934 965 { 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 935 970 int32_t d; 936 971 d = ( p1->i_major << 24 ) + ( p1->i_minor << 16 ) + ( p1->i_revision << 8 ); … … 952 987 * Compare a given release's version number to the current VLC's one 953 988 * 954 * \param p a release989 * \param p_update structure 955 990 * \return UpdateReleaseStatus(Older|Equal|Newer) 956 991 */ … … 977 1012 c.psz_extra = STRDUP( "" ); 978 1013 c.psz_svnrev = STRDUP( VLC_Changeset() ); 979 980 1014 i_result = CompareReleases( &p_update->release, &c ); 981 982 1015 free( c.psz_extra ); 983 1016 free( c.psz_svnrev ); 984 1017 } 1018 985 1019 return i_result; 986 1020 } 987 1021 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 */ 1028 static 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 */ 1046 typedef struct 1047 { 1048 VLC_COMMON_MEMBERS 1049 update_t *p_update; 1050 char *psz_destdir; 1051 } update_download_thread_t; 1052 1053 void 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 */ 1062 void 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 } 1075 void 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 988 1159 #endif
