]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/vlm.cpp
qt4_vlm: fix #3938 (options must be removed from the input)
[vlc] / modules / gui / qt4 / dialogs / vlm.cpp
index 16e2b34cffc4839deb5cb01f70a20379e70c431f..af8adea71e6b92769de1fa96dd5981f3c9959255 100644 (file)
@@ -32,6 +32,7 @@
 #ifdef ENABLE_VLM
 #include "dialogs/open.hpp"
 #include "dialogs/sout.hpp"
+#include "util/qt_dirs.hpp"
 
 #include <QString>
 #include <QComboBox>
@@ -54,9 +55,7 @@
 #include <QFileDialog>
 
 
-VLMDialog *VLMDialog::instance = NULL;
-
-VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
+VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
 {
     p_vlm = vlm_New( p_intf );
 
@@ -157,12 +156,14 @@ VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( pa
     BUTTONACT( ui.saveButton, saveModifications() );
     BUTTONACT( ui.inputButton, selectInput() );
     BUTTONACT( ui.outputButton, selectOutput() );
+    //readSettings( "VLM", QSize( 700, 500 ) );
 }
 
 VLMDialog::~VLMDialog()
 {
     delete vlmWrapper;
 
+    //writeSettings( "VLM" );
    /* TODO :you have to destroy vlm here to close
     * but we shouldn't destroy vlm here in case somebody else wants it */
     if( p_vlm )
@@ -184,7 +185,7 @@ void VLMDialog::selectVLMItem( int i )
         ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
 }
 
-bool VLMDialog::isNameGenuine( QString name )
+bool VLMDialog::isNameGenuine( const QString& name )
 {
     for( int i = 0; i < vlmItems.size(); i++ )
     {
@@ -218,6 +219,7 @@ void VLMDialog::addVLMItem()
     int repeatnum = scherepeatnumber->value();
     int repeatdays = repeatDays->value();
     VLMAWidget * vlmAwidget;
+    outputText.remove( ":sout=" );
 
     switch( type )
     {
@@ -261,10 +263,10 @@ void VLMDialog::addVLMItem()
 /* TODO : VOD are not exported to the file */
 bool VLMDialog::exportVLMConf()
 {
-    QString saveVLMConfFileName = QFileDialog::getSaveFileName(
-            this, qtr( "Save VLM configuration as..." ),
-            qfu( config_GetHomeDir() ),
-            qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
+    QString saveVLMConfFileName = QFileDialog::getSaveFileName( this,
+                                        qtr( "Save VLM configuration as..." ),
+                                        QVLCUserDir( VLC_DOCUMENTS_DIR ),
+                                        qtr( "VLM conf (*.vlm);;All (*)" ) );
 
     if( !saveVLMConfFileName.isEmpty() )
     {
@@ -274,6 +276,7 @@ bool VLMDialog::exportVLMConf()
         vlm_MessageDelete( message );
         return true;
     }
+
     return false;
 }
 
@@ -331,10 +334,11 @@ void VLMDialog::mediasPopulator()
 
 bool VLMDialog::importVLMConf()
 {
-    QString openVLMConfFileName = QFileDialog::getOpenFileName(
+    QString openVLMConfFileName = toNativeSeparators(
+            QFileDialog::getOpenFileName(
             this, qtr( "Open VLM configuration..." ),
-            qfu( config_GetHomeDir() ),
-            qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
+            QVLCUserDir( VLC_DOCUMENTS_DIR ),
+            qtr( "VLM conf (*.vlm);;All (*)" ) ) );
 
     if( !openVLMConfFileName.isEmpty() )
     {
@@ -381,7 +385,7 @@ void VLMDialog::selectInput()
 
 void VLMDialog::selectOutput()
 {
-    SoutDialog *s = SoutDialog::getInstance( this, p_intf, false );
+    SoutDialog *s = new SoutDialog( this, p_intf );
     if( s->exec() == QDialog::Accepted )
         ui.outputLedit->setText( s->getMrl() );
 }
@@ -434,7 +438,7 @@ void VLMDialog::saveModifications()
     if( vlmObj )
     {
         vlmObj->input = ui.inputLedit->text();
-        vlmObj->output = ui.outputLedit->text();
+        vlmObj->output = ui.outputLedit->text().remove( ":sout=" );
         vlmObj->setChecked( ui.enableCheck->isChecked() );
         vlmObj->b_enabled = ui.enableCheck->isChecked();
         switch( vlmObj->type )
@@ -462,9 +466,9 @@ void VLMDialog::saveModifications()
  * VLMAWidget - Abstract class
  ********************************/
 
-VLMAWidget::VLMAWidget( QString _name,
-                        QString _input,
-                        QString _output,
+VLMAWidget::VLMAWidget( const QString& _name,
+                        const QString& _input,
+                        const QString& _output,
                         bool _enabled,
                         VLMDialog *_parent,
                         int _type )
@@ -490,11 +494,11 @@ VLMAWidget::VLMAWidget( QString _name,
     objLayout->addWidget( time, 1, 3, 1, 2 );*/
 
     QToolButton *modifyButton = new QToolButton;
-    modifyButton->setIcon( QIcon( QPixmap( ":/settings" ) ) );
+    modifyButton->setIcon( QIcon( ":/menu/settings" ) );
     objLayout->addWidget( modifyButton, 0, 5 );
 
     QToolButton *deleteButton = new QToolButton;
-    deleteButton->setIcon( QIcon( QPixmap( ":/quit" ) ) );
+    deleteButton->setIcon( QIcon( ":/menu/quit" ) );
     objLayout->addWidget( deleteButton, 0, 6 );
 
     BUTTONACT( modifyButton, modify() );
@@ -520,8 +524,9 @@ void VLMAWidget::toggleEnabled( bool b_enable )
 /****************
  * VLMBroadcast
  ****************/
-VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
-                            bool _enabled, bool _looped, VLMDialog *_parent)
+VLMBroadcast::VLMBroadcast( const QString& _name, const QString& _input,
+                            const QString& _output, bool _enabled,
+                            bool _looped, VLMDialog *_parent )
                           : VLMAWidget( _name, _input, _output,
                                         _enabled, _parent, QVLM_Broadcast )
 {
@@ -530,12 +535,12 @@ VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
     b_looped = _looped;
 
     playButton = new QToolButton;
-    playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
+    playButton->setIcon( QIcon( ":/menu/play" ) );
     objLayout->addWidget( playButton, 1, 0 );
     b_playing = true;
 
     QToolButton *stopButton = new QToolButton;
-    stopButton->setIcon( QIcon( QPixmap( ":/stop_16px" ) ) );
+    stopButton->setIcon( QIcon( ":/toolbar/stop_b" ) );
     objLayout->addWidget( stopButton, 1, 1 );
 
     loopButton = new QToolButton;
@@ -552,22 +557,22 @@ void VLMBroadcast::update()
 {
     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
     if( b_looped )
-        loopButton->setIcon( QIcon( QPixmap( ":/repeat_all" ) ) );
+        loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
     else
-        loopButton->setIcon( QIcon( QPixmap( ":/repeat_off" ) ) );
+        loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_off" ) );
 }
 
 void VLMBroadcast::togglePlayPause()
 {
-    if( b_playing = true )
+    if( b_playing )
     {
         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
-        playButton->setIcon( QIcon( QPixmap( ":/pause_16px" ) ) );
+        playButton->setIcon( QIcon( ":/menu/pause" ) );
     }
     else
     {
         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
-        playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
+        playButton->setIcon( QIcon( ":/menu/play" ) );
     }
     b_playing = !b_playing;
 }
@@ -581,16 +586,16 @@ void VLMBroadcast::toggleLoop()
 void VLMBroadcast::stop()
 {
     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
-    playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
+    playButton->setIcon( QIcon( ":/menu/play" ) );
 }
 
 /****************
  * VLMSchedule
  ****************/
-VLMSchedule::VLMSchedule( QString name, QString input, QString output,
-                          QDateTime _schetime, QDateTime _schedate,
-                          int _scherepeatnumber, int _repeatDays,
-                          bool enabled, VLMDialog *parent )
+VLMSchedule::VLMSchedule( const QString& name, const QString& input,
+                          const QString& output, QDateTime _schetime,
+                          QDateTime _schedate, int _scherepeatnumber,
+                          int _repeatDays, bool enabled, VLMDialog *parent )
             : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
 {
     nameLabel->setText( qtr("Schedule: ") + name );
@@ -611,8 +616,8 @@ void VLMSchedule::update()
 /****************
  * VLMVOD
  ****************/
-VLMVod::VLMVod( QString name, QString input, QString output,
-                bool enabled, QString _mux, VLMDialog *parent)
+VLMVod::VLMVod( const QString& name, const QString& input, const QString& output,
+                bool enabled, const QString& _mux, VLMDialog *parent)
        : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
 {
     nameLabel->setText( qtr("VOD: ") + name );
@@ -646,8 +651,8 @@ VLMWrapper::~VLMWrapper()
     p_vlm = NULL;
 }
 
-void VLMWrapper::AddBroadcast( const QString name, QString input,
-                               QString output,
+void VLMWrapper::AddBroadcast( const QString& name, const QString& input,
+                               const QString& output,
                                bool b_enabled, bool b_loop  )
 {
     vlm_message_t *message;
@@ -657,8 +662,8 @@ void VLMWrapper::AddBroadcast( const QString name, QString input,
     EditBroadcast( name, input, output, b_enabled, b_loop );
 }
 
-void VLMWrapper::EditBroadcast( const QString name, const QString input,
-                                const QString output,
+void VLMWrapper::EditBroadcast( const QString& name, const QString& input,
+                                const QString& output,
                                 bool b_enabled, bool b_loop  )
 {
     vlm_message_t *message;
@@ -667,9 +672,23 @@ void VLMWrapper::EditBroadcast( const QString name, const QString input,
     command = "setup \"" + name + "\" inputdel all";
     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
     vlm_MessageDelete( message );
-    command = "setup \"" + name + "\" input \"" + input + "\"";
-    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
-    vlm_MessageDelete( message );
+
+    if(!input.isEmpty())
+    {
+        QStringList inputs = input.split(":", QString::SkipEmptyParts);
+
+        command = "setup \"" + name + "\" input \"" + inputs[0].trimmed() + "\"";
+        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+        vlm_MessageDelete( message );
+
+        for( int i = 1; i < inputs.size(); i++ )
+        {
+            command = "setup \"" + name + "\" option \"" + inputs[i].trimmed() + "\"";
+            vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+            vlm_MessageDelete( message );
+        }
+    }
+
     if( !output.isEmpty() )
     {
         command = "setup \"" + name + "\" output \"" + output + "\"";
@@ -690,18 +709,20 @@ void VLMWrapper::EditBroadcast( const QString name, const QString input,
     }
 }
 
-void VLMWrapper::EnableItem( const QString name, bool b_enable )
+void VLMWrapper::EnableItem( const QString& name, bool b_enable )
 {
     vlm_message_t *message;
     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
+    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+    vlm_MessageDelete( message );
 }
 
-void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
+void VLMWrapper::ControlBroadcast( const QString& name, int BroadcastStatus,
                                    unsigned int seek )
 {
     vlm_message_t *message;
 
-    QString command = "control \"" + name;
+    QString command = "control \"" + name + "\"";
     switch( BroadcastStatus )
     {
     case ControlBroadcastPlay:
@@ -721,9 +742,9 @@ void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
     vlm_MessageDelete( message );
 }
 
-void VLMWrapper::AddVod( const QString name, const QString input,
-                         const QString output,
-                         bool b_enabled, const QString mux )
+void VLMWrapper::AddVod( const QString& name, const QString& input,
+                         const QString& output,
+                         bool b_enabled, const QString& mux )
 {
     vlm_message_t *message;
     QString command = "new \"" + name + "\" vod";
@@ -732,15 +753,29 @@ void VLMWrapper::AddVod( const QString name, const QString input,
     EditVod(  name, input, output, b_enabled, mux );
 }
 
-void VLMWrapper::EditVod( const QString name, const QString input,
-                          const QString output,
+void VLMWrapper::EditVod( const QString& name, const QString& input,
+                          const QString& output,
                           bool b_enabled,
-                          const QString mux )
+                          const QString& mux )
 {
     vlm_message_t *message;
-    QString command = "setup \"" + name + "\" input \"" + input + "\"";
-    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
-    vlm_MessageDelete( message );
+    QString command;
+
+    if(!input.isEmpty())
+    {
+        QStringList inputs = input.split(":", QString::SkipEmptyParts);
+
+        command = "setup \"" + name + "\" input \"" + inputs[0].trimmed() + "\"";
+        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+        vlm_MessageDelete( message );
+
+        for( int i = 1; i < inputs.size(); i++ )
+        {
+            command = "setup \"" + name + "\" option \"" + inputs[i].trimmed() + "\"";
+            vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+            vlm_MessageDelete( message );
+        }
+    }
 
     if( !output.isEmpty() )
     {
@@ -763,11 +798,11 @@ void VLMWrapper::EditVod( const QString name, const QString input,
     }
 }
 
-void VLMWrapper::AddSchedule( const QString name, const QString input,
-                              const QString output, QDateTime _schetime,
+void VLMWrapper::AddSchedule( const QString& name, const QString& input,
+                              const QString& output, QDateTime _schetime,
                               QDateTime _schedate,
                               int _scherepeatnumber, int _repeatDays,
-                              bool b_enabled, const QString mux )
+                              bool b_enabled, const QString& mux )
 {
     vlm_message_t *message;
     QString command = "new \"" + name + "\" schedule";
@@ -777,16 +812,30 @@ void VLMWrapper::AddSchedule( const QString name, const QString input,
             _scherepeatnumber, _repeatDays, b_enabled, mux );
 }
 
-void VLMWrapper::EditSchedule( const QString name, const QString input,
-                          const QString output, QDateTime _schetime,
-                          QDateTime _schedate, int _scherepeatnumber,
-                          int _repeatDays, bool b_enabled,
-                          const QString mux )
+void VLMWrapper::EditSchedule( const QString& name, const QString& input,
+                               const QString& output, QDateTime _schetime,
+                               QDateTime _schedate, int _scherepeatnumber,
+                               int _repeatDays, bool b_enabled,
+                               const QString& mux )
 {
     vlm_message_t *message;
-    QString command = "setup \"" + name + "\" input \"" + input + "\"";
-    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
-    vlm_MessageDelete( message );
+    QString command;
+
+    if(!input.isEmpty())
+    {
+        QStringList inputs = input.split(":", QString::SkipEmptyParts);
+
+        command = "setup \"" + name + "\" input \"" + inputs[0].trimmed() + "\"";
+        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+        vlm_MessageDelete( message );
+
+        for( int i = 1; i < inputs.size(); i++ )
+        {
+            command = "setup \"" + name + "\" option \"" + inputs[i].trimmed() + "\"";
+            vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+            vlm_MessageDelete( message );
+        }
+    }
 
     if( !output.isEmpty() )
     {
@@ -814,12 +863,35 @@ void VLMWrapper::EditSchedule( const QString name, const QString input,
         _schetime.toString( "hh:mm:ss" ) + "\"";
     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
     vlm_MessageDelete( message );
+
     if( _scherepeatnumber > 0 )
     {
        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
     }
+
+    if( _repeatDays > 0 )
+    {
+       command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
+       vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
+       vlm_MessageDelete( message );
+    }
+}
+
+void VLMDialog::toggleVisible()
+{
+    QList<VLMAWidget *>::iterator it;
+    for( it = vlmItems.begin(); it != vlmItems.end(); it++ )
+    {
+        VLMAWidget *item =  *it;
+        delete item;
+        item = NULL;
+    }
+    vlmItems.clear();
+    ui.vlmListItem->clear();
+    mediasPopulator();
+    QVLCDialog::toggleVisible();
 }