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