Overload toggleVisible() to update list with media from other interfaces.
[vlc.git] / 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     outputText.remove( ":sout=" );
224
225     switch( type )
226     {
227     case QVLM_Broadcast:
228         typeShortName = "Bcast";
229         vlmAwidget = new VLMBroadcast( name, inputText, outputText,
230                                        b_checked, b_looped, this );
231         VLMWrapper::AddBroadcast( name, inputText, outputText, b_checked,
232                                   b_looped );
233     break;
234     case QVLM_VOD:
235         typeShortName = "VOD";
236         vlmAwidget = new VLMVod( name, inputText, outputText,
237                                  b_checked, ui.muxLedit->text(), this );
238         VLMWrapper::AddVod( name, inputText, outputText, b_checked );
239         break;
240     case QVLM_Schedule:
241         typeShortName = "Sched";
242         vlmAwidget = new VLMSchedule( name, inputText, outputText,
243                                       schetime, schedate, repeatnum,
244                                       repeatdays, b_checked, this );
245         VLMWrapper::AddSchedule( name, inputText, outputText, schetime,
246                                  schedate, repeatnum, repeatdays, b_checked);
247         break;
248     default:
249         msg_Warn( p_intf, "Something bad happened" );
250         return;
251     }
252
253     /* Add an Item of the Side List */
254     ui.vlmListItem->addItem( typeShortName + " : " + name );
255     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
256
257     /* Add a new VLMAWidget on the main List */
258
259     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
260     vlmItems.append( vlmAwidget );
261     clearWidgets();
262 }
263
264 /* TODO : VOD are not exported to the file */
265 bool VLMDialog::exportVLMConf()
266 {
267     QString saveVLMConfFileName = QFileDialog::getSaveFileName(
268             this, qtr( "Save VLM configuration as..." ),
269             qfu( config_GetHomeDir() ),
270             qtr( "VLM conf (*.vlm);;All (*)" ) );
271
272     if( !saveVLMConfFileName.isEmpty() )
273     {
274         vlm_message_t *message;
275         QString command = "save \"" + saveVLMConfFileName + "\"";
276         vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
277         vlm_MessageDelete( message );
278         return true;
279     }
280     return false;
281 }
282
283 void VLMDialog::mediasPopulator()
284 {
285     if( p_vlm )
286     {
287         int i_nMedias;
288         QString typeShortName;
289         int vlmItemCount;
290         vlm_media_t ***ppp_dsc = (vlm_media_t ***)malloc( sizeof( vlm_media_t ) );
291
292         /* Get medias informations and numbers */
293         vlm_Control( p_vlm, VLM_GET_MEDIAS, ppp_dsc, &i_nMedias );
294
295         /* Loop on all of them */
296         for( int i = 0; i < i_nMedias; i++ )
297         {
298             VLMAWidget * vlmAwidget;
299             vlmItemCount = vlmItems.size();
300
301             QString mediaName = qfu( (*ppp_dsc)[i]->psz_name );
302             /* It may have several inputs, we take the first one by default
303                  - an evolution will be to manage these inputs in the gui */
304             QString inputText = qfu( (*ppp_dsc)[i]->ppsz_input[0] );
305
306             QString outputText = qfu( (*ppp_dsc)[i]->psz_output );
307
308             /* Schedule media is a quite especial, maybe there is another way to grab informations */
309             if( (*ppp_dsc)[i]->b_vod )
310             {
311                 typeShortName = "VOD";
312                 QString mux = qfu( (*ppp_dsc)[i]->vod.psz_mux );
313                 vlmAwidget = new VLMVod( mediaName, inputText, outputText,
314                                     (*ppp_dsc)[i]->b_enabled, mux, this );
315             }
316             else
317             {
318                 typeShortName = "Bcast";
319                 vlmAwidget = new VLMBroadcast( mediaName, inputText, outputText,
320                                   (*ppp_dsc)[i]->b_enabled, (*ppp_dsc)[i]->broadcast.b_loop, this );
321             }
322             /* Add an Item of the Side List */
323             ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
324             ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
325
326             /* Add a new VLMAWidget on the main List */
327             vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
328             vlmItems.append( vlmAwidget );
329             clearWidgets();
330         }
331         free( ppp_dsc );
332     }
333 }
334
335 bool VLMDialog::importVLMConf()
336 {
337     QString openVLMConfFileName = QFileDialog::getOpenFileName(
338             this, qtr( "Open VLM configuration..." ),
339             qfu( config_GetHomeDir() ),
340             qtr( "VLM conf (*.vlm);;All (*)" ) );
341
342     if( !openVLMConfFileName.isEmpty() )
343     {
344         vlm_message_t *message;
345         int status;
346         QString command = "load \"" + openVLMConfFileName + "\"";
347         status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
348         vlm_MessageDelete( message );
349         if( status == 0 )
350         {
351             mediasPopulator();
352         }
353         else
354         {
355             msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
356             return false;
357         }
358         return true;
359     }
360     return false;
361 }
362
363 void VLMDialog::clearWidgets()
364 {
365     ui.nameLedit->clear();
366     ui.inputLedit->clear();
367     ui.outputLedit->clear();
368     time->setTime( QTime::currentTime() );
369     date->setDate( QDate::currentDate() );
370     ui.enableCheck->setChecked( true );
371     ui.nameLedit->setReadOnly( false );
372     ui.loopBCast->setChecked( false );
373     ui.muxLedit->clear();
374     ui.saveButton->hide();
375     ui.addButton->show();
376 }
377
378 void VLMDialog::selectInput()
379 {
380     OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
381     o->exec();
382     ui.inputLedit->setText( o->getMRL() );
383 }
384
385 void VLMDialog::selectOutput()
386 {
387     SoutDialog *s = SoutDialog::getInstance( this, p_intf, false );
388     if( s->exec() == QDialog::Accepted )
389         ui.outputLedit->setText( s->getMrl() );
390 }
391
392 /* Object Modification */
393 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
394 {
395     int index = vlmItems.indexOf( vlmObj );
396     if( index < 0 ) return;
397     delete ui.vlmListItem->takeItem( index );
398     vlmItems.removeAt( index );
399     delete vlmObj;
400
401     /* HERE BE DRAGONS VLM REQUEST */
402 }
403
404 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
405 {
406     currentIndex = vlmItems.indexOf( vlmObj );
407     if( currentIndex < 0 ) return;
408
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().remove( ":sout=" );
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();
460     }
461     clearWidgets();
462 }
463
464 /*********************************
465  * VLMAWidget - Abstract class
466  ********************************/
467
468 VLMAWidget::VLMAWidget( QString _name,
469                         QString _input,
470                         QString _output,
471                         bool _enabled,
472                         VLMDialog *_parent,
473                         int _type )
474                       : QGroupBox( _name, _parent )
475 {
476     parent = _parent;
477     name = _name;
478     input = _input;
479     output = _output;
480     b_enabled = _enabled;
481     type = _type;
482
483     setCheckable( true );
484     setChecked( b_enabled );
485
486     objLayout = new QGridLayout( this );
487     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
488
489     nameLabel = new QLabel;
490     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
491
492     /*QLabel *time = new QLabel( "--:--/--:--" );
493     objLayout->addWidget( time, 1, 3, 1, 2 );*/
494
495     QToolButton *modifyButton = new QToolButton;
496     modifyButton->setIcon( QIcon( QPixmap( ":/settings" ) ) );
497     objLayout->addWidget( modifyButton, 0, 5 );
498
499     QToolButton *deleteButton = new QToolButton;
500     deleteButton->setIcon( QIcon( QPixmap( ":/quit" ) ) );
501     objLayout->addWidget( deleteButton, 0, 6 );
502
503     BUTTONACT( modifyButton, modify() );
504     BUTTONACT( deleteButton, del() );
505     CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
506 }
507
508 void VLMAWidget::modify()
509 {
510     parent->startModifyVLMItem( this );
511 }
512
513 void VLMAWidget::del()
514 {
515     parent->removeVLMItem( this );
516 }
517
518 void VLMAWidget::toggleEnabled( bool b_enable )
519 {
520     VLMWrapper::EnableItem( name, b_enable );
521 }
522
523 /****************
524  * VLMBroadcast
525  ****************/
526 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
527                             bool _enabled, bool _looped, VLMDialog *_parent)
528                           : VLMAWidget( _name, _input, _output,
529                                         _enabled, _parent, QVLM_Broadcast )
530 {
531     nameLabel->setText( qtr("Broadcast: ") + name );
532     type = QVLM_Broadcast;
533     b_looped = _looped;
534
535     playButton = new QToolButton;
536     playButton->setIcon( QIcon( QPixmap( ":/play" ) ) );
537     objLayout->addWidget( playButton, 1, 0 );
538     b_playing = true;
539
540     QToolButton *stopButton = new QToolButton;
541     stopButton->setIcon( QIcon( QPixmap( ":/stop_b" ) ) );
542     objLayout->addWidget( stopButton, 1, 1 );
543
544     loopButton = new QToolButton;
545     objLayout->addWidget( loopButton, 1, 2 );
546
547     BUTTONACT( playButton, togglePlayPause() );
548     BUTTONACT( stopButton, stop() );
549     BUTTONACT( loopButton, toggleLoop() );
550
551     update();
552 }
553
554 void VLMBroadcast::update()
555 {
556     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
557     if( b_looped )
558         loopButton->setIcon( QIcon( QPixmap( ":/repeat_all" ) ) );
559     else
560         loopButton->setIcon( QIcon( QPixmap( ":/repeat_off" ) ) );
561 }
562
563 void VLMBroadcast::togglePlayPause()
564 {
565     if( b_playing )
566     {
567         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
568         playButton->setIcon( QIcon( QPixmap( ":/pause_16px" ) ) );
569     }
570     else
571     {
572         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
573         playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
574     }
575     b_playing = !b_playing;
576 }
577
578 void VLMBroadcast::toggleLoop()
579 {
580     b_enabled = !b_enabled;
581     update();
582 }
583
584 void VLMBroadcast::stop()
585 {
586     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
587     playButton->setIcon( QIcon( QPixmap( ":/play_16px" ) ) );
588 }
589
590 /****************
591  * VLMSchedule
592  ****************/
593 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
594                           QDateTime _schetime, QDateTime _schedate,
595                           int _scherepeatnumber, int _repeatDays,
596                           bool enabled, VLMDialog *parent )
597             : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
598 {
599     nameLabel->setText( qtr("Schedule: ") + name );
600     schetime = _schetime;
601     schedate = _schedate;
602     rNumber = _scherepeatnumber;
603     rDays = _repeatDays;
604     type = QVLM_Schedule;
605     update();
606 }
607
608 void VLMSchedule::update()
609 {
610    VLMWrapper::EditSchedule( name, input, output, schetime, schedate,
611                              rNumber, rDays, b_enabled);
612 }
613
614 /****************
615  * VLMVOD
616  ****************/
617 VLMVod::VLMVod( QString name, QString input, QString output,
618                 bool enabled, QString _mux, VLMDialog *parent)
619        : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
620 {
621     nameLabel->setText( qtr("VOD: ") + name );
622
623     mux = _mux;
624     muxLabel = new QLabel;
625     objLayout->addWidget( muxLabel, 1, 0 );
626
627     update();
628 }
629
630 void VLMVod::update()
631 {
632     muxLabel->setText( mux );
633     VLMWrapper::EditVod( name, input, output, b_enabled, mux );
634 }
635
636
637 /*******************
638  * VLMWrapper
639  *******************/
640 vlm_t * VLMWrapper::p_vlm = NULL;
641
642 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
643 {
644     p_vlm = _p_vlm;
645 }
646
647 VLMWrapper::~VLMWrapper()
648 {
649     p_vlm = NULL;
650 }
651
652 void VLMWrapper::AddBroadcast( const QString name, QString input,
653                                QString output,
654                                bool b_enabled, bool b_loop  )
655 {
656     vlm_message_t *message;
657     QString command = "new \"" + name + "\" broadcast";
658     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
659     vlm_MessageDelete( message );
660     EditBroadcast( name, input, output, b_enabled, b_loop );
661 }
662
663 void VLMWrapper::EditBroadcast( const QString name, const QString input,
664                                 const QString output,
665                                 bool b_enabled, bool b_loop  )
666 {
667     vlm_message_t *message;
668     QString command;
669
670     command = "setup \"" + name + "\" inputdel all";
671     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
672     vlm_MessageDelete( message );
673     command = "setup \"" + name + "\" input \"" + input + "\"";
674     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
675     vlm_MessageDelete( message );
676     if( !output.isEmpty() )
677     {
678         command = "setup \"" + name + "\" output \"" + output + "\"";
679         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
680         vlm_MessageDelete( message );
681     }
682     if( b_enabled )
683     {
684         command = "setup \"" + name + "\" enabled";
685         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
686         vlm_MessageDelete( message );
687     }
688     if( b_loop )
689     {
690         command = "setup \"" + name + "\" loop";
691         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
692         vlm_MessageDelete( message );
693     }
694 }
695
696 void VLMWrapper::EnableItem( const QString name, bool b_enable )
697 {
698     vlm_message_t *message;
699     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
700     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
701     vlm_MessageDelete( message );
702 }
703
704 void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
705                                    unsigned int seek )
706 {
707     vlm_message_t *message;
708
709     QString command = "control \"" + name + "\"";
710     switch( BroadcastStatus )
711     {
712     case ControlBroadcastPlay:
713         command += " play";
714         break;
715     case ControlBroadcastPause:
716         command += " pause";
717         break;
718     case ControlBroadcastStop:
719         command += " stop";
720         break;
721     case ControlBroadcastSeek:
722         command += " seek" + seek;
723         break;
724     }
725     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
726     vlm_MessageDelete( message );
727 }
728
729 void VLMWrapper::AddVod( const QString name, const QString input,
730                          const QString output,
731                          bool b_enabled, const QString mux )
732 {
733     vlm_message_t *message;
734     QString command = "new \"" + name + "\" vod";
735     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
736     vlm_MessageDelete( message );
737     EditVod(  name, input, output, b_enabled, mux );
738 }
739
740 void VLMWrapper::EditVod( const QString name, const QString input,
741                           const QString output,
742                           bool b_enabled,
743                           const QString mux )
744 {
745     vlm_message_t *message;
746     QString command = "setup \"" + name + "\" input \"" + input + "\"";
747     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
748     vlm_MessageDelete( message );
749
750     if( !output.isEmpty() )
751     {
752         command = "setup \"" + name + "\" output \"" + output + "\"";
753         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
754         vlm_MessageDelete( message );
755     }
756
757     if( b_enabled )
758     {
759         command = "setup \"" + name + "\" enabled";
760         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
761         vlm_MessageDelete( message );
762     }
763     if( !mux.isEmpty() )
764     {
765         command = "setup \"" + name + "\" mux \"" + mux + "\"";
766         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
767         vlm_MessageDelete( message );
768     }
769 }
770
771 void VLMWrapper::AddSchedule( const QString name, const QString input,
772                               const QString output, QDateTime _schetime,
773                               QDateTime _schedate,
774                               int _scherepeatnumber, int _repeatDays,
775                               bool b_enabled, const QString mux )
776 {
777     vlm_message_t *message;
778     QString command = "new \"" + name + "\" schedule";
779     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
780     vlm_MessageDelete( message );
781     EditSchedule(  name, input, output, _schetime, _schedate,
782             _scherepeatnumber, _repeatDays, b_enabled, mux );
783 }
784
785 void VLMWrapper::EditSchedule( const QString name, const QString input,
786                           const QString output, QDateTime _schetime,
787                           QDateTime _schedate, int _scherepeatnumber,
788                           int _repeatDays, bool b_enabled,
789                           const QString mux )
790 {
791     vlm_message_t *message;
792     QString command = "setup \"" + name + "\" input \"" + input + "\"";
793     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
794     vlm_MessageDelete( message );
795
796     if( !output.isEmpty() )
797     {
798         command = "setup \"" + name + "\" output \"" + output + "\"";
799         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
800         vlm_MessageDelete( message );
801     }
802
803     if( b_enabled )
804     {
805         command = "setup \"" + name + "\" enabled";
806         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
807         vlm_MessageDelete( message );
808     }
809
810     if( !mux.isEmpty() )
811     {
812         command = "setup \"" + name + "\" mux \"" + mux + "\"";
813         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
814         vlm_MessageDelete( message );
815     }
816
817     command = "setup \"" + name + "\" date \"" +
818         _schedate.toString( "yyyy/MM/dd" )+ "-" +
819         _schetime.toString( "hh:mm:ss" ) + "\"";
820     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
821     vlm_MessageDelete( message );
822
823     if( _scherepeatnumber > 0 )
824     {
825        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
826        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
827        vlm_MessageDelete( message );
828     }
829
830     if( _repeatDays > 0 )
831     {
832        command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
833        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
834        vlm_MessageDelete( message );
835     }
836 }
837
838 void VLMDialog::toggleVisible()
839 {
840     QList<VLMAWidget *>::iterator it;
841     for( it = vlmItems.begin(); it != vlmItems.end(); it++ )
842     {
843         VLMAWidget *item =  *it;
844         delete item;
845         item = NULL;
846     }
847     vlmItems.clear();
848     ui.vlmListItem->clear();
849     mediasPopulator();
850     QVLCDialog::toggleVisible();
851 }
852
853
854 #endif