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