]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Qt: missing white space between the host and build date
[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     ui.title->setText("<html><head/><body><p><span style=\" font-size:26pt; color:#353535;\"> " + qtr( "VLC media player" ) + " </span></p></body></html>");
92
93     ui.MainBlabla->setText("<html><head/><body>" +
94     qtr( "<p>VLC media player is a free and open source media player, encoder, and streamer made by the volunteers of the <a href=\"http://www.videolan.org/\"><span style=\" text-decoration: underline; color:#0057ae;\">VideoLAN</span></a> community.</p><p>VLC uses its internal codecs, works on essentially every popular platform, and can read almost all files, CDs, DVDs, network streams, capture cards and other media formats!</p><p><a href=\"http://www.videolan.org/contribute/\"><span style=\" text-decoration: underline; color:#0057ae;\">Help and join us!</span></a>" ) +
95     "</p></body> </html>");
96
97 #if 0
98     if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
99         ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128-xmas.png" ) );
100     else
101         ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
102 #endif
103
104 #if 0
105     ifdef UPDATE_CHECK
106 #else
107     ui.update->hide();
108 #endif
109
110     /* GPL License */
111     ui.licensePage->setText( qfu( psz_license ) );
112
113     /* People who helped */
114     ui.creditPage->setText( qfu( psz_thanks ) );
115
116     /* People who wrote the software */
117     ui.authorsPage->setText( qfu( psz_authors ) );
118
119     ui.licenseButton->setText( "<html><head/><body><p><span style=\" text-decoration: underline; color:#0057ae;\">"+qtr( "License" )+"</span></p></body></html>");
120     ui.licenseButton->installEventFilter( this );
121
122     ui.authorsButton->setText( "<html><head/><body><p><span style=\" text-decoration: underline; color:#0057ae;\">"+qtr( "Authors" )+"</span></p></body></html>");
123     ui.authorsButton->installEventFilter( this );
124
125     ui.creditsButton->setText( "<html><head/><body><p><span style=\" text-decoration: underline; color:#0057ae;\">"+qtr( "Credits" )+"</span></p></body></html>");
126     ui.creditsButton->installEventFilter( this );
127
128     ui.version->installEventFilter( this );
129 }
130
131 void AboutDialog::showLicense()
132 {
133     ui.stackedWidget->setCurrentWidget( ui.licensePage );
134 }
135
136 void AboutDialog::showAuthors()
137 {
138     ui.stackedWidget->setCurrentWidget( ui.authorsPage );
139 }
140
141 void AboutDialog::showCredit()
142 {
143     ui.stackedWidget->setCurrentWidget( ui.creditPage );
144 }
145
146 bool AboutDialog::eventFilter(QObject *obj, QEvent *event)
147 {
148     if (event->type() == QEvent::MouseButtonPress )
149     {
150         if( obj == ui.version )
151         {
152             if( !b_advanced )
153             {
154                 ui.version->setText(qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() )
155                     + " " + __DATE__ + " " + __TIME__);
156                 b_advanced = true;
157             }
158             else
159             {
160                 ui.version->setText(qfu( " " VERSION_MESSAGE ) );
161                 b_advanced = false;
162             }
163             return true;
164         }
165         else if( obj == ui.licenseButton )
166             showLicense();
167         else if( obj == ui.authorsButton )
168             showAuthors();
169         else if( obj == ui.creditsButton )
170             showCredit();
171
172         return false;
173     }
174
175     return QVLCDialog::eventFilter( obj, event);
176 }
177
178 void AboutDialog::showEvent( QShowEvent *event )
179 {
180     ui.stackedWidget->setCurrentWidget( ui.blablaPage );
181     QVLCDialog::showEvent( event );
182 }
183
184 #ifdef UPDATE_CHECK
185
186 /*****************************************************************************
187  * UpdateDialog
188  *****************************************************************************/
189 /* callback to get information from the core */
190 static void UpdateCallback( void *data, bool b_ret )
191 {
192     UpdateDialog* UDialog = (UpdateDialog *)data;
193     QEvent* event;
194
195     if( b_ret )
196         event = new QEvent( UpdateDialog::UDOkEvent );
197     else
198         event = new QEvent( UpdateDialog::UDErrorEvent );
199
200     QApplication::postEvent( UDialog, event );
201 }
202
203 const QEvent::Type UpdateDialog::UDOkEvent =
204         (QEvent::Type)QEvent::registerEventType();
205 const QEvent::Type UpdateDialog::UDErrorEvent =
206         (QEvent::Type)QEvent::registerEventType();
207
208 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
209 {
210     /* build Ui */
211     ui.setupUi( this );
212     ui.updateDialogButtonBox->addButton( new QPushButton( qtr("&Close"), this ),
213                                          QDialogButtonBox::RejectRole );
214     QPushButton *recheckButton = new QPushButton( qtr("&Recheck version"), this );
215     ui.updateDialogButtonBox->addButton( recheckButton, QDialogButtonBox::ActionRole );
216
217     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
218                                          QDialogButtonBox::AcceptRole );
219     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
220                                          QDialogButtonBox::RejectRole );
221
222     setWindowTitle( qtr( "VLC media player updates" ) );
223     setWindowRole( "vlc-update" );
224
225     BUTTONACT( recheckButton, UpdateOrDownload() );
226     CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
227
228     CONNECT( ui.updateNotifyButtonBox, accepted(), this, UpdateOrDownload() );
229     CONNECT( ui.updateNotifyButtonBox, rejected(), this, close() );
230
231     /* Create the update structure */
232     p_update = update_New( p_intf );
233     b_checked = false;
234
235     setMinimumSize( 300, 300 );
236     setMaximumSize( 500, 300 );
237
238     restoreWidgetPosition( "Update", maximumSize() );
239
240     /* Check for updates */
241     UpdateOrDownload();
242 }
243
244 UpdateDialog::~UpdateDialog()
245 {
246     update_Delete( p_update );
247     saveWidgetPosition( "Update" );
248 }
249
250 /* Check for updates */
251 void UpdateDialog::UpdateOrDownload()
252 {
253     if( !b_checked )
254     {
255         ui.stackedWidget->setCurrentWidget( ui.updateRequestPage );
256         update_Check( p_update, UpdateCallback, this );
257     }
258     else
259     {
260         QString dest_dir = QDir::tempPath();
261         if( !dest_dir.isEmpty() )
262         {
263             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
264             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
265             toggleVisible();
266             update_Download( p_update, qtu( dest_dir ) );
267             /* FIXME: We should trigger a change to another dialog here ! */
268         }
269     }
270 }
271
272 /* Handle the events */
273 void UpdateDialog::customEvent( QEvent *event )
274 {
275     if( event->type() == UDOkEvent )
276         updateNotify( true );
277     else
278         updateNotify( false );
279 }
280
281 /* Notify the end of the update_Check */
282 void UpdateDialog::updateNotify( bool b_result )
283 {
284     /* The update finish without errors */
285     if( b_result )
286     {
287         if( update_NeedUpgrade( p_update ) )
288         {
289             ui.stackedWidget->setCurrentWidget( ui.updateNotifyPage );
290             update_release_t *p_release = update_GetRelease( p_update );
291             assert( p_release );
292             b_checked = true;
293             QString message = QString(
294                     qtr( "A new version of VLC (%1.%2.%3%4) is available." ) )
295                 .arg( QString::number( p_release->i_major ) )
296                 .arg( QString::number( p_release->i_minor ) )
297                 .arg( QString::number( p_release->i_revision ) )
298                 .arg( p_release->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
299
300             ui.updateNotifyLabel->setText( message );
301             message = qfu( p_release->psz_desc ).replace( "\n", "<br/>" );
302
303             /* Try to highlight releases featuring security changes */
304             int i_index = message.indexOf( "security", Qt::CaseInsensitive );
305             if ( i_index >= 0 )
306             {
307                 message.insert( i_index + 8, "</font>" );
308                 message.insert( i_index, "<font style=\"color:red\">" );
309             }
310             ui.updateNotifyTextEdit->setHtml( message );
311
312             /* Force the dialog to be shown */
313             this->show();
314         }
315         else
316         {
317             ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
318             ui.updateDialogLabel->setText(
319                     qtr( "You have the latest version of VLC media player." ) );
320         }
321     }
322     else
323     {
324         ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
325         ui.updateDialogLabel->setText(
326                     qtr( "An error occurred while checking for updates..." ) );
327     }
328 }
329
330 #endif