]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Remove remaining / in folder names, and use normale DIR_SEP in all platforms.
[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 <QLabel>
45 #include <QString>
46 #include <QDialogButtonBox>
47 #include <QEvent>
48 #include <QFileDialog>
49 #include <QDate>
50
51
52 HelpDialog *HelpDialog::instance = NULL;
53
54 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
55
56 {
57     setWindowTitle( qtr( "Help" ) );
58     setMinimumSize( 250, 300 );
59
60     QGridLayout *layout = new QGridLayout( this );
61     QTextBrowser *helpBrowser = new QTextBrowser( this );
62     helpBrowser->setOpenExternalLinks( true );
63     helpBrowser->setHtml( qtr(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     readSettings( "Help", QSize( 400, 450 ) );
72 }
73
74 HelpDialog::~HelpDialog()
75 {
76     writeSettings( "Help" );
77 }
78
79 void HelpDialog::close()
80 {
81     toggleVisible();
82 }
83
84 AboutDialog *AboutDialog::instance = NULL;
85
86 AboutDialog::AboutDialog( QWidget *parent, intf_thread_t *_p_intf)
87             : QVLCDialog( parent, _p_intf )
88 {
89     setWindowTitle( qtr( "About" ) );
90     resize( 600, 500 );
91     setMinimumSize( 600, 500 );
92
93     QGridLayout *layout = new QGridLayout( this );
94     QTabWidget *tab = new QTabWidget( this );
95
96     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
97     closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
98     closeButton->setDefault( true );
99
100     QLabel *introduction = new QLabel(
101             qtr( "VLC media player" " " VERSION_MESSAGE ) );
102     QLabel *iconVLC = new QLabel;
103     if( QDate::currentDate().dayOfYear() >= 354 )
104         iconVLC->setPixmap( QPixmap( ":/vlc48-christmas.png" ) );
105     else
106         iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
107     layout->addWidget( iconVLC, 0, 0, 1, 1 );
108     layout->addWidget( introduction, 0, 1, 1, 7 );
109     layout->addWidget( tab, 1, 0, 1, 8 );
110     layout->addWidget( closeButton, 2, 6, 1, 2 );
111
112     /* Main Introduction */
113     QWidget *infoWidget = new QWidget( this );
114     QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
115     QLabel *infoLabel = new QLabel(
116             qtr( "VLC media player is a free media player, "
117                 "encoder and streamer that can read from files, "
118                 "CDs, DVDs, network streams, capture cards and even more!\n"
119                 "VLC uses its internal codecs and works on essentially every "
120                 "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             + qtr( "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
128             + qtr( " by the VideoLAN Team.\n" )
129             + "vlc@videolan.org, http://www.videolan.org" );
130     infoLabel->setWordWrap( infoLabel );
131
132     QLabel *iconVLC2 = new QLabel;
133     if( QDate::currentDate().dayOfYear() >= 354 )
134         iconVLC2->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
135     else
136         iconVLC2->setPixmap( QPixmap( ":/vlc128.png" ) );
137     infoLayout->addWidget( iconVLC2 );
138     infoLayout->addWidget( infoLabel );
139
140     /* GPL License */
141     QTextEdit *licenseEdit = new QTextEdit( this );
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                 "VLC community, the testers, our users and the following people "
151                 "(and the missing ones...) for their collaboration to "
152                 "create the best free 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( "About" ) );
167     tab->addTab( authorsEdit, qtr( "Authors" ) );
168     tab->addTab( thanksWidget, qtr("Thanks") );
169     tab->addTab( licenseEdit, qtr("License") );
170
171     BUTTONACT( closeButton, close() );
172 }
173
174 AboutDialog::~AboutDialog()
175 {
176 }
177
178 void AboutDialog::close()
179 {
180     toggleVisible();
181 }
182
183 #ifdef UPDATE_CHECK
184
185 /*****************************************************************************
186  * UpdateDialog
187  *****************************************************************************/
188 /* callback to get information from the core */
189 static void UpdateCallback( void *data, bool b_ret )
190 {
191     UpdateDialog* UDialog = (UpdateDialog *)data;
192     QEvent* event;
193
194     if( b_ret )
195         event = new QEvent( (QEvent::Type)UDOkEvent );
196     else
197         event = new QEvent( (QEvent::Type)UDErrorEvent );
198
199     QApplication::postEvent( UDialog, event );
200 }
201
202 UpdateDialog *UpdateDialog::instance = NULL;
203
204 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
205 {
206     setWindowTitle( qtr( "VLC media player updates" ) );
207
208     QGridLayout *layout = new QGridLayout( this );
209
210     QPushButton *closeButton = new QPushButton( qtr( "&Cancel" ) );
211     updateButton = new QPushButton( qtr( "&Recheck version" ) );
212     updateButton->setDefault( true );
213
214     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
215     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
216     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
217
218     updateLabelTop = new QLabel( qtr( "Checking for an update..." ) );
219     updateLabelTop->setWordWrap( true );
220     updateLabelTop->setMargin( 8 );
221
222     updateLabelDown = new QLabel( qtr( "\nDo you want to download it?\n" ) );
223     updateLabelDown->setWordWrap( true );
224     updateLabelDown->hide();
225
226     updateText = new QTextEdit;
227     updateText->setAcceptRichText(false);
228     updateText->setTextInteractionFlags( Qt::TextSelectableByKeyboard|
229                                          Qt::TextSelectableByMouse);
230     updateText->setEnabled( false );
231
232     layout->addWidget( updateLabelTop, 0, 0 );
233     layout->addWidget( updateText, 1, 0 );
234     layout->addWidget( updateLabelDown, 2, 0 );
235     layout->addWidget( buttonBox, 3, 0 );
236
237     BUTTONACT( updateButton, UpdateOrDownload() );
238     BUTTONACT( closeButton, close() );
239
240     /* Create the update structure */
241     p_update = update_New( p_intf );
242     b_checked = false;
243
244     setMinimumSize( 300, 300 );
245     setMaximumSize( 400, 300 );
246
247     readSettings( "Update", QSize( 300, 250 ) );
248
249     /* Check for updates */
250     UpdateOrDownload();
251 }
252
253 UpdateDialog::~UpdateDialog()
254 {
255     update_Delete( p_update );
256     writeSettings( "Update" );
257 }
258
259 void UpdateDialog::close()
260 {
261     toggleVisible();
262 }
263
264 /* Check for updates */
265 void UpdateDialog::UpdateOrDownload()
266 {
267     if( !b_checked )
268     {
269         updateButton->setEnabled( false );
270         updateLabelTop->setText( qtr( "Launching an update request..." ) );
271         update_Check( p_update, UpdateCallback, this );
272     }
273     else
274     {
275         QString dest_dir = QFileDialog::getExistingDirectory( this,
276                                  qtr( "Select a directory..." ),
277                                  qfu( config_GetHomeDir() ) );
278
279         if( !dest_dir.isEmpty() )
280         {
281             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
282             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
283             toggleVisible();
284             update_Download( p_update, qtu( dest_dir ) );
285         }
286     }
287 }
288
289 /* Handle the events */
290 void UpdateDialog::customEvent( QEvent *event )
291 {
292     if( event->type() == UDOkEvent )
293         updateNotify( true );
294     else
295         updateNotify( false );
296 }
297
298 /* Notify the end of the update_Check */
299 void UpdateDialog::updateNotify( bool b_result )
300 {
301     /* The update finish without errors */
302     if( b_result )
303     {
304         if( update_NeedUpgrade( p_update ) )
305         {
306             update_release_t *p_release = update_GetRelease( p_update );
307             assert( p_release );
308             b_checked = true;
309             updateButton->setText( qtr( "&Yes" ) );
310             QString message = qtr( "A new version of VLC(" )
311                               + QString::number( p_release->i_major ) + "."
312                               + QString::number( p_release->i_minor ) + "."
313                               + QString::number( p_release->i_revision );
314             if( p_release->extra )
315                 message += p_release->extra;
316             message += qtr( ") is available.");
317             updateLabelTop->setText( message );
318
319             updateText->setText( qfu( p_release->psz_desc ) );
320             updateText->setEnabled( true );
321
322             updateLabelDown->show();
323
324             /* Force the dialog to be shown */
325             this->show();
326         }
327         else
328             updateLabelTop->setText(
329                     qtr( "You have the latest version of VLC media player." ) );
330     }
331     else
332         updateLabelTop->setText(
333                     qtr( "An error occurred while checking for updates..." ) );
334
335     updateButton->setEnabled( true );
336 }
337
338 #endif
339