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