]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
About: make the label look like links
[vlc] / modules / gui / qt4 / dialogs / help.cpp
1 /*****************************************************************************
2  * help.cpp : Help and About dialogs
3  ****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *          RĂ©mi Duraffort <ivoire (at) via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "qt4.hpp"
30 #include "dialogs/help.hpp"
31 #include "util/qt_dirs.hpp"
32
33 #include <vlc_about.h>
34 #include <vlc_intf_strings.h>
35
36 #ifdef UPDATE_CHECK
37 # include <vlc_update.h>
38 #endif
39
40 #include <QTextBrowser>
41 #include <QTabWidget>
42 #include <QLabel>
43 #include <QString>
44 #include <QDialogButtonBox>
45 #include <QEvent>
46 #include <QDate>
47 #include <QPushButton>
48
49 #include <assert.h>
50
51 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
52
53 {
54     setWindowTitle( qtr( "Help" ) );
55     setWindowRole( "vlc-help" );
56     setMinimumSize( 350, 300 );
57
58     QVBoxLayout *layout = new QVBoxLayout( this );
59
60     QTextBrowser *helpBrowser = new QTextBrowser( this );
61     helpBrowser->setOpenExternalLinks( true );
62     helpBrowser->setHtml( qtr(I_LONGHELP) );
63
64     QDialogButtonBox *closeButtonBox = new QDialogButtonBox( this );
65     closeButtonBox->addButton(
66         new QPushButton( qtr("&Close") ), QDialogButtonBox::RejectRole );
67     closeButtonBox->setFocus();
68
69     layout->addWidget( helpBrowser );
70     layout->addWidget( closeButtonBox );
71
72     CONNECT( closeButtonBox, rejected(), this, close() );
73     restoreWidgetPosition( "Help", QSize( 500, 450 ) );
74 }
75
76 HelpDialog::~HelpDialog()
77 {
78     saveWidgetPosition( "Help" );
79 }
80
81 AboutDialog::AboutDialog( intf_thread_t *_p_intf)
82             : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf ), b_advanced( false )
83 {
84     /* Build UI */
85     ui.setupUi( this );
86     setWindowTitle( qtr( "About" ) );
87     setWindowRole( "vlc-about" );
88     setWindowModality( Qt::WindowModal );
89
90     ui.version->setText(qfu( " " VERSION_MESSAGE ) );
91 #if 0
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" ) );
94     else
95         ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
96 #endif
97
98 #if 0
99     ifdef UPDATE_CHECK
100 #else
101     ui.update->hide();
102 #endif
103
104     /* GPL License */
105     ui.licensePage->setText( qfu( psz_license ) );
106
107     /* People who helped */
108     ui.creditPage->setText( qfu( psz_thanks ) );
109
110     /* People who wrote the software */
111     ui.authorsPage->setText( qfu( psz_authors ) );
112
113     ui.licenseButton->installEventFilter( this );
114     ui.authorsButton->installEventFilter( this );
115     ui.creditsButton->installEventFilter( this );
116
117     ui.version->installEventFilter( this );
118 }
119
120 void AboutDialog::showLicense()
121 {
122     ui.stackedWidget->setCurrentWidget( ui.licensePage );
123 }
124
125 void AboutDialog::showAuthors()
126 {
127     ui.stackedWidget->setCurrentWidget( ui.authorsPage );
128 }
129
130 void AboutDialog::showCredit()
131 {
132     ui.stackedWidget->setCurrentWidget( ui.creditPage );
133 }
134
135 bool AboutDialog::eventFilter(QObject *obj, QEvent *event)
136 {
137     if (event->type() == QEvent::MouseButtonPress )
138     {
139         if( obj == ui.version )
140         {
141             if( !b_advanced )
142             {
143                 ui.version->setText(qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() )
144                     + __DATE__ + " " +__TIME__);
145                 b_advanced = true;
146             }
147             else
148             {
149                 ui.version->setText(qfu( " " VERSION_MESSAGE ) );
150                 b_advanced = false;
151             }
152             return true;
153         }
154         else if( obj == ui.licenseButton )
155             showLicense();
156         else if( obj == ui.authorsButton )
157             showAuthors();
158         else if( obj == ui.creditsButton )
159             showCredit();
160
161         return false;
162     }
163
164     return QVLCDialog::eventFilter( obj, event);
165 }
166 #ifdef UPDATE_CHECK
167
168 /*****************************************************************************
169  * UpdateDialog
170  *****************************************************************************/
171 /* callback to get information from the core */
172 static void UpdateCallback( void *data, bool b_ret )
173 {
174     UpdateDialog* UDialog = (UpdateDialog *)data;
175     QEvent* event;
176
177     if( b_ret )
178         event = new QEvent( UpdateDialog::UDOkEvent );
179     else
180         event = new QEvent( UpdateDialog::UDErrorEvent );
181
182     QApplication::postEvent( UDialog, event );
183 }
184
185 const QEvent::Type UpdateDialog::UDOkEvent =
186         (QEvent::Type)QEvent::registerEventType();
187 const QEvent::Type UpdateDialog::UDErrorEvent =
188         (QEvent::Type)QEvent::registerEventType();
189
190 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
191 {
192     /* build Ui */
193     ui.setupUi( this );
194     ui.updateDialogButtonBox->addButton( new QPushButton( qtr("&Close"), this ),
195                                          QDialogButtonBox::RejectRole );
196     QPushButton *recheckButton = new QPushButton( qtr("&Recheck version"), this );
197     ui.updateDialogButtonBox->addButton( recheckButton, QDialogButtonBox::ActionRole );
198
199     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
200                                          QDialogButtonBox::AcceptRole );
201     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
202                                          QDialogButtonBox::RejectRole );
203
204     setWindowTitle( qtr( "VLC media player updates" ) );
205     setWindowRole( "vlc-update" );
206
207     BUTTONACT( recheckButton, UpdateOrDownload() );
208     CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
209
210     CONNECT( ui.updateNotifyButtonBox, accepted(), this, UpdateOrDownload() );
211     CONNECT( ui.updateNotifyButtonBox, rejected(), this, close() );
212
213     /* Create the update structure */
214     p_update = update_New( p_intf );
215     b_checked = false;
216
217     setMinimumSize( 300, 300 );
218     setMaximumSize( 500, 300 );
219
220     restoreWidgetPosition( "Update", maximumSize() );
221
222     /* Check for updates */
223     UpdateOrDownload();
224 }
225
226 UpdateDialog::~UpdateDialog()
227 {
228     update_Delete( p_update );
229     saveWidgetPosition( "Update" );
230 }
231
232 /* Check for updates */
233 void UpdateDialog::UpdateOrDownload()
234 {
235     if( !b_checked )
236     {
237         ui.stackedWidget->setCurrentWidget( ui.updateRequestPage );
238         update_Check( p_update, UpdateCallback, this );
239     }
240     else
241     {
242         QString dest_dir = QDir::tempPath();
243         if( !dest_dir.isEmpty() )
244         {
245             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
246             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
247             toggleVisible();
248             update_Download( p_update, qtu( dest_dir ) );
249             /* FIXME: We should trigger a change to another dialog here ! */
250         }
251     }
252 }
253
254 /* Handle the events */
255 void UpdateDialog::customEvent( QEvent *event )
256 {
257     if( event->type() == UDOkEvent )
258         updateNotify( true );
259     else
260         updateNotify( false );
261 }
262
263 /* Notify the end of the update_Check */
264 void UpdateDialog::updateNotify( bool b_result )
265 {
266     /* The update finish without errors */
267     if( b_result )
268     {
269         if( update_NeedUpgrade( p_update ) )
270         {
271             ui.stackedWidget->setCurrentWidget( ui.updateNotifyPage );
272             update_release_t *p_release = update_GetRelease( p_update );
273             assert( p_release );
274             b_checked = true;
275             QString message = QString(
276                     qtr( "A new version of VLC (%1.%2.%3%4) is available." ) )
277                 .arg( QString::number( p_release->i_major ) )
278                 .arg( QString::number( p_release->i_minor ) )
279                 .arg( QString::number( p_release->i_revision ) )
280                 .arg( p_release->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
281
282             ui.updateNotifyLabel->setText( message );
283             message = qfu( p_release->psz_desc ).replace( "\n", "<br/>" );
284
285             /* Try to highlight releases featuring security changes */
286             int i_index = message.indexOf( "security", Qt::CaseInsensitive );
287             if ( i_index >= 0 )
288             {
289                 message.insert( i_index + 8, "</font>" );
290                 message.insert( i_index, "<font style=\"color:red\">" );
291             }
292             ui.updateNotifyTextEdit->setHtml( message );
293
294             /* Force the dialog to be shown */
295             this->show();
296         }
297         else
298         {
299             ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
300             ui.updateDialogLabel->setText(
301                     qtr( "You have the latest version of VLC media player." ) );
302         }
303     }
304     else
305     {
306         ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
307         ui.updateDialogLabel->setText(
308                     qtr( "An error occurred while checking for updates..." ) );
309     }
310 }
311
312 #endif