]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Qt4 - Minimum size for help dialog.
[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 <vlc/vlc.h>
30
31 #include "dialogs/help.hpp"
32 #include <vlc_about.h>
33
34 #ifdef UPDATE_CHECK
35 #include <vlc_update.h>
36 #endif
37
38 #include "dialogs_provider.hpp"
39
40 #include <vlc_intf_strings.h>
41
42 #include <QTextBrowser>
43 #include <QTabWidget>
44 #include <QFile>
45 #include <QLabel>
46 #include <QString>
47 #include <QDialogButtonBox>
48 #include <QEvent>
49 #include <QFileDialog>
50 #include <QDate>
51
52
53 HelpDialog *HelpDialog::instance = NULL;
54
55 HelpDialog::HelpDialog( QWidget *parent, intf_thread_t *_p_intf )
56            : QVLCDialog( parent, _p_intf )
57 {
58     setWindowTitle( qtr( "Help" ) );
59     setMinimumSize( 250, 300 );
60
61     QGridLayout *layout = new QGridLayout( this );
62     QTextBrowser *helpBrowser = new QTextBrowser( this );
63     helpBrowser->setOpenExternalLinks( true );
64     helpBrowser->setHtml( I_LONGHELP );
65     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
66     closeButton->setDefault( true );
67
68     layout->addWidget( helpBrowser, 0, 0, 1, 0 );
69     layout->addWidget( closeButton, 1, 3 );
70
71     BUTTONACT( closeButton, close() );
72     resize( 400, 450 );
73 }
74
75 HelpDialog::~HelpDialog()
76 {
77 }
78 void HelpDialog::close()
79 {
80     this->toggleVisible();
81 }
82
83 AboutDialog *AboutDialog::instance = NULL;
84
85 AboutDialog::AboutDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
86 {
87     setWindowTitle( qtr( "About" ) );
88     resize( 600, 500 );
89     setMinimumSize( 600, 500 );
90
91     QGridLayout *layout = new QGridLayout( this );
92     QTabWidget *tab = new QTabWidget( this );
93
94     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
95     closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
96     closeButton->setDefault( true );
97
98     QLabel *introduction = new QLabel(
99             qtr( "VLC media player " VERSION_MESSAGE ) );
100     QLabel *iconVLC = new QLabel;
101     if( QDate::currentDate().dayOfYear() >= 354 )
102         iconVLC->setPixmap( QPixmap( ":/vlc48-christmas.png" ) );
103     else
104         iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
105     layout->addWidget( iconVLC, 0, 0, 1, 1 );
106     layout->addWidget( introduction, 0, 1, 1, 7 );
107     layout->addWidget( tab, 1, 0, 1, 8 );
108     layout->addWidget( closeButton, 2, 6, 1, 2 );
109
110     /* Main Introduction */
111     QWidget *infoWidget = new QWidget( this );
112     QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
113     QLabel *infoLabel = new QLabel(
114             qtr( "VLC media player is a free media player, "
115                 "encoder and streamer that can read from files, "
116                 "CDs, DVDs, network streams, capture cards and even more!\n"
117                 "Also, VLC works on essentially every popular platform.\n\n" )
118             + qtr( "This version of VLC was compiled by:\n " )
119             + qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() ) + "."
120             + qfu( VLC_CompileDomain() ) + ".\n"
121             + "Compiler: " + qfu( VLC_Compiler() ) + ".\n"
122             + qtr( "Based on SVN revision: " ) + qfu( VLC_Changeset() ) + ".\n"
123             + qtr( "You are using the Qt4 Interface.\n\n" )
124             + qtr( "Copyright (c) " COPYRIGHT_YEARS " by the VideoLAN Team.\n" )
125             + "vlc@videolan.org, http://www.videolan.org" ); 
126     infoLabel->setWordWrap( infoLabel );
127
128     QLabel *iconVLC2 = new QLabel;
129     if( QDate::currentDate().dayOfYear() >= 354 )
130         iconVLC2->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
131     else
132         iconVLC2->setPixmap( QPixmap( ":/vlc128.png" ) );
133     infoLayout->addWidget( iconVLC2 );
134     infoLayout->addWidget( infoLabel );
135
136     /* GPL License */
137     QTextEdit *licenseEdit = new QTextEdit( this );
138     licenseEdit->setText( qfu( psz_license ) );
139     licenseEdit->setReadOnly( true );
140
141     /* People who helped */
142     QWidget *thanksWidget = new QWidget( this );
143     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
144
145     QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
146                 "community, the testers, our users and the following people "
147                 "(and the missing ones...) for their collaboration to "
148                 "provide the best software." ) );
149     thanksLabel->setWordWrap( true );
150     thanksLayout->addWidget( thanksLabel );
151     QTextEdit *thanksEdit = new QTextEdit( this );
152     thanksEdit->setText( qfu( psz_thanks ) );
153     thanksEdit->setReadOnly( true );
154     thanksLayout->addWidget( thanksEdit );
155
156     /* People who wrote the software */
157     QTextEdit *authorsEdit = new QTextEdit( this );
158     authorsEdit->setText( qfu( psz_authors ) );
159     authorsEdit->setReadOnly( true );
160
161     /* add the tabs to the Tabwidget */
162     tab->addTab( infoWidget, qtr( "About" ) );
163     tab->addTab( authorsEdit, qtr( "Authors" ) );
164     tab->addTab( thanksWidget, qtr("Thanks") );
165     tab->addTab( licenseEdit, qtr("License") );
166
167     BUTTONACT( closeButton, close() );
168 }
169
170 AboutDialog::~AboutDialog()
171 {
172 }
173 void AboutDialog::close()
174 {
175     this->toggleVisible();
176 }
177
178 #ifdef UPDATE_CHECK
179
180 /*****************************************************************************
181  * UpdateDialog
182  *****************************************************************************/
183 /* callback to get information from the core */
184 static void UpdateCallback( void *data, vlc_bool_t b_ret )
185 {
186     UpdateDialog* UDialog = (UpdateDialog *)data;
187     QEvent* event;
188
189     if( b_ret )
190         event = new QEvent( (QEvent::Type)UDOkEvent );
191     else
192         event = new QEvent( (QEvent::Type)UDErrorEvent );
193
194     QApplication::postEvent( UDialog, event );
195 }
196
197 UpdateDialog *UpdateDialog::instance = NULL;
198
199 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
200 {
201     setWindowTitle( qtr( "Update" ) );
202     resize( 120, 80 );
203
204     QGridLayout *layout = new QGridLayout( this );
205
206     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
207     updateButton = new QPushButton( qtr( "&Update List" ) );
208     updateButton->setDefault( true );
209     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
210     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
211     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
212
213     updateLabel = new QLabel( qtr( "Checking for the update..." ) );
214     updateLabel->setWordWrap( true );
215
216     layout->addWidget( updateLabel, 0, 0 );
217     layout->addWidget( buttonBox, 1, 0 );
218
219     BUTTONACT( updateButton, UpdateOrDownload() );
220     BUTTONACT( closeButton, close() );
221
222     /* Create the update structure */
223     p_update = update_New( p_intf );
224     b_checked = false;
225
226     /* Check for updates */
227     UpdateOrDownload();
228 }
229
230 UpdateDialog::~UpdateDialog()
231 {
232     update_Delete( p_update );
233 }
234
235 void UpdateDialog::close()
236 {
237     toggleVisible();
238 }
239
240 /* Check for updates */
241 void UpdateDialog::UpdateOrDownload()
242 {
243     if( !b_checked )
244     {
245         updateButton->setEnabled( false );
246         msg_Dbg( p_intf, "Launching an update Request" );
247         update_Check( p_update, UpdateCallback, this );
248     }
249     else
250     {
251         updateButton->setEnabled( false );
252         QString dest_dir = QFileDialog::getExistingDirectory( this,
253                                  qtr( "Select a directory ..." ),
254                                  qfu( p_update->p_libvlc->psz_homedir ) );
255
256         if( dest_dir != "" )
257         {
258             toggleVisible();
259             update_Download( p_update, qtu( dest_dir ) );
260         }
261         else
262             updateButton->setEnabled( true );
263     }
264 }
265
266 /* Handle the events */
267 void UpdateDialog::customEvent( QEvent *event )
268 {
269     if( event->type() == UDOkEvent )
270         updateNotify( true );
271     else
272         updateNotify( false );
273 }
274
275 /* Notify the end of the update_Check */
276 void UpdateDialog::updateNotify( bool b_result )
277 {
278     /* The update finish without errors */
279     if( b_result )
280     {
281         if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer )
282         {
283             b_checked = true;
284             updateButton->setText( "Download" );
285             updateLabel->setText( qtr( "There is a new version of vlc :\n" ) 
286                                 + qfu( p_update->release.psz_desc )  );
287         }
288         else
289             updateLabel->setText( qtr( "You have the latest version of vlc" ) );
290     }
291     else
292         updateLabel->setText(
293                         qtr( "An error occured while checking for updates" ) );
294
295     adjustSize();
296     updateButton->setEnabled( true );
297 }
298
299 #endif
300