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