]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Qt: use %tmp%/$TMP folder for updates
[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     readSettings( "Help", QSize( 500, 450 ) );
74 }
75
76 HelpDialog::~HelpDialog()
77 {
78     writeSettings( "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 Qt4 Interface.\n\n" )
118             + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
119             + qtr( " by the VideoLAN Team.\n" )
120             + "vlc@videolan.org, http://www.videolan.org" );
121
122     /* GPL License */
123     ui.licenseEdit->setText( qfu( psz_license ) );
124
125     /* People who helped */
126     ui.thanksEdit->setText( qfu( psz_thanks ) );
127
128     /* People who wrote the software */
129     ui.authorsEdit->setText( qfu( psz_authors ) );
130 }
131
132 #ifdef UPDATE_CHECK
133
134 /*****************************************************************************
135  * UpdateDialog
136  *****************************************************************************/
137 /* callback to get information from the core */
138 static void UpdateCallback( void *data, bool b_ret )
139 {
140     UpdateDialog* UDialog = (UpdateDialog *)data;
141     QEvent* event;
142
143     if( b_ret )
144         event = new QEvent( (QEvent::Type)UDOkEvent );
145     else
146         event = new QEvent( (QEvent::Type)UDErrorEvent );
147
148     QApplication::postEvent( UDialog, event );
149 }
150
151 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
152 {
153     /* build Ui */
154     ui.setupUi( this );
155     ui.updateDialogButtonBox->addButton( new QPushButton( qtr("&Close"), this ),
156                                          QDialogButtonBox::RejectRole );
157     QPushButton *recheckButton = new QPushButton( qtr("&Recheck version"), this );
158     ui.updateDialogButtonBox->addButton( recheckButton, QDialogButtonBox::ActionRole );
159
160     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&Yes"), this ),
161                                          QDialogButtonBox::AcceptRole );
162     ui.updateNotifyButtonBox->addButton( new QPushButton( qtr("&No"), this ),
163                                          QDialogButtonBox::RejectRole );
164
165     setWindowTitle( qtr( "VLC media player updates" ) );
166     setWindowRole( "vlc-update" );
167
168     BUTTONACT( recheckButton, UpdateOrDownload() );
169     CONNECT( ui.updateDialogButtonBox, rejected(), this, close() );
170
171     CONNECT( ui.updateNotifyButtonBox, accepted(), this, UpdateOrDownload() );
172     CONNECT( ui.updateNotifyButtonBox, rejected(), this, close() );
173
174     /* Create the update structure */
175     p_update = update_New( p_intf );
176     b_checked = false;
177
178     setMinimumSize( 300, 300 );
179     setMaximumSize( 400, 300 );
180
181     readSettings( "Update", QSize( 300, 250 ) );
182
183     /* Check for updates */
184     UpdateOrDownload();
185 }
186
187 UpdateDialog::~UpdateDialog()
188 {
189     update_Delete( p_update );
190     writeSettings( "Update" );
191 }
192
193 /* Check for updates */
194 void UpdateDialog::UpdateOrDownload()
195 {
196     if( !b_checked )
197     {
198         ui.stackedWidget->setCurrentWidget( ui.updateRequestPage );
199         update_Check( p_update, UpdateCallback, this );
200     }
201     else
202     {
203         QString dest_dir = QDir::tempPath();
204         if( !dest_dir.isEmpty() )
205         {
206             dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
207             msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
208             toggleVisible();
209             update_Download( p_update, qtu( dest_dir ) );
210             /* FIXME: We should trigger a change to another dialog here ! */
211         }
212     }
213 }
214
215 /* Handle the events */
216 void UpdateDialog::customEvent( QEvent *event )
217 {
218     if( event->type() == UDOkEvent )
219         updateNotify( true );
220     else
221         updateNotify( false );
222 }
223
224 /* Notify the end of the update_Check */
225 void UpdateDialog::updateNotify( bool b_result )
226 {
227     /* The update finish without errors */
228     if( b_result )
229     {
230         if( update_NeedUpgrade( p_update ) )
231         {
232             ui.stackedWidget->setCurrentWidget( ui.updateNotifyPage );
233             update_release_t *p_release = update_GetRelease( p_update );
234             assert( p_release );
235             b_checked = true;
236             QString message = QString(
237                     qtr( "A new version of VLC (%1.%2.%3%4) is available." ) )
238                 .arg( QString::number( p_release->i_major ) )
239                 .arg( QString::number( p_release->i_minor ) )
240                 .arg( QString::number( p_release->i_revision ) )
241                 .arg( p_release->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
242
243             ui.updateNotifyLabel->setText( message );
244             ui.updateNotifyTextEdit->setText( qfu( p_release->psz_desc ) );
245
246             /* Force the dialog to be shown */
247             this->show();
248         }
249         else
250         {
251             ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
252             ui.updateDialogLabel->setText(
253                     qtr( "You have the latest version of VLC media player." ) );
254         }
255     }
256     else
257     {
258         ui.stackedWidget->setCurrentWidget( ui.updateDialogPage );
259         ui.updateDialogLabel->setText(
260                     qtr( "An error occurred while checking for updates..." ) );
261     }
262 }
263
264 #endif