errors.cpp 3.35 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1 2 3
/*****************************************************************************
 * errors.cpp : Errors
 ****************************************************************************
4
 * Copyright ( C ) 2006 the VideoLAN team
5
 * $Id$
Clément Stenac's avatar
Clément Stenac committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
Clément Stenac's avatar
Clément Stenac committed
9 10 11 12
 *
 * 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
13
 * ( at your option ) any later version.
Clément Stenac's avatar
Clément Stenac committed
14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/
24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Clément Stenac's avatar
Clément Stenac committed
27 28 29 30 31 32 33

#include "dialogs/errors.hpp"

#include <QTextCursor>
#include <QTextEdit>
#include <QCheckBox>
#include <QGridLayout>
34
#include <QDialogButtonBox>
Clément Stenac's avatar
Clément Stenac committed
35 36
#include <QPushButton>

37 38
ErrorsDialog::ErrorsDialog( intf_thread_t *_p_intf )
             : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
Clément Stenac's avatar
Clément Stenac committed
39
{
40
    setWindowTitle( qtr( "Errors" ) );
Nick Pope's avatar
Nick Pope committed
41
    setWindowRole( "vlc-errors" );
42
    resize( 500 , 300 );
Clément Stenac's avatar
Clément Stenac committed
43 44

    QGridLayout *layout = new QGridLayout( this );
45

46 47
    QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal, this );
    QPushButton *clearButton = new QPushButton( qtr( "Cl&ear" ), this );
48
    buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
49
    buttonBox->addButton( new QPushButton( qtr("&Close"), this ), QDialogButtonBox::RejectRole );
50

Clément Stenac's avatar
Clément Stenac committed
51 52 53
    messages = new QTextEdit();
    messages->setReadOnly( true );
    messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
54
    stopShowing = new QCheckBox( qtr( "Hide future errors" ) );
55
    stopShowing->setChecked( var_InheritInteger( p_intf, "qt-error-dialogs" ) != 0 );
Clément Stenac's avatar
Clément Stenac committed
56 57 58

    layout->addWidget( messages, 0, 0, 1, 3 );
    layout->addWidget( stopShowing, 1, 0 );
59
    layout->addWidget( buttonBox, 1, 2 );
Clément Stenac's avatar
Clément Stenac committed
60

61
    CONNECT( buttonBox, rejected(), this, close() );
62 63
    BUTTONACT( clearButton, clear() );
    BUTTONACT( stopShowing, dontShow() );
Clément Stenac's avatar
Clément Stenac committed
64 65
}

66
void ErrorsDialog::addError( const QString& title, const QString& text )
Clément Stenac's avatar
Clément Stenac committed
67 68 69 70
{
    add( true, title, text );
}

71
/*void ErrorsDialog::addWarning( QString title, QString text )
Clément Stenac's avatar
Clément Stenac committed
72 73
{
    add( false, title, text );
74
}*/
Clément Stenac's avatar
Clément Stenac committed
75

76
void ErrorsDialog::add( bool error, const QString& title, const QString& text )
Clément Stenac's avatar
Clément Stenac committed
77 78 79
{
    messages->textCursor().movePosition( QTextCursor::End );
    messages->setTextColor( error ? "red" : "yellow" );
80
    messages->insertPlainText( title + QString( ":\n" ) );
Clément Stenac's avatar
Clément Stenac committed
81 82 83
    messages->setTextColor( "black" );
    messages->insertPlainText( text + QString( "\n" ) );
    messages->ensureCursorVisible();
84 85
    if ( var_InheritInteger( p_intf, "qt-error-dialogs" ) != 0 )
        show();
Clément Stenac's avatar
Clément Stenac committed
86 87
}

88
void ErrorsDialog::close()
Clément Stenac's avatar
Clément Stenac committed
89 90 91 92
{
    hide();
}

93
void ErrorsDialog::clear()
Clément Stenac's avatar
Clément Stenac committed
94 95 96 97 98 99 100 101
{
    messages->clear();
}

void ErrorsDialog::dontShow()
{
    if( stopShowing->isChecked() )
    {
102
        config_PutInt( p_intf, "qt-error-dialogs", 0 );
Clément Stenac's avatar
Clément Stenac committed
103 104
    }
}