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>
42 MessagesDialog *MessagesDialog::instance = NULL;
44 MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) : QVLCFrame( _p_intf )
46 setWindowTitle( qtr( "Messages" ) );
50 QGridLayout *mainLayout = new QGridLayout( this );
51 QTabWidget *mainTab = new QTabWidget( this );
52 mainTab->setTabPosition( QTabWidget::North );
54 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
55 closeButton->setDefault( true );
56 BUTTONACT( closeButton, close() );
58 mainLayout->addWidget( mainTab, 0, 0, 1, 0 );
59 mainLayout->addWidget( closeButton, 1, 5 );
63 QWidget *msgWidget = new QWidget;
64 QGridLayout *msgLayout = new QGridLayout( msgWidget );
66 QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
67 QPushButton *saveLogButton = new QPushButton( qtr( "&Save as..." ) );
69 verbosityBox = new QSpinBox();
70 verbosityBox->setRange( 0, 2 );
71 verbosityBox->setValue( config_GetInt( p_intf, "verbose" ) );
72 verbosityBox->setWrapping( true );
73 verbosityBox->setMaximumWidth( 50 );
75 QLabel *verbosityLabel = new QLabel( qtr( "Verbosity Level" ) );
77 messages = new QTextEdit();
78 messages->setReadOnly( true );
79 messages->setGeometry( 0, 0, 440, 600 );
80 messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
82 msgLayout->addWidget( messages, 0, 0, 1, 0 );
83 msgLayout->addWidget( verbosityLabel, 1, 0, 1, 1 );
84 msgLayout->addWidget( verbosityBox, 1, 1 );
85 msgLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ), 1, 2 );
86 msgLayout->addWidget( saveLogButton, 1, 3 );
87 msgLayout->addWidget( clearButton, 1, 4 );
89 BUTTONACT( clearButton, clear() );
90 BUTTONACT( saveLogButton, save() );
91 ON_TIMEOUT( updateLog() );
93 mainTab->addTab( msgWidget, qtr( "Messages" ) );
96 QWidget *treeWidget = new QWidget;
97 QGridLayout *treeLayout = new QGridLayout( treeWidget );
99 modulesTree = new QTreeWidget();
100 modulesTree->setGeometry( 0, 0, 440, 600 );
102 QPushButton *updateButton = new QPushButton( qtr( "&Update" ) );
104 treeLayout->addWidget( modulesTree, 0, 0, 1, 0 );
105 treeLayout->addWidget( updateButton, 1, 6 );
107 BUTTONACT( updateButton, updateTree() );
109 mainTab->addTab( treeWidget, qtr( "Modules tree" ) );
112 readSettings( "Messages" );
115 void MessagesDialog::updateLog()
117 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
120 vlc_mutex_lock( p_sub->p_lock );
121 int i_stop = *p_sub->pi_stop;
122 vlc_mutex_unlock( p_sub->p_lock );
124 if( p_sub->i_start != i_stop )
126 messages->textCursor().movePosition( QTextCursor::End );
128 for( i_start = p_sub->i_start;
130 i_start = (i_start+1) % VLC_MSG_QSIZE )
132 if( p_sub->p_msg[i_start].i_type == VLC_MSG_INFO ||
133 p_sub->p_msg[i_start].i_type == VLC_MSG_ERR ||
134 p_sub->p_msg[i_start].i_type == VLC_MSG_WARN &&
135 verbosityBox->value() >= 1 ||
136 p_sub->p_msg[i_start].i_type == VLC_MSG_DBG &&
137 verbosityBox->value() >= 2 )
139 messages->setFontItalic( true );
140 messages->setTextColor( "darkBlue" );
141 messages->insertPlainText( qfu( p_sub->p_msg[i_start].psz_module ) );
146 switch( p_sub->p_msg[i_start].i_type )
149 messages->setTextColor( "blue" );
150 messages->insertPlainText( " info: " );
153 messages->setTextColor( "red" );
154 messages->insertPlainText( " error: " );
157 messages->setTextColor( "green" );
158 messages->insertPlainText( " warning: " );
162 messages->setTextColor( "grey" );
163 messages->insertPlainText( " debug: " );
167 /* Add message Regular black Font */
168 messages->setFontItalic( false );
169 messages->setTextColor( "black" );
170 messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
171 messages->insertPlainText( "\n" );
173 messages->ensureCursorVisible();
175 vlc_mutex_lock( p_sub->p_lock );
176 p_sub->i_start = i_start;
177 vlc_mutex_unlock( p_sub->p_lock );
181 void MessagesDialog::buildTree( QTreeWidgetItem *parentItem, vlc_object_t *p_obj )
183 vlc_object_yield( p_obj );
184 QTreeWidgetItem *item;
187 item = new QTreeWidgetItem( parentItem );
189 item = new QTreeWidgetItem( modulesTree );
191 if( p_obj->psz_object_name )
192 item->setText( 0, qfu( p_obj->psz_object_type ) + " \"" + qfu( p_obj->psz_object_name ) + "\" (" + QString::number(p_obj->i_object_id) + ")\n" );
194 item->setText( 0, qfu( p_obj->psz_object_type ) + " (" + QString::number(p_obj->i_object_id) + ")\n" );
196 for( int i=0; i < p_obj->i_children; i++ )
198 buildTree( item, p_obj->pp_children[i]);
201 vlc_object_release( p_obj );
204 void MessagesDialog::updateTree()
206 modulesTree->clear();
208 buildTree( NULL, VLC_OBJECT( p_intf->p_libvlc ) );
211 void MessagesDialog::close()
216 void MessagesDialog::clear()
221 bool MessagesDialog::save()
223 QString saveLogFileName = QFileDialog::getSaveFileName(
224 this, qtr( "Choose a filename to save the logs under..." ),
225 qfu( p_intf->p_libvlc->psz_homedir ),
226 qtr( "Texts / Logs (*.log *.txt);; All (*.*) ") );
228 if( !saveLogFileName.isNull() )
230 QFile file( saveLogFileName );
231 if ( !file.open( QFile::WriteOnly | QFile::Text ) ) {
232 QMessageBox::warning( this, qtr( "Application" ),
233 qtr( "Cannot write file %1:\n%2." )
234 .arg( saveLogFileName )
235 .arg( file.errorString() ) );
239 QTextStream out( &file );
240 out << messages->toPlainText() << "\n";