]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/messages.cpp
Qt4 - Remove the enqueue button and regroup it under the play button, since it is...
[vlc] / modules / gui / qt4 / dialogs / messages.cpp
index 51cd1f12f361bf64e004e121e7d1ca2755bd2a2b..6f0aaf41d01ac048acd6b6dcbb12f0e609e37727 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "input_manager.hpp"
 #include "dialogs/messages.hpp"
 #include "dialogs_provider.hpp"
 #include "util/qvlcframe.hpp"
 #include "qt4.hpp"
+#include <QSpacerItem>
+#include <QSpinBox>
+#include <QLabel>
+#include <QTextEdit>
+#include <QTextCursor>
+#include <QFileDialog>
+#include <QTextStream>
+#include <QMessageBox>
 
 MessagesDialog *MessagesDialog::instance = NULL;
 
-MessagesDialog::MessagesDialog( intf_thread_t *_p_intf, bool _main_input ) :
-                              QVLCFrame( _p_intf ), main_input( _main_input )
+MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
 {
-    setWindowTitle( _("Messages" ) );
+    setWindowTitle( qtr( "Messages" ) );
     resize(600, 400);
 
-    QGridLayout *layout = new QGridLayout(this);
-    QPushButton *closeButton = new QPushButton(qtr("&Close"));
-    QPushButton *clearButton = new QPushButton(qtr("&Clear"));
-    QPushButton *saveLogButton = new QPushButton(qtr("&Save as..."));
-    QSpinBox *verbosityBox = new QSpinBox();
-    verbosityBox->setRange(1, 3);
-    verbosityBox->setWrapping(true);
-    QLabel *verbosityLabel = new QLabel(qtr("Verbosity Level"));
+    QGridLayout *layout = new QGridLayout( this );
+    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
+    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);
-
-    layout->addWidget(messages, 0, 0, 1, 0);
-    layout->addWidget(verbosityLabel, 1, 0, 1, 1);
-    layout->addWidget(verbosityBox, 1, 2);
-    layout->addWidget(saveLogButton, 2, 0);
-    layout->addWidget(clearButton, 2, 1);
-    layout->addWidget(closeButton, 2, 2);
-
-    connect( closeButton, SIGNAL( clicked() ) ,
-           this, SLOT( onCloseButton()));
-    connect( clearButton, SIGNAL( clicked() ) ,
-           this, SLOT( onClearButton()));
-    connect( saveLogButton, SIGNAL( clicked() ) ,
-           this, SLOT( onSaveButton()));
-    connect( verbosityBox, SIGNAL( valueChanged(int) ),
-           this, SLOT( onVerbosityChanged(int)));
-    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
-             SIGNAL( timeout() ), this, SLOT(updateLog() ) );
-
-    p_input = NULL;
+    messages->setReadOnly( true );
+    messages->setGeometry( 0, 0, 440, 600 );
+    messages->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+
+    layout->addWidget( messages, 0, 0, 1, 0 );
+    layout->addWidget( verbosityLabel, 1, 0, 1,1 );
+    layout->addWidget( verbosityBox, 1, 1 );
+    layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ), 1,2 );
+    layout->addWidget( saveLogButton, 1, 3 );
+    layout->addWidget( clearButton, 1, 4 );
+    layout->addWidget( closeButton, 1, 5 );
+
+    BUTTONACT( closeButton, close() );
+    BUTTONACT( clearButton, clear() );
+    BUTTONACT( saveLogButton, save() );
+    ON_TIMEOUT( updateLog() );
 }
 
 MessagesDialog::~MessagesDialog()
@@ -82,51 +83,51 @@ void MessagesDialog::updateLog()
     int i_stop = *p_sub->pi_stop;
     vlc_mutex_unlock( p_sub->p_lock );
 
+    messages->textCursor().movePosition( QTextCursor::End );
     if( p_sub->i_start != i_stop )
     {
         for( i_start = p_sub->i_start;
                 i_start != i_stop;
                 i_start = (i_start+1) % VLC_MSG_QSIZE )
         {
-          // [FIXME] Does not work as the old one
-          // Outputs too much data ?
-          // if (p_sub->p_msg[i_start].i_type = VLC_MSG_ERR)
-          //          continue;
-          //  if( !b_verbose &&
-          //         VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
-          //                continue;
-
-            /* Append all messages to log window */
-
-
-            messages->setFontItalic(true);
-            messages->setTextColor("darkBlue");
-            messages->insertPlainText(p_sub->p_msg[i_start].psz_module);
+            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: ");
+                    messages->setTextColor( "blue" );
+                    messages->insertPlainText( " info: " );
                     break;
                 case VLC_MSG_ERR:
-                    messages->setTextColor("red");
-                    messages->insertPlainText(" error: ");
+                    messages->setTextColor( "red" );
+                    messages->insertPlainText( " error: " );
                     break;
                 case VLC_MSG_WARN:
-                    messages->setTextColor("green");
-                    messages->insertPlainText(" warning: ");
+                    messages->setTextColor( "green" );
+                    messages->insertPlainText( " warning: " );
                     break;
                 case VLC_MSG_DBG:
                 default:
-                    messages->setTextColor("grey");
-                    messages->insertPlainText(" debug: ");
+                    messages->setTextColor( "grey" );
+                    messages->insertPlainText( " debug: " );
                     break;
             }
 
             /* Add message Regular black Font */
-            messages->setFontItalic(false);
-            messages->setTextColor("black");
+            messages->setFontItalic( false );
+            messages->setTextColor( "black" );
             messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
             messages->insertPlainText( "\n" );
         }
@@ -138,36 +139,35 @@ void MessagesDialog::updateLog()
     }
 }
 
-void MessagesDialog::onCloseButton()
+void MessagesDialog::close()
 {
     this->toggleVisible();
 }
 
-void MessagesDialog::onClearButton()
+void MessagesDialog::clear()
 {
     messages->clear();
 }
 
-bool MessagesDialog::onSaveButton()
+bool MessagesDialog::save()
 {
     QString saveLogFileName = QFileDialog::getSaveFileName(
-            this,
-            "Choose a filename to save the logs under...",
-            p_intf->p_vlc->psz_homedir,
-            "Texts / Logs (*.log *.txt);; All (*.*) ");
+            this, qtr( "Choose a filename to save the logs under..." ),
+            qfu( p_intf->p_libvlc->psz_homedir ),
+            "Texts / Logs (*.log *.txt);; All (*.*) " );
 
-    if (saveLogFileName != NULL)
+    if( !saveLogFileName.isNull() )
     {
-        QFile file(saveLogFileName);
-        if (!file.open(QFile::WriteOnly | QFile::Text)) {
-            QMessageBox::warning(this, qtr("Application"),
-                    qtr("Cannot write file %1:\n%2.")
-                    .arg(saveLogFileName)
-                    .arg(file.errorString()));
+        QFile file( saveLogFileName );
+        if ( !file.open( QFile::WriteOnly | QFile::Text ) ) {
+            QMessageBox::warning( this, qtr( "Application" ),
+                    qtr( "Cannot write file %1:\n%2." )
+                    .arg( saveLogFileName )
+                    .arg( file.errorString() ) );
             return false;
         }
 
-        QTextStream out(&file);
+        QTextStream out( &file );
         out << messages->toPlainText() << "\n";
 
         return true;
@@ -175,11 +175,3 @@ bool MessagesDialog::onSaveButton()
     return false;
 }
 
-void MessagesDialog::onVerbosityChanged(int verbosityLevel)
-{
-    //FIXME: Does not seems to work.
-    vlc_value_t  val;
-    val.i_int = verbosityLevel - 1;
-    var_Set( p_intf->p_vlc, "verbose", val );
-}
-