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