1 /*****************************************************************************
2 * Messages.cpp : Information about an item
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id: Messages.cpp 16024 2006-07-13 13:51:05Z xtophe $
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
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.
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.
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 *****************************************************************************/
24 #include "dialogs/messages.hpp"
25 #include "dialogs_provider.hpp"
26 #include "util/qvlcframe.hpp"
28 #include <QSpacerItem>
32 #include <QTextCursor>
33 #include <QFileDialog>
34 #include <QTextStream>
35 #include <QMessageBox>
37 MessagesDialog *MessagesDialog::instance = NULL;
39 MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) : QVLCFrame( _p_intf )
41 setWindowTitle( qtr( "Messages" ) );
44 QGridLayout *layout = new QGridLayout( this );
45 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
46 QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
47 QPushButton *saveLogButton = new QPushButton( qtr( "&Save as..." ) );
48 verbosityBox = new QSpinBox();
49 verbosityBox->setRange( 0, 2 );
50 verbosityBox->setValue( config_GetInt( p_intf, "verbose" ) );
51 verbosityBox->setWrapping( true );
52 verbosityBox->setMaximumWidth( 50 );
53 QLabel *verbosityLabel = new QLabel(qtr( "Verbosity Level" ) );
54 messages = new QTextEdit();
55 messages->setReadOnly( true );
56 messages->setGeometry( 0, 0, 440, 600 );
57 messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
59 layout->addWidget( messages, 0, 0, 1, 0 );
60 layout->addWidget( verbosityLabel, 1, 0, 1,1 );
61 layout->addWidget( verbosityBox, 1, 1 );
62 layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ), 1,2 );
63 layout->addWidget( saveLogButton, 1, 3 );
64 layout->addWidget( clearButton, 1, 4 );
65 layout->addWidget( closeButton, 1, 5 );
67 BUTTONACT( closeButton, close() );
68 BUTTONACT( clearButton, clear() );
69 BUTTONACT( saveLogButton, save() );
70 ON_TIMEOUT( updateLog() );
73 MessagesDialog::~MessagesDialog()
77 void MessagesDialog::updateLog()
79 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
82 vlc_mutex_lock( p_sub->p_lock );
83 int i_stop = *p_sub->pi_stop;
84 vlc_mutex_unlock( p_sub->p_lock );
86 messages->textCursor().movePosition( QTextCursor::End );
87 if( p_sub->i_start != i_stop )
89 for( i_start = p_sub->i_start;
91 i_start = (i_start+1) % VLC_MSG_QSIZE )
93 if( p_sub->p_msg[i_start].i_type == VLC_MSG_INFO ||
94 p_sub->p_msg[i_start].i_type == VLC_MSG_ERR ||
95 p_sub->p_msg[i_start].i_type == VLC_MSG_WARN &&
96 verbosityBox->value() >= 1 ||
97 p_sub->p_msg[i_start].i_type == VLC_MSG_DBG &&
98 verbosityBox->value() >= 2 )
100 messages->setFontItalic( true );
101 messages->setTextColor( "darkBlue" );
102 messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_module));
107 switch( p_sub->p_msg[i_start].i_type )
110 messages->setTextColor( "blue" );
111 messages->insertPlainText( " info: " );
114 messages->setTextColor( "red" );
115 messages->insertPlainText( " error: " );
118 messages->setTextColor( "green" );
119 messages->insertPlainText( " warning: " );
123 messages->setTextColor( "grey" );
124 messages->insertPlainText( " debug: " );
128 /* Add message Regular black Font */
129 messages->setFontItalic( false );
130 messages->setTextColor( "black" );
131 messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
132 messages->insertPlainText( "\n" );
134 messages->ensureCursorVisible();
136 vlc_mutex_lock( p_sub->p_lock );
137 p_sub->i_start = i_start;
138 vlc_mutex_unlock( p_sub->p_lock );
142 void MessagesDialog::close()
144 this->toggleVisible();
147 void MessagesDialog::clear()
152 bool MessagesDialog::save()
154 QString saveLogFileName = QFileDialog::getSaveFileName(
155 this, qtr( "Choose a filename to save the logs under..." ),
156 qfu( p_intf->p_libvlc->psz_homedir ),
157 "Texts / Logs (*.log *.txt);; All (*.*) " );
159 if( !saveLogFileName.isNull() )
161 QFile file( saveLogFileName );
162 if ( !file.open( QFile::WriteOnly | QFile::Text ) ) {
163 QMessageBox::warning( this, qtr( "Application" ),
164 qtr( "Cannot write file %1:\n%2." )
165 .arg( saveLogFileName )
166 .arg( file.errorString() ) );
170 QTextStream out( &file );
171 out << messages->toPlainText() << "\n";