]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Check for the updates when showing the dialog.
[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 #include <vlc/vlc.h>
26
27 #include "dialogs/help.hpp"
28 #include <vlc_about.h>
29
30 #ifdef UPDATE_CHECK
31 #include <vlc_update.h>
32 #endif
33
34 #include "dialogs_provider.hpp"
35
36 #include <vlc_intf_strings.h>
37
38 #include <QTextBrowser>
39 #include <QTabWidget>
40 #include <QFile>
41 #include <QLabel>
42 #include <QString>
43 #include <QDialogButtonBox>
44 #include <QEvent>
45 #include <QFileDialog>
46 #include <QDate>
47
48
49 HelpDialog *HelpDialog::instance = NULL;
50
51 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
52 {
53     setWindowTitle( qtr( "Help" ) );
54     resize( 600, 560 );
55
56     QGridLayout *layout = new QGridLayout( this );
57     QTextBrowser *helpBrowser = new QTextBrowser( this );
58     helpBrowser->setOpenExternalLinks( true );
59     helpBrowser->setHtml( 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 }
68
69 HelpDialog::~HelpDialog()
70 {
71 }
72 void HelpDialog::close()
73 {
74     this->toggleVisible();
75 }
76
77 AboutDialog *AboutDialog::instance = NULL;
78
79 AboutDialog::AboutDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
80 {
81     setWindowTitle( qtr( "About" ) );
82     resize( 600, 500 );
83
84     QGridLayout *layout = new QGridLayout( this );
85     QTabWidget *tab = new QTabWidget( this );
86
87     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
88     closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
89     closeButton->setDefault( true );
90
91     QLabel *introduction = new QLabel(
92             qtr( "Information about VLC media player." ) );
93     QLabel *iconVLC = new QLabel;
94     if( QDate::currentDate().dayOfYear() >= 354 )
95         iconVLC->setPixmap( QPixmap( ":/vlc48-christmas.png" ) );
96     else
97         iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
98     layout->addWidget( iconVLC, 0, 0, 1, 1 );
99     layout->addWidget( introduction, 0, 1, 1, 7 );
100     layout->addWidget( tab, 1, 0, 1, 8 );
101     layout->addWidget( closeButton, 2, 6, 1, 2 );
102
103     /* Main Introduction */
104     QWidget *infoWidget = new QWidget( this );
105     QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
106     QLabel *infoLabel = new QLabel( "VLC media player " VERSION_MESSAGE "\n\n"
107             "(c) " COPYRIGHT_YEARS " - the VideoLAN Team\n\n" +
108             qtr( "VLC media player is a free media player, made by the "
109                  "VideoLAN Team.\nIt is a standalone multimedia player, "
110                  "encoder and streamer, that can read from many supports "
111                  "(files, CDs, DVDs, networks, capture cards...) and that "
112                  "works on many platforms.\n\n" )
113             + qtr( "You are using the new Qt4 Interface.\n" )
114             + qtr( "Compiled by " ) + qfu( VLC_CompileBy() )+ "@"
115             + qfu( VLC_CompileHost() ) + "."
116             + qfu( VLC_CompileDomain() ) + ".\n"
117             + "Compiler: " + qfu( VLC_Compiler() ) + ".\n"
118             + qtr( "Based on SVN revision: " ) + qfu( VLC_Changeset() )
119             + ".\n\n"
120             + qtr( "This program comes with NO WARRANTY, to the extent "
121                 "permitted by the law; read the distribution tab.\n\n" )
122             + "The VideoLAN team <videolan@videolan.org> \n"
123               "http://www.videolan.org/\n" );
124     infoLabel->setWordWrap( infoLabel );
125
126     QLabel *iconVLC2 = new QLabel;
127     if( QDate::currentDate().dayOfYear() >= 354 )
128         iconVLC2->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
129     else
130         iconVLC2->setPixmap( QPixmap( ":/vlc128.png" ) );
131     infoLayout->addWidget( iconVLC2 );
132     infoLayout->addWidget( infoLabel );
133
134     /* GPL License */
135     QTextEdit *licenseEdit = new QTextEdit( this );
136     licenseEdit->setFontFamily( "Monospace" );
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                 "community, the testers, our users and the following people "
146                 "(and the missing ones...) for their collaboration to "
147                 "provide the best 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( "General Info" ) );
162     tab->addTab( authorsEdit, qtr( "Authors" ) );
163     tab->addTab( thanksWidget, qtr("Thanks") );
164     tab->addTab( licenseEdit, qtr("Distribution License") );
165
166     BUTTONACT( closeButton, close() );
167 }
168
169 AboutDialog::~AboutDialog()
170 {
171 }
172 void AboutDialog::close()
173 {
174     this->toggleVisible();
175 }
176
177 #ifdef UPDATE_CHECK
178
179 /*****************************************************************************
180  * UpdateDialog
181  *****************************************************************************/
182 /* callback to get information from the core */
183 static void UpdateCallback( void *data, vlc_bool_t b_ret )
184 {
185     UpdateDialog* UDialog = (UpdateDialog *)data;
186     QEvent* event;
187
188     if( b_ret )
189         event = new QEvent( (QEvent::Type)UDOkEvent );
190     else
191         event = new QEvent( (QEvent::Type)UDErrorEvent );
192
193     QApplication::postEvent( UDialog, event );
194 }
195
196 UpdateDialog *UpdateDialog::instance = NULL;
197
198 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
199 {
200     setWindowTitle( qtr( "Update" ) );
201     resize( 120, 80 );
202
203     QGridLayout *layout = new QGridLayout( this );
204
205     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
206     updateButton = new QPushButton( qtr( "&Update List" ) );
207     updateButton->setDefault( true );
208     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
209     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
210     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
211
212     updateLabel = new QLabel( qtr( "Checking for the update..." ) );
213     updateLabel->setWordWrap( true );
214
215     layout->addWidget( updateLabel, 0, 0 );
216     layout->addWidget( buttonBox, 1, 0 );
217
218     BUTTONACT( updateButton, UpdateOrDownload() );
219     BUTTONACT( closeButton, close() );
220
221     /* create the update structure and the callback */
222     p_update = update_New( _p_intf );
223     b_checked = false;
224
225     /* Check for updates */
226     UpdateOrDownload();
227 }
228
229 UpdateDialog::~UpdateDialog()
230 {
231     update_Delete( p_update );
232 }
233
234 void UpdateDialog::close()
235 {
236     toggleVisible();
237 }
238
239 /* Check for updates */
240 void UpdateDialog::UpdateOrDownload()
241 {
242     if( !b_checked )
243     {
244         updateButton->setEnabled( false );
245         update_Check( p_update, UpdateCallback, this );
246     }
247     else
248     {
249         updateButton->setEnabled( false );
250         QString dest_dir = QFileDialog::getExistingDirectory( this, qtr( "Select a directory ..." ),
251                                                               qfu( p_update->p_libvlc->psz_homedir ) );
252
253         if( dest_dir != "" )
254         {
255             toggleVisible();
256             update_Download( p_update, qtu( dest_dir ) );
257         }
258         else
259             updateButton->setEnabled( true );
260     }
261 }
262
263 /* Handle the events */
264 void UpdateDialog::customEvent( QEvent *event )
265 {
266     if( event->type() == UDOkEvent )
267         updateNotify( true );
268     else
269         updateNotify( false );
270 }
271
272 /* Notify the end of the update_Check */
273 void UpdateDialog::updateNotify( bool b_result )
274 {
275     /* The update finish without errors */
276     if( b_result )
277     {
278         if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer )
279         {
280             b_checked = true;
281             updateButton->setText( "Download" );
282             updateLabel->setText( qtr( "There is a new version of vlc :\n" ) + qfu( p_update->release.psz_desc )  );
283         }
284         else
285             updateLabel->setText( qtr( "You have the latest version of vlc" ) );
286     }
287     else
288         updateLabel->setText( qtr( "An error occure while checking for updates" ) );
289
290     adjustSize();
291     updateButton->setEnabled( true );
292 }
293
294
295 #endif