]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Qt: Simplify includes.
[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
31 #include <vlc_about.h>
32 #include <vlc_intf_strings.h>
33
34 #ifdef UPDATE_CHECK
35 # include <vlc_update.h>
36 #endif
37
38 #include <QTextBrowser>
39 #include <QTabWidget>
40 #include <QLabel>
41 #include <QString>
42 #include <QDialogButtonBox>
43 #include <QEvent>
44 #include <QFileDialog>
45 #include <QDate>
46
47
48 HelpDialog *HelpDialog::instance = NULL;
49
50 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
51
52 {
53     setWindowTitle( qtr( "Help" ) );
54     setMinimumSize( 250, 300 );
55
56     QGridLayout *layout = new QGridLayout( this );
57     QTextBrowser *helpBrowser = new QTextBrowser( this );
58     helpBrowser->setOpenExternalLinks( true );
59     helpBrowser->setHtml( qtr(I_LONGHELP) );
60     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
61     closeButton->setDefault( true );
62
63     layout->addWidget( helpBrowser, 0, 0, 1, 0 );
64     layout->addWidget( closeButton, 1, 3 );
65
66     BUTTONACT( closeButton, close() );
67     readSettings( "Help", QSize( 400, 450 ) );
68 }
69
70 HelpDialog::~HelpDialog()
71 {
72     writeSettings( "Help" );
73 }
74
75 void HelpDialog::close()
76 {
77     toggleVisible();
78 }
79
80 AboutDialog *AboutDialog::instance = NULL;
81
82 AboutDialog::AboutDialog( QWidget *parent, intf_thread_t *_p_intf)
83             : QVLCDialog( parent, _p_intf )
84 {
85     setWindowTitle( qtr( "About" ) );
86     resize( 600, 500 );
87     setMinimumSize( 600, 500 );
88
89     QGridLayout *layout = new QGridLayout( this );
90     QTabWidget *tab = new QTabWidget( this );
91
92     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
93     closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
94     closeButton->setDefault( true );
95
96     QLabel *introduction = new QLabel(
97             qtr( "VLC media player" " " VERSION_MESSAGE ) );
98     QLabel *iconVLC = new QLabel;
99     if( QDate::currentDate().dayOfYear() >= 354 )
100         iconVLC->setPixmap( QPixmap( ":/vlc48-christmas.png" ) );
101     else
102         iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
103     layout->addWidget( iconVLC, 0, 0, 1, 1 );
104     layout->addWidget( introduction, 0, 1, 1, 7 );
105     layout->addWidget( tab, 1, 0, 1, 8 );
106     layout->addWidget( closeButton, 2, 6, 1, 2 );
107
108     /* Main Introduction */
109     QWidget *infoWidget = new QWidget( this );
110     QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
111     QLabel *infoLabel = new QLabel(
112             qtr( "VLC media player is a free media player, "
113                 "encoder and streamer that can read from files, "
114                 "CDs, DVDs, network streams, capture cards and even more!\n"
115                 "VLC uses its internal codecs and works on essentially every "
116                 "popular platform.\n\n" )
117             + qtr( "This version of VLC was compiled by:\n " )
118             + qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() ) + "."
119             + qfu( VLC_CompileDomain() ) + ".\n"
120             + qtr( "Compiler: " ) + qfu( VLC_Compiler() ) + ".\n"
121             + qtr( "Based on Git commit: " ) + qfu( VLC_Changeset() ) + ".\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( ":/vlc128-christmas.png" ) );
131     else
132         iconVLC2->setPixmap( QPixmap( ":/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::instance = NULL;
199
200 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
201 {
202     setWindowTitle( qtr( "VLC media player updates" ) );
203
204     QGridLayout *layout = new QGridLayout( this );
205
206     QPushButton *closeButton = new QPushButton( qtr( "&Cancel" ) );
207     updateButton = new QPushButton( qtr( "&Recheck version" ) );
208     updateButton->setDefault( true );
209
210     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
211     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
212     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
213
214     updateLabelTop = new QLabel( qtr( "Checking for an update..." ) );
215     updateLabelTop->setWordWrap( true );
216     updateLabelTop->setMargin( 8 );
217
218     updateLabelDown = new QLabel( qtr( "\nDo you want to download it?\n" ) );
219     updateLabelDown->setWordWrap( true );
220     updateLabelDown->hide();
221
222     updateText = new QTextEdit;
223     updateText->setAcceptRichText(false);
224     updateText->setTextInteractionFlags( Qt::TextSelectableByKeyboard|
225                                          Qt::TextSelectableByMouse);
226     updateText->setEnabled( false );
227
228     layout->addWidget( updateLabelTop, 0, 0 );
229     layout->addWidget( updateText, 1, 0 );
230     layout->addWidget( updateLabelDown, 2, 0 );
231     layout->addWidget( buttonBox, 3, 0 );
232
233     BUTTONACT( updateButton, UpdateOrDownload() );
234     BUTTONACT( closeButton, close() );
235
236     /* Create the update structure */
237     p_update = update_New( p_intf );
238     b_checked = false;
239
240     setMinimumSize( 300, 300 );
241     setMaximumSize( 400, 300 );
242
243     readSettings( "Update", QSize( 300, 250 ) );
244
245     /* Check for updates */
246     UpdateOrDownload();
247 }
248
249 UpdateDialog::~UpdateDialog()
250 {
251     update_Delete( p_update );
252     writeSettings( "Update" );
253 }
254
255 void UpdateDialog::close()
256 {
257     toggleVisible();
258 }
259
260 /* Check for updates */
261 void UpdateDialog::UpdateOrDownload()
262 {
263     if( !b_checked )
264     {
265         updateButton->setEnabled( false );
266         updateLabelTop->setText( qtr( "Launching an update request..." ) );
267         update_Check( p_update, UpdateCallback, this );
268     }
269     else
270     {
271         QString dest_dir = QFileDialog::getExistingDirectory( this,
272                                  qtr( "Select a directory..." ),
273                                  qfu( config_GetHomeDir() ) );
274
275         if( !dest_dir.isEmpty() )
276         {
277             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
278             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
279             toggleVisible();
280             update_Download( p_update, qtu( dest_dir ) );
281         }
282     }
283 }
284
285 /* Handle the events */
286 void UpdateDialog::customEvent( QEvent *event )
287 {
288     if( event->type() == UDOkEvent )
289         updateNotify( true );
290     else
291         updateNotify( false );
292 }
293
294 /* Notify the end of the update_Check */
295 void UpdateDialog::updateNotify( bool b_result )
296 {
297     /* The update finish without errors */
298     if( b_result )
299     {
300         if( update_NeedUpgrade( p_update ) )
301         {
302             update_release_t *p_release = update_GetRelease( p_update );
303             assert( p_release );
304             b_checked = true;
305             updateButton->setText( qtr( "&Yes" ) );
306             QString message = qtr( "A new version of VLC(" )
307                               + QString::number( p_release->i_major ) + "."
308                               + QString::number( p_release->i_minor ) + "."
309                               + QString::number( p_release->i_revision );
310             if( p_release->extra )
311                 message += p_release->extra;
312             message += qtr( ") is available.");
313             updateLabelTop->setText( message );
314
315             updateText->setText( qfu( p_release->psz_desc ) );
316             updateText->setEnabled( true );
317
318             updateLabelDown->show();
319
320             /* Force the dialog to be shown */
321             this->show();
322         }
323         else
324             updateLabelTop->setText(
325                     qtr( "You have the latest version of VLC media player." ) );
326     }
327     else
328         updateLabelTop->setText(
329                     qtr( "An error occurred while checking for updates..." ) );
330
331     updateButton->setEnabled( true );
332 }
333
334 #endif
335