]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
Qt: change dialog size.
[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     //readSettings( "VLM", QSize( 700, 500 ) );
161 }
162
163 VLMDialog::~VLMDialog()
164 {
165     delete vlmWrapper;
166
167     //writeSettings( "VLM" );
168    /* TODO :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_Err( 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 /* TODO : VOD are not exported to the file */
264 bool VLMDialog::exportVLMConf()
265 {
266     QString saveVLMConfFileName = QFileDialog::getSaveFileName(
267             this, qtr( "Save VLM configuration as..." ),
268             qfu( config_GetHomeDir() ),
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( "Open VLM configuration..." ),
338             qfu( config_GetHomeDir() ),
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_Warn( 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, false, 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     ui.vlmListItem->setCurrentRow( currentIndex );
409     ui.nameLedit->setText( vlmObj->name );
410     ui.inputLedit->setText( vlmObj->input );
411     ui.outputLedit->setText( vlmObj->output );
412     ui.enableCheck->setChecked( vlmObj->b_enabled );
413
414     switch( vlmObj->type )
415     {
416     case QVLM_Broadcast:
417         ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
418         break;
419     case QVLM_VOD:
420         ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
421         break;
422     case QVLM_Schedule:
423         time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
424         date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
425         break;
426     }
427
428     ui.nameLedit->setReadOnly( true );
429     ui.addButton->hide();
430     ui.saveButton->show();
431 }
432
433 void VLMDialog::saveModifications()
434 {
435     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
436     if( vlmObj )
437     {
438         vlmObj->input = ui.inputLedit->text();
439         vlmObj->output = ui.outputLedit->text();
440         vlmObj->setChecked( ui.enableCheck->isChecked() );
441         vlmObj->b_enabled = ui.enableCheck->isChecked();
442         switch( vlmObj->type )
443         {
444         case QVLM_Broadcast:
445             (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
446             break;
447         case QVLM_VOD:
448             (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
449             break;
450         case QVLM_Schedule:
451             (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
452             (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
453             (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
454             (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
455             break;
456            //           vlmObj->
457         }
458         vlmObj->update();
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( ":/settings" ) ) );
496     objLayout->addWidget( modifyButton, 0, 5 );
497
498     QToolButton *deleteButton = new QToolButton;
499     deleteButton->setIcon( QIcon( QPixmap( ":/quit" ) ) );
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 void VLMAWidget::toggleEnabled( bool b_enable )
518 {
519     VLMWrapper::EnableItem( name, b_enable );
520 }
521
522 /****************
523  * VLMBroadcast
524  ****************/
525 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
526                             bool _enabled, bool _looped, VLMDialog *_parent)
527                           : VLMAWidget( _name, _input, _output,
528                                         _enabled, _parent, QVLM_Broadcast )
529 {
530     nameLabel->setText( qtr("Broadcast: ") + name );
531     type = QVLM_Broadcast;
532     b_looped = _looped;
533
534     playButton = new QToolButton;
535     playButton->setIcon( QIcon( QPixmap( ":/play" ) ) );
536     objLayout->addWidget( playButton, 1, 0 );
537     b_playing = true;
538
539     QToolButton *stopButton = new QToolButton;
540     stopButton->setIcon( QIcon( QPixmap( ":/stop_b" ) ) );
541     objLayout->addWidget( stopButton, 1, 1 );
542
543     loopButton = new QToolButton;
544     objLayout->addWidget( loopButton, 1, 2 );
545
546     BUTTONACT( playButton, togglePlayPause() );
547     BUTTONACT( stopButton, stop() );
548     BUTTONACT( loopButton, toggleLoop() );
549
550     update();
551 }
552
553 void VLMBroadcast::update()
554 {
555     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
556     if( b_looped )
557         loopButton->setIcon( QIcon( QPixmap( ":/repeat_all" ) ) );
558     else
559         loopButton->setIcon( QIcon( QPixmap( ":/repeat_off" ) ) );
560 }
561
562 void VLMBroadcast::togglePlayPause()
563 {
564     if( b_playing )
565     {
566         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
567         playButton->setIcon( QIcon( QPixmap( ":/pause_16px" ) ) );
568     }
569     else
570     {
571         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
572         playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
573     }
574     b_playing = !b_playing;
575 }
576
577 void VLMBroadcast::toggleLoop()
578 {
579     b_enabled = !b_enabled;
580     update();
581 }
582
583 void VLMBroadcast::stop()
584 {
585     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
586     playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
587 }
588
589 /****************
590  * VLMSchedule
591  ****************/
592 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
593                           QDateTime _schetime, QDateTime _schedate,
594                           int _scherepeatnumber, int _repeatDays,
595                           bool enabled, VLMDialog *parent )
596             : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
597 {
598     nameLabel->setText( qtr("Schedule: ") + name );
599     schetime = _schetime;
600     schedate = _schedate;
601     rNumber = _scherepeatnumber;
602     rDays = _repeatDays;
603     type = QVLM_Schedule;
604     update();
605 }
606
607 void VLMSchedule::update()
608 {
609    VLMWrapper::EditSchedule( name, input, output, schetime, schedate,
610                              rNumber, rDays, b_enabled);
611 }
612
613 /****************
614  * VLMVOD
615  ****************/
616 VLMVod::VLMVod( QString name, QString input, QString output,
617                 bool enabled, QString _mux, VLMDialog *parent)
618        : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
619 {
620     nameLabel->setText( qtr("VOD: ") + name );
621
622     mux = _mux;
623     muxLabel = new QLabel;
624     objLayout->addWidget( muxLabel, 1, 0 );
625
626     update();
627 }
628
629 void VLMVod::update()
630 {
631     muxLabel->setText( mux );
632     VLMWrapper::EditVod( name, input, output, b_enabled, mux );
633 }
634
635
636 /*******************
637  * VLMWrapper
638  *******************/
639 vlm_t * VLMWrapper::p_vlm = NULL;
640
641 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
642 {
643     p_vlm = _p_vlm;
644 }
645
646 VLMWrapper::~VLMWrapper()
647 {
648     p_vlm = NULL;
649 }
650
651 void VLMWrapper::AddBroadcast( const QString name, QString input,
652                                QString output,
653                                bool b_enabled, bool b_loop  )
654 {
655     vlm_message_t *message;
656     QString command = "new \"" + name + "\" broadcast";
657     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
658     vlm_MessageDelete( message );
659     EditBroadcast( name, input, output, b_enabled, b_loop );
660 }
661
662 void VLMWrapper::EditBroadcast( const QString name, const QString input,
663                                 const QString output,
664                                 bool b_enabled, bool b_loop  )
665 {
666     vlm_message_t *message;
667     QString command;
668
669     command = "setup \"" + name + "\" inputdel all";
670     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
671     vlm_MessageDelete( message );
672     command = "setup \"" + name + "\" input \"" + input + "\"";
673     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
674     vlm_MessageDelete( message );
675     if( !output.isEmpty() )
676     {
677         command = "setup \"" + name + "\" output \"" + output + "\"";
678         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
679         vlm_MessageDelete( message );
680     }
681     if( b_enabled )
682     {
683         command = "setup \"" + name + "\" enabled";
684         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
685         vlm_MessageDelete( message );
686     }
687     if( b_loop )
688     {
689         command = "setup \"" + name + "\" loop";
690         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
691         vlm_MessageDelete( message );
692     }
693 }
694
695 void VLMWrapper::EnableItem( const QString name, bool b_enable )
696 {
697     vlm_message_t *message;
698     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
699     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
700     vlm_MessageDelete( message );
701 }
702
703 void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
704                                    unsigned int seek )
705 {
706     vlm_message_t *message;
707
708     QString command = "control \"" + name;
709     switch( BroadcastStatus )
710     {
711     case ControlBroadcastPlay:
712         command += " play";
713         break;
714     case ControlBroadcastPause:
715         command += " pause";
716         break;
717     case ControlBroadcastStop:
718         command += " stop";
719         break;
720     case ControlBroadcastSeek:
721         command += " seek" + seek;
722         break;
723     }
724     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
725     vlm_MessageDelete( message );
726 }
727
728 void VLMWrapper::AddVod( const QString name, const QString input,
729                          const QString output,
730                          bool b_enabled, const QString mux )
731 {
732     vlm_message_t *message;
733     QString command = "new \"" + name + "\" vod";
734     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
735     vlm_MessageDelete( message );
736     EditVod(  name, input, output, b_enabled, mux );
737 }
738
739 void VLMWrapper::EditVod( const QString name, const QString input,
740                           const QString output,
741                           bool b_enabled,
742                           const QString mux )
743 {
744     vlm_message_t *message;
745     QString command = "setup \"" + name + "\" input \"" + input + "\"";
746     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
747     vlm_MessageDelete( message );
748
749     if( !output.isEmpty() )
750     {
751         command = "setup \"" + name + "\" output \"" + output + "\"";
752         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
753         vlm_MessageDelete( message );
754     }
755
756     if( b_enabled )
757     {
758         command = "setup \"" + name + "\" enabled";
759         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
760         vlm_MessageDelete( message );
761     }
762     if( !mux.isEmpty() )
763     {
764         command = "setup \"" + name + "\" mux \"" + mux + "\"";
765         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
766         vlm_MessageDelete( message );
767     }
768 }
769
770 void VLMWrapper::AddSchedule( const QString name, const QString input,
771                               const QString output, QDateTime _schetime,
772                               QDateTime _schedate,
773                               int _scherepeatnumber, int _repeatDays,
774                               bool b_enabled, const QString mux )
775 {
776     vlm_message_t *message;
777     QString command = "new \"" + name + "\" schedule";
778     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
779     vlm_MessageDelete( message );
780     EditSchedule(  name, input, output, _schetime, _schedate,
781             _scherepeatnumber, _repeatDays, b_enabled, mux );
782 }
783
784 void VLMWrapper::EditSchedule( const QString name, const QString input,
785                           const QString output, QDateTime _schetime,
786                           QDateTime _schedate, int _scherepeatnumber,
787                           int _repeatDays, bool b_enabled,
788                           const QString mux )
789 {
790     vlm_message_t *message;
791     QString command = "setup \"" + name + "\" input \"" + input + "\"";
792     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
793     vlm_MessageDelete( message );
794
795     if( !output.isEmpty() )
796     {
797         command = "setup \"" + name + "\" output \"" + output + "\"";
798         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
799         vlm_MessageDelete( message );
800     }
801
802     if( b_enabled )
803     {
804         command = "setup \"" + name + "\" enabled";
805         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
806         vlm_MessageDelete( message );
807     }
808
809     if( !mux.isEmpty() )
810     {
811         command = "setup \"" + name + "\" mux \"" + mux + "\"";
812         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
813         vlm_MessageDelete( message );
814     }
815
816     command = "setup \"" + name + "\" date \"" +
817         _schedate.toString( "yyyy/MM/dd" )+ "-" +
818         _schetime.toString( "hh:mm:ss" ) + "\"";
819     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
820     vlm_MessageDelete( message );
821
822     if( _scherepeatnumber > 0 )
823     {
824        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
825        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
826        vlm_MessageDelete( message );
827     }
828
829     if( _repeatDays > 0 )
830     {
831        command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
832        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
833        vlm_MessageDelete( message );
834     }
835 }
836
837
838 #endif