]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
Added import of configuration file support
[vlc] / 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 static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
57
58 VLMDialog *VLMDialog::instance = NULL;
59
60 VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
61 {
62     p_vlm = vlm_New( p_intf );
63
64     if( !p_vlm )
65     {
66         msg_Warn( p_intf, "Couldn't build VLM object ");
67         return;
68     }
69     vlmWrapper = new VLMWrapper( p_vlm );
70
71     // UI stuff
72     ui.setupUi( this );
73     ui.saveButton->hide();
74
75 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
76     ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
77     ADDMEDIATYPES( "Schedule", QVLM_Schedule );
78     ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
79 #undef ADDMEDIATYPES
80
81     /* Schedule Stuffs */
82     QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
83     QLabel *schetimelabel = new QLabel( qtr( "Hours/Minutes/Seconds:" ) );
84     schetimelayout->addWidget( schetimelabel, 0, 0 );
85     QLabel *schedatelabel = new QLabel( qtr( "Day Month Year:" ) );
86     schetimelayout->addWidget( schedatelabel, 1, 0 );
87     QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
88     schetimelayout->addWidget( scherepeatLabel, 2, 0 );
89     QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
90     schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
91
92     time = new QDateTimeEdit( QTime::currentTime() );
93     time->setAlignment( Qt::AlignRight );
94     time->setDisplayFormat( "hh:mm:ss" );
95     schetimelayout->addWidget( time, 0, 1, 1, 3 );
96
97     date = new QDateTimeEdit( QDate::currentDate() );
98     date->setAlignment( Qt::AlignRight );
99     date->setCalendarPopup( true );
100 #ifdef WIN32
101     date->setDisplayFormat( "dd MM yyyy" );
102 #else
103     date->setDisplayFormat( "dd MMMM yyyy" );
104 #endif
105     schetimelayout->addWidget( date, 1, 1, 1, 3 );
106
107     scherepeatnumber = new QSpinBox;
108     scherepeatnumber->setAlignment( Qt::AlignRight );
109     schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
110
111     repeatDays = new QSpinBox;
112     repeatDays->setAlignment( Qt::AlignRight );
113     schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
114     repeatDays->setSuffix( qtr(" days") );
115
116     repeatTime = new QDateTimeEdit;
117     repeatTime->setAlignment( Qt::AlignRight );
118     schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
119     repeatTime->setDisplayFormat( "hh:mm:ss" );
120
121     /* scrollArea */
122     ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
123     ui.vlmItemScroll->setWidgetResizable( true );
124     vlmItemWidget = new QWidget;
125     vlmItemLayout = new QVBoxLayout( vlmItemWidget );
126     vlmItemWidget->setLayout( vlmItemLayout );
127     ui.vlmItemScroll->setWidget( vlmItemWidget );
128
129     QSpacerItem *spacer =
130         new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
131     vlmItemLayout->addItem( spacer );
132
133     QPushButton *importButton = new QPushButton( qtr(  "Import" ) );
134     ui.buttonBox->addButton( importButton, QDialogButtonBox::ActionRole );
135
136     QPushButton *exportButton = new QPushButton( qtr( "Export" ) );
137     ui.buttonBox->addButton( exportButton, QDialogButtonBox::ActionRole );
138
139     QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
140     ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
141
142
143     showScheduleWidget( QVLM_Broadcast );
144
145     /* Connect the comboBox to show the right Widgets */
146     CONNECT( ui.mediaType, currentIndexChanged( int ),
147              this, showScheduleWidget( int ) );
148
149     /* Connect the leftList to show the good VLMItem */
150     CONNECT( ui.vlmListItem, currentRowChanged( int ),
151              this, selectVLMItem( int ) );
152
153     BUTTONACT( closeButton, close() );
154     BUTTONACT( exportButton, exportVLMConf() );
155     BUTTONACT( importButton, importVLMConf() );
156     BUTTONACT( ui.addButton, addVLMItem() );
157     BUTTONACT( ui.clearButton, clearWidgets() );
158     BUTTONACT( ui.saveButton, saveModifications() );
159     BUTTONACT( ui.inputButton, selectInput() );
160     BUTTONACT( ui.outputButton, selectOutput() );
161 }
162
163 VLMDialog::~VLMDialog()
164 {
165    /* FIXME :you have to destroy vlm here to close
166     * but we shouldn't destroy vlm here in case somebody else wants it */
167     if( p_vlm )
168         vlm_Delete( p_vlm );
169 }
170
171 void VLMDialog::showScheduleWidget( int i )
172 {
173     ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
174     ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
175     ui.vodBox->setVisible( ( i == QVLM_VOD ) );
176 }
177
178 void VLMDialog::selectVLMItem( int i )
179 {
180     if( i >= 0 )
181         ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
182 }
183
184 bool VLMDialog::isNameGenuine( QString name )
185 {
186     for( int i = 0; i < vlmItems.size(); i++ )
187     {
188         if( vlmItems.at( i )->name == name )
189             return false;
190     }
191     return true;
192 }
193
194 void VLMDialog::addVLMItem()
195 {
196     int vlmItemCount = vlmItems.size();
197
198     /* Take the name and Check it */
199     QString name = ui.nameLedit->text();
200     if( name.isEmpty() || !isNameGenuine( name ) )
201     {
202         msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
203         return;
204     }
205
206     int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
207
208     QString typeShortName;
209     QString inputText = ui.inputLedit->text();
210     QString outputText = ui.outputLedit->text();
211     bool b_checked = ui.enableCheck->isChecked();
212     bool b_looped = ui.loopBCast->isChecked();
213     QDateTime schetime = time->dateTime();
214     QDateTime schedate = date->dateTime();
215     int repeatnum = scherepeatnumber->value();
216     int repeatdays = repeatDays->value();
217     VLMAWidget * vlmAwidget;
218
219     switch( type )
220     {
221     case QVLM_Broadcast:
222         typeShortName = "Bcast";
223         vlmAwidget = new VLMBroadcast( name, inputText, outputText,
224                                        b_checked, b_looped, this );
225         VLMWrapper::AddBroadcast( name, inputText, outputText, b_checked,
226                                   b_looped );
227     break;
228     case QVLM_VOD:
229         typeShortName = "VOD";
230         vlmAwidget = new VLMVod( name, inputText, outputText,
231                                  b_checked, ui.muxLedit->text(), this );
232         VLMWrapper::AddVod( name, inputText, outputText, b_checked );
233         break;
234     case QVLM_Schedule:
235         typeShortName = "Sched";
236         vlmAwidget = new VLMSchedule( name, inputText, outputText,
237                                       schetime, schedate, repeatnum,
238                                       repeatdays, b_checked, this );
239         VLMWrapper::AddSchedule( name, inputText, outputText, schetime,
240                                  schedate, repeatnum, repeatdays, b_checked);
241         break;
242     default:
243         msg_Warn( p_intf, "Something bad happened" );
244         return;
245     }
246
247     /* Add an Item of the Side List */
248     ui.vlmListItem->addItem( typeShortName + " : " + name );
249     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
250
251     /* Add a new VLMAWidget on the main List */
252
253     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
254     vlmItems.append( vlmAwidget );
255     clearWidgets();
256 }
257
258 // FIXME : VOD are not exported to the file
259 bool VLMDialog::exportVLMConf()
260 {
261     QString saveVLMConfFileName = QFileDialog::getSaveFileName(
262             this, qtr( "Choose a filename to save the VLM configuration..." ),
263             qfu( p_intf->p_libvlc->psz_homedir ),
264             qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
265
266     if( !saveVLMConfFileName.isEmpty() )
267     {
268         vlm_message_t *message;
269         QString command = "save \"" + saveVLMConfFileName + "\"";
270         vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
271         vlm_MessageDelete( message );
272         return true;
273     }
274     return false;
275 }
276
277
278 bool VLMDialog::importVLMConf()
279 {
280     QString openVLMConfFileName = QFileDialog::getOpenFileName(
281             this, qtr( "Choose a VLM configuration file to open..." ),
282             qfu( p_intf->p_libvlc->psz_homedir ),
283             qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );
284
285     if( !openVLMConfFileName.isEmpty() )
286     {
287         vlm_message_t *message;
288         QString command = "load \"" + openVLMConfFileName + "\"";
289         vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
290         vlm_MessageDelete( message );
291         return true;
292     }
293     return false;
294 }
295
296 void VLMDialog::clearWidgets()
297 {
298     ui.nameLedit->clear();
299     ui.inputLedit->clear();
300     ui.outputLedit->clear();
301     time->setTime( QTime::currentTime() );
302     date->setDate( QDate::currentDate() );
303     ui.enableCheck->setChecked( true );
304     ui.nameLedit->setReadOnly( false );
305     ui.loopBCast->setChecked( false );
306     ui.muxLedit->clear();
307     ui.saveButton->hide();
308     ui.addButton->show();
309 }
310
311 void VLMDialog::selectInput()
312 {
313     OpenDialog *o = OpenDialog::getInstance( this, p_intf, SELECT, true );
314     o->exec();
315     ui.inputLedit->setText( o->getMRL() );
316 }
317
318 void VLMDialog::selectOutput()
319 {
320     SoutDialog *s = SoutDialog::getInstance( this, p_intf, false );
321     if( s->exec() == QDialog::Accepted )
322         ui.outputLedit->setText( s->getMrl() );
323 }
324
325 /* Object Modification */
326 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
327 {
328     int index = vlmItems.indexOf( vlmObj );
329     if( index < 0 ) return;
330     delete ui.vlmListItem->takeItem( index );
331     vlmItems.removeAt( index );
332     delete vlmObj;
333
334     /* HERE BE DRAGONS VLM REQUEST */
335 }
336
337 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
338 {
339     currentIndex = vlmItems.indexOf( vlmObj );
340     if( currentIndex < 0 ) return;
341
342     msg_Dbg( p_intf, "Type: %i", vlmObj->type );
343     ui.vlmListItem->setCurrentRow( currentIndex );
344     ui.nameLedit->setText( vlmObj->name );
345     ui.inputLedit->setText( vlmObj->input );
346     ui.outputLedit->setText( vlmObj->output );
347     ui.enableCheck->setChecked( vlmObj->b_enabled );
348
349     switch( vlmObj->type )
350     {
351     case QVLM_Broadcast:
352         ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
353         break;
354     case QVLM_VOD:
355         ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
356         break;
357     case QVLM_Schedule:
358         time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
359         date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
360         break;
361     }
362
363     ui.nameLedit->setReadOnly( true );
364     ui.addButton->hide();
365     ui.saveButton->show();
366 }
367
368 void VLMDialog::saveModifications()
369 {
370     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
371     if( vlmObj )
372     {
373         vlmObj->input = ui.inputLedit->text();
374         vlmObj->output = ui.outputLedit->text();
375         vlmObj->setChecked( ui.enableCheck->isChecked() );
376         vlmObj->b_enabled = ui.enableCheck->isChecked();
377         switch( vlmObj->type )
378         {
379         case QVLM_Broadcast:
380             (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
381             break;
382         case QVLM_VOD:
383             (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
384             break;
385         case QVLM_Schedule:
386             (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
387             (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
388             (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
389             (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
390             break;
391            //           vlmObj->
392         }
393         vlmObj->update(); /* It should call the correct function is VLMAWidget
394                              is abstract, but I am far from sure... FIXME ? */
395     }
396     clearWidgets();
397 }
398
399 /*********************************
400  * VLMAWidget - Abstract class
401  ********************************/
402
403 VLMAWidget::VLMAWidget( QString _name,
404                         QString _input,
405                         QString _output,
406                         bool _enabled,
407                         VLMDialog *_parent,
408                         int _type )
409                       : QGroupBox( _name, _parent )
410 {
411     parent = _parent;
412     name = _name;
413     input = _input;
414     output = _output;
415     b_enabled = _enabled;
416     type = _type;
417
418     setCheckable( true );
419     setChecked( b_enabled );
420
421     objLayout = new QGridLayout( this );
422     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
423
424     nameLabel = new QLabel;
425     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
426
427     /*QLabel *time = new QLabel( "--:--/--:--" );
428     objLayout->addWidget( time, 1, 3, 1, 2 );*/
429
430     QToolButton *modifyButton = new QToolButton;
431     modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
432     objLayout->addWidget( modifyButton, 0, 5 );
433
434     QToolButton *deleteButton = new QToolButton;
435     deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
436     objLayout->addWidget( deleteButton, 0, 6 );
437
438     BUTTONACT( modifyButton, modify() );
439     BUTTONACT( deleteButton, del() );
440     CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
441 }
442
443 void VLMAWidget::modify()
444 {
445     parent->startModifyVLMItem( this );
446 }
447
448 void VLMAWidget::del()
449 {
450     parent->removeVLMItem( this );
451 }
452
453 //FIXME, remove me before release
454 void VLMAWidget::enterEvent( QEvent *event )
455 {
456     printf( "test" );
457 }
458
459 void VLMAWidget::toggleEnabled( bool b_enable )
460 {
461     VLMWrapper::EnableItem( name, b_enable );
462 }
463
464 /****************
465  * VLMBroadcast
466  ****************/
467 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
468                             bool _enabled, bool _looped, VLMDialog *_parent)
469                           : VLMAWidget( _name, _input, _output,
470                                         _enabled, _parent, QVLM_Broadcast )
471 {
472     nameLabel->setText( "Broadcast: " + name );
473     type = QVLM_Broadcast;
474     b_looped = _looped;
475
476     playButton = new QToolButton;
477     playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
478     objLayout->addWidget( playButton, 1, 0 );
479     b_playing = true;
480
481     QToolButton *stopButton = new QToolButton;
482     stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
483     objLayout->addWidget( stopButton, 1, 1 );
484
485     loopButton = new QToolButton;
486     objLayout->addWidget( loopButton, 1, 2 );
487
488     BUTTONACT( playButton, togglePlayPause() );
489     BUTTONACT( stopButton, stop() );
490     BUTTONACT( loopButton, toggleLoop() );
491
492     update();
493 }
494
495 void VLMBroadcast::update()
496 {
497     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
498     if( b_looped )
499         loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_all.png" ) ) );
500     else
501         loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
502 }
503
504 void VLMBroadcast::togglePlayPause()
505 {
506     if( b_playing = true )
507     {
508         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
509         playButton->setIcon( QIcon( QPixmap( ":/pixmaps/pause_16px.png" ) ) );
510     }
511     else
512     {
513         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
514         playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
515     }
516     b_playing = !b_playing;
517 }
518
519 void VLMBroadcast::toggleLoop()
520 {
521     b_enabled = !b_enabled;
522     update();
523 }
524
525 void VLMBroadcast::stop()
526 {
527     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
528     playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
529 }
530
531 /****************
532  * VLMSchedule
533  ****************/
534 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
535                           QDateTime _schetime, QDateTime _schedate,
536                           int _scherepeatnumber, int _repeatDays,
537                           bool enabled, VLMDialog *parent )
538             : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
539 {
540     nameLabel->setText( "Schedule: " + name );
541     schetime = _schetime;
542     schedate = _schedate;
543     rNumber = _scherepeatnumber;
544     rDays = _repeatDays;
545     type = QVLM_Schedule;
546     update();
547 }
548
549 void VLMSchedule::update()
550 {
551    VLMWrapper::EditSchedule( name, input, output, schetime, schedate,
552                              rNumber, rDays, b_enabled);
553 }
554
555 /****************
556  * VLMVOD
557  ****************/
558 VLMVod::VLMVod( QString name, QString input, QString output,
559                 bool enabled, QString _mux, VLMDialog *parent)
560        : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
561 {
562     nameLabel->setText( "VOD:" + name );
563
564     mux = _mux;
565     muxLabel = new QLabel;
566     objLayout->addWidget( muxLabel, 1, 0 );
567
568     update();
569 }
570
571 void VLMVod::update()
572 {
573     muxLabel->setText( mux );
574     VLMWrapper::EditVod( name, input, output, b_enabled, mux );
575 }
576
577
578 /*******************
579  * VLMWrapper
580  *******************/
581 vlm_t * VLMWrapper::p_vlm = NULL;
582
583 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
584 {
585     p_vlm = _p_vlm;
586 }
587
588 VLMWrapper::~VLMWrapper()
589 {}
590
591 void VLMWrapper::AddBroadcast( const QString name, QString input,
592                                QString output,
593                                bool b_enabled, bool b_loop  )
594 {
595     vlm_message_t *message;
596     QString command = "new \"" + name + "\" broadcast";
597     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
598     vlm_MessageDelete( message );
599     EditBroadcast( name, input, output, b_enabled, b_loop );
600 }
601
602 void VLMWrapper::EditBroadcast( const QString name, const QString input,
603                                 const QString output,
604                                 bool b_enabled, bool b_loop  )
605 {
606     vlm_message_t *message;
607     QString command;
608
609     command = "setup \"" + name + "\" inputdel all";
610     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
611     vlm_MessageDelete( message );
612     command = "setup \"" + name + "\" input \"" + input + "\"";
613     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
614     vlm_MessageDelete( message );
615     if( !output.isEmpty() )
616     {
617         command = "setup \"" + name + "\" output \"" + output + "\"";
618         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
619         vlm_MessageDelete( message );
620     }
621     if( b_enabled )
622     {
623         command = "setup \"" + name + "\" enabled";
624         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
625         vlm_MessageDelete( message );
626     }
627     if( b_loop )
628     {
629         command = "setup \"" + name + "\" loop";
630         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
631         vlm_MessageDelete( message );
632     }
633 }
634
635 void VLMWrapper::EnableItem( const QString name, bool b_enable )
636 {
637     vlm_message_t *message;
638     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
639 }
640
641 void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
642                                    unsigned int seek )
643 {
644     vlm_message_t *message;
645
646     QString command = "control \"" + name;
647     switch( BroadcastStatus )
648     {
649     case ControlBroadcastPlay:
650         command += " play";
651         break;
652     case ControlBroadcastPause:
653         command += " pause";
654         break;
655     case ControlBroadcastStop:
656         command += " stop";
657         break;
658     case ControlBroadcastSeek:
659         command += " seek" + seek;
660         break;
661     }
662     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
663     vlm_MessageDelete( message );
664 }
665
666 void VLMWrapper::AddVod( const QString name, const QString input,
667                          const QString output,
668                          bool b_enabled, const QString mux )
669 {
670     vlm_message_t *message;
671     QString command = "new \"" + name + "\" vod";
672     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
673     vlm_MessageDelete( message );
674     EditVod(  name, input, output, b_enabled, mux );
675 }
676
677 void VLMWrapper::EditVod( const QString name, const QString input,
678                           const QString output,
679                           bool b_enabled,
680                           const QString mux )
681 {
682     vlm_message_t *message;
683     QString command = "setup \"" + name + "\" input \"" + input + "\"";
684     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
685     vlm_MessageDelete( message );
686     if( !output.isEmpty() )
687     {
688         command = "setup \"" + name + "\" output \"" + output + "\"";
689         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
690         vlm_MessageDelete( message );
691     }
692     if( b_enabled )
693     {
694         command = "setup \"" + name + "\" enabled";
695         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
696         vlm_MessageDelete( message );
697     }
698     if( !mux.isEmpty() )
699     {
700         command = "setup \"" + name + "\" mux \"" + mux + "\"";
701         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
702         vlm_MessageDelete( message );
703     }
704 }
705
706 void VLMWrapper::AddSchedule( const QString name, const QString input,
707                               const QString output, QDateTime _schetime,
708                               QDateTime _schedate,
709                               int _scherepeatnumber, int _repeatDays,
710                               bool b_enabled, const QString mux )
711 {
712     vlm_message_t *message;
713     QString command = "new \"" + name + "\" schedule";
714     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
715     vlm_MessageDelete( message );
716     EditSchedule(  name, input, output, _schetime, _schedate,
717             _scherepeatnumber, _repeatDays, b_enabled, mux );
718 }
719
720 void VLMWrapper::EditSchedule( const QString name, const QString input,
721                           const QString output, QDateTime _schetime,
722                           QDateTime _schedate, int _scherepeatnumber,
723                           int _repeatDays, bool b_enabled,
724                           const QString mux )
725 {
726     vlm_message_t *message;
727     QString command = "setup \"" + name + "\" input \"" + input + "\"";
728     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
729     vlm_MessageDelete( message );
730
731     if( !output.isEmpty() )
732     {
733         command = "setup \"" + name + "\" output \"" + output + "\"";
734         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
735         vlm_MessageDelete( message );
736     }
737
738     if( b_enabled )
739     {
740         command = "setup \"" + name + "\" enabled";
741         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
742         vlm_MessageDelete( message );
743     }
744
745     if( !mux.isEmpty() )
746     {
747         command = "setup \"" + name + "\" mux \"" + mux + "\"";
748         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
749         vlm_MessageDelete( message );
750     }
751
752     command = "setup \"" + name + "\" date \"" +
753         _schedate.toString( "yyyy/MM/dd" )+ "-" +
754         _schetime.toString( "hh:mm:ss" ) + "\"";
755     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
756     vlm_MessageDelete( message );
757     if( _scherepeatnumber > 0 )
758     {
759        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
760        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
761        vlm_MessageDelete( message );
762     }
763 }
764
765
766 #endif