1 /*****************************************************************************
2 * Messages.cpp : Information about an item
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
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"
27 #include <QSpacerItem>
31 #include <QTextCursor>
32 #include <QFileDialog>
33 #include <QTextStream>
34 #include <QMessageBox>
36 MessagesDialog *MessagesDialog::instance = NULL;
38 MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) : QVLCFrame( _p_intf )
40 setWindowTitle( qtr( "Messages" ) );
43 QGridLayout *layout = new QGridLayout( this );
44 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
45 QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
46 QPushButton *saveLogButton = new QPushButton( qtr( "&Save as..." ) );
47 closeButton->setDefault( true );
49 verbosityBox = new QSpinBox();
50 verbosityBox->setRange( 0, 2 );
51 verbosityBox->setValue( config_GetInt( p_intf, "verbose" ) );
52 verbosityBox->setWrapping( true );
53 verbosityBox->setMaximumWidth( 50 );
55 QLabel *verbosityLabel = new QLabel( qtr( "Verbosity Level" ) );
57 messages = new QTextEdit();
58 messages->setReadOnly( true );
59 messages->setGeometry( 0, 0, 440, 600 );
60 messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
62 layout->addWidget( messages, 0, 0, 1, 0 );
63 layout->addWidget( verbosityLabel, 1, 0, 1,1 );
64 layout->addWidget( verbosityBox, 1, 1 );
65 layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ), 1,2 );
66 layout->addWidget( saveLogButton, 1, 3 );
67 layout->addWidget( clearButton, 1, 4 );
68 layout->addWidget( closeButton, 1, 5 );
70 BUTTONACT( closeButton, close() );
71 BUTTONACT( clearButton, clear() );
72 BUTTONACT( saveLogButton, save() );
73 ON_TIMEOUT( updateLog() );
76 MessagesDialog::~MessagesDialog()
80 void MessagesDialog::updateLog()
82 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
85 vlc_mutex_lock( p_sub->p_lock );
86 int i_stop = *p_sub->pi_stop;
87 vlc_mutex_unlock( p_sub->p_lock );
89 if( p_sub->i_start != i_stop )
91 messages->textCursor().movePosition( QTextCursor::End );
93 for( i_start = p_sub->i_start;
95 i_start = (i_start+1) % VLC_MSG_QSIZE )
97 if( p_sub->p_msg[i_start].i_type == VLC_MSG_INFO ||
98 p_sub->p_msg[i_start].i_type == VLC_MSG_ERR ||
99 p_sub->p_msg[i_start].i_type == VLC_MSG_WARN &&
100 verbosityBox->value() >= 1 ||
101 p_sub->p_msg[i_start].i_type == VLC_MSG_DBG &&
102 verbosityBox->value() >= 2 )
104 messages->setFontItalic( true );
105 messages->setTextColor( "darkBlue" );
106 messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_module));
111 switch( p_sub->p_msg[i_start].i_type )
114 messages->setTextColor( "blue" );
115 messages->insertPlainText( " info: " );
118 messages->setTextColor( "red" );
119 messages->insertPlainText( " error: " );
122 messages->setTextColor( "green" );
123 messages->insertPlainText( " warning: " );
127 messages->setTextColor( "grey" );
128 messages->insertPlainText( " debug: " );
132 /* Add message Regular black Font */
133 messages->setFontItalic( false );
134 messages->setTextColor( "black" );
135 messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
136 messages->insertPlainText( "\n" );
138 messages->ensureCursorVisible();
140 vlc_mutex_lock( p_sub->p_lock );
141 p_sub->i_start = i_start;
142 vlc_mutex_unlock( p_sub->p_lock );
146 void MessagesDialog::close()
151 void MessagesDialog::clear()
156 bool MessagesDialog::save()
158 QString saveLogFileName = QFileDialog::getSaveFileName(
159 this, qtr( "Choose a filename to save the logs under..." ),
160 qfu( p_intf->p_libvlc->psz_homedir ),
161 "Texts / Logs (*.log *.txt);; All (*.*) " );
163 if( !saveLogFileName.isNull() )
165 QFile file( saveLogFileName );
166 if ( !file.open( QFile::WriteOnly | QFile::Text ) ) {
167 QMessageBox::warning( this, qtr( "Application" ),
168 qtr( "Cannot write file %1:\n%2." )
169 .arg( saveLogFileName )
170 .arg( file.errorString() ) );
174 QTextStream out( &file );
175 out << messages->toPlainText() << "\n";