errors.cpp 3.38 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 37 38
#include <QPushButton>

ErrorsDialog *ErrorsDialog::instance = NULL;

39 40
ErrorsDialog::ErrorsDialog( QWidget *parent, intf_thread_t *_p_intf )
             : QVLCDialog( parent, _p_intf )
Clément Stenac's avatar
Clément Stenac committed
41
{
42
    setWindowTitle( qtr( "Errors" ) );
43
    resize( 500 , 300 );
Clément Stenac's avatar
Clément Stenac committed
44

45 46
    setWindowModality( Qt::ApplicationModal );

Clément Stenac's avatar
Clément Stenac committed
47
    QGridLayout *layout = new QGridLayout( this );
48 49

    QDialogButtonBox *buttonBox = new QDialogButtonBox;
50 51
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
    QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
52 53 54
    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
    buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );

Clément Stenac's avatar
Clément Stenac committed
55 56 57
    messages = new QTextEdit();
    messages->setReadOnly( true );
    messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
58
    stopShowing = new QCheckBox( qtr( "Hide future errors" ) );
Clément Stenac's avatar
Clément Stenac committed
59 60 61 62

    layout->addWidget( messages, 0, 0, 1, 3 );
    layout->addWidget( stopShowing, 1, 0 );
    layout->addItem( new QSpacerItem( 200, 20, QSizePolicy::Expanding ), 2,0 );
63
    layout->addWidget( buttonBox, 2, 2 );
Clément Stenac's avatar
Clément Stenac committed
64

65
    CONNECT( buttonBox, accepted(), this, close() );
Clément Stenac's avatar
Clément Stenac committed
66 67
    BUTTONACT( clearButton, clear() );
    BUTTONACT( stopShowing, dontShow() );
Clément Stenac's avatar
Clément Stenac committed
68 69
}

70
void ErrorsDialog::addError( const QString& title, const QString& text )
Clément Stenac's avatar
Clément Stenac committed
71 72 73 74
{
    add( true, title, text );
}

75
/*void ErrorsDialog::addWarning( QString title, QString text )
Clément Stenac's avatar
Clément Stenac committed
76 77
{
    add( false, title, text );
78
}*/
Clément Stenac's avatar
Clément Stenac committed
79

80
void ErrorsDialog::add( bool error, const QString& title, const QString& text )
Clément Stenac's avatar
Clément Stenac committed
81 82 83 84
{
    if( stopShowing->isChecked() ) return;
    messages->textCursor().movePosition( QTextCursor::End );
    messages->setTextColor( error ? "red" : "yellow" );
85
    messages->insertPlainText( title + QString( ":\n" ) );
Clément Stenac's avatar
Clément Stenac committed
86 87 88 89 90 91
    messages->setTextColor( "black" );
    messages->insertPlainText( text + QString( "\n" ) );
    messages->ensureCursorVisible();
    show();
}

Clément Stenac's avatar
Clément Stenac committed
92
void ErrorsDialog::close()
Clément Stenac's avatar
Clément Stenac committed
93 94 95 96
{
    hide();
}

Clément Stenac's avatar
Clément Stenac committed
97
void ErrorsDialog::clear()
Clément Stenac's avatar
Clément Stenac committed
98 99 100 101 102 103 104 105 106 107 108
{
    messages->clear();
}

void ErrorsDialog::dontShow()
{
    if( stopShowing->isChecked() )
    {
        config_PutInt( p_intf, "qt-show-errors", 0 );
    }
}