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