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