]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Qt: Use the singleton class, to simplify the code
[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
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" ) + qfu( " " VERSION_MESSAGE ) );
98     QLabel *iconVLC = new QLabel;
99     if( QDate::currentDate().dayOfYear() >= 354 )
100         iconVLC->setPixmap( QPixmap( ":/logo/vlc48-christmas.png" ) );
101     else
102         iconVLC->setPixmap( QPixmap( ":/logo/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( "You are using the Qt4 Interface.\n\n" )
122             + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
123             + qtr( " by the VideoLAN Team.\n" )
124             + "vlc@videolan.org, http://www.videolan.org" );
125     infoLabel->setWordWrap( infoLabel );
126
127     QLabel *iconVLC2 = new QLabel;
128     if( QDate::currentDate().dayOfYear() >= 354 )
129         iconVLC2->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
130     else
131         iconVLC2->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
132     infoLayout->addWidget( iconVLC2 );
133     infoLayout->addWidget( infoLabel );
134
135     /* GPL License */
136     QTextEdit *licenseEdit = new QTextEdit( this );
137     licenseEdit->setText( qfu( psz_license ) );
138     licenseEdit->setReadOnly( true );
139
140     /* People who helped */
141     QWidget *thanksWidget = new QWidget( this );
142     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
143
144     QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
145                 "VLC community, the testers, our users and the following people "
146                 "(and the missing ones...) for their collaboration to "
147                 "create the best free software." ) );
148     thanksLabel->setWordWrap( true );
149     thanksLayout->addWidget( thanksLabel );
150     QTextEdit *thanksEdit = new QTextEdit( this );
151     thanksEdit->setText( qfu( psz_thanks ) );
152     thanksEdit->setReadOnly( true );
153     thanksLayout->addWidget( thanksEdit );
154
155     /* People who wrote the software */
156     QTextEdit *authorsEdit = new QTextEdit( this );
157     authorsEdit->setText( qfu( psz_authors ) );
158     authorsEdit->setReadOnly( true );
159
160     /* add the tabs to the Tabwidget */
161     tab->addTab( infoWidget, qtr( "About" ) );
162     tab->addTab( authorsEdit, qtr( "Authors" ) );
163     tab->addTab( thanksWidget, qtr("Thanks") );
164     tab->addTab( licenseEdit, qtr("License") );
165
166     BUTTONACT( closeButton, close() );
167 }
168
169 AboutDialog::~AboutDialog()
170 {
171 }
172
173 void AboutDialog::close()
174 {
175     toggleVisible();
176 }
177
178 #ifdef UPDATE_CHECK
179
180 /*****************************************************************************
181  * UpdateDialog
182  *****************************************************************************/
183 /* callback to get information from the core */
184 static void UpdateCallback( void *data, bool b_ret )
185 {
186     UpdateDialog* UDialog = (UpdateDialog *)data;
187     QEvent* event;
188
189     if( b_ret )
190         event = new QEvent( (QEvent::Type)UDOkEvent );
191     else
192         event = new QEvent( (QEvent::Type)UDErrorEvent );
193
194     QApplication::postEvent( UDialog, event );
195 }
196
197 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
198 {
199     setWindowTitle( qtr( "VLC media player updates" ) );
200     setWindowRole( "vlc-update" );
201
202     QGridLayout *layout = new QGridLayout( this );
203
204     QPushButton *closeButton = new QPushButton( qtr( "&Cancel" ) );
205     updateButton = new QPushButton( qtr( "&Recheck version" ) );
206     updateButton->setDefault( true );
207
208     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
209     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
210     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
211
212     updateLabelTop = new QLabel( qtr( "Checking for an update..." ) );
213     updateLabelTop->setWordWrap( true );
214     updateLabelTop->setMargin( 8 );
215
216     updateLabelDown = new QLabel( qtr( "\nDo you want to download it?\n" ) );
217     updateLabelDown->setWordWrap( true );
218     updateLabelDown->hide();
219
220     updateText = new QTextEdit( this );
221     updateText->setAcceptRichText(false);
222     updateText->setTextInteractionFlags( Qt::TextSelectableByKeyboard|
223                                          Qt::TextSelectableByMouse);
224     updateText->setEnabled( false );
225
226     layout->addWidget( updateLabelTop, 0, 0 );
227     layout->addWidget( updateText, 1, 0 );
228     layout->addWidget( updateLabelDown, 2, 0 );
229     layout->addWidget( buttonBox, 3, 0 );
230
231     BUTTONACT( updateButton, UpdateOrDownload() );
232     BUTTONACT( closeButton, close() );
233
234     /* Create the update structure */
235     p_update = update_New( p_intf );
236     b_checked = false;
237
238     setMinimumSize( 300, 300 );
239     setMaximumSize( 400, 300 );
240
241     readSettings( "Update", QSize( 300, 250 ) );
242
243     /* Check for updates */
244     UpdateOrDownload();
245 }
246
247 UpdateDialog::~UpdateDialog()
248 {
249     update_Delete( p_update );
250     writeSettings( "Update" );
251 }
252
253 void UpdateDialog::close()
254 {
255     toggleVisible();
256 }
257
258 /* Check for updates */
259 void UpdateDialog::UpdateOrDownload()
260 {
261     if( !b_checked )
262     {
263         updateButton->setEnabled( false );
264         updateLabelTop->setText( qtr( "Launching an update request..." ) );
265         update_Check( p_update, UpdateCallback, this );
266     }
267     else
268     {
269         QString dest_dir = QFileDialog::getExistingDirectory( this,
270                                  qtr( "Select a directory..." ),
271                                  QVLCUserDir( VLC_DOWNLOAD_DIR ) );
272
273         if( !dest_dir.isEmpty() )
274         {
275             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
276             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
277             toggleVisible();
278             update_Download( p_update, qtu( dest_dir ) );
279         }
280     }
281 }
282
283 /* Handle the events */
284 void UpdateDialog::customEvent( QEvent *event )
285 {
286     if( event->type() == UDOkEvent )
287         updateNotify( true );
288     else
289         updateNotify( false );
290 }
291
292 /* Notify the end of the update_Check */
293 void UpdateDialog::updateNotify( bool b_result )
294 {
295     /* The update finish without errors */
296     if( b_result )
297     {
298         if( update_NeedUpgrade( p_update ) )
299         {
300             update_release_t *p_release = update_GetRelease( p_update );
301             assert( p_release );
302             b_checked = true;
303             updateButton->setText( qtr( "&Yes" ) );
304             QString message = qtr( "A new version of VLC(" )
305                               + QString::number( p_release->i_major ) + "."
306                               + QString::number( p_release->i_minor ) + "."
307                               + QString::number( p_release->i_revision );
308             if( p_release->extra )
309                 message += p_release->extra;
310             message += qtr( ") is available.");
311             updateLabelTop->setText( message );
312
313             updateText->setText( qfu( p_release->psz_desc ) );
314             updateText->setEnabled( true );
315
316             updateLabelDown->show();
317
318             /* Force the dialog to be shown */
319             this->show();
320         }
321         else
322             updateLabelTop->setText(
323                     qtr( "You have the latest version of VLC media player." ) );
324     }
325     else
326         updateLabelTop->setText(
327                     qtr( "An error occurred while checking for updates..." ) );
328
329     updateButton->setEnabled( true );
330 }
331
332 #endif
333