#endif
#include "dialogs/messages.hpp"
-#include "dialogs_provider.hpp"
-#include <QSpacerItem>
#include <QSpinBox>
#include <QLabel>
#include <QTextEdit>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QHeaderView>
+#include <QMutex>
+
+#include <assert.h>
MessagesDialog *MessagesDialog::instance = NULL;
+enum {
+ MsgEvent_Type = QEvent::User + MsgEventType + 1,
+};
+
+class MsgEvent : public QEvent
+{
+public:
+ MsgEvent( msg_item_t *msg )
+ : QEvent( (QEvent::Type)MsgEvent_Type ), msg(msg)
+ {
+ msg_Hold( msg );
+ }
+ virtual ~MsgEvent()
+ {
+ msg_Release( msg );
+ }
+
+ msg_item_t *msg;
+};
+
+struct msg_cb_data_t
+{
+ MessagesDialog *self;
+};
+static void MsgCallback( msg_cb_data_t *, msg_item_t *, unsigned );
+
MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
: QVLCFrame( _p_intf )
{
msgLayout->addWidget( messages, 0, 0, 1, 0 );
mainTab->addTab( msgWidget, qtr( "Messages" ) );
- // ON_TIMEOUT( updateLog() );
/* Modules tree */
/* General action */
readSettings( "Messages", QSize( 600, 450 ) );
+
+
+ /* Hook up to LibVLC messaging */
+ cbData = new msg_cb_data_t;
+ cbData->self = this;
+ sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, cbData );
}
+MessagesDialog::~MessagesDialog()
+{
+ writeSettings( "Messages" );
+ msg_Unsubscribe( sub );
+ delete cbData;
+};
+
void MessagesDialog::updateTab( int index )
{
/* Second tab : modules tree */
}
}
-void MessagesDialog::updateLog()
+void MessagesDialog::sinkMessage (msg_item_t *item, unsigned)
{
-#if 0
- msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
- int i_start;
-
- vlc_mutex_lock( p_sub->p_lock );
- int i_stop = *p_sub->pi_stop;
- vlc_mutex_unlock( p_sub->p_lock );
-
- if( p_sub->i_start != i_stop )
+ if ((item->i_type == VLC_MSG_WARN && verbosityBox->value() < 1)
+ || (item->i_type == VLC_MSG_DBG && verbosityBox->value() < 2 ))
+ return;
+
+ // Saving cursor selection
+ int startPos = messages->textCursor().selectionStart();
+ int endPos = messages->textCursor().selectionEnd();
+
+ messages->moveCursor( QTextCursor::End );
+ if( startPos == endPos && messages->textCursor().selectionEnd() == endPos )
+ endPos = 0;
+ messages->setFontItalic( true );
+ messages->setTextColor( "darkBlue" );
+ messages->insertPlainText( qfu( item->psz_module ) );
+
+ switch (item->i_type)
{
- messages->textCursor().movePosition( QTextCursor::End );
-
- for( i_start = p_sub->i_start;
- i_start != i_stop;
- i_start = (i_start+1) % VLC_MSG_QSIZE )
- {
- if( p_sub->p_msg[i_start].i_type == VLC_MSG_INFO ||
- p_sub->p_msg[i_start].i_type == VLC_MSG_ERR ||
- p_sub->p_msg[i_start].i_type == VLC_MSG_WARN &&
- verbosityBox->value() >= 1 ||
- p_sub->p_msg[i_start].i_type == VLC_MSG_DBG &&
- verbosityBox->value() >= 2 )
- {
- messages->setFontItalic( true );
- messages->setTextColor( "darkBlue" );
- messages->insertPlainText( qfu( p_sub->p_msg[i_start].psz_module ) );
- }
- else
- continue;
-
- switch( p_sub->p_msg[i_start].i_type )
- {
- case VLC_MSG_INFO:
- messages->setTextColor( "blue" );
- messages->insertPlainText( " info: " );
- break;
- case VLC_MSG_ERR:
- messages->setTextColor( "red" );
- messages->insertPlainText( " error: " );
- break;
- case VLC_MSG_WARN:
- messages->setTextColor( "green" );
- messages->insertPlainText( " warning: " );
- break;
- case VLC_MSG_DBG:
- default:
- messages->setTextColor( "grey" );
- messages->insertPlainText( " debug: " );
- break;
- }
-
- /* Add message Regular black Font */
- messages->setFontItalic( false );
- messages->setTextColor( "black" );
- messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
- messages->insertPlainText( "\n" );
- }
- messages->ensureCursorVisible();
+ case VLC_MSG_INFO:
+ messages->setTextColor( "blue" );
+ messages->insertPlainText( " info: " );
+ break;
+ case VLC_MSG_ERR:
+ messages->setTextColor( "red" );
+ messages->insertPlainText( " error: " );
+ break;
+ case VLC_MSG_WARN:
+ messages->setTextColor( "green" );
+ messages->insertPlainText( " warning: " );
+ break;
+ case VLC_MSG_DBG:
+ default:
+ messages->setTextColor( "grey" );
+ messages->insertPlainText( " debug: " );
+ break;
+ }
- vlc_mutex_lock( p_sub->p_lock );
- p_sub->i_start = i_start;
- vlc_mutex_unlock( p_sub->p_lock );
+ /* Add message Regular black Font */
+ messages->setFontItalic( false );
+ messages->setTextColor( "black" );
+ messages->insertPlainText( qfu(item->psz_msg) );
+ messages->insertPlainText( "\n" );
+ messages->ensureCursorVisible();
+
+ // Restoring saved cursor selection
+ // If the cursor was at this end, put it at the end,
+ // so we don't need to scroll down.
+ if( endPos == 0 )
+ messages->moveCursor( QTextCursor::End );
+ else
+ {
+ QTextCursor cur = messages->textCursor();
+ cur.movePosition( QTextCursor::Start );
+ cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, startPos );
+ cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, endPos - startPos );
+ messages->setTextCursor( cur );
}
-#endif
+}
+void MessagesDialog::customEvent( QEvent *event )
+{
+ MsgEvent *msg = dynamic_cast<MsgEvent*>(event);
+
+ assert( msg );
+ sinkMessage( msg->msg, 0 );
}
void MessagesDialog::buildTree( QTreeWidgetItem *parentItem,
}
return false;
}
+
+static void MsgCallback( msg_cb_data_t *data, msg_item_t *item, unsigned )
+{
+ int canc = vlc_savecancel();
+
+ QApplication::postEvent( data->self, new MsgEvent( item ) );
+
+ vlc_restorecancel( canc );
+}
+