]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Qt4 - Update: clean and message Debug. My fault for the mess...
[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
60     QGridLayout *layout = new QGridLayout( this );
61     QTextBrowser *helpBrowser = new QTextBrowser( this );
62     helpBrowser->setOpenExternalLinks( true );
63     helpBrowser->setHtml( I_LONGHELP );
64     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
65     closeButton->setDefault( true );
66
67     layout->addWidget( helpBrowser, 0, 0, 1, 0 );
68     layout->addWidget( closeButton, 1, 3 );
69
70     BUTTONACT( closeButton, close() );
71 }
72
73 HelpDialog::~HelpDialog()
74 {
75 }
76 void HelpDialog::close()
77 {
78     this->toggleVisible();
79 }
80
81 AboutDialog *AboutDialog::instance = NULL;
82
83 AboutDialog::AboutDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
84 {
85     setWindowTitle( qtr( "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 " VERSION_MESSAGE ) );
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(
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                 "Also, VLC works on essentially every popular platform.\n\n" )
116             + qtr( "This version of VLC was compiled by:\n " )
117             + qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() ) + "."
118             + qfu( VLC_CompileDomain() ) + ".\n"
119             + "Compiler: " + qfu( VLC_Compiler() ) + ".\n"
120             + qtr( "Based on SVN revision: " ) + qfu( VLC_Changeset() ) + ".\n"
121             + qtr( "You are using the Qt4 Interface.\n\n" )
122             + qtr( "Copyright (c) " COPYRIGHT_YEARS " by the VideoLAN Team.\n" )
123             + "vlc@videolan.org, http://www.videolan.org" ); 
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->setText( qfu( psz_license ) );
137     licenseEdit->setReadOnly( true );
138
139     /* People who helped */
140     QWidget *thanksWidget = new QWidget( this );
141     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
142
143     QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
144                 "community, the testers, our users and the following people "
145                 "(and the missing ones...) for their collaboration to "
146                 "provide the best software." ) );
147     thanksLabel->setWordWrap( true );
148     thanksLayout->addWidget( thanksLabel );
149     QTextEdit *thanksEdit = new QTextEdit( this );
150     thanksEdit->setText( qfu( psz_thanks ) );
151     thanksEdit->setReadOnly( true );
152     thanksLayout->addWidget( thanksEdit );
153
154     /* People who wrote the software */
155     QTextEdit *authorsEdit = new QTextEdit( this );
156     authorsEdit->setText( qfu( psz_authors ) );
157     authorsEdit->setReadOnly( true );
158
159     /* add the tabs to the Tabwidget */
160     tab->addTab( infoWidget, qtr( "About" ) );
161     tab->addTab( authorsEdit, qtr( "Authors" ) );
162     tab->addTab( thanksWidget, qtr("Thanks") );
163     tab->addTab( licenseEdit, qtr("License") );
164
165     BUTTONACT( closeButton, close() );
166 }
167
168 AboutDialog::~AboutDialog()
169 {
170 }
171 void AboutDialog::close()
172 {
173     this->toggleVisible();
174 }
175
176 #ifdef UPDATE_CHECK
177
178 /*****************************************************************************
179  * UpdateDialog
180  *****************************************************************************/
181 /* callback to get information from the core */
182 static void UpdateCallback( void *data, vlc_bool_t b_ret )
183 {
184     UpdateDialog* UDialog = (UpdateDialog *)data;
185     QEvent* event;
186
187     if( b_ret )
188         event = new QEvent( (QEvent::Type)UDOkEvent );
189     else
190         event = new QEvent( (QEvent::Type)UDErrorEvent );
191
192     QApplication::postEvent( UDialog, event );
193 }
194
195 UpdateDialog *UpdateDialog::instance = NULL;
196
197 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
198 {
199     setWindowTitle( qtr( "Update" ) );
200     resize( 120, 80 );
201
202     QGridLayout *layout = new QGridLayout( this );
203
204     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
205     updateButton = new QPushButton( qtr( "&Update List" ) );
206     updateButton->setDefault( true );
207     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
208     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
209     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
210
211     updateLabel = new QLabel( qtr( "Checking for the update..." ) );
212     updateLabel->setWordWrap( true );
213
214     layout->addWidget( updateLabel, 0, 0 );
215     layout->addWidget( buttonBox, 1, 0 );
216
217     BUTTONACT( updateButton, UpdateOrDownload() );
218     BUTTONACT( closeButton, close() );
219
220     /* Create the update structure */
221     p_update = update_New( p_intf );
222     b_checked = false;
223
224     /* Check for updates */
225     UpdateOrDownload();
226 }
227
228 UpdateDialog::~UpdateDialog()
229 {
230     update_Delete( p_update );
231 }
232
233 void UpdateDialog::close()
234 {
235     toggleVisible();
236 }
237
238 /* Check for updates */
239 void UpdateDialog::UpdateOrDownload()
240 {
241     if( !b_checked )
242     {
243         updateButton->setEnabled( false );
244         msg_Dbg( p_intf, "Launching an update Request" );
245         update_Check( p_update, UpdateCallback, this );
246     }
247     else
248     {
249         updateButton->setEnabled( false );
250         QString dest_dir = QFileDialog::getExistingDirectory( this,
251                                  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" ) 
284                                 + qfu( p_update->release.psz_desc )  );
285         }
286         else
287             updateLabel->setText( qtr( "You have the latest version of vlc" ) );
288     }
289     else
290         updateLabel->setText(
291                         qtr( "An error occured while checking for updates" ) );
292
293     adjustSize();
294     updateButton->setEnabled( true );
295 }
296
297 #endif
298