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