Commit 16454068 authored by Antoine Cellerier's avatar Antoine Cellerier

use VLC threads instead of wxWidgets threads.

(i just had to find the suxor thread exemple in video_output.c :p )
parent ca3c860f
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*****************************************************************************/ *****************************************************************************/
#include "updatevlc.hpp" #include "updatevlc.hpp"
#include <wx/imaglist.h> #include <wx/imaglist.h>
#include <wx/thread.h>
#include "bitmaps/update_ascii.xpm" #include "bitmaps/update_ascii.xpm"
#include "bitmaps/update_binary.xpm" #include "bitmaps/update_binary.xpm"
...@@ -168,26 +167,6 @@ void UpdateVLC::OnCheckForUpdate( wxCommandEvent& event ) ...@@ -168,26 +167,6 @@ void UpdateVLC::OnCheckForUpdate( wxCommandEvent& event )
} }
} }
class DownloadThread : public wxThread
{
public:
DownloadThread( update_iterator_t *p_uit, char *psz_dest )
:p_uit( p_uit ),psz_dest( psz_dest )
{
Create();
Run();
};
ExitCode Entry()
{
update_download( p_uit, psz_dest );
update_iterator_Delete( p_uit );
LocaleFree( psz_dest );
return 0;
};
update_iterator_t *p_uit;
char *psz_dest;
};
void UpdateVLC::OnChooseItem( wxListEvent& event ) void UpdateVLC::OnChooseItem( wxListEvent& event )
{ {
update_iterator_t *p_uit = update_iterator_New( p_u ); update_iterator_t *p_uit = update_iterator_New( p_u );
...@@ -213,14 +192,10 @@ void UpdateVLC::OnChooseItem( wxListEvent& event ) ...@@ -213,14 +192,10 @@ void UpdateVLC::OnChooseItem( wxListEvent& event )
{ {
char *psz_dest = ToLocale( filedialog->GetPath().mb_str() ); char *psz_dest = ToLocale( filedialog->GetPath().mb_str() );
/* Launch the download process in a new thread so it doesn't update_download( p_uit, psz_dest );
* block the interface */ LocaleFree( psz_dest );
new DownloadThread( p_uit, psz_dest );
}
else
{
update_iterator_Delete( p_uit );
} }
update_iterator_Delete( p_uit );
delete filedialog; delete filedialog;
} }
} }
...@@ -1181,7 +1181,20 @@ unsigned int update_iterator_Action( update_iterator_t *p_uit, int i_action ) ...@@ -1181,7 +1181,20 @@ unsigned int update_iterator_Action( update_iterator_t *p_uit, int i_action )
} }
/** /**
* Download the file selected by the update iterator * Object to launch download thread in a different object
*/
typedef struct {
VLC_COMMON_MEMBERS
char *psz_dest; //< Download destination
char *psz_src; //< Download source
char *psz_status; //< Download status displayed in progress dialog
} download_thread_t;
void update_download_for_real( download_thread_t *p_this );
/**
* Download the file selected by the update iterator. This function will
* launch the download in a new thread (downloads can be long)
* *
* \param p_uit update iterator * \param p_uit update iterator
* \param psz_dest destination file path * \param psz_dest destination file path
...@@ -1189,9 +1202,32 @@ unsigned int update_iterator_Action( update_iterator_t *p_uit, int i_action ) ...@@ -1189,9 +1202,32 @@ unsigned int update_iterator_Action( update_iterator_t *p_uit, int i_action )
*/ */
void update_download( update_iterator_t *p_uit, char *psz_dest ) void update_download( update_iterator_t *p_uit, char *psz_dest )
{ {
char *psz_src = p_uit->file.psz_url; download_thread_t *p_dt =
vlc_object_create( p_uit->p_u->p_vlc, sizeof( download_thread_t ) );
p_dt->psz_dest = strdup( psz_dest );
p_dt->psz_src = strdup( p_uit->file.psz_url );
asprintf( &p_dt->psz_status, "%s - %s (%s)\nSource: %s\nDestination: %s",
p_uit->file.psz_description, p_uit->release.psz_version,
p_uit->release.psz_svn_revision, p_uit->file.psz_url,
psz_dest);
vlc_thread_create( p_dt, "download thread", update_download_for_real,
VLC_THREAD_PRIORITY_LOW, VLC_FALSE );
}
/**
* The true download function.
*
* \param p_this the download_thread_t object
* \return nothing
*/
void update_download_for_real( download_thread_t *p_this )
{
char *psz_dest = p_this->psz_dest;
char *psz_src = p_this->psz_src;
stream_t *p_stream; stream_t *p_stream;
vlc_t *p_vlc = p_uit->p_u->p_vlc; vlc_t *p_vlc = p_this->p_vlc;
FILE *p_file = NULL; FILE *p_file = NULL;
void *p_buffer; void *p_buffer;
...@@ -1202,55 +1238,62 @@ void update_download( update_iterator_t *p_uit, char *psz_dest ) ...@@ -1202,55 +1238,62 @@ void update_download( update_iterator_t *p_uit, char *psz_dest )
int i_size; int i_size;
int i_done = 0; int i_done = 0;
vlc_thread_ready( p_this );
p_stream = stream_UrlNew( p_vlc, psz_src ); p_stream = stream_UrlNew( p_vlc, psz_src );
if( !p_stream ) if( !p_stream )
{ {
msg_Err( p_vlc, "Failed to open %s for reading", psz_src ); msg_Err( p_vlc, "Failed to open %s for reading", psz_src );
return;
} }
else
p_file = fopen( psz_dest, "w" );
if( !p_file )
{ {
msg_Err( p_vlc, "Failed to open %s for writing", psz_dest );
return;
}
i_size = (int)(stream_Size(p_stream)/(1<<10)); p_file = fopen( psz_dest, "w" );
p_buffer = (void *)malloc( 1<<10 ); if( !p_file )
{
msg_Err( p_vlc, "Failed to open %s for writing", psz_dest );
}
else
{
i_size = (int)(stream_Size(p_stream)/(1<<10));
p_buffer = (void *)malloc( 1<<10 );
asprintf( &psz_status, asprintf( &psz_status, "%s\nDownloading... %.1f%% done",
"%s - %s (%s)\n" p_this->psz_status, 0.0 );
"Source: %s\n" i_progress = intf_UserProgress( p_vlc, "Downloading...",
"Destination: %s\n" psz_status, 0.0 );
"Downloading... %.1f%% done",
p_uit->file.psz_description, p_uit->release.psz_version,
p_uit->release.psz_svn_revision, p_uit->file.psz_url,
psz_dest, 0.0 );
i_progress = intf_UserProgress( p_vlc, "Downloading...", psz_status, 0.0 );
while( stream_Read( p_stream, p_buffer, 1<<10 ) ) while( stream_Read( p_stream, p_buffer, 1<<10 ) )
{ {
float f_progress; float f_progress;
fwrite( p_buffer, 1<<10, 1, p_file ); fwrite( p_buffer, 1<<10, 1, p_file );
i_done++; i_done++;
free( psz_status ); free( psz_status );
f_progress = 100.0*(float)i_done/(float)i_size; f_progress = 100.0*(float)i_done/(float)i_size;
asprintf( &psz_status, asprintf( &psz_status, "%s\nDownloading... %.1f%% done",
"%s - %s (%s)\n" p_this->psz_status, f_progress );
"Source: %s\n" intf_UserProgressUpdate( p_vlc, i_progress,
"Destination: %s\n" psz_status, f_progress );
"Downloading... %.1f%% done", }
p_uit->file.psz_description, p_uit->release.psz_version,
p_uit->release.psz_svn_revision, p_uit->file.psz_url, free( p_buffer );
psz_dest, f_progress ); free( psz_status );
intf_UserProgressUpdate( p_vlc, i_progress, psz_status, f_progress ); fclose( p_file );
stream_Delete( p_stream );
}
} }
free( p_buffer ); free( p_this->psz_dest );
free( psz_status ); free( p_this->psz_src );
fclose( p_file ); free( p_this->psz_status );
stream_Delete( p_stream );
#ifdef WIN32
CloseHandle( p_this->thread_id );
#endif
vlc_object_destroy( p_this );
} }
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