+
+UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
+{
+ /* build Ui */
+ ui.setupUi( this );
+ ui.updateDialogButtonBox->addButton( new QPushButton( qtr("&Close"), this ),
+ QDialogButtonBox::RejectRole );
+ QPushButton *recheckButton = new QPushButton( qtr("&Recheck version"), this );
+ ui.updateDialogButtonBox->addButton( recheckButton, QDialogButtonBox::ActionRole );
+
+ ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
+ QDialogButtonBox::AcceptRole );
+ ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
+ QDialogButtonBox::RejectRole );
+
+ setWindowTitle( qtr( "VLC media player updates" ) );
+ setWindowRole( "vlc-update" );
+
+ BUTTONACT( recheckButton, UpdateOrDownload() );
+ CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
+
+ CONNECT( ui.updateNotifyButtonBox, accepted(), this, UpdateOrDownload() );
+ CONNECT( ui.updateNotifyButtonBox, rejected(), this, close() );
+
+ /* Create the update structure */
+ p_update = update_New( p_intf );
+ b_checked = false;
+
+ setMinimumSize( 300, 300 );
+ setMaximumSize( 400, 300 );
+
+ readSettings( "Update", QSize( 300, 250 ) );
+
+ /* Check for updates */
+ UpdateOrDownload();
+}
+
+UpdateDialog::~UpdateDialog()
+{
+ update_Delete( p_update );
+ writeSettings( "Update" );
+}
+
+void UpdateDialog::close()
+{
+ toggleVisible();
+}
+
+/* Check for updates */
+void UpdateDialog::UpdateOrDownload()
+{
+ if( !b_checked )
+ {
+ ui.stackedWidget->setCurrentWidget( ui.updateRequestPage );
+ update_Check( p_update, UpdateCallback, this );
+ }
+ else
+ {
+ QString dest_dir = QFileDialog::getExistingDirectory( this,
+ qtr( I_OP_SEL_DIR ),
+ QVLCUserDir( VLC_DOWNLOAD_DIR ) );
+
+ if( !dest_dir.isEmpty() )
+ {
+ dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
+ msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
+ toggleVisible();
+ update_Download( p_update, qtu( dest_dir ) );
+ /* FIXME: We should trigger a change to another dialog here ! */
+ }
+ }
+}
+
+/* Handle the events */
+void UpdateDialog::customEvent( QEvent *event )
+{
+ if( event->type() == UDOkEvent )
+ updateNotify( true );
+ else
+ updateNotify( false );
+}
+
+/* Notify the end of the update_Check */
+void UpdateDialog::updateNotify( bool b_result )
+{
+ /* The update finish without errors */
+ if( b_result )
+ {
+ if( update_NeedUpgrade( p_update ) )
+ {
+ ui.stackedWidget->setCurrentWidget( ui.updateNotifyPage );
+ update_release_t *p_release = update_GetRelease( p_update );
+ assert( p_release );
+ b_checked = true;
+ QString message = QString(
+ qtr( "A new version of VLC (%1.%2.%3%4) is available." ) )
+ .arg( QString::number( p_release->i_major ) )
+ .arg( QString::number( p_release->i_minor ) )
+ .arg( QString::number( p_release->i_revision ) )
+ .arg( ( p_release->extra )?QString( p_release->extra ):"" );
+
+ ui.updateNotifyLabel->setText( message );
+ ui.updateNotifyTextEdit->setText( qfu( p_release->psz_desc ) );
+
+ /* Force the dialog to be shown */
+ this->show();
+ }
+ else
+ {
+ ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
+ ui.updateDialogLabel->setText(
+ qtr( "You have the latest version of VLC media player." ) );
+ }
+ }
+ else
+ {
+ ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
+ ui.updateDialogLabel->setText(
+ qtr( "An error occurred while checking for updates..." ) );
+ }
+}
+
+#endif
+