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 *****************************************************************************/
27 #include "dialogs/messages.hpp"
28 #include "dialogs_provider.hpp"
30 #include <QSpacerItem>
34 #include <QTextCursor>
35 #include <QFileDialog>
36 #include <QTextStream>
37 #include <QMessageBox>
39 #include <QTreeWidget>
40 #include <QTreeWidgetItem>
41 #include <QHeaderView>
43 MessagesDialog *MessagesDialog::instance = NULL;
45 MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) : QVLCFrame( _p_intf )
47 setWindowTitle( qtr( "Messages" ) );
51 QGridLayout *mainLayout = new QGridLayout( this );
52 QTabWidget *mainTab = new QTabWidget( this );
53 mainTab->setTabPosition( QTabWidget::North );
55 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
56 closeButton->setDefault( true );
57 clearButton = new QPushButton( qtr( "&Clear" ) );
58 saveLogButton = new QPushButton( qtr( "&Save as..." ) );
60 verbosityBox = new QSpinBox();
61 verbosityBox->setRange( 0, 2 );
62 verbosityBox->setValue( config_GetInt( p_intf, "verbose" ) );
63 verbosityBox->setWrapping( true );
64 verbosityBox->setMaximumWidth( 50 );
66 verbosityLabel = new QLabel( qtr( "Verbosity Level" ) );
69 mainLayout->addWidget( mainTab, 0, 0, 1, 0 );
70 mainLayout->addWidget( verbosityLabel, 1, 0, 1, 1 );
71 mainLayout->addWidget( verbosityBox, 1, 1 );
72 mainLayout->addWidget( saveLogButton, 1, 3 );
73 mainLayout->addWidget( clearButton, 1, 4 );
74 mainLayout->addWidget( closeButton, 1, 5 );
76 BUTTONACT( closeButton, close() );
77 BUTTONACT( clearButton, clear() );
78 BUTTONACT( saveLogButton, save() );
79 CONNECT( mainTab, currentChanged( int ), this, updateTab( int ) );
83 QWidget *msgWidget = new QWidget;
84 QGridLayout *msgLayout = new QGridLayout( msgWidget );
86 messages = new QTextEdit();
87 messages->setReadOnly( true );
88 messages->setGeometry( 0, 0, 440, 600 );
89 messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
91 msgLayout->addWidget( messages, 0, 0, 1, 0 );
92 mainTab->addTab( msgWidget, qtr( "Messages" ) );
93 ON_TIMEOUT( updateLog() );
97 QWidget *treeWidget = new QWidget;
98 QGridLayout *treeLayout = new QGridLayout( treeWidget );
100 modulesTree = new QTreeWidget();
101 modulesTree->header()->hide();
103 treeLayout->addWidget( modulesTree, 0, 0, 1, 0 );
104 mainTab->addTab( treeWidget, qtr( "Modules tree" ) );
108 readSettings( "Messages" );
111 void MessagesDialog::updateTab( int index )
115 verbosityLabel->hide();
116 verbosityBox->hide();
118 saveLogButton->hide();
123 verbosityLabel->show();
124 verbosityBox->show();
126 saveLogButton->show();
130 void MessagesDialog::updateLog()
132 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
135 vlc_mutex_lock( p_sub->p_lock );
136 int i_stop = *p_sub->pi_stop;
137 vlc_mutex_unlock( p_sub->p_lock );
139 if( p_sub->i_start != i_stop )
141 messages->textCursor().movePosition( QTextCursor::End );
143 for( i_start = p_sub->i_start;
145 i_start = (i_start+1) % VLC_MSG_QSIZE )
147 if( p_sub->p_msg[i_start].i_type == VLC_MSG_INFO ||
148 p_sub->p_msg[i_start].i_type == VLC_MSG_ERR ||
149 p_sub->p_msg[i_start].i_type == VLC_MSG_WARN &&
150 verbosityBox->value() >= 1 ||
151 p_sub->p_msg[i_start].i_type == VLC_MSG_DBG &&
152 verbosityBox->value() >= 2 )
154 messages->setFontItalic( true );
155 messages->setTextColor( "darkBlue" );
156 messages->insertPlainText( qfu( p_sub->p_msg[i_start].psz_module ) );
161 switch( p_sub->p_msg[i_start].i_type )
164 messages->setTextColor( "blue" );
165 messages->insertPlainText( " info: " );
168 messages->setTextColor( "red" );
169 messages->insertPlainText( " error: " );
172 messages->setTextColor( "green" );
173 messages->insertPlainText( " warning: " );
177 messages->setTextColor( "grey" );
178 messages->insertPlainText( " debug: " );
182 /* Add message Regular black Font */
183 messages->setFontItalic( false );
184 messages->setTextColor( "black" );
185 messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
186 messages->insertPlainText( "\n" );
188 messages->ensureCursorVisible();
190 vlc_mutex_lock( p_sub->p_lock );
191 p_sub->i_start = i_start;
192 vlc_mutex_unlock( p_sub->p_lock );
196 void MessagesDialog::buildTree( QTreeWidgetItem *parentItem, vlc_object_t *p_obj )
198 vlc_object_yield( p_obj );
199 QTreeWidgetItem *item;
202 item = new QTreeWidgetItem( parentItem );
204 item = new QTreeWidgetItem( modulesTree );
206 if( p_obj->psz_object_name )
207 item->setText( 0, qfu( p_obj->psz_object_type ) + " \"" +
208 qfu( p_obj->psz_object_name ) + "\" (" +
209 QString::number(p_obj->i_object_id) + ")\n" );
211 item->setText( 0, qfu( p_obj->psz_object_type ) + " (" +
212 QString::number(p_obj->i_object_id) + ")\n" );
214 for( int i=0; i < p_obj->i_children; i++ )
216 buildTree( item, p_obj->pp_children[i]);
219 vlc_object_release( p_obj );
222 void MessagesDialog::updateTree()
224 modulesTree->clear();
226 buildTree( NULL, VLC_OBJECT( p_intf->p_libvlc ) );
229 void MessagesDialog::close()
234 void MessagesDialog::clear()
239 bool MessagesDialog::save()
241 QString saveLogFileName = QFileDialog::getSaveFileName(
242 this, qtr( "Choose a filename to save the logs under..." ),
243 qfu( p_intf->p_libvlc->psz_homedir ),
244 qtr( "Texts / Logs (*.log *.txt);; All (*.*) ") );
246 if( !saveLogFileName.isNull() )
248 QFile file( saveLogFileName );
249 if ( !file.open( QFile::WriteOnly | QFile::Text ) ) {
250 QMessageBox::warning( this, qtr( "Application" ),
251 qtr( "Cannot write file %1:\n%2." )
252 .arg( saveLogFileName )
253 .arg( file.errorString() ) );
257 QTextStream out( &file );
258 out << messages->toPlainText() << "\n";