]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/errors.cpp
b49a097a7ef57b90db50a78efbf5d7271b7a69b1
[vlc] / modules / gui / qt4 / dialogs / errors.cpp
1 /*****************************************************************************
2  * errors.cpp : Errors
3  ****************************************************************************
4  * Copyright ( C ) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * ( at your option ) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "dialogs/errors.hpp"
29
30 #include <QTextCursor>
31 #include <QTextEdit>
32 #include <QCheckBox>
33 #include <QGridLayout>
34 #include <QDialogButtonBox>
35 #include <QPushButton>
36
37 ErrorsDialog *ErrorsDialog::instance = NULL;
38
39 ErrorsDialog::ErrorsDialog( QWidget *parent, intf_thread_t *_p_intf )
40              : QVLCDialog( parent, _p_intf )
41 {
42     setWindowTitle( qtr( "Errors" ) );
43     resize( 500 , 300 );
44
45     setWindowModality( Qt::ApplicationModal );
46
47     QGridLayout *layout = new QGridLayout( this );
48
49     QDialogButtonBox *buttonBox = new QDialogButtonBox;
50     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
51     QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
52     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
53     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
54
55     messages = new QTextEdit();
56     messages->setReadOnly( true );
57     messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
58     stopShowing = new QCheckBox( qtr( "Hide future errors" ) );
59
60     layout->addWidget( messages, 0, 0, 1, 3 );
61     layout->addWidget( stopShowing, 1, 0 );
62     layout->addItem( new QSpacerItem( 200, 20, QSizePolicy::Expanding ), 2,0 );
63     layout->addWidget( buttonBox, 2, 2 );
64
65     CONNECT( buttonBox, accepted(), this, close() );
66     BUTTONACT( clearButton, clear() );
67     BUTTONACT( stopShowing, dontShow() );
68 }
69
70 void ErrorsDialog::addError( QString title, QString text )
71 {
72     add( true, title, text );
73 }
74
75 /*void ErrorsDialog::addWarning( QString title, QString text )
76 {
77     add( false, title, text );
78 }*/
79
80 void ErrorsDialog::add( bool error, QString title, QString text )
81 {
82     if( stopShowing->isChecked() ) return;
83     messages->textCursor().movePosition( QTextCursor::End );
84     messages->setTextColor( error ? "red" : "yellow" );
85     messages->insertPlainText( title + QString( ":\n" ) );
86     messages->setTextColor( "black" );
87     messages->insertPlainText( text + QString( "\n" ) );
88     messages->ensureCursorVisible();
89     show();
90 }
91
92 void ErrorsDialog::close()
93 {
94     hide();
95 }
96
97 void ErrorsDialog::clear()
98 {
99     messages->clear();
100 }
101
102 void ErrorsDialog::dontShow()
103 {
104     if( stopShowing->isChecked() )
105     {
106         config_PutInt( p_intf, "qt-show-errors", 0 );
107     }
108 }