]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/vlm.cpp
Qt: fix missing 's' in function name
[vlc] / modules / gui / qt4 / dialogs / vlm.cpp
index 3bc4725753d2e94ac324d65d33a39ce76bb5fdb1..f9954ce1804ec1627c6952366d526d4b6987072d 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>
@@ -53,7 +54,6 @@
 #include <QScrollArea>
 #include <QFileDialog>
 
-static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
 
 VLMDialog *VLMDialog::instance = NULL;
 
@@ -73,16 +73,16 @@ VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( pa
     ui.saveButton->hide();
 
 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
-    ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
-    ADDMEDIATYPES( "Schedule", QVLM_Schedule );
-    ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
+    ADDMEDIATYPES( N_("Broadcast"), QVLM_Broadcast );
+    ADDMEDIATYPES( N_("Schedule"), QVLM_Schedule );
+    ADDMEDIATYPES( N_("Video On Demand ( VOD )"), QVLM_VOD );
 #undef ADDMEDIATYPES
 
     /* Schedule Stuffs */
     QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
-    QLabel *schetimelabel = new QLabel( qtr( "Hours/Minutes/Seconds:" ) );
+    QLabel *schetimelabel = new QLabel( qtr( "Hours / Minutes / Seconds:" ) );
     schetimelayout->addWidget( schetimelabel, 0, 0 );
-    QLabel *schedatelabel = new QLabel( qtr( "Day Month Year:" ) );
+    QLabel *schedatelabel = new QLabel( qtr( "Day / Month / Year:" ) );
     schetimelayout->addWidget( schedatelabel, 1, 0 );
     QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
     schetimelayout->addWidget( scherepeatLabel, 2, 0 );
@@ -130,13 +130,13 @@ VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( pa
         new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
     vlmItemLayout->addItem( spacer );
 
-    QPushButton *importButton = new QPushButton( qtr(  "Import" ) );
+    QPushButton *importButton = new QPushButton( qtr( "I&mport" ) );
     ui.buttonBox->addButton( importButton, QDialogButtonBox::ActionRole );
 
-    QPushButton *exportButton = new QPushButton( qtr( "Export" ) );
+    QPushButton *exportButton = new QPushButton( qtr( "E&xport" ) );
     ui.buttonBox->addButton( exportButton, QDialogButtonBox::ActionRole );
 
-    QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
+    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
     ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
 
 
@@ -158,13 +158,15 @@ 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;
 
-   /* FIXME :you have to destroy vlm here to close
+    //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 )
     {
@@ -185,7 +187,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++ )
     {
@@ -219,6 +221,7 @@ void VLMDialog::addVLMItem()
     int repeatnum = scherepeatnumber->value();
     int repeatdays = repeatDays->value();
     VLMAWidget * vlmAwidget;
+    outputText.remove( ":sout=" );
 
     switch( type )
     {
@@ -259,23 +262,38 @@ void VLMDialog::addVLMItem()
     clearWidgets();
 }
 
-// FIXME : VOD are not exported to the file
+/* TODO : VOD are not exported to the file */
 bool VLMDialog::exportVLMConf()
 {
-    QString saveVLMConfFileName = QFileDialog::getSaveFileName(
-            this, qtr( "Choose a filename to save the VLM configuration..." ),
-            qfu( p_intf->p_libvlc->psz_homedir ),
-            qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
+    QFileDialog* qfd = new QFileDialog( this, qtr( "Save VLM configuration as..." ),
+                                        qfu( config_GetHomeDir() ),
+                                        qtr( "VLM conf (*.vlm);;All (*)" ) );
+    qfd->setFileMode( QFileDialog::AnyFile );
+    qfd->setAcceptMode( QFileDialog::AcceptSave );
+    qfd->setConfirmOverwrite( true );
 
-    if( !saveVLMConfFileName.isEmpty() )
+    bool exported = false;
+    if( qfd->exec() == QDialog::Accepted )
     {
-        vlm_message_t *message;
-        QString command = "save \"" + saveVLMConfFileName + "\"";
-        vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
-        vlm_MessageDelete( message );
-        return true;
+        QString saveVLMConfFileName = qfd->selectedFiles().first();
+        QString filter = qfd->selectedFilter();
+
+        // If *.vlm is selected, add .vlm at the end if needed
+        if( filter.contains( "VLM" ) && !saveVLMConfFileName.contains( ".vlm" ) )
+            saveVLMConfFileName.append( ".vlm" );
+
+        if( !saveVLMConfFileName.isEmpty() )
+        {
+            vlm_message_t *message;
+            QString command = "save \"" + saveVLMConfFileName + "\"";
+            vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
+            vlm_MessageDelete( message );
+            exported = true;
+        }
     }
-    return false;
+
+    delete qfd;
+    return exported;
 }
 
 void VLMDialog::mediasPopulator()
@@ -332,10 +350,11 @@ void VLMDialog::mediasPopulator()
 
 bool VLMDialog::importVLMConf()
 {
-    QString openVLMConfFileName = QFileDialog::getOpenFileName(
-            this, qtr( "Choose a VLM configuration file to open..." ),
-            qfu( p_intf->p_libvlc->psz_homedir ),
-            qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
+    QString openVLMConfFileName = toNativeSeparators(
+            QFileDialog::getOpenFileName(
+            this, qtr( "Open VLM configuration..." ),
+            qfu( config_GetHomeDir() ),
+            qtr( "VLM conf (*.vlm);;All (*)" ) ) );
 
     if( !openVLMConfFileName.isEmpty() )
     {
@@ -375,14 +394,14 @@ void VLMDialog::clearWidgets()
 
 void VLMDialog::selectInput()
 {
-    OpenDialog *o = OpenDialog::getInstance( this, p_intf, SELECT, true );
+    OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
     o->exec();
     ui.inputLedit->setText( o->getMRL() );
 }
 
 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() );
 }
@@ -435,7 +454,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 )
@@ -454,8 +473,7 @@ void VLMDialog::saveModifications()
             break;
            //           vlmObj->
         }
-        vlmObj->update(); /* It should call the correct function is VLMAWidget
-                             is abstract, but I am far from sure... FIXME ? */
+        vlmObj->update();
     }
     clearWidgets();
 }
@@ -464,9 +482,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 )
@@ -492,11 +510,11 @@ VLMAWidget::VLMAWidget( QString _name,
     objLayout->addWidget( time, 1, 3, 1, 2 );*/
 
     QToolButton *modifyButton = new QToolButton;
-    modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
+    modifyButton->setIcon( QIcon( QPixmap( ":/settings" ) ) );
     objLayout->addWidget( modifyButton, 0, 5 );
 
     QToolButton *deleteButton = new QToolButton;
-    deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
+    deleteButton->setIcon( QIcon( QPixmap( ":/quit" ) ) );
     objLayout->addWidget( deleteButton, 0, 6 );
 
     BUTTONACT( modifyButton, modify() );
@@ -514,12 +532,6 @@ void VLMAWidget::del()
     parent->removeVLMItem( this );
 }
 
-//FIXME, remove me before release
-void VLMAWidget::enterEvent( QEvent *event )
-{
-    printf( "test" );
-}
-
 void VLMAWidget::toggleEnabled( bool b_enable )
 {
     VLMWrapper::EnableItem( name, b_enable );
@@ -528,22 +540,23 @@ 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 )
 {
-    nameLabel->setText( "Broadcast: " + name );
+    nameLabel->setText( qtr("Broadcast: ") + name );
     type = QVLM_Broadcast;
     b_looped = _looped;
 
     playButton = new QToolButton;
-    playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
+    playButton->setIcon( QIcon( QPixmap( ":/play" ) ) );
     objLayout->addWidget( playButton, 1, 0 );
     b_playing = true;
 
     QToolButton *stopButton = new QToolButton;
-    stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
+    stopButton->setIcon( QIcon( QPixmap( ":/stop_b" ) ) );
     objLayout->addWidget( stopButton, 1, 1 );
 
     loopButton = new QToolButton;
@@ -560,22 +573,22 @@ void VLMBroadcast::update()
 {
     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
     if( b_looped )
-        loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_all.png" ) ) );
+        loopButton->setIcon( QIcon( QPixmap( ":/repeat_all" ) ) );
     else
-        loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
+        loopButton->setIcon( QIcon( QPixmap( ":/repeat_off" ) ) );
 }
 
 void VLMBroadcast::togglePlayPause()
 {
-    if( b_playing = true )
+    if( b_playing )
     {
         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
-        playButton->setIcon( QIcon( QPixmap( ":/pixmaps/pause_16px.png" ) ) );
+        playButton->setIcon( QIcon( QPixmap( ":/pause_16px" ) ) );
     }
     else
     {
         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
-        playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
+        playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
     }
     b_playing = !b_playing;
 }
@@ -589,19 +602,19 @@ void VLMBroadcast::toggleLoop()
 void VLMBroadcast::stop()
 {
     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
-    playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
+    playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
 }
 
 /****************
  * 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( "Schedule: " + name );
+    nameLabel->setText( qtr("Schedule: ") + name );
     schetime = _schetime;
     schedate = _schedate;
     rNumber = _scherepeatnumber;
@@ -619,11 +632,11 @@ 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( "VOD:" + name );
+    nameLabel->setText( qtr("VOD: ") + name );
 
     mux = _mux;
     muxLabel = new QLabel;
@@ -654,8 +667,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;
@@ -665,8 +678,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;
@@ -698,18 +711,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:
@@ -729,9 +744,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";
@@ -740,10 +755,10 @@ 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 + "\"";
@@ -771,11 +786,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";
@@ -785,11 +800,11 @@ 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 + "\"";
@@ -822,12 +837,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();
 }