]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
19fc589b49a2bb0ee2108270e55ec2a080a6951c
[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/vlc.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( QWidget *parent, intf_thread_t *_p_intf )
56            : QVLCDialog( parent, _p_intf )
57 {
58     setWindowTitle( qtr( "Help" ) );
59     resize( 600, 560 );
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 }
73
74 HelpDialog::~HelpDialog()
75 {
76 }
77 void HelpDialog::close()
78 {
79     this->toggleVisible();
80 }
81
82 AboutDialog *AboutDialog::instance = NULL;
83
84 AboutDialog::AboutDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
85 {
86     setWindowTitle( qtr( "About" ) );
87     resize( 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( "Information about VLC media player." ) );
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( "VLC media player " VERSION_MESSAGE "\n\n"
112             "(c) " COPYRIGHT_YEARS " - the VideoLAN Team\n\n" +
113             qtr( "VLC media player is a free media player, made by the "
114                  "VideoLAN Team.\nIt is a standalone multimedia player, "
115                  "encoder and streamer, that can read from many supports "
116                  "(files, CDs, DVDs, networks, capture cards...) and that "
117                  "works on many platforms.\n\n" )
118             + qtr( "You are using the Qt4 Interface.\n" )
119             + qtr( "Compiled by " ) + qfu( VLC_CompileBy() )+ "@"
120             + qfu( VLC_CompileHost() ) + "."
121             + qfu( VLC_CompileDomain() ) + ".\n"
122             + "Compiler: " + qfu( VLC_Compiler() ) + ".\n"
123             + qtr( "Based on SVN revision: " ) + qfu( VLC_Changeset() )
124             + ".\n\n"
125             + qtr( "This program comes with NO WARRANTY, to the extent "
126                 "permitted by the law; read the distribution tab.\n\n" )
127             + "The VideoLAN team <videolan@videolan.org> \n"
128               "http://www.videolan.org/\n" );
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->setFontFamily( "Monospace" );
142     licenseEdit->setText( qfu( psz_license ) );
143     licenseEdit->setReadOnly( true );
144
145     /* People who helped */
146     QWidget *thanksWidget = new QWidget( this );
147     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
148
149     QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
150                 "community, the testers, our users and the following people "
151                 "(and the missing ones...) for their collaboration to "
152                 "provide the best software." ) );
153     thanksLabel->setWordWrap( true );
154     thanksLayout->addWidget( thanksLabel );
155     QTextEdit *thanksEdit = new QTextEdit( this );
156     thanksEdit->setText( qfu( psz_thanks ) );
157     thanksEdit->setReadOnly( true );
158     thanksLayout->addWidget( thanksEdit );
159
160     /* People who wrote the software */
161     QTextEdit *authorsEdit = new QTextEdit( this );
162     authorsEdit->setText( qfu( psz_authors ) );
163     authorsEdit->setReadOnly( true );
164
165     /* add the tabs to the Tabwidget */
166     tab->addTab( infoWidget, qtr( "General Info" ) );
167     tab->addTab( authorsEdit, qtr( "Authors" ) );
168     tab->addTab( thanksWidget, qtr("Thanks") );
169     tab->addTab( licenseEdit, qtr("Distribution License") );
170
171     BUTTONACT( closeButton, close() );
172 }
173
174 AboutDialog::~AboutDialog()
175 {
176 }
177 void AboutDialog::close()
178 {
179     this->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, vlc_bool_t 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     resize( 120, 80 );
207
208     QGridLayout *layout = new QGridLayout( this );
209
210     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
211     updateButton = new QPushButton( qtr( "&Update List" ) );
212     updateButton->setDefault( true );
213     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
214     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
215     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
216
217     updateLabel = new QLabel( qtr( "Checking for the update..." ) );
218     updateLabel->setWordWrap( true );
219
220     layout->addWidget( updateLabel, 0, 0 );
221     layout->addWidget( buttonBox, 1, 0 );
222
223     BUTTONACT( updateButton, UpdateOrDownload() );
224     BUTTONACT( closeButton, close() );
225
226     /* create the update structure and the callback */
227     p_update = update_New( _p_intf );
228     b_checked = false;
229
230     /* Check for updates */
231     UpdateOrDownload();
232 }
233
234 UpdateDialog::~UpdateDialog()
235 {
236     update_Delete( p_update );
237 }
238
239 void UpdateDialog::close()
240 {
241     toggleVisible();
242 }
243
244 /* Check for updates */
245 void UpdateDialog::UpdateOrDownload()
246 {
247     if( !b_checked )
248     {
249         updateButton->setEnabled( false );
250         update_Check( p_update, UpdateCallback, this );
251     }
252     else
253     {
254         updateButton->setEnabled( false );
255         QString dest_dir = QFileDialog::getExistingDirectory( this, qtr( "Select a directory ..." ),
256                                                               qfu( p_update->p_libvlc->psz_homedir ) );
257
258         if( dest_dir != "" )
259         {
260             toggleVisible();
261             update_Download( p_update, qtu( dest_dir ) );
262         }
263         else
264             updateButton->setEnabled( true );
265     }
266 }
267
268 /* Handle the events */
269 void UpdateDialog::customEvent( QEvent *event )
270 {
271     if( event->type() == UDOkEvent )
272         updateNotify( true );
273     else
274         updateNotify( false );
275 }
276
277 /* Notify the end of the update_Check */
278 void UpdateDialog::updateNotify( bool b_result )
279 {
280     /* The update finish without errors */
281     if( b_result )
282     {
283         if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer )
284         {
285             b_checked = true;
286             updateButton->setText( "Download" );
287             updateLabel->setText( qtr( "There is a new version of vlc :\n" ) + qfu( p_update->release.psz_desc )  );
288         }
289         else
290             updateLabel->setText( qtr( "You have the latest version of vlc" ) );
291     }
292     else
293         updateLabel->setText( qtr( "An error occure while checking for updates" ) );
294
295     adjustSize();
296     updateButton->setEnabled( true );
297 }
298
299
300 #endif