]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/errors.cpp
Qt: standardbuttons are bad for win32 and translation. Only use custom
[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( intf_thread_t *_p_intf )
38              : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
39 {
40     setWindowTitle( qtr( "Errors" ) );
41     setWindowRole( "vlc-errors" );
42     resize( 500 , 300 );
43
44     QGridLayout *layout = new QGridLayout( this );
45
46     QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal, this );
47     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
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->addWidget( buttonBox, 1, 2 );
59
60     CONNECT( buttonBox, rejected(), this, close() );
61     BUTTONACT( clearButton, clear() );
62     BUTTONACT( stopShowing, dontShow() );
63 }
64
65 void ErrorsDialog::addError( const QString& title, const QString& text )
66 {
67     add( true, title, text );
68 }
69
70 /*void ErrorsDialog::addWarning( QString title, QString text )
71 {
72     add( false, title, text );
73 }*/
74
75 void ErrorsDialog::add( bool error, const QString& title, const QString& text )
76 {
77     if( stopShowing->isChecked() ) return;
78     messages->textCursor().movePosition( QTextCursor::End );
79     messages->setTextColor( error ? "red" : "yellow" );
80     messages->insertPlainText( title + QString( ":\n" ) );
81     messages->setTextColor( "black" );
82     messages->insertPlainText( text + QString( "\n" ) );
83     messages->ensureCursorVisible();
84     show();
85 }
86
87 void ErrorsDialog::close()
88 {
89     hide();
90 }
91
92 void ErrorsDialog::clear()
93 {
94     messages->clear();
95 }
96
97 void ErrorsDialog::dontShow()
98 {
99     if( stopShowing->isChecked() )
100     {
101         config_PutInt( p_intf, "qt-show-errors", 0 );
102     }
103 }