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