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