]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Add build date/time in the version infos
[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 "dialogs/help.hpp"
30 #include "util/qt_dirs.hpp"
31
32 #include <vlc_about.h>
33 #include <vlc_intf_strings.h>
34
35 #ifdef UPDATE_CHECK
36 # include <vlc_update.h>
37 #endif
38
39 #include <QTextBrowser>
40 #include <QTabWidget>
41 #include <QLabel>
42 #include <QString>
43 #include <QDialogButtonBox>
44 #include <QEvent>
45 #include <QFileDialog>
46 #include <QDate>
47
48 #include <assert.h>
49
50 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
51
52 {
53     setWindowTitle( qtr( "Help" ) );
54     setWindowRole( "vlc-help" );
55     setMinimumSize( 350, 300 );
56
57     QGridLayout *layout = new QGridLayout( this );
58     QTextBrowser *helpBrowser = new QTextBrowser( this );
59     helpBrowser->setOpenExternalLinks( true );
60     helpBrowser->setHtml( qtr(I_LONGHELP) );
61     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
62     closeButton->setDefault( true );
63
64     layout->addWidget( helpBrowser, 0, 0, 1, 0 );
65     layout->addWidget( closeButton, 1, 3 );
66
67     BUTTONACT( closeButton, close() );
68     readSettings( "Help", QSize( 500, 450 ) );
69 }
70
71 HelpDialog::~HelpDialog()
72 {
73     writeSettings( "Help" );
74 }
75
76 void HelpDialog::close()
77 {
78     toggleVisible();
79 }
80
81 AboutDialog::AboutDialog( intf_thread_t *_p_intf)
82             : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
83 {
84     setWindowTitle( qtr( "About" ) );
85     setWindowRole( "vlc-about" );
86     resize( 600, 500 );
87     setMinimumSize( 600, 500 );
88     setWindowModality( Qt::WindowModal );
89
90     QGridLayout *layout = new QGridLayout( this );
91     QTabWidget *tab = new QTabWidget( this );
92
93     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
94     closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
95     closeButton->setDefault( true );
96
97     QLabel *introduction = new QLabel(
98             qtr( "VLC media player" ) + qfu( " " VERSION_MESSAGE ) );
99     QLabel *iconVLC = new QLabel;
100     if( QDate::currentDate().dayOfYear() >= 354 )
101         iconVLC->setPixmap( QPixmap( ":/logo/vlc48-christmas.png" ) );
102     else
103         iconVLC->setPixmap( QPixmap( ":/logo/vlc48.png" ) );
104     layout->addWidget( iconVLC, 0, 0, 1, 1 );
105     layout->addWidget( introduction, 0, 1, 1, 7 );
106     layout->addWidget( tab, 1, 0, 1, 8 );
107     layout->addWidget( closeButton, 2, 6, 1, 2 );
108
109     /* Main Introduction */
110     QWidget *infoWidget = new QWidget( this );
111     QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
112     QLabel *infoLabel = new QLabel(
113             qtr( "VLC media player is a free media player, "
114                 "encoder and streamer that can read from files, "
115                 "CDs, DVDs, network streams, capture cards and even more!\n"
116                 "VLC uses its internal codecs and works on essentially every "
117                 "popular platform.\n\n" )
118             + qtr( "This version of VLC was compiled by:\n " )
119             + qfu( VLC_CompileBy() )+ " on " + qfu( VLC_CompileHost() ) +
120             + " ("__DATE__" "__TIME__").\n"
121             + qtr( "Compiler: " ) + qfu( VLC_Compiler() ) + ".\n"
122             + qtr( "You are using the Qt4 Interface.\n\n" )
123             + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
124             + qtr( " by the VideoLAN Team.\n" )
125             + "vlc@videolan.org, http://www.videolan.org" );
126     infoLabel->setWordWrap( infoLabel );
127
128     QLabel *iconVLC2 = new QLabel;
129     if( QDate::currentDate().dayOfYear() >= 354 )
130         iconVLC2->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
131     else
132         iconVLC2->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
133     infoLayout->addWidget( iconVLC2 );
134     infoLayout->addWidget( infoLabel );
135
136     /* GPL License */
137     QTextEdit *licenseEdit = new QTextEdit( this );
138     licenseEdit->setText( qfu( psz_license ) );
139     licenseEdit->setReadOnly( true );
140
141     /* People who helped */
142     QWidget *thanksWidget = new QWidget( this );
143     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
144
145     QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
146                 "VLC community, the testers, our users and the following people "
147                 "(and the missing ones...) for their collaboration to "
148                 "create the best free software." ) );
149     thanksLabel->setWordWrap( true );
150     thanksLayout->addWidget( thanksLabel );
151     QTextEdit *thanksEdit = new QTextEdit( this );
152     thanksEdit->setText( qfu( psz_thanks ) );
153     thanksEdit->setReadOnly( true );
154     thanksLayout->addWidget( thanksEdit );
155
156     /* People who wrote the software */
157     QTextEdit *authorsEdit = new QTextEdit( this );
158     authorsEdit->setText( qfu( psz_authors ) );
159     authorsEdit->setReadOnly( true );
160
161     /* add the tabs to the Tabwidget */
162     tab->addTab( infoWidget, qtr( "About" ) );
163     tab->addTab( authorsEdit, qtr( "Authors" ) );
164     tab->addTab( thanksWidget, qtr("Thanks") );
165     tab->addTab( licenseEdit, qtr("License") );
166
167     BUTTONACT( closeButton, close() );
168 }
169
170 AboutDialog::~AboutDialog()
171 {
172 }
173
174 void AboutDialog::close()
175 {
176     toggleVisible();
177 }
178
179 #ifdef UPDATE_CHECK
180
181 /*****************************************************************************
182  * UpdateDialog
183  *****************************************************************************/
184 /* callback to get information from the core */
185 static void UpdateCallback( void *data, bool b_ret )
186 {
187     UpdateDialog* UDialog = (UpdateDialog *)data;
188     QEvent* event;
189
190     if( b_ret )
191         event = new QEvent( (QEvent::Type)UDOkEvent );
192     else
193         event = new QEvent( (QEvent::Type)UDErrorEvent );
194
195     QApplication::postEvent( UDialog, event );
196 }
197
198 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
199 {
200     setWindowTitle( qtr( "VLC media player updates" ) );
201     setWindowRole( "vlc-update" );
202
203     QGridLayout *layout = new QGridLayout( this );
204
205     QPushButton *closeButton = new QPushButton( qtr( "&Cancel" ) );
206     updateButton = new QPushButton( qtr( "&Recheck version" ) );
207     updateButton->setDefault( true );
208
209     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
210     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
211     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
212
213     updateLabelTop = new QLabel( qtr( "Checking for an update..." ) );
214     updateLabelTop->setWordWrap( true );
215     updateLabelTop->setMargin( 8 );
216
217     updateLabelDown = new QLabel( qtr( "\nDo you want to download it?\n" ) );
218     updateLabelDown->setWordWrap( true );
219     updateLabelDown->hide();
220
221     updateText = new QTextEdit( this );
222     updateText->setAcceptRichText(false);
223     updateText->setTextInteractionFlags( Qt::TextSelectableByKeyboard|
224                                          Qt::TextSelectableByMouse);
225     updateText->setEnabled( false );
226
227     layout->addWidget( updateLabelTop, 0, 0 );
228     layout->addWidget( updateText, 1, 0 );
229     layout->addWidget( updateLabelDown, 2, 0 );
230     layout->addWidget( buttonBox, 3, 0 );
231
232     BUTTONACT( updateButton, UpdateOrDownload() );
233     BUTTONACT( closeButton, close() );
234
235     /* Create the update structure */
236     p_update = update_New( p_intf );
237     b_checked = false;
238
239     setMinimumSize( 300, 300 );
240     setMaximumSize( 400, 300 );
241
242     readSettings( "Update", QSize( 300, 250 ) );
243
244     /* Check for updates */
245     UpdateOrDownload();
246 }
247
248 UpdateDialog::~UpdateDialog()
249 {
250     update_Delete( p_update );
251     writeSettings( "Update" );
252 }
253
254 void UpdateDialog::close()
255 {
256     toggleVisible();
257 }
258
259 /* Check for updates */
260 void UpdateDialog::UpdateOrDownload()
261 {
262     if( !b_checked )
263     {
264         updateButton->setEnabled( false );
265         updateLabelTop->setText( qtr( "Launching an update request..." ) );
266         update_Check( p_update, UpdateCallback, this );
267     }
268     else
269     {
270         QString dest_dir = QFileDialog::getExistingDirectory( this,
271                                  qtr( "Select a directory..." ),
272                                  QVLCUserDir( VLC_DOWNLOAD_DIR ) );
273
274         if( !dest_dir.isEmpty() )
275         {
276             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
277             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
278             toggleVisible();
279             update_Download( p_update, qtu( dest_dir ) );
280         }
281     }
282 }
283
284 /* Handle the events */
285 void UpdateDialog::customEvent( QEvent *event )
286 {
287     if( event->type() == UDOkEvent )
288         updateNotify( true );
289     else
290         updateNotify( false );
291 }
292
293 /* Notify the end of the update_Check */
294 void UpdateDialog::updateNotify( bool b_result )
295 {
296     /* The update finish without errors */
297     if( b_result )
298     {
299         if( update_NeedUpgrade( p_update ) )
300         {
301             update_release_t *p_release = update_GetRelease( p_update );
302             assert( p_release );
303             b_checked = true;
304             updateButton->setText( qtr( "&Yes" ) );
305             QString message = qtr( "A new version of VLC(" )
306                               + QString::number( p_release->i_major ) + "."
307                               + QString::number( p_release->i_minor ) + "."
308                               + QString::number( p_release->i_revision );
309             if( p_release->extra )
310                 message += p_release->extra;
311             message += qtr( ") is available.");
312             updateLabelTop->setText( message );
313
314             updateText->setText( qfu( p_release->psz_desc ) );
315             updateText->setEnabled( true );
316
317             updateLabelDown->show();
318
319             /* Force the dialog to be shown */
320             this->show();
321         }
322         else
323             updateLabelTop->setText(
324                     qtr( "You have the latest version of VLC media player." ) );
325     }
326     else
327         updateLabelTop->setText(
328                     qtr( "An error occurred while checking for updates..." ) );
329
330     updateButton->setEnabled( true );
331 }
332
333 #endif
334