help.cpp 10.7 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
27
28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
29
#include "dialogs/help.hpp"
30
#include "util/qt_dirs.hpp"
31

Christophe Mutricy's avatar
Christophe Mutricy committed
32
#include <vlc_about.h>
33
#include <vlc_intf_strings.h>
34
35

#ifdef UPDATE_CHECK
36
# include <vlc_update.h>
37
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
38

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

48
#include <assert.h>
49

50
51
HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
52
53
{
    setWindowTitle( qtr( "Help" ) );
Nick Pope's avatar
Nick Pope committed
54
    setWindowRole( "vlc-help" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
55
    setMinimumSize( 350, 300 );
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 );
Christophe Mutricy's avatar
Christophe Mutricy committed
60
    helpBrowser->setHtml( qtr(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
    BUTTONACT( closeButton, close() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
68
    readSettings( "Help", QSize( 500, 450 ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
69
70
71
72
}

HelpDialog::~HelpDialog()
{
73
    writeSettings( "Help" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
74
}
75

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
76
77
void HelpDialog::close()
{
78
    toggleVisible();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
79
80
}

81
82
AboutDialog::AboutDialog( intf_thread_t *_p_intf)
            : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
83
84
{
    setWindowTitle( qtr( "About" ) );
Nick Pope's avatar
Nick Pope committed
85
    setWindowRole( "vlc-about" );
86
    resize( 600, 500 );
87
    setMinimumSize( 600, 500 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
88
    setWindowModality( Qt::WindowModal );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
89

90
91
    QGridLayout *layout = new QGridLayout( this );
    QTabWidget *tab = new QTabWidget( this );
92

93
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
94
    closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
95
    closeButton->setDefault( true );
96

97
    QLabel *introduction = new QLabel(
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
98
            qtr( "VLC media player" ) + qfu( " " VERSION_MESSAGE ) );
99
    QLabel *iconVLC = new QLabel;
100
    if( QDate::currentDate().dayOfYear() >= 354 )
101
        iconVLC->setPixmap( QPixmap( ":/logo/vlc48-christmas.png" ) );
102
    else
103
        iconVLC->setPixmap( QPixmap( ":/logo/vlc48.png" ) );
104
105
106
107
108
109
110
111
    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 );
112
113
114
115
    QLabel *infoLabel = new QLabel(
            qtr( "VLC media player is a free media player, "
                "encoder and streamer that can read from files, "
                "CDs, DVDs, network streams, capture cards and even more!\n"
116
117
                "VLC uses its internal codecs and works on essentially every "
                "popular platform.\n\n" )
118
119
            + qtr( "This version of VLC was compiled by:\n " )
            + qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() ) + "."
120
            + qfu( VLC_CompileDomain() ) + ".\n"
Christophe Mutricy's avatar
Christophe Mutricy committed
121
            + qtr( "Compiler: " ) + qfu( VLC_Compiler() ) + ".\n"
122
            + qtr( "You are using the Qt4 Interface.\n\n" )
Christophe Mutricy's avatar
Christophe Mutricy committed
123
124
            + qtr( "Copyright (C) " ) + COPYRIGHT_YEARS
            + qtr( " by the VideoLAN Team.\n" )
125
            + "vlc@videolan.org, http://www.videolan.org" );
126
127
128
    infoLabel->setWordWrap( infoLabel );

    QLabel *iconVLC2 = new QLabel;
129
    if( QDate::currentDate().dayOfYear() >= 354 )
130
        iconVLC2->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
131
    else
132
        iconVLC2->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
133
134
    infoLayout->addWidget( iconVLC2 );
    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
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
                "VLC community, the testers, our users and the following people "
147
                "(and the missing ones...) for their collaboration to "
148
                "create the best free software." ) );
149
150
    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( "About" ) );
163
    tab->addTab( authorsEdit, qtr( "Authors" ) );
164
    tab->addTab( thanksWidget, qtr("Thanks") );
165
    tab->addTab( licenseEdit, qtr("License") );
166

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

AboutDialog::~AboutDialog()
{
}
173

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
174
175
void AboutDialog::close()
{
176
    toggleVisible();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
177
}
178

179
#ifdef UPDATE_CHECK
180
181
182
183
184

/*****************************************************************************
 * UpdateDialog
 *****************************************************************************/
/* callback to get information from the core */
185
static void UpdateCallback( void *data, bool b_ret )
186
187
{
    UpdateDialog* UDialog = (UpdateDialog *)data;
188
189
190
191
192
193
194
    QEvent* event;

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

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

198
UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
199
{
200
    setWindowTitle( qtr( "VLC media player updates" ) );
Nick Pope's avatar
Nick Pope committed
201
    setWindowRole( "vlc-update" );
202
203
204

    QGridLayout *layout = new QGridLayout( this );

205
    QPushButton *closeButton = new QPushButton( qtr( "&Cancel" ) );
206
    updateButton = new QPushButton( qtr( "&Recheck version" ) );
207
    updateButton->setDefault( true );
208

209
    QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
210
211
212
    buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );

213
214
215
    updateLabelTop = new QLabel( qtr( "Checking for an update..." ) );
    updateLabelTop->setWordWrap( true );
    updateLabelTop->setMargin( 8 );
216

217
218
219
220
    updateLabelDown = new QLabel( qtr( "\nDo you want to download it?\n" ) );
    updateLabelDown->setWordWrap( true );
    updateLabelDown->hide();

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
221
    updateText = new QTextEdit( this );
222
223
224
225
226
227
228
229
230
    updateText->setAcceptRichText(false);
    updateText->setTextInteractionFlags( Qt::TextSelectableByKeyboard|
                                         Qt::TextSelectableByMouse);
    updateText->setEnabled( false );

    layout->addWidget( updateLabelTop, 0, 0 );
    layout->addWidget( updateText, 1, 0 );
    layout->addWidget( updateLabelDown, 2, 0 );
    layout->addWidget( buttonBox, 3, 0 );
231

232
    BUTTONACT( updateButton, UpdateOrDownload() );
233
234
    BUTTONACT( closeButton, close() );

235
    /* Create the update structure */
236
    p_update = update_New( p_intf );
237
    b_checked = false;
238

239
    setMinimumSize( 300, 300 );
240
241
    setMaximumSize( 400, 300 );

242
    readSettings( "Update", QSize( 300, 250 ) );
243

244
245
    /* Check for updates */
    UpdateOrDownload();
246
247
248
249
250
}

UpdateDialog::~UpdateDialog()
{
    update_Delete( p_update );
251
    writeSettings( "Update" );
252
253
254
255
256
257
258
}

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

259
260
261
262
263
264
/* Check for updates */
void UpdateDialog::UpdateOrDownload()
{
    if( !b_checked )
    {
        updateButton->setEnabled( false );
265
        updateLabelTop->setText( qtr( "Launching an update request..." ) );
266
        update_Check( p_update, UpdateCallback, this );
267
268
269
    }
    else
    {
270
        QString dest_dir = QFileDialog::getExistingDirectory( this,
271
                                 qtr( "Select a directory..." ),
272
                                 QVLCUserDir( VLC_DOWNLOAD_DIR ) );
273

274
        if( !dest_dir.isEmpty() )
275
        {
276
            dest_dir = toNativeSepNoSlash( dest_dir ) + DIR_SEP;
277
            msg_Dbg( p_intf, "Downloading to folder: %s", qtu( dest_dir ) );
278
279
280
281
282
283
284
285
            toggleVisible();
            update_Download( p_update, qtu( dest_dir ) );
        }
    }
}

/* Handle the events */
void UpdateDialog::customEvent( QEvent *event )
286
{
287
288
289
290
    if( event->type() == UDOkEvent )
        updateNotify( true );
    else
        updateNotify( false );
291
}
292

293
/* Notify the end of the update_Check */
294
void UpdateDialog::updateNotify( bool b_result )
295
{
296
297
    /* The update finish without errors */
    if( b_result )
298
    {
299
        if( update_NeedUpgrade( p_update ) )
300
        {
301
302
            update_release_t *p_release = update_GetRelease( p_update );
            assert( p_release );
303
            b_checked = true;
304
            updateButton->setText( qtr( "&Yes" ) );
305
306
307
308
309
310
            QString message = qtr( "A new version of VLC(" )
                              + QString::number( p_release->i_major ) + "."
                              + QString::number( p_release->i_minor ) + "."
                              + QString::number( p_release->i_revision );
            if( p_release->extra )
                message += p_release->extra;
311
312
313
314
315
            message += qtr( ") is available.");
            updateLabelTop->setText( message );

            updateText->setText( qfu( p_release->psz_desc ) );
            updateText->setEnabled( true );
316

317
            updateLabelDown->show();
318
319
320

            /* Force the dialog to be shown */
            this->show();
321
322
        }
        else
323
            updateLabelTop->setText(
324
                    qtr( "You have the latest version of VLC media player." ) );
325
326
    }
    else
327
        updateLabelTop->setText(
328
                    qtr( "An error occurred while checking for updates..." ) );
329

330
    updateButton->setEnabled( true );
331
}
332
333

#endif
334