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