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