Commit c3c637e5 authored by Ludovic Fauvet's avatar Ludovic Fauvet Committed by Jean-Baptiste Kempf

qt4: filters messages in real time as you type

The old verbose-objects syntax is also discarded because it doesn't make
much sense to keep it.
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 51220a6a
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
#include "dialogs/messages.hpp" #include "dialogs/messages.hpp"
#include <QTextEdit> #include <QPlainTextEdit>
#include <QTextCursor> #include <QTextCursor>
#include <QTextBlock>
#include <QFileDialog> #include <QFileDialog>
#include <QTextStream> #include <QTextStream>
#include <QMessageBox> #include <QMessageBox>
...@@ -37,6 +38,8 @@ ...@@ -37,6 +38,8 @@
#include <QMutex> #include <QMutex>
#include <QLineEdit> #include <QLineEdit>
#include <QScrollBar> #include <QScrollBar>
#include <QMutex>
#include <QMutexLocker>
#include <assert.h> #include <assert.h>
...@@ -89,16 +92,9 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) ...@@ -89,16 +92,9 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
changeVerbosity( i_verbosity ); changeVerbosity( i_verbosity );
ui.verbosityBox->setValue( qMin( i_verbosity, 2 ) ); ui.verbosityBox->setValue( qMin( i_verbosity, 2 ) );
char *objs = var_InheritString( p_intf, "verbose-objects" ); getSettings()->beginGroup( "Messages" );
if( objs != NULL ) ui.filterEdit->setText( getSettings()->value( "messages-filter" ).toString() );
{ getSettings()->endGroup();
ui.vbobjectsEdit->setText( qfu(objs) );
free( objs );
}
updateConfig();
ui.vbobjectsEdit->setToolTip( "verbose-objects usage: \n"
"--verbose-objects=+printthatobject,-dontprintthatone\n"
"(keyword 'all' to applies to all objects)");
updateButton = new QPushButton( QIcon(":/update"), "" ); updateButton = new QPushButton( QIcon(":/update"), "" );
updateButton->setToolTip( qtr("Update the tree") ); updateButton->setToolTip( qtr("Update the tree") );
...@@ -109,7 +105,8 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) ...@@ -109,7 +105,8 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
BUTTONACT( ui.clearButton, clear() ); BUTTONACT( ui.clearButton, clear() );
BUTTONACT( updateButton, updateTree() ); BUTTONACT( updateButton, updateTree() );
BUTTONACT( ui.saveLogButton, save() ); BUTTONACT( ui.saveLogButton, save() );
CONNECT( ui.vbobjectsEdit, editingFinished(), this, updateConfig()); CONNECT( ui.filterEdit, editingFinished(), this, updateConfig() );
CONNECT( ui.filterEdit, textChanged(QString), this, filterMessages() );
CONNECT( ui.bottomButtonsBox, rejected(), this, hide() ); CONNECT( ui.bottomButtonsBox, rejected(), this, hide() );
CONNECT( ui.verbosityBox, valueChanged( int ), CONNECT( ui.verbosityBox, valueChanged( int ),
this, changeVerbosity( int ) ); this, changeVerbosity( int ) );
...@@ -136,43 +133,47 @@ void MessagesDialog::changeVerbosity( int i_verbosity ) ...@@ -136,43 +133,47 @@ void MessagesDialog::changeVerbosity( int i_verbosity )
void MessagesDialog::updateConfig() void MessagesDialog::updateConfig()
{ {
const QString& objects = ui.vbobjectsEdit->text(); getSettings()->beginGroup( "Messages" );
/* FIXME: config item should be part of Qt4 module */ getSettings()->setValue( "messages-filter", ui.filterEdit->text() );
config_PutPsz(p_intf, "verbose-objects", qtu(objects)); getSettings()->endGroup();
}
QStringList filterOut, filterIn;
/* If a filter is set, disable by default */
/* If no filters are set, enable */
filterDefault = objects.isEmpty();
foreach( const QString& elem, objects.split(QChar(',')) )
{
QString object = elem;
bool add = true;
if( elem.startsWith(QChar('-')) ) void MessagesDialog::filterMessages()
{ {
add = false; QMutexLocker locker( &messageLocker );
object.remove( 0, 1 ); QPlainTextEdit *messages = ui.messages;
} QTextBlock block = messages->document()->firstBlock();
else if( elem.startsWith(QChar('+')) )
object.remove( 0, 1 );
if( object.compare(qfu("all"), Qt::CaseInsensitive) == 0 ) while( block.isValid() )
filterDefault = add; {
else block.setVisible( matchFilter( block.text().toLower() ) );
(add ? &filterIn : &filterOut)->append( object ); block = block.next();
} }
filter = filterDefault ? filterOut : filterIn;
filter.removeDuplicates(); /* Consider the whole QTextDocument as dirty now */
messages->document()->markContentsDirty( 0, messages->document()->characterCount() );
/* FIXME This solves a bug (Qt?) with the viewport not resizing the
vertical scroll bar when one or more QTextBlock are hidden */
QSize vsize = messages->viewport()->size();
messages->viewport()->resize( vsize + QSize( 1, 1 ) );
messages->viewport()->resize( vsize );
}
bool MessagesDialog::matchFilter( const QString& text )
{
const QString& filter = ui.filterEdit->text();
if( filter.isEmpty() || text.contains( filter.toLower() ) )
return true;
return false;
} }
void MessagesDialog::sinkMessage( const MsgEvent *msg ) void MessagesDialog::sinkMessage( const MsgEvent *msg )
{ {
if( (filter.contains(msg->module) || filter.contains(msg->object_type)) QMutexLocker locker( &messageLocker );
== filterDefault )
return;
QTextEdit *messages = ui.messages; QPlainTextEdit *messages = ui.messages;
/* Only scroll if the viewport is at the end. /* Only scroll if the viewport is at the end.
Don't bug user by auto-changing/losing viewport on insert(). */ Don't bug user by auto-changing/losing viewport on insert(). */
bool b_autoscroll = ( messages->verticalScrollBar()->value() bool b_autoscroll = ( messages->verticalScrollBar()->value()
...@@ -188,36 +189,41 @@ void MessagesDialog::sinkMessage( const MsgEvent *msg ) ...@@ -188,36 +189,41 @@ void MessagesDialog::sinkMessage( const MsgEvent *msg )
messages->textCursor().anchor() != messages->textCursor().position() ) messages->textCursor().anchor() != messages->textCursor().position() )
messages->moveCursor( QTextCursor::End ); messages->moveCursor( QTextCursor::End );
messages->setFontItalic( true ); /* Start a new logic block so we can hide it on-demand */
messages->setTextColor( "darkBlue" ); messages->textCursor().insertBlock();
messages->insertPlainText( msg->module );
QString buf = QString( "<i><font color='darkblue'>%1</font>" ).arg( msg->module );
switch (msg->priority) switch ( msg->priority )
{ {
case VLC_MSG_INFO: case VLC_MSG_INFO:
messages->setTextColor( "blue" ); buf += "<font color='blue'> info: </font>";
messages->insertPlainText( " info: " );
break; break;
case VLC_MSG_ERR: case VLC_MSG_ERR:
messages->setTextColor( "red" ); buf += "<font color='red'> error: </font>";
messages->insertPlainText( " error: " );
break; break;
case VLC_MSG_WARN: case VLC_MSG_WARN:
messages->setTextColor( "green" ); buf += "<font color='green'> warning: </font>";
messages->insertPlainText( " warning: " );
break; break;
case VLC_MSG_DBG: case VLC_MSG_DBG:
default: default:
messages->setTextColor( "grey" ); buf += "<font color='grey'> debug: </font>";
messages->insertPlainText( " debug: " );
break; break;
} }
/* Add message Regular black Font */ /* Insert the prefix */
messages->setFontItalic( false ); messages->textCursor().insertHtml( buf /* + "</i>" */ );
messages->setTextColor( "black" );
messages->insertPlainText( msg->text ); /* Insert the message */
messages->insertPlainText( "\n" ); messages->textCursor().insertHtml( msg->text );
/* Pass the new message thru the filter */
QTextBlock b = messages->document()->lastBlock();
b.setVisible( matchFilter( b.text() ) );
/* Tell the QTextDocument to recompute the size of the given area */
messages->document()->markContentsDirty( b.position(), b.length() );
if ( b_autoscroll ) messages->ensureCursorVisible(); if ( b_autoscroll ) messages->ensureCursorVisible();
} }
...@@ -253,8 +259,15 @@ bool MessagesDialog::save() ...@@ -253,8 +259,15 @@ bool MessagesDialog::save()
} }
QTextStream out( &file ); QTextStream out( &file );
out << ui.messages->toPlainText() << "\n";
QTextBlock block = ui.messages->document()->firstBlock();
while( block.isValid() )
{
if( block.isVisible() )
out << block.text() << "\n";
block = block.next();
}
return true; return true;
} }
return false; return false;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ui/messages_panel.h" #include "ui/messages_panel.h"
#include <stdarg.h> #include <stdarg.h>
#include <vlc_atomic.h> #include <vlc_atomic.h>
#include <QMutex>
class QTabWidget; class QTabWidget;
class QPushButton; class QPushButton;
...@@ -53,14 +54,12 @@ private: ...@@ -53,14 +54,12 @@ private:
static void sinkMessage( void *, msg_item_t *, unsigned ); static void sinkMessage( void *, msg_item_t *, unsigned );
void customEvent( QEvent * ); void customEvent( QEvent * );
void sinkMessage( const MsgEvent * ); void sinkMessage( const MsgEvent * );
bool matchFilter( const QString& );
vlc_atomic_t verbosity; vlc_atomic_t verbosity;
static void MsgCallback( void *, int, const msg_item_t *, const char *, static void MsgCallback( void *, int, const msg_item_t *, const char *,
va_list ); va_list );
QStringList filter;
bool filterDefault;
private slots: private slots:
bool save(); bool save();
void updateConfig(); void updateConfig();
...@@ -68,12 +67,14 @@ private slots: ...@@ -68,12 +67,14 @@ private slots:
void clear(); void clear();
void updateTree(); void updateTree();
void tabChanged( int ); void tabChanged( int );
void filterMessages();
private: private:
void buildTree( QTreeWidgetItem *, vlc_object_t * ); void buildTree( QTreeWidgetItem *, vlc_object_t * );
friend class Singleton<MessagesDialog>; friend class Singleton<MessagesDialog>;
QPushButton *updateButton; QPushButton *updateButton;
QMutex messageLocker;
}; };
#endif #endif
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</attribute> </attribute>
<layout class="QGridLayout" name="msgLayout"> <layout class="QGridLayout" name="msgLayout">
<item row="0" column="0" colspan="6"> <item row="0" column="0" colspan="6">
<widget class="QTextEdit" name="messages"> <widget class="QPlainTextEdit" name="messages">
<property name="horizontalScrollBarPolicy"> <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="3"> <item row="1" column="3">
<widget class="QLineEdit" name="vbobjectsEdit"> <widget class="QLineEdit" name="filterEdit">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>80</width>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment