]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/vlm.cpp
i18n fixes
[vlc] / modules / gui / qt4 / dialogs / vlm.cpp
index 264d66be28e7c0fc757edad582d3d51697868a09..16e2b34cffc4839deb5cb01f70a20379e70c431f 100644 (file)
@@ -53,7 +53,6 @@
 #include <QScrollArea>
 #include <QFileDialog>
 
-static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
 
 VLMDialog *VLMDialog::instance = NULL;
 
@@ -73,16 +72,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 +129,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 );
 
 
@@ -162,10 +161,14 @@ VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( pa
 
 VLMDialog::~VLMDialog()
 {
-   /* FIXME :you have to destroy vlm here to close
+    delete vlmWrapper;
+
+   /* 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 )
+    {
         vlm_Delete( p_vlm );
+    }
 }
 
 void VLMDialog::showScheduleWidget( int i )
@@ -199,7 +202,7 @@ void VLMDialog::addVLMItem()
     QString name = ui.nameLedit->text();
     if( name.isEmpty() || !isNameGenuine( name ) )
     {
-        msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
+        msg_Err( p_intf, "VLM Name is empty or already exists, I can't do it" );
         return;
     }
 
@@ -255,12 +258,12 @@ 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 ),
+            this, qtr( "Save VLM configuration as..." ),
+            qfu( config_GetHomeDir() ),
             qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
 
     if( !saveVLMConfFileName.isEmpty() )
@@ -274,20 +277,81 @@ bool VLMDialog::exportVLMConf()
     return false;
 }
 
+void VLMDialog::mediasPopulator()
+{
+    if( p_vlm )
+    {
+        int i_nMedias;
+        QString typeShortName;
+        int vlmItemCount;
+        vlm_media_t ***ppp_dsc = (vlm_media_t ***)malloc( sizeof( vlm_media_t ) );
+
+        /* Get medias informations and numbers */
+        vlm_Control( p_vlm, VLM_GET_MEDIAS, ppp_dsc, &i_nMedias );
+
+        /* Loop on all of them */
+        for( int i = 0; i < i_nMedias; i++ )
+        {
+            VLMAWidget * vlmAwidget;
+            vlmItemCount = vlmItems.size();
+
+            QString mediaName = qfu( (*ppp_dsc)[i]->psz_name );
+            /* It may have several inputs, we take the first one by default
+                 - an evolution will be to manage these inputs in the gui */
+            QString inputText = qfu( (*ppp_dsc)[i]->ppsz_input[0] );
+
+            QString outputText = qfu( (*ppp_dsc)[i]->psz_output );
+
+            /* Schedule media is a quite especial, maybe there is another way to grab informations */
+            if( (*ppp_dsc)[i]->b_vod )
+            {
+                typeShortName = "VOD";
+                QString mux = qfu( (*ppp_dsc)[i]->vod.psz_mux );
+                vlmAwidget = new VLMVod( mediaName, inputText, outputText,
+                                    (*ppp_dsc)[i]->b_enabled, mux, this );
+            }
+            else
+            {
+                typeShortName = "Bcast";
+                vlmAwidget = new VLMBroadcast( mediaName, inputText, outputText,
+                                  (*ppp_dsc)[i]->b_enabled, (*ppp_dsc)[i]->broadcast.b_loop, this );
+            }
+            /* Add an Item of the Side List */
+            ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
+            ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
+
+            /* Add a new VLMAWidget on the main List */
+            vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
+            vlmItems.append( vlmAwidget );
+            clearWidgets();
+        }
+        free( ppp_dsc );
+    }
+}
 
 bool VLMDialog::importVLMConf()
 {
     QString openVLMConfFileName = QFileDialog::getOpenFileName(
-            this, qtr( "Choose a VLM configuration file to open..." ),
-            qfu( p_intf->p_libvlc->psz_homedir ),
+            this, qtr( "Open VLM configuration..." ),
+            qfu( config_GetHomeDir() ),
             qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
 
     if( !openVLMConfFileName.isEmpty() )
     {
         vlm_message_t *message;
+        int status;
         QString command = "load \"" + openVLMConfFileName + "\"";
-        vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
+        status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
         vlm_MessageDelete( message );
+        if( status == 0 )
+        {
+            mediasPopulator();
+        }
+        else
+        {
+            msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
+            return false;
+        }
         return true;
     }
     return false;
@@ -310,7 +374,7 @@ 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() );
 }
@@ -339,7 +403,6 @@ void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
     currentIndex = vlmItems.indexOf( vlmObj );
     if( currentIndex < 0 ) return;
 
-    msg_Dbg( p_intf, "Type: %i", vlmObj->type );
     ui.vlmListItem->setCurrentRow( currentIndex );
     ui.nameLedit->setText( vlmObj->name );
     ui.inputLedit->setText( vlmObj->input );
@@ -390,8 +453,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();
 }
@@ -428,11 +490,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() );
@@ -450,12 +512,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 );
@@ -469,17 +525,17 @@ VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
                           : 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_16px" ) ) );
     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_16px" ) ) );
     objLayout->addWidget( stopButton, 1, 1 );
 
     loopButton = new QToolButton;
@@ -496,9 +552,9 @@ 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()
@@ -506,12 +562,12 @@ void VLMBroadcast::togglePlayPause()
     if( b_playing = true )
     {
         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;
 }
@@ -525,7 +581,7 @@ void VLMBroadcast::toggleLoop()
 void VLMBroadcast::stop()
 {
     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
-    playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
+    playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
 }
 
 /****************
@@ -537,7 +593,7 @@ VLMSchedule::VLMSchedule( QString name, QString input, QString output,
                           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;
@@ -559,7 +615,7 @@ VLMVod::VLMVod( QString name, QString input, QString output,
                 bool enabled, 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;
@@ -586,7 +642,9 @@ VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
 }
 
 VLMWrapper::~VLMWrapper()
-{}
+{
+    p_vlm = NULL;
+}
 
 void VLMWrapper::AddBroadcast( const QString name, QString input,
                                QString output,
@@ -683,12 +741,14 @@ void VLMWrapper::EditVod( const QString name, const QString input,
     QString command = "setup \"" + name + "\" input \"" + input + "\"";
     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
     vlm_MessageDelete( message );
+
     if( !output.isEmpty() )
     {
         command = "setup \"" + name + "\" output \"" + output + "\"";
         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
         vlm_MessageDelete( message );
     }
+
     if( b_enabled )
     {
         command = "setup \"" + name + "\" enabled";