]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/help.cpp
Add fonctionality to the update dialog - Patches by Rémi Duraffort
[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 "dialogs/help.hpp"
26 #include <vlc_about.h>
27 #include <vlc_update.h>
28
29 #include "dialogs_provider.hpp"
30
31 #include <vlc_intf_strings.h>
32
33 #include <QTextBrowser>
34 #include <QTabWidget>
35 #include <QFile>
36 #include <QLabel>
37 #include <QString>
38 #include <QCheckBox>
39 #include <QGroupBox>
40 #include <QDialogButtonBox>
41 #include <QFileDialog>
42
43
44 HelpDialog *HelpDialog::instance = NULL;
45
46 HelpDialog::HelpDialog( intf_thread_t *_p_intf) : QVLCFrame( _p_intf )
47 {
48     setWindowTitle( qtr( "Help" ) );
49     resize( 600, 560 );
50
51     QGridLayout *layout = new QGridLayout( this );
52     QTextBrowser *helpBrowser = new QTextBrowser( this );
53     helpBrowser->setOpenExternalLinks( true );
54     helpBrowser->setHtml( I_LONGHELP );
55     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
56     closeButton->setDefault( true );
57
58     layout->addWidget( helpBrowser, 0, 0, 1, 0 );
59     layout->addWidget( closeButton, 1, 3 );
60
61     BUTTONACT( closeButton, close() );
62 }
63
64 HelpDialog::~HelpDialog()
65 {
66 }
67 void HelpDialog::close()
68 {
69     this->toggleVisible();
70 }
71
72 AboutDialog *AboutDialog::instance = NULL;
73
74 AboutDialog::AboutDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
75 {
76     setWindowTitle( qtr( "About" ) );
77     resize( 600, 500 );
78
79     QGridLayout *layout = new QGridLayout( this );
80     QTabWidget *tab = new QTabWidget( this );
81
82     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
83     closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
84     closeButton->setDefault( true );
85
86     QLabel *introduction = new QLabel(
87             qtr( "Information about VLC media player." ) );
88     QLabel *iconVLC = new QLabel;
89     iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
90     layout->addWidget( iconVLC, 0, 0, 1, 1 );
91     layout->addWidget( introduction, 0, 1, 1, 7 );
92     layout->addWidget( tab, 1, 0, 1, 8 );
93     layout->addWidget( closeButton, 2, 6, 1, 2 );
94
95     /* Main Introduction */
96     QWidget *infoWidget = new QWidget( this );
97     QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
98     QLabel *infoLabel = new QLabel( "VLC media player " PACKAGE_VERSION "\n\n"
99             "(c) 1996-2007 - the VideoLAN Team\n\n" +
100             qtr( "VLC media player is a free media player, made by the "
101                 "VideoLAN Team.\nIt is a standalone multimedia player, "
102                 "encoder and streamer, that can read from many supports "
103                 "(files, CDs, DVDs, networks, capture cards...) and that "
104                 "works on many platforms.\n\n" )
105             + qtr( "You are using the new Qt4 Interface.\n" )
106             + qtr( "Compiled by " ) + qfu( VLC_CompileBy() )+ "@"
107             + qfu( VLC_CompileDomain() ) + ".\n"
108             + "Compiler: " + qfu( VLC_Compiler() ) +".\n"
109             + qtr( "Based on SVN revision: " ) + qfu( VLC_Changeset() )
110             + ".\n\n"
111             + qtr( "This program comes with NO WARRANTY, to the extent "
112                 "permitted by the law; read the distribution tab.\n\n" )
113             + "The VideoLAN team <videolan@videolan.org> \n"
114               "http://www.videolan.org/\n") ;
115     infoLabel->setWordWrap( infoLabel );
116
117     QLabel *iconVLC2 = new QLabel;
118     iconVLC2->setPixmap( QPixmap( ":/vlc128.png" ) );
119     infoLayout->addWidget( iconVLC2 );
120     infoLayout->addWidget( infoLabel );
121
122     /* GPL License */
123     QTextEdit *licenseEdit = new QTextEdit( this );
124     licenseEdit->setFontFamily( "Monospace" );
125     licenseEdit->setText( qfu( psz_license ) );
126     licenseEdit->setReadOnly( true );
127
128     /* People who helped */
129     QWidget *thanksWidget = new QWidget( this );
130     QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );
131
132     QLabel *thanksLabel = new QLabel( qtr("We would like to thank the whole "
133                 "community, the testers, our users and the following people "
134                 "(and the missing ones...) for their collaboration to "
135                 "provide the best software." ) );
136     thanksLabel->setWordWrap( true );
137     thanksLayout->addWidget( thanksLabel );
138     QTextEdit *thanksEdit = new QTextEdit( this );
139     thanksEdit->setText( qfu( psz_thanks ) );
140     thanksEdit->setReadOnly( true );
141     thanksLayout->addWidget( thanksEdit );
142
143     /* People who wrote the software */
144     QTextEdit *authorsEdit = new QTextEdit( this );
145     authorsEdit->setText( qfu( psz_authors ) );
146     authorsEdit->setReadOnly( true );
147
148     /* add the tabs to the Tabwidget */
149     tab->addTab( infoWidget, qtr( "General Info" ) );
150     tab->addTab( authorsEdit, qtr( "Authors" ) );
151     tab->addTab( thanksWidget, qtr("Thanks") );
152     tab->addTab( licenseEdit, qtr("Distribution License") );
153
154     BUTTONACT( closeButton, close() );
155 }
156
157 AboutDialog::~AboutDialog()
158 {
159 }
160 void AboutDialog::close()
161 {
162     this->toggleVisible();
163 }
164
165
166 UpdateDialog *UpdateDialog::instance = NULL;
167
168 UpdateDialog::UpdateDialog( intf_thread_t *_p_intf) : QVLCFrame( _p_intf )
169 {
170     setWindowTitle( qtr( "Update" ) );
171     resize( 230, 180 );
172
173     QGridLayout *layout = new QGridLayout( this );
174
175     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
176     updateButton = new QPushButton( qtr( "&Update List" ) );
177     updateButton->setDefault( true );
178     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal);
179     buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
180     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
181
182     QGroupBox *checkGroup = new QGroupBox( qtr( "Select Package" ) );
183     QGridLayout *checkLayout = new QGridLayout( checkGroup );
184     checkInfo = new QCheckBox( qtr( "Information" ) );
185     checkSource = new QCheckBox( qtr( "Sources" ) );
186     checkBinary = new QCheckBox( qtr( "Binary" ) );
187     checkPlugin = new QCheckBox( qtr( "Plugin" ) );
188
189     checkInfo->setDisabled( true );
190     checkSource->setDisabled( true );
191     checkBinary->setDisabled( true );
192     checkPlugin->setDisabled( true );
193
194     checkLayout->addWidget( checkInfo, 0, 0 );
195     checkLayout->addWidget( checkSource, 1, 0 );
196     checkLayout->addWidget( checkBinary, 2, 0 );
197     checkLayout->addWidget( checkPlugin, 3, 0 );
198
199     layout->addWidget( checkGroup, 0, 0 );
200     layout->addWidget( buttonBox, 1, 0 );
201
202     BUTTONACT( updateButton, updateOrUpload() );
203     BUTTONACT( closeButton, close() );
204
205     p_update = update_New( _p_intf );
206     b_updated = false;
207 }
208
209 UpdateDialog::~UpdateDialog()
210 {
211     update_Delete( p_update );
212 }
213
214 void UpdateDialog::close()
215 {
216     toggleVisible();
217 }
218
219 void UpdateDialog::updateOrUpload()
220 {
221     if( !b_updated )
222     {
223         update_Check( p_update, VLC_FALSE );
224         update_iterator_t *p_updateit = update_iterator_New( p_update );
225         bool b_download = false;
226         if( p_updateit )
227         {
228             p_updateit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
229             p_updateit->i_t = UPDATE_FILE_TYPE_ALL;
230             update_iterator_Action( p_updateit, UPDATE_MIRROR );
231             while( update_iterator_Action( p_updateit, UPDATE_FILE ) != UPDATE_FAIL )
232             {
233                 switch( p_updateit->file.i_type )
234                 {
235                     case UPDATE_FILE_TYPE_INFO:
236                     checkInfo->setText( qtr( "Information" ) + " (" + qfu( p_updateit->release.psz_version ) + ")" );
237                     checkInfo->setDisabled( false );
238                     checkInfo->setCheckState( Qt::Checked );
239                     b_download = true;
240                     break;
241                 case UPDATE_FILE_TYPE_SOURCE:
242                     checkSource->setText( qtr( "Source" ) + " (" + qfu( p_updateit->release.psz_version ) + ")" );
243                     checkSource->setDisabled( false );
244                     checkSource->setCheckState( Qt::Checked );
245                     b_download = true;
246                     break;
247                 case UPDATE_FILE_TYPE_BINARY:
248                     checkBinary->setText( qtr( "Binary" ) + " (" + qfu( p_updateit->release.psz_version ) + ")" );
249                     checkBinary->setDisabled( false );
250                     checkBinary->setCheckState( Qt::Checked );
251                     b_download = true;
252                     break;
253                 case UPDATE_FILE_TYPE_PLUGIN:
254                     checkPlugin->setText( qtr( "Plugin" ) + " (" + qfu( p_updateit->release.psz_version ) + ")");
255                     checkPlugin->setDisabled( false );
256                     checkPlugin->setCheckState( Qt::Checked );
257                     b_download = true;
258                     break;
259                 default:
260                     break;
261                 }
262             }
263         }
264         if( b_download )
265         {
266             updateButton->setText(qtr( "Download" ) );
267             b_updated = true;
268         }
269         update_iterator_Delete( p_updateit );
270     }
271     else
272     {
273         update_iterator_t *p_updateit = update_iterator_New( p_update );
274         bool b_download = false;
275         if( p_updateit )
276         {
277             QString saveDir = QFileDialog::getExistingDirectory( this, qtr( "Choose a direcctory..." ),
278                                                                 qfu( p_intf->p_libvlc->psz_homedir ) );
279
280             p_updateit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
281             p_updateit->i_t = UPDATE_FILE_TYPE_ALL;
282             update_iterator_Action( p_updateit, UPDATE_MIRROR );
283
284             while( update_iterator_Action( p_updateit, UPDATE_FILE ) != UPDATE_FAIL )
285             {
286                 b_download = false;
287                 switch( p_updateit->file.i_type )
288                 {
289                 case UPDATE_FILE_TYPE_INFO:
290                     if( checkInfo->isChecked() )
291                         b_download = true;
292                     break;
293                 case UPDATE_FILE_TYPE_SOURCE:
294                     if( checkSource->isChecked() )
295                         b_download = true;
296                     break;
297                 case UPDATE_FILE_TYPE_BINARY:
298                     if( checkBinary->isChecked() )
299                         b_download = true;
300                     break;
301                 case UPDATE_FILE_TYPE_PLUGIN:
302                     if( checkPlugin->isChecked() )
303                         b_download = true;
304                     break;
305                         default:
306                         break;
307                 }
308                 if( b_download )
309                 {
310                     QString strFileName = p_updateit->file.psz_url;
311                     strFileName.remove( 0, strFileName.lastIndexOf( "/" ) + 1 );
312                     update_download( p_updateit, qtu( ( saveDir + strFileName ) ) );
313                 }
314             }
315         }
316     }
317 }