]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Added window roles for X11
[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 "dialogs/help.hpp"
30 #include "util/qt_dirs.hpp"
31
32 #include <vlc_about.h>
33 #include <vlc_intf_strings.h>
34
35 #ifdef UPDATE_CHECK
36 # include <vlc_update.h>
37 #endif
38
39 #include <QTextBrowser>
40 #include <QTabWidget>
41 #include <QLabel>
42 #include <QString>
43 #include <QDialogButtonBox>
44 #include <QEvent>
45 #include <QFileDialog>
46 #include <QDate>
47
48 #include <assert.h>
49
50 HelpDialog *HelpDialog::instance = NULL;
51
52 HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
53
54 {
55     setWindowTitle( qtr( "Help" ) );
56     setWindowRole( "vlc-help" );
57     setMinimumSize( 350, 300 );
58
59     QGridLayout *layout = new QGridLayout( this );
60     QTextBrowser *helpBrowser = new QTextBrowser( this );
61     helpBrowser->setOpenExternalLinks( true );
62     helpBrowser->setHtml( qtr(I_LONGHELP) );
63     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
64     closeButton->setDefault( true );
65
66     layout->addWidget( helpBrowser, 0, 0, 1, 0 );
67     layout->addWidget( closeButton, 1, 3 );
68
69     BUTTONACT( closeButton, close() );
70     readSettings( "Help", QSize( 500, 450 ) );
71 }
72
73 HelpDialog::~HelpDialog()
74 {
75     writeSettings( "Help" );
76 }
77
78 void HelpDialog::close()
79 {
80     toggleVisible();
81 }
82
83 AboutDialog *AboutDialog::instance = NULL;
84
85 AboutDialog::AboutDialog( QWidget *parent, intf_thread_t *_p_intf)
86             : QVLCDialog( parent, _p_intf )
87 {
88     setWindowTitle( qtr( "About" ) );
89     setWindowRole( "vlc-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" ) + qfu( " " VERSION_MESSAGE ) );
102     QLabel *iconVLC = new QLabel;
103     if( QDate::currentDate().dayOfYear() >= 354 )
104         iconVLC->setPixmap( QPixmap( ":/logo/vlc48-christmas.png" ) );
105     else
106         iconVLC->setPixmap( QPixmap( ":/logo/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( "You are using the Qt4 Interface.\n\n" )
126             + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
127             + qtr( " by the VideoLAN Team.\n" )
128             + "vlc@videolan.org, http://www.videolan.org" );
129     infoLabel->setWordWrap( infoLabel );
130
131     QLabel *iconVLC2 = new QLabel;
132     if( QDate::currentDate().dayOfYear() >= 354 )
133         iconVLC2->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
134     else
135         iconVLC2->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
136     infoLayout->addWidget( iconVLC2 );
137     infoLayout->addWidget( infoLabel );
138
139     /* GPL License */
140     QTextEdit *licenseEdit = new QTextEdit( this );
141     licenseEdit->setText( qfu( psz_license ) );
142     licenseEdit->setReadOnly( true );
143
144     /* People who helped */
145     QWidget *thanksWidget = new QWidget( this );
146     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
147
148     QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
149                 "VLC community, the testers, our users and the following people "
150                 "(and the missing ones...) for their collaboration to "
151                 "create the best free software." ) );
152     thanksLabel->setWordWrap( true );
153     thanksLayout->addWidget( thanksLabel );
154     QTextEdit *thanksEdit = new QTextEdit( this );
155     thanksEdit->setText( qfu( psz_thanks ) );
156     thanksEdit->setReadOnly( true );
157     thanksLayout->addWidget( thanksEdit );
158
159     /* People who wrote the software */
160     QTextEdit *authorsEdit = new QTextEdit( this );
161     authorsEdit->setText( qfu( psz_authors ) );
162     authorsEdit->setReadOnly( true );
163
164     /* add the tabs to the Tabwidget */
165     tab->addTab( infoWidget, qtr( "About" ) );
166     tab->addTab( authorsEdit, qtr( "Authors" ) );
167     tab->addTab( thanksWidget, qtr("Thanks") );
168     tab->addTab( licenseEdit, qtr("License") );
169
170     BUTTONACT( closeButton, close() );
171 }
172
173 AboutDialog::~AboutDialog()
174 {
175 }
176
177 void AboutDialog::close()
178 {
179     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, bool 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( "VLC media player updates" ) );
206     setWindowRole( "vlc-update" );
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( this );
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                                  QVLCUserDir( VLC_DOWNLOAD_DIR ) );
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