help.cpp 9.4 KB
Newer Older
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
1
2
3
/*****************************************************************************
 * Help.cpp : Help and About dialogs
 ****************************************************************************
4
 * Copyright (C) 2007 the VideoLAN team
5
 * $Id$
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
6
7
 *
 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
ivoire's avatar
ivoire committed
8
 *          Rémi Duraffort <ivoire (at) via.ecp.fr>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

25
26
#include <vlc/vlc.h>

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
27
#include "dialogs/help.hpp"
Christophe Mutricy's avatar
Christophe Mutricy committed
28
#include <vlc_about.h>
29
30

#ifdef UPDATE_CHECK
31
#include <vlc_update.h>
32
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
33
34
35

#include "dialogs_provider.hpp"

36
37
#include <vlc_intf_strings.h>

38
#include <QTextBrowser>
39
#include <QTabWidget>
40
41
#include <QFile>
#include <QLabel>
42
#include <QString>
43
#include <QDialogButtonBox>
44
45
#include <QEvent>
#include <QFileDialog>
46
#include <QDate>
47

48

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
49
50
HelpDialog *HelpDialog::instance = NULL;

51
52
HelpDialog::HelpDialog( QWidget *parent, intf_thread_t *_p_intf )
           : QVLCDialog( parent, _p_intf )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
53
54
{
    setWindowTitle( qtr( "Help" ) );
55
    resize( 600, 560 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
56

57
58
    QGridLayout *layout = new QGridLayout( this );
    QTextBrowser *helpBrowser = new QTextBrowser( this );
59
    helpBrowser->setOpenExternalLinks( true );
60
    helpBrowser->setHtml( I_LONGHELP );
61
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
62
    closeButton->setDefault( true );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
63

64
65
    layout->addWidget( helpBrowser, 0, 0, 1, 0 );
    layout->addWidget( closeButton, 1, 3 );
66

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    BUTTONACT( closeButton, close() );
}

HelpDialog::~HelpDialog()
{
}
void HelpDialog::close()
{
    this->toggleVisible();
}

AboutDialog *AboutDialog::instance = NULL;

AboutDialog::AboutDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
{
    setWindowTitle( qtr( "About" ) );
83
    resize( 600, 500 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
84

85
86
    QGridLayout *layout = new QGridLayout( this );
    QTabWidget *tab = new QTabWidget( this );
87

88
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
89
    closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
90
    closeButton->setDefault( true );
91

92
    QLabel *introduction = new QLabel(
93
94
            qtr( "Information about VLC media player." ) );
    QLabel *iconVLC = new QLabel;
95
96
97
98
    if( QDate::currentDate().dayOfYear() >= 354 )
        iconVLC->setPixmap( QPixmap( ":/vlc48-christmas.png" ) );
    else
        iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
99
100
101
102
103
104
105
106
    layout->addWidget( iconVLC, 0, 0, 1, 1 );
    layout->addWidget( introduction, 0, 1, 1, 7 );
    layout->addWidget( tab, 1, 0, 1, 8 );
    layout->addWidget( closeButton, 2, 6, 1, 2 );

    /* Main Introduction */
    QWidget *infoWidget = new QWidget( this );
    QHBoxLayout *infoLayout = new QHBoxLayout( infoWidget );
Christophe Mutricy's avatar
Christophe Mutricy committed
107
108
    QLabel *infoLabel = new QLabel( "VLC media player " VERSION_MESSAGE "\n\n"
            "(c) " COPYRIGHT_YEARS " - the VideoLAN Team\n\n" +
109
            qtr( "VLC media player is a free media player, made by the "
110
111
112
113
                 "VideoLAN Team.\nIt is a standalone multimedia player, "
                 "encoder and streamer, that can read from many supports "
                 "(files, CDs, DVDs, networks, capture cards...) and that "
                 "works on many platforms.\n\n" )
114
            + qtr( "You are using the Qt4 Interface.\n" )
115
            + qtr( "Compiled by " ) + qfu( VLC_CompileBy() )+ "@"
116
            + qfu( VLC_CompileHost() ) + "."
117
            + qfu( VLC_CompileDomain() ) + ".\n"
118
            + "Compiler: " + qfu( VLC_Compiler() ) + ".\n"
119
120
121
122
123
            + qtr( "Based on SVN revision: " ) + qfu( VLC_Changeset() )
            + ".\n\n"
            + qtr( "This program comes with NO WARRANTY, to the extent "
                "permitted by the law; read the distribution tab.\n\n" )
            + "The VideoLAN team <videolan@videolan.org> \n"
124
              "http://www.videolan.org/\n" );
125
126
127
    infoLabel->setWordWrap( infoLabel );

    QLabel *iconVLC2 = new QLabel;
128
129
130
131
    if( QDate::currentDate().dayOfYear() >= 354 )
        iconVLC2->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
    else
        iconVLC2->setPixmap( QPixmap( ":/vlc128.png" ) );
132
133
    infoLayout->addWidget( iconVLC2 );
    infoLayout->addWidget( infoLabel );
134

135
    /* GPL License */
136
    QTextEdit *licenseEdit = new QTextEdit( this );
137
    licenseEdit->setFontFamily( "Monospace" );
138
    licenseEdit->setText( qfu( psz_license ) );
139
    licenseEdit->setReadOnly( true );
140
141

    /* People who helped */
142
143
144
    QWidget *thanksWidget = new QWidget( this );
    QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );

145
    QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
146
147
148
149
150
                "community, the testers, our users and the following people "
                "(and the missing ones...) for their collaboration to "
                "provide the best software." ) );
    thanksLabel->setWordWrap( true );
    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
158
159
160
    QTextEdit *authorsEdit = new QTextEdit( this );
    authorsEdit->setText( qfu( psz_authors ) );
    authorsEdit->setReadOnly( true );

161
    /* add the tabs to the Tabwidget */
162
    tab->addTab( infoWidget, qtr( "General Info" ) );
163
    tab->addTab( authorsEdit, qtr( "Authors" ) );
164
    tab->addTab( thanksWidget, qtr("Thanks") );
Christophe Mutricy's avatar
Christophe Mutricy committed
165
    tab->addTab( licenseEdit, qtr("Distribution License") );
166

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
167
168
169
170
171
172
173
174
175
176
    BUTTONACT( closeButton, close() );
}

AboutDialog::~AboutDialog()
{
}
void AboutDialog::close()
{
    this->toggleVisible();
}
177

178
#ifdef UPDATE_CHECK
179
180
181
182
183

/*****************************************************************************
 * UpdateDialog
 *****************************************************************************/
/* 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
188
189
190
191
192
193
    QEvent* event;

    if( b_ret )
        event = new QEvent( (QEvent::Type)UDOkEvent );
    else
        event = new QEvent( (QEvent::Type)UDErrorEvent );

194
195
196
    QApplication::postEvent( UDialog, event );
}

197
198
UpdateDialog *UpdateDialog::instance = NULL;

199
UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
200
201
{
    setWindowTitle( qtr( "Update" ) );
202
    resize( 120, 80 );
203
204
205
206

    QGridLayout *layout = new QGridLayout( this );

    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
211
212
    buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );

213
214
215
216
    updateLabel = new QLabel( qtr( "Checking for the update..." ) );
    updateLabel->setWordWrap( true );

    layout->addWidget( updateLabel, 0, 0 );
217
218
    layout->addWidget( buttonBox, 1, 0 );

219
    BUTTONACT( updateButton, UpdateOrDownload() );
220
221
    BUTTONACT( closeButton, close() );

222
    /* create the update structure and the callback */
223
    p_update = update_New( _p_intf );
224
    b_checked = false;
225
226
227

    /* Check for updates */
    UpdateOrDownload();
228
229
230
231
232
233
234
235
236
237
238
239
}

UpdateDialog::~UpdateDialog()
{
    update_Delete( p_update );
}

void UpdateDialog::close()
{
    toggleVisible();
}

240
241
242
243
244
245
/* Check for updates */
void UpdateDialog::UpdateOrDownload()
{
    if( !b_checked )
    {
        updateButton->setEnabled( false );
246
        update_Check( p_update, UpdateCallback, this );
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
    }
    else
    {
        updateButton->setEnabled( false );
        QString dest_dir = QFileDialog::getExistingDirectory( this, qtr( "Select a directory ..." ),
                                                              qfu( p_update->p_libvlc->psz_homedir ) );

        if( dest_dir != "" )
        {
            toggleVisible();
            update_Download( p_update, qtu( dest_dir ) );
        }
        else
            updateButton->setEnabled( true );
    }
}

/* Handle the events */
void UpdateDialog::customEvent( QEvent *event )
266
{
267
268
269
270
    if( event->type() == UDOkEvent )
        updateNotify( true );
    else
        updateNotify( false );
271
}
272

273
/* Notify the end of the update_Check */
274
void UpdateDialog::updateNotify( bool b_result )
275
{
276
277
    /* The update finish without errors */
    if( b_result )
278
    {
279
280
281
282
283
284
285
286
        if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer )
        {
            b_checked = true;
            updateButton->setText( "Download" );
            updateLabel->setText( qtr( "There is a new version of vlc :\n" ) + qfu( p_update->release.psz_desc )  );
        }
        else
            updateLabel->setText( qtr( "You have the latest version of vlc" ) );
287
288
    }
    else
289
290
        updateLabel->setText( qtr( "An error occure while checking for updates" ) );

291
292
    adjustSize();
    updateButton->setEnabled( true );
293
}
294

295

296
#endif