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