]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
4fee7ed452ebc002e0e215cfe06da646739bcc5a
[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 "qt4.hpp"
30 #include "dialogs/help.hpp"
31 #include "util/qt_dirs.hpp"
32
33 #include <vlc_about.h>
34 #include <vlc_intf_strings.h>
35
36 #ifdef UPDATE_CHECK
37 # include <vlc_update.h>
38 #endif
39
40 #include <QTextBrowser>
41 #include <QTabWidget>
42 #include <QLabel>
43 #include <QString>
44 #include <QDialogButtonBox>
45 #include <QEvent>
46 #include <QFileDialog>
47 #include <QDate>
48 #include <QPushButton>
49
50 #include <assert.h>
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     QVBoxLayout *layout = new QVBoxLayout( this );
60
61     QTextBrowser *helpBrowser = new QTextBrowser( this );
62     helpBrowser->setOpenExternalLinks( true );
63     helpBrowser->setHtml( qtr(I_LONGHELP) );
64
65     QDialogButtonBox *closeButtonBox = new QDialogButtonBox( this );
66     closeButtonBox->addButton(
67         new QPushButton( qtr("&Close") ), QDialogButtonBox::RejectRole );
68     closeButtonBox->setFocus();
69
70     layout->addWidget( helpBrowser );
71     layout->addWidget( closeButtonBox );
72
73     CONNECT( closeButtonBox, rejected(), this, close() );
74     readSettings( "Help", QSize( 500, 450 ) );
75 }
76
77 HelpDialog::~HelpDialog()
78 {
79     writeSettings( "Help" );
80 }
81
82 AboutDialog::AboutDialog( intf_thread_t *_p_intf)
83             : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
84 {
85     /* Build UI */
86     ui.setupUi( this );
87     ui.closeButtonBox->addButton(
88         new QPushButton( qtr("&Close"), this ), QDialogButtonBox::RejectRole );
89
90     setWindowTitle( qtr( "About" ) );
91     setWindowRole( "vlc-about" );
92     setMinimumSize( 600, 500 );
93     resize( 600, 500 );
94     setWindowModality( Qt::WindowModal );
95
96     CONNECT( ui.closeButtonBox, rejected(), this, close() );
97     ui.closeButtonBox->setFocus();
98
99     ui.introduction->setText(
100             qtr( "VLC media player" ) + qfu( " " VERSION_MESSAGE ) );
101
102     if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
103         ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128-xmas.png" ) );
104     else
105         ui.iconVLC->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
106
107     /* Main Introduction */
108     ui.infoLabel->setText(
109             qtr( "VLC media player is a free media player, "
110                 "encoder and streamer that can read from files, "
111                 "CDs, DVDs, network streams, capture cards and even more!\n"
112                 "VLC uses its internal codecs and works on essentially every "
113                 "popular platform.\n\n" )
114             + qtr( "This version of VLC was compiled by:\n " )
115             + qfu( VLC_CompileBy() )+ " on " + qfu( VLC_CompileHost() ) +
116             + " ("__DATE__" "__TIME__").\n"
117             + qtr( "Compiler: " ) + qfu( VLC_Compiler() ) + ".\n"
118             + qtr( "You are using the Qt4 Interface.\n\n" )
119             + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
120             + qtr( " by the VideoLAN Team.\n" )
121             + "vlc@videolan.org, http://www.videolan.org" );
122
123     /* GPL License */
124     ui.licenseEdit->setText( qfu( psz_license ) );
125
126     /* People who helped */
127     ui.thanksEdit->setText( qfu( psz_thanks ) );
128
129     /* People who wrote the software */
130     ui.authorsEdit->setText( qfu( psz_authors ) );
131 }
132
133 #ifdef UPDATE_CHECK
134
135 /*****************************************************************************
136  * UpdateDialog
137  *****************************************************************************/
138 /* callback to get information from the core */
139 static void UpdateCallback( void *data, bool b_ret )
140 {
141     UpdateDialog* UDialog = (UpdateDialog *)data;
142     QEvent* event;
143
144     if( b_ret )
145         event = new QEvent( (QEvent::Type)UDOkEvent );
146     else
147         event = new QEvent( (QEvent::Type)UDErrorEvent );
148
149     QApplication::postEvent( UDialog, event );
150 }
151
152 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
153 {
154     /* build Ui */
155     ui.setupUi( this );
156     ui.updateDialogButtonBox->addButton( new QPushButton( qtr("&Close"), this ),
157                                          QDialogButtonBox::RejectRole );
158     QPushButton *recheckButton = new QPushButton( qtr("&Recheck version"), this );
159     ui.updateDialogButtonBox->addButton( recheckButton, QDialogButtonBox::ActionRole );
160
161     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
162                                          QDialogButtonBox::AcceptRole );
163     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
164                                          QDialogButtonBox::RejectRole );
165
166     setWindowTitle( qtr( "VLC media player updates" ) );
167     setWindowRole( "vlc-update" );
168
169     BUTTONACT( recheckButton, UpdateOrDownload() );
170     CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
171
172     CONNECT( ui.updateNotifyButtonBox, accepted(), this, UpdateOrDownload() );
173     CONNECT( ui.updateNotifyButtonBox, rejected(), this, close() );
174
175     /* Create the update structure */
176     p_update = update_New( p_intf );
177     b_checked = false;
178
179     setMinimumSize( 300, 300 );
180     setMaximumSize( 400, 300 );
181
182     readSettings( "Update", QSize( 300, 250 ) );
183
184     /* Check for updates */
185     UpdateOrDownload();
186 }
187
188 UpdateDialog::~UpdateDialog()
189 {
190     update_Delete( p_update );
191     writeSettings( "Update" );
192 }
193
194 /* Check for updates */
195 void UpdateDialog::UpdateOrDownload()
196 {
197     if( !b_checked )
198     {
199         ui.stackedWidget->setCurrentWidget( ui.updateRequestPage );
200         update_Check( p_update, UpdateCallback, this );
201     }
202     else
203     {
204         QString dest_dir = QFileDialog::getExistingDirectory( this,
205                                  qtr( I_OP_SEL_DIR ),
206                                  QVLCUserDir( VLC_DOWNLOAD_DIR ) );
207
208         if( !dest_dir.isEmpty() )
209         {
210             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
211             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
212             toggleVisible();
213             update_Download( p_update, qtu( dest_dir ) );
214             /* FIXME: We should trigger a change to another dialog here ! */
215         }
216     }
217 }
218
219 /* Handle the events */
220 void UpdateDialog::customEvent( QEvent *event )
221 {
222     if( event->type() == UDOkEvent )
223         updateNotify( true );
224     else
225         updateNotify( false );
226 }
227
228 /* Notify the end of the update_Check */
229 void UpdateDialog::updateNotify( bool b_result )
230 {
231     /* The update finish without errors */
232     if( b_result )
233     {
234         if( update_NeedUpgrade( p_update ) )
235         {
236             ui.stackedWidget->setCurrentWidget( ui.updateNotifyPage );
237             update_release_t *p_release = update_GetRelease( p_update );
238             assert( p_release );
239             b_checked = true;
240             QString message = QString(
241                     qtr( "A new version of VLC (%1.%2.%3%4) is available." ) )
242                 .arg( QString::number( p_release->i_major ) )
243                 .arg( QString::number( p_release->i_minor ) )
244                 .arg( QString::number( p_release->i_revision ) )
245                 .arg( p_release->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
246
247             ui.updateNotifyLabel->setText( message );
248             ui.updateNotifyTextEdit->setText( qfu( p_release->psz_desc ) );
249
250             /* Force the dialog to be shown */
251             this->show();
252         }
253         else
254         {
255             ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
256             ui.updateDialogLabel->setText(
257                     qtr( "You have the latest version of VLC media player." ) );
258         }
259     }
260     else
261     {
262         ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
263         ui.updateDialogLabel->setText(
264                     qtr( "An error occurred while checking for updates..." ) );
265     }
266 }
267
268 #endif