]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/help.cpp
Qt: UpdateDialog: highlight security changes
[vlc] / modules / gui / qt4 / dialogs / help.cpp
index 93989498d99ff24ba68e5b06e88c9bd7a91ea405..31187b7ec897f25a5d905a219eb847d3fd4c04a2 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Help.cpp : Help and About dialogs
+ * help.cpp : Help and About dialogs
  ****************************************************************************
  * Copyright (C) 2007 the VideoLAN team
  * $Id$
@@ -26,6 +26,7 @@
 # include "config.h"
 #endif
 
+#include "qt4.hpp"
 #include "dialogs/help.hpp"
 #include "util/qt_dirs.hpp"
 
@@ -42,7 +43,6 @@
 #include <QString>
 #include <QDialogButtonBox>
 #include <QEvent>
-#include <QFileDialog>
 #include <QDate>
 #include <QPushButton>
 
@@ -55,28 +55,27 @@ HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
     setWindowRole( "vlc-help" );
     setMinimumSize( 350, 300 );
 
-    QGridLayout *layout = new QGridLayout( this );
+    QVBoxLayout *layout = new QVBoxLayout( this );
+
     QTextBrowser *helpBrowser = new QTextBrowser( this );
     helpBrowser->setOpenExternalLinks( true );
     helpBrowser->setHtml( qtr(I_LONGHELP) );
-    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
-    closeButton->setDefault( true );
 
-    layout->addWidget( helpBrowser, 0, 0, 1, 0 );
-    layout->addWidget( closeButton, 1, 3 );
+    QDialogButtonBox *closeButtonBox = new QDialogButtonBox( this );
+    closeButtonBox->addButton(
+        new QPushButton( qtr("&Close") ), QDialogButtonBox::RejectRole );
+    closeButtonBox->setFocus();
 
-    BUTTONACT( closeButton, close() );
-    readSettings( "Help", QSize( 500, 450 ) );
-}
+    layout->addWidget( helpBrowser );
+    layout->addWidget( closeButtonBox );
 
-HelpDialog::~HelpDialog()
-{
-    writeSettings( "Help" );
+    CONNECT( closeButtonBox, rejected(), this, close() );
+    restoreWidgetPosition( "Help", QSize( 500, 450 ) );
 }
 
-void HelpDialog::close()
+HelpDialog::~HelpDialog()
 {
-    toggleVisible();
+    saveWidgetPosition( "Help" );
 }
 
 AboutDialog::AboutDialog( intf_thread_t *_p_intf)
@@ -84,11 +83,13 @@ AboutDialog::AboutDialog( intf_thread_t *_p_intf)
 {
     /* Build UI */
     ui.setupUi( this );
+    ui.closeButtonBox->addButton(
+        new QPushButton( qtr("&Close"), this ), QDialogButtonBox::RejectRole );
 
     setWindowTitle( qtr( "About" ) );
     setWindowRole( "vlc-about" );
-    resize( 600, 500 );
     setMinimumSize( 600, 500 );
+    resize( 600, 500 );
     setWindowModality( Qt::WindowModal );
 
     CONNECT( ui.closeButtonBox, rejected(), this, close() );
@@ -97,8 +98,8 @@ AboutDialog::AboutDialog( intf_thread_t *_p_intf)
     ui.introduction->setText(
             qtr( "VLC media player" ) + qfu( " " VERSION_MESSAGE ) );
 
-    if( QDate::currentDate().dayOfYear() >= 354 )
-        ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
+    if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
+        ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128-xmas.png" ) );
     else
         ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
 
@@ -113,10 +114,13 @@ AboutDialog::AboutDialog( intf_thread_t *_p_intf)
             + qfu( VLC_CompileBy() )+ " on " + qfu( VLC_CompileHost() ) +
             + " ("__DATE__" "__TIME__").\n"
             + qtr( "Compiler: " ) + qfu( VLC_Compiler() ) + ".\n"
-            + qtr( "You are using the Qt4 Interface.\n\n" )
+            + qtr( "You are using the Qt Interface.\n\n" )
             + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
             + qtr( " by the VideoLAN Team.\n" )
-            + "vlc@videolan.org, http://www.videolan.org" );
+            + "<a href=\"http://www.videolan.org\">http://www.videolan.org</a>" );
+
+    /* Be translators friendly: Convert to rich text */
+    ui.infoLabel->setText( ui.infoLabel->text().replace( "\n", "<br/>" ) );
 
     /* GPL License */
     ui.licenseEdit->setText( qfu( psz_license ) );
@@ -128,15 +132,6 @@ AboutDialog::AboutDialog( intf_thread_t *_p_intf)
     ui.authorsEdit->setText( qfu( psz_authors ) );
 }
 
-AboutDialog::~AboutDialog()
-{
-}
-
-void AboutDialog::close()
-{
-    toggleVisible();
-}
-
 #ifdef UPDATE_CHECK
 
 /*****************************************************************************
@@ -149,58 +144,49 @@ static void UpdateCallback( void *data, bool b_ret )
     QEvent* event;
 
     if( b_ret )
-        event = new QEvent( (QEvent::Type)UDOkEvent );
+        event = new QEvent( UpdateDialog::UDOkEvent );
     else
-        event = new QEvent( (QEvent::Type)UDErrorEvent );
+        event = new QEvent( UpdateDialog::UDErrorEvent );
 
     QApplication::postEvent( UDialog, event );
 }
 
+const QEvent::Type UpdateDialog::UDOkEvent =
+        (QEvent::Type)QEvent::registerEventType();
+const QEvent::Type UpdateDialog::UDErrorEvent =
+        (QEvent::Type)QEvent::registerEventType();
+
 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 {
-    setWindowTitle( qtr( "VLC media player updates" ) );
-    setWindowRole( "vlc-update" );
-
-    QGridLayout *layout = new QGridLayout( this );
-
-    QPushButton *closeButton = new QPushButton( qtr( "&Cancel" ) );
-    updateButton = new QPushButton( qtr( "&Recheck version" ) );
-    updateButton->setDefault( true );
-
-    QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
-    buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
-    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
-
-    updateLabelTop = new QLabel( qtr( "Checking for an update..." ) );
-    updateLabelTop->setWordWrap( true );
-    updateLabelTop->setMargin( 8 );
+    /* 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 );
 
-    updateLabelDown = new QLabel( qtr( "\nDo you want to download it?\n" ) );
-    updateLabelDown->setWordWrap( true );
-    updateLabelDown->hide();
+    ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
+                                         QDialogButtonBox::AcceptRole );
+    ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
+                                         QDialogButtonBox::RejectRole );
 
-    updateText = new QTextEdit( this );
-    updateText->setAcceptRichText(false);
-    updateText->setTextInteractionFlags( Qt::TextSelectableByKeyboard|
-                                         Qt::TextSelectableByMouse);
-    updateText->setEnabled( false );
+    setWindowTitle( qtr( "VLC media player updates" ) );
+    setWindowRole( "vlc-update" );
 
-    layout->addWidget( updateLabelTop, 0, 0 );
-    layout->addWidget( updateText, 1, 0 );
-    layout->addWidget( updateLabelDown, 2, 0 );
-    layout->addWidget( buttonBox, 3, 0 );
+    BUTTONACT( recheckButton, UpdateOrDownload() );
+    CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
 
-    BUTTONACT( updateButton, UpdateOrDownload() );
-    BUTTONACT( closeButton, 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 );
+    setMaximumSize( 500, 300 );
 
-    readSettings( "Update", QSize( 300, 250 ) );
+    restoreWidgetPosition( "Update", maximumSize() );
 
     /* Check for updates */
     UpdateOrDownload();
@@ -209,12 +195,7 @@ UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 UpdateDialog::~UpdateDialog()
 {
     update_Delete( p_update );
-    writeSettings( "Update" );
-}
-
-void UpdateDialog::close()
-{
-    toggleVisible();
+    saveWidgetPosition( "Update" );
 }
 
 /* Check for updates */
@@ -222,22 +203,19 @@ void UpdateDialog::UpdateOrDownload()
 {
     if( !b_checked )
     {
-        updateButton->setEnabled( false );
-        updateLabelTop->setText( qtr( "Launching an update request..." ) );
+        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 ) );
-
+        QString dest_dir = QDir::tempPath();
         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 ! */
         }
     }
 }
@@ -259,37 +237,45 @@ void UpdateDialog::updateNotify( bool 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;
-            updateButton->setText( qtr( "&Yes" ) );
-            QString message = qtr( "A new version of VLC(" )
-                              + QString::number( p_release->i_major ) + "."
-                              + QString::number( p_release->i_minor ) + "."
-                              + QString::number( p_release->i_revision );
-            if( p_release->extra )
-                message += p_release->extra;
-            message += qtr( ") is available.");
-            updateLabelTop->setText( message );
-
-            updateText->setText( qfu( p_release->psz_desc ) );
-            updateText->setEnabled( true );
-
-            updateLabelDown->show();
+            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->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
+
+            ui.updateNotifyLabel->setText( message );
+            message = qfu( p_release->psz_desc ).replace( "\n", "<br/>" );
+
+            /* Try to highlight releases featuring security changes */
+            int i_index = message.indexOf( "security", Qt::CaseInsensitive );
+            if ( i_index >= 0 )
+            {
+                message.insert( i_index + 8, "</font>" );
+                message.insert( i_index, "<font style=\"color:red\">" );
+            }
+            ui.updateNotifyTextEdit->setHtml( message );
 
             /* Force the dialog to be shown */
             this->show();
         }
         else
-            updateLabelTop->setText(
+        {
+            ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
+            ui.updateDialogLabel->setText(
                     qtr( "You have the latest version of VLC media player." ) );
+        }
     }
     else
-        updateLabelTop->setText(
+    {
+        ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
+        ui.updateDialogLabel->setText(
                     qtr( "An error occurred while checking for updates..." ) );
-
-    updateButton->setEnabled( true );
+    }
 }
 
 #endif
-