1 /*****************************************************************************
2 * help.cpp : Help and About dialogs
3 ****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8 * RĂ©mi Duraffort <ivoire (at) via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include "dialogs/help.hpp"
31 #include "util/qt_dirs.hpp"
33 #include <vlc_about.h>
34 #include <vlc_intf_strings.h>
37 # include <vlc_update.h>
40 #include <QTextBrowser>
44 #include <QDialogButtonBox>
47 #include <QPushButton>
51 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
54 setWindowTitle( qtr( "Help" ) );
55 setWindowRole( "vlc-help" );
56 setMinimumSize( 350, 300 );
58 QVBoxLayout *layout = new QVBoxLayout( this );
60 QTextBrowser *helpBrowser = new QTextBrowser( this );
61 helpBrowser->setOpenExternalLinks( true );
62 helpBrowser->setHtml( qtr(I_LONGHELP) );
64 QDialogButtonBox *closeButtonBox = new QDialogButtonBox( this );
65 closeButtonBox->addButton(
66 new QPushButton( qtr("&Close") ), QDialogButtonBox::RejectRole );
67 closeButtonBox->setFocus();
69 layout->addWidget( helpBrowser );
70 layout->addWidget( closeButtonBox );
72 CONNECT( closeButtonBox, rejected(), this, close() );
73 restoreWidgetPosition( "Help", QSize( 500, 450 ) );
76 HelpDialog::~HelpDialog()
78 saveWidgetPosition( "Help" );
81 AboutDialog::AboutDialog( intf_thread_t *_p_intf)
82 : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
86 setWindowTitle( qtr( "About" ) );
87 setWindowRole( "vlc-about" );
88 setWindowModality( Qt::WindowModal );
90 ui.version->setText(qfu( " " VERSION_MESSAGE ) );
92 if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
93 ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128-xmas.png" ) );
95 ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
105 ui.licensePage->setText( qfu( psz_license ) );
107 /* People who helped */
108 ui.creditPage->setText( qfu( psz_thanks ) );
110 /* People who wrote the software */
111 ui.authorsPage->setText( qfu( psz_authors ) );
113 BUTTONACT(ui.licenseButton, showLicense() );
114 BUTTONACT(ui.authorsButton, showAuthors() );
115 BUTTONACT(ui.creditsButton, showCredit() );
118 void AboutDialog::showLicense()
120 ui.stackedWidget->setCurrentWidget( ui.licensePage );
123 void AboutDialog::showAuthors()
125 ui.stackedWidget->setCurrentWidget( ui.authorsPage );
128 void AboutDialog::showCredit()
130 ui.stackedWidget->setCurrentWidget( ui.creditPage );
135 /*****************************************************************************
137 *****************************************************************************/
138 /* callback to get information from the core */
139 static void UpdateCallback( void *data, bool b_ret )
141 UpdateDialog* UDialog = (UpdateDialog *)data;
145 event = new QEvent( UpdateDialog::UDOkEvent );
147 event = new QEvent( UpdateDialog::UDErrorEvent );
149 QApplication::postEvent( UDialog, event );
152 const QEvent::Type UpdateDialog::UDOkEvent =
153 (QEvent::Type)QEvent::registerEventType();
154 const QEvent::Type UpdateDialog::UDErrorEvent =
155 (QEvent::Type)QEvent::registerEventType();
157 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
161 ui.updateDialogButtonBox->addButton( new QPushButton( qtr("&Close"), this ),
162 QDialogButtonBox::RejectRole );
163 QPushButton *recheckButton = new QPushButton( qtr("&Recheck version"), this );
164 ui.updateDialogButtonBox->addButton( recheckButton, QDialogButtonBox::ActionRole );
166 ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
167 QDialogButtonBox::AcceptRole );
168 ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
169 QDialogButtonBox::RejectRole );
171 setWindowTitle( qtr( "VLC media player updates" ) );
172 setWindowRole( "vlc-update" );
174 BUTTONACT( recheckButton, UpdateOrDownload() );
175 CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
177 CONNECT( ui.updateNotifyButtonBox, accepted(), this, UpdateOrDownload() );
178 CONNECT( ui.updateNotifyButtonBox, rejected(), this, close() );
180 /* Create the update structure */
181 p_update = update_New( p_intf );
184 setMinimumSize( 300, 300 );
185 setMaximumSize( 500, 300 );
187 restoreWidgetPosition( "Update", maximumSize() );
189 /* Check for updates */
193 UpdateDialog::~UpdateDialog()
195 update_Delete( p_update );
196 saveWidgetPosition( "Update" );
199 /* Check for updates */
200 void UpdateDialog::UpdateOrDownload()
204 ui.stackedWidget->setCurrentWidget( ui.updateRequestPage );
205 update_Check( p_update, UpdateCallback, this );
209 QString dest_dir = QDir::tempPath();
210 if( !dest_dir.isEmpty() )
212 dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
213 msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
215 update_Download( p_update, qtu( dest_dir ) );
216 /* FIXME: We should trigger a change to another dialog here ! */
221 /* Handle the events */
222 void UpdateDialog::customEvent( QEvent *event )
224 if( event->type() == UDOkEvent )
225 updateNotify( true );
227 updateNotify( false );
230 /* Notify the end of the update_Check */
231 void UpdateDialog::updateNotify( bool b_result )
233 /* The update finish without errors */
236 if( update_NeedUpgrade( p_update ) )
238 ui.stackedWidget->setCurrentWidget( ui.updateNotifyPage );
239 update_release_t *p_release = update_GetRelease( p_update );
242 QString message = QString(
243 qtr( "A new version of VLC (%1.%2.%3%4) is available." ) )
244 .arg( QString::number( p_release->i_major ) )
245 .arg( QString::number( p_release->i_minor ) )
246 .arg( QString::number( p_release->i_revision ) )
247 .arg( p_release->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
249 ui.updateNotifyLabel->setText( message );
250 message = qfu( p_release->psz_desc ).replace( "\n", "<br/>" );
252 /* Try to highlight releases featuring security changes */
253 int i_index = message.indexOf( "security", Qt::CaseInsensitive );
256 message.insert( i_index + 8, "</font>" );
257 message.insert( i_index, "<font style=\"color:red\">" );
259 ui.updateNotifyTextEdit->setHtml( message );
261 /* Force the dialog to be shown */
266 ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
267 ui.updateDialogLabel->setText(
268 qtr( "You have the latest version of VLC media player." ) );
273 ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
274 ui.updateDialogLabel->setText(
275 qtr( "An error occurred while checking for updates..." ) );