Qt: reindent after last commit.
[vlc.git] / modules / gui / qt4 / dialogs / vlm.cpp
1 /*****************************************************************************
2  * vlm.cpp : VLM Management
3  ****************************************************************************
4  * Copyright © 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *          Jean-François Massol <jf.massol -at- gmail.com>
9  *          Clément Sténac <zorglub@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * ( at your option ) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "dialogs/vlm.hpp"
31
32 #ifdef ENABLE_VLM
33 #include "dialogs/open.hpp"
34 #include "dialogs/sout.hpp"
35
36 #include <QString>
37 #include <QComboBox>
38 #include <QVBoxLayout>
39 #include <QStackedWidget>
40 #include <QLabel>
41 #include <QWidget>
42 #include <QGridLayout>
43 #include <QLineEdit>
44 #include <QCheckBox>
45 #include <QToolButton>
46 #include <QGroupBox>
47 #include <QPushButton>
48 #include <QHBoxLayout>
49 #include <QDateTimeEdit>
50 #include <QDateTime>
51 #include <QSpinBox>
52 #include <QHeaderView>
53 #include <QScrollArea>
54 #include <QFileDialog>
55
56
57 VLMDialog *VLMDialog::instance = NULL;
58
59 VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
60 {
61     p_vlm = vlm_New( p_intf );
62
63     if( !p_vlm )
64     {
65         msg_Warn( p_intf, "Couldn't build VLM object ");
66         return;
67     }
68     vlmWrapper = new VLMWrapper( p_vlm );
69
70     // UI stuff
71     ui.setupUi( this );
72     ui.saveButton->hide();
73
74 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
75     ADDMEDIATYPES( N_("Broadcast"), QVLM_Broadcast );
76     ADDMEDIATYPES( N_("Schedule"), QVLM_Schedule );
77     ADDMEDIATYPES( N_("Video On Demand ( VOD )"), QVLM_VOD );
78 #undef ADDMEDIATYPES
79
80     /* Schedule Stuffs */
81     QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
82     QLabel *schetimelabel = new QLabel( qtr( "Hours / Minutes / Seconds:" ) );
83     schetimelayout->addWidget( schetimelabel, 0, 0 );
84     QLabel *schedatelabel = new QLabel( qtr( "Day / Month / Year:" ) );
85     schetimelayout->addWidget( schedatelabel, 1, 0 );
86     QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
87     schetimelayout->addWidget( scherepeatLabel, 2, 0 );
88     QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
89     schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
90
91     time = new QDateTimeEdit( QTime::currentTime() );
92     time->setAlignment( Qt::AlignRight );
93     time->setDisplayFormat( "hh:mm:ss" );
94     schetimelayout->addWidget( time, 0, 1, 1, 3 );
95
96     date = new QDateTimeEdit( QDate::currentDate() );
97     date->setAlignment( Qt::AlignRight );
98     date->setCalendarPopup( true );
99 #ifdef WIN32
100     date->setDisplayFormat( "dd MM yyyy" );
101 #else
102     date->setDisplayFormat( "dd MMMM yyyy" );
103 #endif
104     schetimelayout->addWidget( date, 1, 1, 1, 3 );
105
106     scherepeatnumber = new QSpinBox;
107     scherepeatnumber->setAlignment( Qt::AlignRight );
108     schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
109
110     repeatDays = new QSpinBox;
111     repeatDays->setAlignment( Qt::AlignRight );
112     schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
113     repeatDays->setSuffix( qtr(" days") );
114
115     repeatTime = new QDateTimeEdit;
116     repeatTime->setAlignment( Qt::AlignRight );
117     schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
118     repeatTime->setDisplayFormat( "hh:mm:ss" );
119
120     /* scrollArea */
121     ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
122     ui.vlmItemScroll->setWidgetResizable( true );
123     vlmItemWidget = new QWidget;
124     vlmItemLayout = new QVBoxLayout( vlmItemWidget );
125     vlmItemWidget->setLayout( vlmItemLayout );
126     ui.vlmItemScroll->setWidget( vlmItemWidget );
127
128     QSpacerItem *spacer =
129         new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
130     vlmItemLayout->addItem( spacer );
131
132     QPushButton *importButton = new QPushButton( qtr( "I&mport" ) );
133     ui.buttonBox->addButton( importButton, QDialogButtonBox::ActionRole );
134
135     QPushButton *exportButton = new QPushButton( qtr( "E&xport" ) );
136     ui.buttonBox->addButton( exportButton, QDialogButtonBox::ActionRole );
137
138     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
139     ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
140
141
142     showScheduleWidget( QVLM_Broadcast );
143
144     /* Connect the comboBox to show the right Widgets */
145     CONNECT( ui.mediaType, currentIndexChanged( int ),
146              this, showScheduleWidget( int ) );
147
148     /* Connect the leftList to show the good VLMItem */
149     CONNECT( ui.vlmListItem, currentRowChanged( int ),
150              this, selectVLMItem( int ) );
151
152     BUTTONACT( closeButton, close() );
153     BUTTONACT( exportButton, exportVLMConf() );
154     BUTTONACT( importButton, importVLMConf() );
155     BUTTONACT( ui.addButton, addVLMItem() );
156     BUTTONACT( ui.clearButton, clearWidgets() );
157     BUTTONACT( ui.saveButton, saveModifications() );
158     BUTTONACT( ui.inputButton, selectInput() );
159     BUTTONACT( ui.outputButton, selectOutput() );
160     //readSettings( "VLM", QSize( 700, 500 ) );
161 }
162
163 VLMDialog::~VLMDialog()
164 {
165     delete vlmWrapper;
166
167     //writeSettings( "VLM" );
168    /* TODO :you have to destroy vlm here to close
169     * but we shouldn't destroy vlm here in case somebody else wants it */
170     if( p_vlm )
171     {
172         vlm_Delete( p_vlm );
173     }
174 }
175
176 void VLMDialog::showScheduleWidget( int i )
177 {
178     ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
179     ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
180     ui.vodBox->setVisible( ( i == QVLM_VOD ) );
181 }
182
183 void VLMDialog::selectVLMItem( int i )
184 {
185     if( i >= 0 )
186         ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
187 }
188
189 bool VLMDialog::isNameGenuine( const QString& name )
190 {
191     for( int i = 0; i < vlmItems.size(); i++ )
192     {
193         if( vlmItems.at( i )->name == name )
194             return false;
195     }
196     return true;
197 }
198
199 void VLMDialog::addVLMItem()
200 {
201     int vlmItemCount = vlmItems.size();
202
203     /* Take the name and Check it */
204     QString name = ui.nameLedit->text();
205     if( name.isEmpty() || !isNameGenuine( name ) )
206     {
207         msg_Err( p_intf, "VLM Name is empty or already exists, I can't do it" );
208         return;
209     }
210
211     int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
212
213     QString typeShortName;
214     QString inputText = ui.inputLedit->text();
215     QString outputText = ui.outputLedit->text();
216     bool b_checked = ui.enableCheck->isChecked();
217     bool b_looped = ui.loopBCast->isChecked();
218     QDateTime schetime = time->dateTime();
219     QDateTime schedate = date->dateTime();
220     int repeatnum = scherepeatnumber->value();
221     int repeatdays = repeatDays->value();
222     VLMAWidget * vlmAwidget;
223     outputText.remove( ":sout=" );
224
225     switch( type )
226     {
227     case QVLM_Broadcast:
228         typeShortName = "Bcast";
229         vlmAwidget = new VLMBroadcast( name, inputText, outputText,
230                                        b_checked, b_looped, this );
231         VLMWrapper::AddBroadcast( name, inputText, outputText, b_checked,
232                                   b_looped );
233     break;
234     case QVLM_VOD:
235         typeShortName = "VOD";
236         vlmAwidget = new VLMVod( name, inputText, outputText,
237                                  b_checked, ui.muxLedit->text(), this );
238         VLMWrapper::AddVod( name, inputText, outputText, b_checked );
239         break;
240     case QVLM_Schedule:
241         typeShortName = "Sched";
242         vlmAwidget = new VLMSchedule( name, inputText, outputText,
243                                       schetime, schedate, repeatnum,
244                                       repeatdays, b_checked, this );
245         VLMWrapper::AddSchedule( name, inputText, outputText, schetime,
246                                  schedate, repeatnum, repeatdays, b_checked);
247         break;
248     default:
249         msg_Warn( p_intf, "Something bad happened" );
250         return;
251     }
252
253     /* Add an Item of the Side List */
254     ui.vlmListItem->addItem( typeShortName + " : " + name );
255     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
256
257     /* Add a new VLMAWidget on the main List */
258
259     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
260     vlmItems.append( vlmAwidget );
261     clearWidgets();
262 }
263
264 /* TODO : VOD are not exported to the file */
265 bool VLMDialog::exportVLMConf()
266 {
267     QFileDialog* qfd = new QFileDialog( this, qtr( "Save VLM configuration as..." ),
268                                         qfu( config_GetHomeDir() ),
269                                         qtr( "VLM conf (*.vlm);;All (*)" ) );
270     qfd->setFileMode( QFileDialog::AnyFile );
271     qfd->setAcceptMode( QFileDialog::AcceptSave );
272     qfd->setConfirmOverwrite( true );
273
274     bool exported = false;
275     if( qfd->exec() == QDialog::Accepted )
276     {
277         QString saveVLMConfFileName = qfd->selectedFiles().first();
278         QString filter = qfd->selectedFilter();
279
280         // If *.vlm is selected, add .vlm at the end if needed
281         if( filter.contains( "VLM" ) && !saveVLMConfFileName.contains( ".vlm" ) )
282             saveVLMConfFileName.append( ".vlm" );
283
284         if( !saveVLMConfFileName.isEmpty() )
285         {
286             vlm_message_t *message;
287             QString command = "save \"" + saveVLMConfFileName + "\"";
288             vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
289             vlm_MessageDelete( message );
290             exported = true;
291         }
292     }
293
294     delete qfd;
295     return exported;
296 }
297
298 void VLMDialog::mediasPopulator()
299 {
300     if( p_vlm )
301     {
302         int i_nMedias;
303         QString typeShortName;
304         int vlmItemCount;
305         vlm_media_t ***ppp_dsc = (vlm_media_t ***)malloc( sizeof( vlm_media_t ) );
306
307         /* Get medias informations and numbers */
308         vlm_Control( p_vlm, VLM_GET_MEDIAS, ppp_dsc, &i_nMedias );
309
310         /* Loop on all of them */
311         for( int i = 0; i < i_nMedias; i++ )
312         {
313             VLMAWidget * vlmAwidget;
314             vlmItemCount = vlmItems.size();
315
316             QString mediaName = qfu( (*ppp_dsc)[i]->psz_name );
317             /* It may have several inputs, we take the first one by default
318                  - an evolution will be to manage these inputs in the gui */
319             QString inputText = qfu( (*ppp_dsc)[i]->ppsz_input[0] );
320
321             QString outputText = qfu( (*ppp_dsc)[i]->psz_output );
322
323             /* Schedule media is a quite especial, maybe there is another way to grab informations */
324             if( (*ppp_dsc)[i]->b_vod )
325             {
326                 typeShortName = "VOD";
327                 QString mux = qfu( (*ppp_dsc)[i]->vod.psz_mux );
328                 vlmAwidget = new VLMVod( mediaName, inputText, outputText,
329                                     (*ppp_dsc)[i]->b_enabled, mux, this );
330             }
331             else
332             {
333                 typeShortName = "Bcast";
334                 vlmAwidget = new VLMBroadcast( mediaName, inputText, outputText,
335                                   (*ppp_dsc)[i]->b_enabled, (*ppp_dsc)[i]->broadcast.b_loop, this );
336             }
337             /* Add an Item of the Side List */
338             ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
339             ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
340
341             /* Add a new VLMAWidget on the main List */
342             vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
343             vlmItems.append( vlmAwidget );
344             clearWidgets();
345         }
346         free( ppp_dsc );
347     }
348 }
349
350 bool VLMDialog::importVLMConf()
351 {
352     QString openVLMConfFileName = QFileDialog::getOpenFileName(
353             this, qtr( "Open VLM configuration..." ),
354             qfu( config_GetHomeDir() ),
355             qtr( "VLM conf (*.vlm);;All (*)" ) );
356
357     if( !openVLMConfFileName.isEmpty() )
358     {
359         vlm_message_t *message;
360         int status;
361         QString command = "load \"" + openVLMConfFileName + "\"";
362         status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
363         vlm_MessageDelete( message );
364         if( status == 0 )
365         {
366             mediasPopulator();
367         }
368         else
369         {
370             msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
371             return false;
372         }
373         return true;
374     }
375     return false;
376 }
377
378 void VLMDialog::clearWidgets()
379 {
380     ui.nameLedit->clear();
381     ui.inputLedit->clear();
382     ui.outputLedit->clear();
383     time->setTime( QTime::currentTime() );
384     date->setDate( QDate::currentDate() );
385     ui.enableCheck->setChecked( true );
386     ui.nameLedit->setReadOnly( false );
387     ui.loopBCast->setChecked( false );
388     ui.muxLedit->clear();
389     ui.saveButton->hide();
390     ui.addButton->show();
391 }
392
393 void VLMDialog::selectInput()
394 {
395     OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
396     o->exec();
397     ui.inputLedit->setText( o->getMRL() );
398 }
399
400 void VLMDialog::selectOutput()
401 {
402     SoutDialog *s = new SoutDialog( this, p_intf );
403     if( s->exec() == QDialog::Accepted )
404         ui.outputLedit->setText( s->getMrl() );
405 }
406
407 /* Object Modification */
408 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
409 {
410     int index = vlmItems.indexOf( vlmObj );
411     if( index < 0 ) return;
412     delete ui.vlmListItem->takeItem( index );
413     vlmItems.removeAt( index );
414     delete vlmObj;
415
416     /* HERE BE DRAGONS VLM REQUEST */
417 }
418
419 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
420 {
421     currentIndex = vlmItems.indexOf( vlmObj );
422     if( currentIndex < 0 ) return;
423
424     ui.vlmListItem->setCurrentRow( currentIndex );
425     ui.nameLedit->setText( vlmObj->name );
426     ui.inputLedit->setText( vlmObj->input );
427     ui.outputLedit->setText( vlmObj->output );
428     ui.enableCheck->setChecked( vlmObj->b_enabled );
429
430     switch( vlmObj->type )
431     {
432     case QVLM_Broadcast:
433         ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
434         break;
435     case QVLM_VOD:
436         ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
437         break;
438     case QVLM_Schedule:
439         time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
440         date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
441         break;
442     }
443
444     ui.nameLedit->setReadOnly( true );
445     ui.addButton->hide();
446     ui.saveButton->show();
447 }
448
449 void VLMDialog::saveModifications()
450 {
451     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
452     if( vlmObj )
453     {
454         vlmObj->input = ui.inputLedit->text();
455         vlmObj->output = ui.outputLedit->text().remove( ":sout=" );
456         vlmObj->setChecked( ui.enableCheck->isChecked() );
457         vlmObj->b_enabled = ui.enableCheck->isChecked();
458         switch( vlmObj->type )
459         {
460         case QVLM_Broadcast:
461             (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
462             break;
463         case QVLM_VOD:
464             (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
465             break;
466         case QVLM_Schedule:
467             (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
468             (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
469             (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
470             (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
471             break;
472            //           vlmObj->
473         }
474         vlmObj->update();
475     }
476     clearWidgets();
477 }
478
479 /*********************************
480  * VLMAWidget - Abstract class
481  ********************************/
482
483 VLMAWidget::VLMAWidget( const QString& _name,
484                         const QString& _input,
485                         const QString& _output,
486                         bool _enabled,
487                         VLMDialog *_parent,
488                         int _type )
489                       : QGroupBox( _name, _parent )
490 {
491     parent = _parent;
492     name = _name;
493     input = _input;
494     output = _output;
495     b_enabled = _enabled;
496     type = _type;
497
498     setCheckable( true );
499     setChecked( b_enabled );
500
501     objLayout = new QGridLayout( this );
502     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
503
504     nameLabel = new QLabel;
505     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
506
507     /*QLabel *time = new QLabel( "--:--/--:--" );
508     objLayout->addWidget( time, 1, 3, 1, 2 );*/
509
510     QToolButton *modifyButton = new QToolButton;
511     modifyButton->setIcon( QIcon( QPixmap( ":/settings" ) ) );
512     objLayout->addWidget( modifyButton, 0, 5 );
513
514     QToolButton *deleteButton = new QToolButton;
515     deleteButton->setIcon( QIcon( QPixmap( ":/quit" ) ) );
516     objLayout->addWidget( deleteButton, 0, 6 );
517
518     BUTTONACT( modifyButton, modify() );
519     BUTTONACT( deleteButton, del() );
520     CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
521 }
522
523 void VLMAWidget::modify()
524 {
525     parent->startModifyVLMItem( this );
526 }
527
528 void VLMAWidget::del()
529 {
530     parent->removeVLMItem( this );
531 }
532
533 void VLMAWidget::toggleEnabled( bool b_enable )
534 {
535     VLMWrapper::EnableItem( name, b_enable );
536 }
537
538 /****************
539  * VLMBroadcast
540  ****************/
541 VLMBroadcast::VLMBroadcast( const QString& _name, const QString& _input,
542                             const QString& _output, bool _enabled,
543                             bool _looped, VLMDialog *_parent )
544                           : VLMAWidget( _name, _input, _output,
545                                         _enabled, _parent, QVLM_Broadcast )
546 {
547     nameLabel->setText( qtr("Broadcast: ") + name );
548     type = QVLM_Broadcast;
549     b_looped = _looped;
550
551     playButton = new QToolButton;
552     playButton->setIcon( QIcon( QPixmap( ":/play" ) ) );
553     objLayout->addWidget( playButton, 1, 0 );
554     b_playing = true;
555
556     QToolButton *stopButton = new QToolButton;
557     stopButton->setIcon( QIcon( QPixmap( ":/stop_b" ) ) );
558     objLayout->addWidget( stopButton, 1, 1 );
559
560     loopButton = new QToolButton;
561     objLayout->addWidget( loopButton, 1, 2 );
562
563     BUTTONACT( playButton, togglePlayPause() );
564     BUTTONACT( stopButton, stop() );
565     BUTTONACT( loopButton, toggleLoop() );
566
567     update();
568 }
569
570 void VLMBroadcast::update()
571 {
572     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
573     if( b_looped )
574         loopButton->setIcon( QIcon( QPixmap( ":/repeat_all" ) ) );
575     else
576         loopButton->setIcon( QIcon( QPixmap( ":/repeat_off" ) ) );
577 }
578
579 void VLMBroadcast::togglePlayPause()
580 {
581     if( b_playing )
582     {
583         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
584         playButton->setIcon( QIcon( QPixmap( ":/pause_16px" ) ) );
585     }
586     else
587     {
588         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
589         playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
590     }
591     b_playing = !b_playing;
592 }
593
594 void VLMBroadcast::toggleLoop()
595 {
596     b_enabled = !b_enabled;
597     update();
598 }
599
600 void VLMBroadcast::stop()
601 {
602     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
603     playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
604 }
605
606 /****************
607  * VLMSchedule
608  ****************/
609 VLMSchedule::VLMSchedule( const QString& name, const QString& input,
610                           const QString& output, QDateTime _schetime,
611                           QDateTime _schedate, int _scherepeatnumber,
612                           int _repeatDays, bool enabled, VLMDialog *parent )
613             : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
614 {
615     nameLabel->setText( qtr("Schedule: ") + name );
616     schetime = _schetime;
617     schedate = _schedate;
618     rNumber = _scherepeatnumber;
619     rDays = _repeatDays;
620     type = QVLM_Schedule;
621     update();
622 }
623
624 void VLMSchedule::update()
625 {
626    VLMWrapper::EditSchedule( name, input, output, schetime, schedate,
627                              rNumber, rDays, b_enabled);
628 }
629
630 /****************
631  * VLMVOD
632  ****************/
633 VLMVod::VLMVod( const QString& name, const QString& input, const QString& output,
634                 bool enabled, const QString& _mux, VLMDialog *parent)
635        : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
636 {
637     nameLabel->setText( qtr("VOD: ") + name );
638
639     mux = _mux;
640     muxLabel = new QLabel;
641     objLayout->addWidget( muxLabel, 1, 0 );
642
643     update();
644 }
645
646 void VLMVod::update()
647 {
648     muxLabel->setText( mux );
649     VLMWrapper::EditVod( name, input, output, b_enabled, mux );
650 }
651
652
653 /*******************
654  * VLMWrapper
655  *******************/
656 vlm_t * VLMWrapper::p_vlm = NULL;
657
658 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
659 {
660     p_vlm = _p_vlm;
661 }
662
663 VLMWrapper::~VLMWrapper()
664 {
665     p_vlm = NULL;
666 }
667
668 void VLMWrapper::AddBroadcast( const QString& name, const QString& input,
669                                const QString& output,
670                                bool b_enabled, bool b_loop  )
671 {
672     vlm_message_t *message;
673     QString command = "new \"" + name + "\" broadcast";
674     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
675     vlm_MessageDelete( message );
676     EditBroadcast( name, input, output, b_enabled, b_loop );
677 }
678
679 void VLMWrapper::EditBroadcast( const QString& name, const QString& input,
680                                 const QString& output,
681                                 bool b_enabled, bool b_loop  )
682 {
683     vlm_message_t *message;
684     QString command;
685
686     command = "setup \"" + name + "\" inputdel all";
687     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
688     vlm_MessageDelete( message );
689     command = "setup \"" + name + "\" input \"" + input + "\"";
690     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
691     vlm_MessageDelete( message );
692     if( !output.isEmpty() )
693     {
694         command = "setup \"" + name + "\" output \"" + output + "\"";
695         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
696         vlm_MessageDelete( message );
697     }
698     if( b_enabled )
699     {
700         command = "setup \"" + name + "\" enabled";
701         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
702         vlm_MessageDelete( message );
703     }
704     if( b_loop )
705     {
706         command = "setup \"" + name + "\" loop";
707         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
708         vlm_MessageDelete( message );
709     }
710 }
711
712 void VLMWrapper::EnableItem( const QString& name, bool b_enable )
713 {
714     vlm_message_t *message;
715     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
716     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
717     vlm_MessageDelete( message );
718 }
719
720 void VLMWrapper::ControlBroadcast( const QString& name, int BroadcastStatus,
721                                    unsigned int seek )
722 {
723     vlm_message_t *message;
724
725     QString command = "control \"" + name + "\"";
726     switch( BroadcastStatus )
727     {
728     case ControlBroadcastPlay:
729         command += " play";
730         break;
731     case ControlBroadcastPause:
732         command += " pause";
733         break;
734     case ControlBroadcastStop:
735         command += " stop";
736         break;
737     case ControlBroadcastSeek:
738         command += " seek" + seek;
739         break;
740     }
741     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
742     vlm_MessageDelete( message );
743 }
744
745 void VLMWrapper::AddVod( const QString& name, const QString& input,
746                          const QString& output,
747                          bool b_enabled, const QString& mux )
748 {
749     vlm_message_t *message;
750     QString command = "new \"" + name + "\" vod";
751     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
752     vlm_MessageDelete( message );
753     EditVod(  name, input, output, b_enabled, mux );
754 }
755
756 void VLMWrapper::EditVod( const QString& name, const QString& input,
757                           const QString& output,
758                           bool b_enabled,
759                           const QString& mux )
760 {
761     vlm_message_t *message;
762     QString command = "setup \"" + name + "\" input \"" + input + "\"";
763     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
764     vlm_MessageDelete( message );
765
766     if( !output.isEmpty() )
767     {
768         command = "setup \"" + name + "\" output \"" + output + "\"";
769         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
770         vlm_MessageDelete( message );
771     }
772
773     if( b_enabled )
774     {
775         command = "setup \"" + name + "\" enabled";
776         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
777         vlm_MessageDelete( message );
778     }
779     if( !mux.isEmpty() )
780     {
781         command = "setup \"" + name + "\" mux \"" + mux + "\"";
782         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
783         vlm_MessageDelete( message );
784     }
785 }
786
787 void VLMWrapper::AddSchedule( const QString& name, const QString& input,
788                               const QString& output, QDateTime _schetime,
789                               QDateTime _schedate,
790                               int _scherepeatnumber, int _repeatDays,
791                               bool b_enabled, const QString& mux )
792 {
793     vlm_message_t *message;
794     QString command = "new \"" + name + "\" schedule";
795     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
796     vlm_MessageDelete( message );
797     EditSchedule(  name, input, output, _schetime, _schedate,
798             _scherepeatnumber, _repeatDays, b_enabled, mux );
799 }
800
801 void VLMWrapper::EditSchedule( const QString& name, const QString& input,
802                                const QString& output, QDateTime _schetime,
803                                QDateTime _schedate, int _scherepeatnumber,
804                                int _repeatDays, bool b_enabled,
805                                const QString& mux )
806 {
807     vlm_message_t *message;
808     QString command = "setup \"" + name + "\" input \"" + input + "\"";
809     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
810     vlm_MessageDelete( message );
811
812     if( !output.isEmpty() )
813     {
814         command = "setup \"" + name + "\" output \"" + output + "\"";
815         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
816         vlm_MessageDelete( message );
817     }
818
819     if( b_enabled )
820     {
821         command = "setup \"" + name + "\" enabled";
822         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
823         vlm_MessageDelete( message );
824     }
825
826     if( !mux.isEmpty() )
827     {
828         command = "setup \"" + name + "\" mux \"" + mux + "\"";
829         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
830         vlm_MessageDelete( message );
831     }
832
833     command = "setup \"" + name + "\" date \"" +
834         _schedate.toString( "yyyy/MM/dd" )+ "-" +
835         _schetime.toString( "hh:mm:ss" ) + "\"";
836     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
837     vlm_MessageDelete( message );
838
839     if( _scherepeatnumber > 0 )
840     {
841        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
842        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
843        vlm_MessageDelete( message );
844     }
845
846     if( _repeatDays > 0 )
847     {
848        command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
849        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
850        vlm_MessageDelete( message );
851     }
852 }
853
854 void VLMDialog::toggleVisible()
855 {
856     QList<VLMAWidget *>::iterator it;
857     for( it = vlmItems.begin(); it != vlmItems.end(); it++ )
858     {
859         VLMAWidget *item =  *it;
860         delete item;
861         item = NULL;
862     }
863     vlmItems.clear();
864     ui.vlmListItem->clear();
865     mediasPopulator();
866     QVLCDialog::toggleVisible();
867 }
868
869
870 #endif