]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/messages.cpp
Merge branch 'df-for-upstream' of git://repo.or.cz/vlc/davidf-public
[vlc] / modules / gui / qt4 / dialogs / messages.cpp
index 56c3fe81b1cecdc8a440ab49a1bfdce2d3da92d4..59e8fbad0c530a0528120325fa7fa81af175b0be 100644 (file)
 #include <QTabWidget>
 #include <QTreeWidget>
 #include <QTreeWidgetItem>
+#include <QHeaderView>
 
 MessagesDialog *MessagesDialog::instance = NULL;
 
-MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
+MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
+               : QVLCFrame( _p_intf )
 {
     setWindowTitle( qtr( "Messages" ) );
-    resize( 600, 450 );
 
     /* General widgets */
     QGridLayout *mainLayout = new QGridLayout( this );
-    QTabWidget  *mainTab = new QTabWidget( this );
+    mainTab = new QTabWidget( this );
     mainTab->setTabPosition( QTabWidget::North );
 
-    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
-    closeButton->setDefault( true );
-    BUTTONACT( closeButton, close() );
-
-    mainLayout->addWidget( mainTab, 0, 0, 1, 0 );
-    mainLayout->addWidget( closeButton, 1, 5 );
-
 
     /* Messages */
     QWidget     *msgWidget = new QWidget;
     QGridLayout *msgLayout = new QGridLayout( msgWidget );
 
-    QPushButton *clearButton = new QPushButton( qtr( "&Clear" ) );
-    QPushButton *saveLogButton = new QPushButton( qtr( "&Save as..." ) );
-
-    verbosityBox = new QSpinBox();
-    verbosityBox->setRange( 0, 2 );
-    verbosityBox->setValue( config_GetInt( p_intf, "verbose" ) );
-    verbosityBox->setWrapping( true );
-    verbosityBox->setMaximumWidth( 50 );
-
-    QLabel *verbosityLabel = new QLabel( qtr( "Verbosity Level" ) );
-
     messages = new QTextEdit();
     messages->setReadOnly( true );
     messages->setGeometry( 0, 0, 440, 600 );
     messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 
     msgLayout->addWidget( messages, 0, 0, 1, 0 );
-    msgLayout->addWidget( verbosityLabel, 1, 0, 1, 1 );
-    msgLayout->addWidget( verbosityBox, 1, 1 );
-    msgLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ), 1, 2 );
-    msgLayout->addWidget( saveLogButton, 1, 3 );
-    msgLayout->addWidget( clearButton, 1, 4 );
-
-    BUTTONACT( clearButton, clear() );
-    BUTTONACT( saveLogButton, save() );
+    mainTab->addTab( msgWidget, qtr( "Messages" ) );
     ON_TIMEOUT( updateLog() );
 
-    mainTab->addTab( msgWidget, qtr( "Messages" ) );
 
-    /* Module tree */
+    /* Modules tree */
     QWidget     *treeWidget = new QWidget;
     QGridLayout *treeLayout = new QGridLayout( treeWidget );
 
     modulesTree = new QTreeWidget();
-    modulesTree->setGeometry( 0, 0, 440, 600 );
-
-    QPushButton *updateButton = new QPushButton( qtr( "&Update" ) );
+    modulesTree->header()->hide();
 
     treeLayout->addWidget( modulesTree, 0, 0, 1, 0 );
-    treeLayout->addWidget( updateButton, 1, 6 );
+    mainTab->addTab( treeWidget, qtr( "Modules tree" ) );
 
-    BUTTONACT( updateButton, updateTree() );
 
-    mainTab->addTab( treeWidget, qtr( "Modules tree" ) );
+    /* Buttons and general layout */
+    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
+    closeButton->setDefault( true );
+    clearUpdateButton = new QPushButton( qtr( "&Clear" ) );
+    saveLogButton = new QPushButton( qtr( "&Save as..." ) );
+    saveLogButton->setToolTip( qtr( "Save all the displayed logs to a file" ) );
+
+    verbosityBox = new QSpinBox();
+    verbosityBox->setRange( 0, 2 );
+    verbosityBox->setValue( config_GetInt( p_intf, "verbose" ) );
+    verbosityBox->setWrapping( true );
+    verbosityBox->setMaximumWidth( 50 );
 
+    verbosityLabel = new QLabel( qtr( "Verbosity Level" ) );
 
-    readSettings( "Messages" );
+    mainLayout->addWidget( mainTab, 0, 0, 1, 0 );
+    mainLayout->addWidget( verbosityLabel, 1, 0, 1, 1 );
+    mainLayout->addWidget( verbosityBox, 1, 1 );
+    mainLayout->setColumnStretch( 2, 10 );
+    mainLayout->addWidget( saveLogButton, 1, 3 );
+    mainLayout->addWidget( clearUpdateButton, 1, 4 );
+    mainLayout->addWidget( closeButton, 1, 5 );
+
+    BUTTONACT( closeButton, hide() );
+    BUTTONACT( clearUpdateButton, clearOrUpdate() );
+    BUTTONACT( saveLogButton, save() );
+    CONNECT( mainTab, currentChanged( int ),
+             this, updateTab( int ) );
+
+    /* General action */
+    readSettings( "Messages", QSize( 600, 450 ) );
+}
+
+void MessagesDialog::updateTab( int index )
+{
+    /* Second tab : modules tree */
+    if( index == 1 )
+    {
+        verbosityLabel->hide();
+        verbosityBox->hide();
+        clearUpdateButton->setText( qtr( "&Update" ) );
+        saveLogButton->hide();
+        updateTree();
+    }
+    /* First tab : messages */
+    else
+    {
+        verbosityLabel->show();
+        verbosityBox->show();
+        clearUpdateButton->setText( qtr( "&Clear" ) );
+        saveLogButton->show();
+    }
 }
 
 void MessagesDialog::updateLog()
@@ -178,9 +198,9 @@ void MessagesDialog::updateLog()
     }
 }
 
-void MessagesDialog::buildTree( QTreeWidgetItem *parentItem, vlc_object_t *p_obj )
+void MessagesDialog::buildTree( QTreeWidgetItem *parentItem,
+                                vlc_object_t *p_obj )
 {
-    vlc_object_yield( p_obj );
     QTreeWidgetItem *item;
 
     if( parentItem )
@@ -189,28 +209,33 @@ void MessagesDialog::buildTree( QTreeWidgetItem *parentItem, vlc_object_t *p_obj
         item = new QTreeWidgetItem( modulesTree );
 
     if( p_obj->psz_object_name )
-        item->setText( 0, qfu( p_obj->psz_object_type ) + " \"" + qfu( p_obj->psz_object_name ) + "\" (" + QString::number(p_obj->i_object_id) + ")\n" );
+        item->setText( 0, qfu( p_obj->psz_object_type ) + " \"" +
+                       qfu( p_obj->psz_object_name ) + "\" (" +
+                       QString::number(p_obj->i_object_id) + ")" );
     else
-        item->setText( 0, qfu( p_obj->psz_object_type ) + " (" + QString::number(p_obj->i_object_id) + ")\n" );
+        item->setText( 0, qfu( p_obj->psz_object_type ) + " (" +
+                       QString::number(p_obj->i_object_id) + ")" );
 
-    for( int i=0; i < p_obj->i_children; i++ )
-    {
-        buildTree( item, p_obj->pp_children[i]);
-    }
+    item->setExpanded( true );
 
-    vlc_object_release( p_obj );
+    vlc_list_t *l = vlc_list_children( p_obj );
+    for( int i=0; i < l->i_count; i++ )
+        buildTree( item, l->p_values[i].p_object );
+    vlc_list_release( l );
 }
 
-void MessagesDialog::updateTree()
+void MessagesDialog::clearOrUpdate()
 {
-    modulesTree->clear();
-
-    buildTree( NULL, VLC_OBJECT( p_intf->p_libvlc ) );
+    if( mainTab->currentIndex() )
+        updateTree();
+    else
+        clear();
 }
 
-void MessagesDialog::close()
+void MessagesDialog::updateTree()
 {
-    hide();
+    modulesTree->clear();
+    buildTree( NULL, VLC_OBJECT( p_intf->p_libvlc ) );
 }
 
 void MessagesDialog::clear()
@@ -221,8 +246,8 @@ void MessagesDialog::clear()
 bool MessagesDialog::save()
 {
     QString saveLogFileName = QFileDialog::getSaveFileName(
-            this, qtr( "Choose a filename to save the logs under..." ),
-            qfu( p_intf->p_libvlc->psz_homedir ),
+            this, qtr( "Select a name for the logs file" ),
+            qfu( config_GetHomeDir() ),
             qtr( "Texts / Logs (*.log *.txt);; All (*.*) ") );
 
     if( !saveLogFileName.isNull() )