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