help.cpp 9.41 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

29 30
#include <vlc/vlc.h>

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
31
#include "dialogs/help.hpp"
Christophe Mutricy's avatar
Christophe Mutricy committed
32
#include <vlc_about.h>
33 34

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

#include "dialogs_provider.hpp"

40 41
#include <vlc_intf_strings.h>

42
#include <QTextBrowser>
43
#include <QTabWidget>
44 45
#include <QFile>
#include <QLabel>
46
#include <QString>
47
#include <QDialogButtonBox>
48 49
#include <QEvent>
#include <QFileDialog>
50
#include <QDate>
51

52

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
53 54
HelpDialog *HelpDialog::instance = NULL;

55 56
HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
57 58
{
    setWindowTitle( qtr( "Help" ) );
59
    setMinimumSize( 250, 300 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
60

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

68 69
    layout->addWidget( helpBrowser, 0, 0, 1, 0 );
    layout->addWidget( closeButton, 1, 3 );
70

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
71
    BUTTONACT( closeButton, close() );
72
    readSettings( "Help", QSize( 400, 450 ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
73 74 75 76
}

HelpDialog::~HelpDialog()
{
77
    writeSettings( "Help" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
78
}
79

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
80 81
void HelpDialog::close()
{
82
    toggleVisible();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
83 84 85 86
}

AboutDialog *AboutDialog::instance = NULL;

87 88
AboutDialog::AboutDialog( QWidget *parent, intf_thread_t *_p_intf)
            : QVLCDialog( parent, _p_intf )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
89 90
{
    setWindowTitle( qtr( "About" ) );
91
    resize( 600, 500 );
92
    setMinimumSize( 600, 500 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
93

94 95
    QGridLayout *layout = new QGridLayout( this );
    QTabWidget *tab = new QTabWidget( this );
96

97
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
98
    closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
99
    closeButton->setDefault( true );
100

101
    QLabel *introduction = new QLabel(
102
            qtr( "VLC media player " VERSION_MESSAGE ) );
103
    QLabel *iconVLC = new QLabel;
104 105 106 107
    if( QDate::currentDate().dayOfYear() >= 354 )
        iconVLC->setPixmap( QPixmap( ":/vlc48-christmas.png" ) );
    else
        iconVLC->setPixmap( QPixmap( ":/vlc48.png" ) );
108 109 110 111 112 113 114 115
    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 );
116 117 118 119 120 121 122
    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"
                "Also, VLC works on essentially every popular platform.\n\n" )
            + qtr( "This version of VLC was compiled by:\n " )
            + qfu( VLC_CompileBy() )+ "@" + qfu( VLC_CompileHost() ) + "."
123
            + qfu( VLC_CompileDomain() ) + ".\n"
124
            + "Compiler: " + qfu( VLC_Compiler() ) + ".\n"
125
            + qtr( "Based on Git commit: " ) + qfu( VLC_Changeset() ) + ".\n"
126 127
            + qtr( "You are using the Qt4 Interface.\n\n" )
            + qtr( "Copyright (c) " COPYRIGHT_YEARS " by the VideoLAN Team.\n" )
128
            + "vlc@videolan.org, http://www.videolan.org" );
129 130 131
    infoLabel->setWordWrap( infoLabel );

    QLabel *iconVLC2 = new QLabel;
132 133 134 135
    if( QDate::currentDate().dayOfYear() >= 354 )
        iconVLC2->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
    else
        iconVLC2->setPixmap( QPixmap( ":/vlc128.png" ) );
136 137
    infoLayout->addWidget( iconVLC2 );
    infoLayout->addWidget( infoLabel );
138

139
    /* GPL License */
140
    QTextEdit *licenseEdit = new QTextEdit( this );
141
    licenseEdit->setText( qfu( psz_license ) );
142
    licenseEdit->setReadOnly( true );
143 144

    /* People who helped */
145 146 147
    QWidget *thanksWidget = new QWidget( this );
    QVBoxLayout *thanksLayout = new QVBoxLayout( thanksWidget );

148
    QLabel *thanksLabel = new QLabel( qtr( "We would like to thank the whole "
149 150 151 152 153
                "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 );
154
    QTextEdit *thanksEdit = new QTextEdit( this );
155
    thanksEdit->setText( qfu( psz_thanks ) );
156
    thanksEdit->setReadOnly( true );
157
    thanksLayout->addWidget( thanksEdit );
158

159
    /* People who wrote the software */
160 161 162 163
    QTextEdit *authorsEdit = new QTextEdit( this );
    authorsEdit->setText( qfu( psz_authors ) );
    authorsEdit->setReadOnly( true );

164
    /* add the tabs to the Tabwidget */
165
    tab->addTab( infoWidget, qtr( "About" ) );
166
    tab->addTab( authorsEdit, qtr( "Authors" ) );
167
    tab->addTab( thanksWidget, qtr("Thanks") );
168
    tab->addTab( licenseEdit, qtr("License") );
169

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

AboutDialog::~AboutDialog()
{
}
176

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
177 178
void AboutDialog::close()
{
179
    toggleVisible();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
180
}
181

182
#ifdef UPDATE_CHECK
183 184 185 186 187

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

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

198 199 200
    QApplication::postEvent( UDialog, event );
}

201 202
UpdateDialog *UpdateDialog::instance = NULL;

203
UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
204 205 206 207 208 209
{
    setWindowTitle( qtr( "Update" ) );

    QGridLayout *layout = new QGridLayout( this );

    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
210
    updateButton = new QPushButton( qtr( "&Update List" ) );
211
    updateButton->setDefault( true );
212
    QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal );
213 214 215
    buttonBox->addButton( updateButton, QDialogButtonBox::ActionRole );
    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );

Plouj's avatar
Plouj committed
216
    updateLabel = new QLabel( qtr( "Checking for an update..." ) );
217 218 219
    updateLabel->setWordWrap( true );

    layout->addWidget( updateLabel, 0, 0 );
220 221
    layout->addWidget( buttonBox, 1, 0 );

222
    BUTTONACT( updateButton, UpdateOrDownload() );
223 224
    BUTTONACT( closeButton, close() );

225
    /* Create the update structure */
226
    p_update = update_New( p_intf );
227
    b_checked = false;
228

229 230
    readSettings( "Update", QSize( 120, 80 ) );

231 232
    /* Check for updates */
    UpdateOrDownload();
233 234 235 236 237
}

UpdateDialog::~UpdateDialog()
{
    update_Delete( p_update );
238
    writeSettings( "Update" );
239 240 241 242 243 244 245
}

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

246 247 248 249 250 251
/* Check for updates */
void UpdateDialog::UpdateOrDownload()
{
    if( !b_checked )
    {
        updateButton->setEnabled( false );
Plouj's avatar
Plouj committed
252
        msg_Dbg( p_intf, "Launching an update request" );
253
        update_Check( p_update, UpdateCallback, this );
254 255 256 257
    }
    else
    {
        updateButton->setEnabled( false );
258 259
        QString dest_dir = QFileDialog::getExistingDirectory( this,
                                 qtr( "Select a directory ..." ),
260
                                 qfu( config_GetHomeDir() ) );
261 262 263 264 265 266 267 268 269 270 271 272 273

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

/* Handle the events */
void UpdateDialog::customEvent( QEvent *event )
274
{
275 276 277 278
    if( event->type() == UDOkEvent )
        updateNotify( true );
    else
        updateNotify( false );
279
}
280

281
/* Notify the end of the update_Check */
282
void UpdateDialog::updateNotify( bool b_result )
283
{
284 285
    /* The update finish without errors */
    if( b_result )
286
    {
287
        if( update_NeedUpgrade( p_update ) )
288
        {
289 290
            update_release_t *p_release = update_GetRelease( p_update );
            assert( p_release );
291 292
            b_checked = true;
            updateButton->setText( "Download" );
Plouj's avatar
Plouj committed
293
            updateLabel->setText( qtr( "There is a new version of VLC :\n" )
294
                                + qfu( p_release->psz_desc )  );
295 296
        }
        else
Plouj's avatar
Plouj committed
297
            updateLabel->setText( qtr( "You have the latest version of VLC" ) );
298 299
    }
    else
300
        updateLabel->setText(
sam's avatar
sam committed
301
                        qtr( "An error occurred while checking for updates" ) );
302

303 304
    adjustSize();
    updateButton->setEnabled( true );
305
}
306 307

#endif
308