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