]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/errors.cpp
Qt4 - renaming functions cosmetic and KDE/GNome/Windows button fight.
[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
25 #include "dialogs/errors.hpp"
26
27 #include <QTextCursor>
28 #include <QTextEdit>
29 #include <QCheckBox>
30 #include <QGridLayout>
31 #include <QDialogButtonBox>
32 #include <QPushButton>
33
34 ErrorsDialog *ErrorsDialog::instance = NULL;
35
36 ErrorsDialog::ErrorsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
37 {
38     setWindowTitle( qtr( "Errors" ) );
39     resize( 500 , 300 );
40
41     setWindowModality( Qt::ApplicationModal );
42
43     QGridLayout *layout = new QGridLayout( this );
44
45     QDialogButtonBox *buttonBox = new QDialogButtonBox;
46     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
47     QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
48     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
49     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
50
51     messages = new QTextEdit();
52     messages->setReadOnly( true );
53     messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
54     stopShowing = new QCheckBox( qtr( "Hide future errors" ) );
55
56     layout->addWidget( messages, 0, 0, 1, 3 );
57     layout->addWidget( stopShowing, 1, 0 );
58     layout->addItem( new QSpacerItem( 200, 20, QSizePolicy::Expanding ), 2,0 );
59     layout->addWidget( buttonBox, 2, 2 );
60
61     CONNECT( buttonBox, accepted(), this, close() );
62     BUTTONACT( clearButton, clear() );
63     BUTTONACT( stopShowing, dontShow() );
64 }
65
66 void ErrorsDialog::addError( QString title, QString text )
67 {
68     add( true, title, text );
69 }
70
71 void ErrorsDialog::addWarning( QString title, QString text )
72 {
73     add( false, title, text );
74 }
75
76 void ErrorsDialog::add( bool error, QString title, QString text )
77 {
78     if( stopShowing->isChecked() ) return;
79     messages->textCursor().movePosition( QTextCursor::End );
80     messages->setTextColor( error ? "red" : "yellow" );
81     messages->insertPlainText( title + QString( ":\n" ) );
82     messages->setTextColor( "black" );
83     messages->insertPlainText( text + QString( "\n" ) );
84     messages->ensureCursorVisible();
85     show();
86 }
87
88 void ErrorsDialog::close()
89 {
90     hide();
91 }
92
93 void ErrorsDialog::clear()
94 {
95     messages->clear();
96 }
97
98 void ErrorsDialog::dontShow()
99 {
100     if( stopShowing->isChecked() )
101     {
102         config_PutInt( p_intf, "qt-show-errors", 0 );
103     }
104 }