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