]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
Qt: add a bunch of virtual for destructors
[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 #include "util/qt_dirs.hpp"
36
37 #include <QString>
38 #include <QComboBox>
39 #include <QVBoxLayout>
40 #include <QStackedWidget>
41 #include <QLabel>
42 #include <QWidget>
43 #include <QGridLayout>
44 #include <QLineEdit>
45 #include <QCheckBox>
46 #include <QToolButton>
47 #include <QGroupBox>
48 #include <QPushButton>
49 #include <QHBoxLayout>
50 #include <QDateTimeEdit>
51 #include <QDateTime>
52 #include <QSpinBox>
53 #include <QScrollArea>
54 #include <QFileDialog>
55
56
57 VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
58 {
59     p_vlm = vlm_New( p_intf );
60
61     if( !p_vlm )
62     {
63         msg_Warn( p_intf, "Couldn't build VLM object ");
64         return;
65     }
66     vlmWrapper = new VLMWrapper( p_vlm );
67
68     // UI stuff
69     ui.setupUi( this );
70     ui.saveButton->hide();
71
72 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
73     ADDMEDIATYPES( N_("Broadcast"), QVLM_Broadcast );
74     ADDMEDIATYPES( N_("Schedule"), QVLM_Schedule );
75     ADDMEDIATYPES( N_("Video On Demand ( VOD )"), QVLM_VOD );
76 #undef ADDMEDIATYPES
77
78     /* Schedule Stuffs */
79     QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
80     QLabel *schetimelabel = new QLabel( qtr( "Hours / Minutes / Seconds:" ) );
81     schetimelayout->addWidget( schetimelabel, 0, 0 );
82     QLabel *schedatelabel = new QLabel( qtr( "Day / Month / Year:" ) );
83     schetimelayout->addWidget( schedatelabel, 1, 0 );
84     QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
85     schetimelayout->addWidget( scherepeatLabel, 2, 0 );
86     QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
87     schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
88
89     time = new QDateTimeEdit( QTime::currentTime() );
90     time->setAlignment( Qt::AlignRight );
91     time->setDisplayFormat( "hh:mm:ss" );
92     schetimelayout->addWidget( time, 0, 1, 1, 3 );
93
94     date = new QDateTimeEdit( QDate::currentDate() );
95     date->setAlignment( Qt::AlignRight );
96     date->setCalendarPopup( true );
97 #ifdef _WIN32
98     date->setDisplayFormat( "dd MM yyyy" );
99 #else
100     date->setDisplayFormat( "dd MMMM yyyy" );
101 #endif
102     schetimelayout->addWidget( date, 1, 1, 1, 3 );
103
104     scherepeatnumber = new QSpinBox;
105     scherepeatnumber->setAlignment( Qt::AlignRight );
106     schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
107
108     repeatDays = new QSpinBox;
109     repeatDays->setAlignment( Qt::AlignRight );
110     schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
111     repeatDays->setSuffix( qtr(" days") );
112
113     repeatTime = new QDateTimeEdit;
114     repeatTime->setAlignment( Qt::AlignRight );
115     schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
116     repeatTime->setDisplayFormat( "hh:mm:ss" );
117
118     /* scrollArea */
119     ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
120     ui.vlmItemScroll->setWidgetResizable( true );
121     vlmItemWidget = new QWidget;
122     vlmItemLayout = new QVBoxLayout( vlmItemWidget );
123     vlmItemWidget->setLayout( vlmItemLayout );
124     ui.vlmItemScroll->setWidget( vlmItemWidget );
125
126     QSpacerItem *spacer =
127         new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
128     vlmItemLayout->addItem( spacer );
129
130     QPushButton *importButton = new QPushButton( qtr( "I&mport" ) );
131     ui.buttonBox->addButton( importButton, QDialogButtonBox::ActionRole );
132
133     QPushButton *exportButton = new QPushButton( qtr( "E&xport" ) );
134     ui.buttonBox->addButton( exportButton, QDialogButtonBox::ActionRole );
135
136     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
137     ui.buttonBox->addButton( closeButton, QDialogButtonBox::RejectRole );
138
139
140     showScheduleWidget( QVLM_Broadcast );
141
142     /* Connect the comboBox to show the right Widgets */
143     CONNECT( ui.mediaType, currentIndexChanged( int ),
144              this, showScheduleWidget( int ) );
145
146     /* Connect the leftList to show the good VLMItem */
147     CONNECT( ui.vlmListItem, currentRowChanged( int ),
148              this, selectVLMItem( int ) );
149
150     BUTTONACT( closeButton, close() );
151     BUTTONACT( exportButton, exportVLMConf() );
152     BUTTONACT( importButton, importVLMConf() );
153     BUTTONACT( ui.addButton, addVLMItem() );
154     BUTTONACT( ui.clearButton, clearWidgets() );
155     BUTTONACT( ui.saveButton, saveModifications() );
156     BUTTONACT( ui.inputButton, selectInput() );
157     BUTTONACT( ui.outputButton, selectOutput() );
158
159     if( !restoreGeometry( getSettings()->value("VLM/geometry").toByteArray() ) )
160     {
161         resize( QSize( 700, 500 ) );
162     }
163 }
164
165 VLMDialog::~VLMDialog()
166 {
167     delete vlmWrapper;
168
169     getSettings()->setValue("VLM/geometry", saveGeometry());
170    /* TODO :you have to destroy vlm here to close
171     * but we shouldn't destroy vlm here in case somebody else wants it */
172     if( p_vlm )
173     {
174         vlm_Delete( p_vlm );
175     }
176 }
177
178 void VLMDialog::showScheduleWidget( int i )
179 {
180     ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
181     ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
182     ui.vodBox->setVisible( ( i == QVLM_VOD ) );
183 }
184
185 void VLMDialog::selectVLMItem( int i )
186 {
187     if( i >= 0 )
188         ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
189 }
190
191 bool VLMDialog::isNameGenuine( const QString& name )
192 {
193     for( int i = 0; i < vlmItems.count(); i++ )
194     {
195         if( vlmItems.at( i )->name == name )
196             return false;
197     }
198     return true;
199 }
200
201 void VLMDialog::addVLMItem()
202 {
203     int vlmItemCount = vlmItems.count();
204
205     /* Take the name and Check it */
206     QString name = ui.nameLedit->text();
207     if( name.isEmpty() || !isNameGenuine( name ) )
208     {
209         msg_Err( p_intf, "VLM Name is empty or already exists, I can't do it" );
210         return;
211     }
212
213     int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
214
215     QString typeShortName;
216     QString inputText = ui.inputLedit->text();
217     QString outputText = ui.outputLedit->text();
218     bool b_checked = ui.enableCheck->isChecked();
219     bool b_looped = ui.loopBCast->isChecked();
220     QDateTime schetime = time->dateTime();
221     QDateTime schedate = date->dateTime();
222     int repeatnum = scherepeatnumber->value();
223     int repeatdays = repeatDays->value();
224     VLMAWidget * vlmAwidget;
225     outputText.remove( ":sout=" );
226
227     switch( type )
228     {
229     case QVLM_Broadcast:
230         typeShortName = "Bcast";
231         vlmAwidget = new VLMBroadcast( name, inputText, inputOptions, outputText,
232                                        b_checked, b_looped, this );
233         VLMWrapper::AddBroadcast( name, inputText, inputOptions, outputText, b_checked,
234                                   b_looped );
235     break;
236     case QVLM_VOD:
237         typeShortName = "VOD";
238         vlmAwidget = new VLMVod( name, inputText, inputOptions, outputText,
239                                  b_checked, ui.muxLedit->text(), this );
240         VLMWrapper::AddVod( name, inputText, inputOptions, outputText, b_checked );
241         break;
242     case QVLM_Schedule:
243         typeShortName = "Sched";
244         vlmAwidget = new VLMSchedule( name, inputText, inputOptions, outputText,
245                                       schetime, schedate, repeatnum,
246                                       repeatdays, b_checked, this );
247         VLMWrapper::AddSchedule( name, inputText, inputOptions, outputText, schetime,
248                                  schedate, repeatnum, repeatdays, b_checked);
249         break;
250     default:
251         msg_Warn( p_intf, "Something bad happened" );
252         return;
253     }
254
255     /* Add an Item of the Side List */
256     ui.vlmListItem->addItem( typeShortName + " : " + name );
257     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
258
259     /* Add a new VLMAWidget on the main List */
260
261     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
262     vlmItems.append( vlmAwidget );
263     clearWidgets();
264 }
265
266 /* TODO : VOD are not exported to the file */
267 bool VLMDialog::exportVLMConf()
268 {
269     QString saveVLMConfFileName = QFileDialog::getSaveFileName( this,
270                                         qtr( "Save VLM configuration as..." ),
271                                         QVLCUserDir( VLC_DOCUMENTS_DIR ),
272                                         qtr( "VLM conf (*.vlm);;All (*)" ) );
273
274     if( !saveVLMConfFileName.isEmpty() )
275     {
276         vlm_message_t *message;
277         QString command = "save \"" + saveVLMConfFileName + "\"";
278         vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
279         vlm_MessageDelete( message );
280         return true;
281     }
282
283     return false;
284 }
285
286 void VLMDialog::mediasPopulator()
287 {
288     if( p_vlm )
289     {
290         int i_nMedias;
291         QString typeShortName;
292         int vlmItemCount;
293         vlm_media_t ***ppp_dsc = (vlm_media_t ***)malloc( sizeof( vlm_media_t** ) );
294
295         /* Get medias information and numbers */
296         vlm_Control( p_vlm, VLM_GET_MEDIAS, ppp_dsc, &i_nMedias );
297
298         /* Loop on all of them */
299         for( int i = 0; i < i_nMedias; i++ )
300         {
301             VLMAWidget * vlmAwidget;
302             vlmItemCount = vlmItems.count();
303
304             QString mediaName = qfu( (*ppp_dsc)[i]->psz_name );
305             /* It may have several inputs, we take the first one by default
306                  - an evolution will be to manage these inputs in the gui */
307             QString inputText = qfu( (*ppp_dsc)[i]->ppsz_input[0] );
308
309             QString outputText = qfu( (*ppp_dsc)[i]->psz_output );
310
311             /* Schedule media is a quite especial, maybe there is another way to grab information */
312             if( (*ppp_dsc)[i]->b_vod )
313             {
314                 typeShortName = "VOD";
315                 QString mux = qfu( (*ppp_dsc)[i]->vod.psz_mux );
316                 vlmAwidget = new VLMVod( mediaName, inputText, inputOptions,
317                                          outputText, (*ppp_dsc)[i]->b_enabled,
318                                          mux, this );
319             }
320             else
321             {
322                 typeShortName = "Bcast";
323                 vlmAwidget = new VLMBroadcast( mediaName, inputText, inputOptions,
324                                                outputText, (*ppp_dsc)[i]->b_enabled,
325                                                (*ppp_dsc)[i]->broadcast.b_loop, this );
326             }
327             /* Add an Item of the Side List */
328             ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
329             ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
330
331             /* Add a new VLMAWidget on the main List */
332             vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
333             vlmItems.append( vlmAwidget );
334             clearWidgets();
335         }
336         free( ppp_dsc );
337     }
338 }
339
340 bool VLMDialog::importVLMConf()
341 {
342     QString openVLMConfFileName = toNativeSeparators(
343             QFileDialog::getOpenFileName(
344             this, qtr( "Open VLM configuration..." ),
345             QVLCUserDir( VLC_DOCUMENTS_DIR ),
346             qtr( "VLM conf (*.vlm);;All (*)" ) ) );
347
348     if( !openVLMConfFileName.isEmpty() )
349     {
350         vlm_message_t *message;
351         int status;
352         QString command = "load \"" + openVLMConfFileName + "\"";
353         status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
354         vlm_MessageDelete( message );
355         if( status == 0 )
356         {
357             mediasPopulator();
358         }
359         else
360         {
361             msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
362             return false;
363         }
364         return true;
365     }
366     return false;
367 }
368
369 void VLMDialog::clearWidgets()
370 {
371     ui.nameLedit->clear();
372     ui.inputLedit->clear();
373     inputOptions.clear();
374     ui.outputLedit->clear();
375     time->setTime( QTime::currentTime() );
376     date->setDate( QDate::currentDate() );
377     ui.enableCheck->setChecked( true );
378     ui.nameLedit->setReadOnly( false );
379     ui.loopBCast->setChecked( false );
380     ui.muxLedit->clear();
381     ui.saveButton->hide();
382     ui.addButton->show();
383 }
384
385 void VLMDialog::selectInput()
386 {
387     OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
388     o->exec();
389     ui.inputLedit->setText( o->getMRL( false ) );
390     inputOptions = o->getOptions();
391 }
392
393 void VLMDialog::selectOutput()
394 {
395     SoutDialog *s = new SoutDialog( this, p_intf );
396     if( s->exec() == QDialog::Accepted )
397     {
398         int i = s->getMrl().indexOf( " " );
399         ui.outputLedit->setText( s->getMrl().left( i ) );
400     }
401 }
402
403 /* Object Modification */
404 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
405 {
406     int index = vlmItems.indexOf( vlmObj );
407     if( index < 0 ) return;
408     delete ui.vlmListItem->takeItem( index );
409     vlmItems.removeAt( index );
410     delete vlmObj;
411
412     /* HERE BE DRAGONS VLM REQUEST */
413 }
414
415 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
416 {
417     currentIndex = vlmItems.indexOf( vlmObj );
418     if( currentIndex < 0 ) return;
419
420     ui.vlmListItem->setCurrentRow( currentIndex );
421     ui.nameLedit->setText( vlmObj->name );
422     ui.inputLedit->setText( vlmObj->input );
423     ui.outputLedit->setText( vlmObj->output );
424     ui.enableCheck->setChecked( vlmObj->b_enabled );
425
426     switch( vlmObj->type )
427     {
428     case QVLM_Broadcast:
429         ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
430         break;
431     case QVLM_VOD:
432         ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
433         break;
434     case QVLM_Schedule:
435         time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
436         date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
437         break;
438     }
439
440     ui.nameLedit->setReadOnly( true );
441     ui.addButton->hide();
442     ui.saveButton->show();
443 }
444
445 void VLMDialog::saveModifications()
446 {
447     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
448     if( vlmObj )
449     {
450         vlmObj->input = ui.inputLedit->text();
451         vlmObj->output = ui.outputLedit->text().remove( ":sout=" );
452         vlmObj->setChecked( ui.enableCheck->isChecked() );
453         vlmObj->b_enabled = ui.enableCheck->isChecked();
454         switch( vlmObj->type )
455         {
456         case QVLM_Broadcast:
457             (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
458             break;
459         case QVLM_VOD:
460             (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
461             break;
462         case QVLM_Schedule:
463             (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
464             (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
465             (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
466             (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
467             break;
468            //           vlmObj->
469         }
470         vlmObj->update();
471     }
472     clearWidgets();
473 }
474
475 /*********************************
476  * VLMAWidget - Abstract class
477  ********************************/
478
479 VLMAWidget::VLMAWidget( const QString& _name, const QString& _input,
480                         const QString& _inputOptions, const QString& _output,
481                         bool _enabled, VLMDialog *_parent, int _type )
482                       : QGroupBox( _name, _parent )
483 {
484     parent = _parent;
485     name = _name;
486     input = _input;
487     inputOptions = _inputOptions;
488     output = _output;
489     b_enabled = _enabled;
490     type = _type;
491
492     setCheckable( true );
493     setChecked( b_enabled );
494
495     objLayout = new QGridLayout( this );
496     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
497
498     nameLabel = new QLabel;
499     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
500
501     /*QLabel *time = new QLabel( "--:--/--:--" );
502     objLayout->addWidget( time, 1, 3, 1, 2 );*/
503
504     QToolButton *modifyButton = new QToolButton;
505     modifyButton->setIcon( QIcon( ":/menu/settings" ) );
506     modifyButton->setToolTip( qtr("Change") );
507     objLayout->addWidget( modifyButton, 0, 5 );
508
509     QToolButton *deleteButton = new QToolButton;
510     deleteButton->setIcon( QIcon( ":/menu/quit" ) );
511     deleteButton->setToolTip("Delete");
512     objLayout->addWidget( deleteButton, 0, 6 );
513
514     BUTTONACT( modifyButton, modify() );
515     BUTTONACT( deleteButton, del() );
516     CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
517 }
518
519 void VLMAWidget::modify()
520 {
521     parent->startModifyVLMItem( this );
522 }
523
524 void VLMAWidget::del()
525 {
526     parent->removeVLMItem( this );
527 }
528
529 void VLMAWidget::toggleEnabled( bool b_enable )
530 {
531     VLMWrapper::EnableItem( name, b_enable );
532 }
533
534 /****************
535  * VLMBroadcast
536  ****************/
537 VLMBroadcast::VLMBroadcast( const QString& _name, const QString& _input,
538                             const QString& _inputOptions,
539                             const QString& _output, bool _enabled,
540                             bool _looped, VLMDialog *_parent )
541                           : VLMAWidget( _name, _input, _inputOptions, _output,
542                                         _enabled, _parent, QVLM_Broadcast )
543 {
544     nameLabel->setText( qtr("Broadcast: ") + name );
545     type = QVLM_Broadcast;
546     b_looped = _looped;
547
548     playButton = new QToolButton;
549     playButton->setIcon( QIcon( ":/menu/play" ) );
550     playButton->setToolTip( qtr("Play") );
551     objLayout->addWidget( playButton, 1, 0 );
552     b_playing = true;
553
554     QToolButton *stopButton = new QToolButton;
555     stopButton->setIcon( QIcon( ":/toolbar/stop_b" ) );
556     stopButton->setToolTip( qtr("Stop") );
557     objLayout->addWidget( stopButton, 1, 1 );
558
559     loopButton = new QToolButton;
560     loopButton->setToolTip( qtr("Repeat") );
561     objLayout->addWidget( loopButton, 1, 2 );
562
563     BUTTONACT( playButton, togglePlayPause() );
564     BUTTONACT( stopButton, stop() );
565     BUTTONACT( loopButton, toggleLoop() );
566
567     update();
568 }
569
570 void VLMBroadcast::update()
571 {
572     VLMWrapper::EditBroadcast( name, input, inputOptions, output, b_enabled, b_looped );
573     if( b_looped )
574         loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
575     else
576         loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_off" ) );
577 }
578
579 void VLMBroadcast::togglePlayPause()
580 {
581     if( b_playing )
582     {
583         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
584         playButton->setIcon( QIcon( ":/menu/pause" ) );
585     }
586     else
587     {
588         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
589         playButton->setIcon( QIcon( ":/menu/play" ) );
590     }
591     b_playing = !b_playing;
592 }
593
594 void VLMBroadcast::toggleLoop()
595 {
596     b_enabled = !b_enabled;
597     update();
598 }
599
600 void VLMBroadcast::stop()
601 {
602     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
603     playButton->setIcon( QIcon( ":/menu/play" ) );
604 }
605
606 /****************
607  * VLMSchedule
608  ****************/
609 VLMSchedule::VLMSchedule( const QString& name_, const QString& input,
610                           const QString& inputOptions,
611                           const QString& output, QDateTime _schetime,
612                           QDateTime _schedate, int _scherepeatnumber,
613                           int _repeatDays, bool enabled, VLMDialog *parent )
614             : VLMAWidget( name_, input, inputOptions, output, enabled, parent,
615                           QVLM_Schedule )
616 {
617     nameLabel->setText( qtr("Schedule: ") + name );
618     schetime = _schetime;
619     schedate = _schedate;
620     rNumber = _scherepeatnumber;
621     rDays = _repeatDays;
622     type = QVLM_Schedule;
623     update();
624 }
625
626 void VLMSchedule::update()
627 {
628    VLMWrapper::EditSchedule( name, input, inputOptions, output, schetime, schedate,
629                              rNumber, rDays, b_enabled);
630 }
631
632 /****************
633  * VLMVOD
634  ****************/
635 VLMVod::VLMVod( const QString& name_, const QString& input,
636                 const QString& inputOptions, const QString& output,
637                 bool enabled, const QString& _mux, VLMDialog *parent)
638        : VLMAWidget( name_, input, inputOptions, output, enabled, parent,
639                      QVLM_VOD )
640 {
641     nameLabel->setText( qtr("VOD: ") + name );
642
643     mux = _mux;
644     muxLabel = new QLabel;
645     objLayout->addWidget( muxLabel, 1, 0 );
646
647     update();
648 }
649
650 void VLMVod::update()
651 {
652     muxLabel->setText( mux );
653     VLMWrapper::EditVod( name, input, inputOptions, output, b_enabled, mux );
654 }
655
656
657 /*******************
658  * VLMWrapper
659  *******************/
660 vlm_t * VLMWrapper::p_vlm = NULL;
661
662 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
663 {
664     p_vlm = _p_vlm;
665 }
666
667 VLMWrapper::~VLMWrapper()
668 {
669     p_vlm = NULL;
670 }
671
672 void VLMWrapper::AddBroadcast( const QString& name, const QString& input,
673                                const QString& inputOptions, const QString& output,
674                                bool b_enabled, bool b_loop  )
675 {
676     vlm_message_t *message;
677     QString command = "new \"" + name + "\" broadcast";
678     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
679     vlm_MessageDelete( message );
680     EditBroadcast( name, input, inputOptions, output, b_enabled, b_loop );
681 }
682
683 void VLMWrapper::EditBroadcast( const QString& name, const QString& input,
684                                 const QString& inputOptions, const QString& output,
685                                 bool b_enabled, bool b_loop  )
686 {
687     vlm_message_t *message;
688     QString command;
689
690     command = "setup \"" + name + "\" inputdel all";
691     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
692     vlm_MessageDelete( message );
693
694     if( !input.isEmpty() )
695     {
696         command = "setup \"" + name + "\" input \"" + input + "\"";
697         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
698         vlm_MessageDelete( message );
699
700         QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
701         for( int i = 0; i < options.count(); i++ )
702         {
703             command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
704             vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
705             vlm_MessageDelete( message );
706         }
707     }
708
709     if( !output.isEmpty() )
710     {
711         command = "setup \"" + name + "\" output \"" + output + "\"";
712         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
713         vlm_MessageDelete( message );
714     }
715     if( b_enabled )
716     {
717         command = "setup \"" + name + "\" enabled";
718         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
719         vlm_MessageDelete( message );
720     }
721     if( b_loop )
722     {
723         command = "setup \"" + name + "\" loop";
724         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
725         vlm_MessageDelete( message );
726     }
727 }
728
729 void VLMWrapper::EnableItem( const QString& name, bool b_enable )
730 {
731     vlm_message_t *message;
732     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
733     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
734     vlm_MessageDelete( message );
735 }
736
737 void VLMWrapper::ControlBroadcast( const QString& name, int BroadcastStatus,
738                                    unsigned int seek )
739 {
740     vlm_message_t *message;
741
742     QString command = "control \"" + name + "\"";
743     switch( BroadcastStatus )
744     {
745     case ControlBroadcastPlay:
746         command += " play";
747         break;
748     case ControlBroadcastPause:
749         command += " pause";
750         break;
751     case ControlBroadcastStop:
752         command += " stop";
753         break;
754     case ControlBroadcastSeek:
755         command += " seek " + QString::number( seek );
756         break;
757     }
758     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
759     vlm_MessageDelete( message );
760 }
761
762 void VLMWrapper::AddVod( const QString& name, const QString& input,
763                          const QString& inputOptions, const QString& output,
764                          bool b_enabled, const QString& mux )
765 {
766     vlm_message_t *message;
767     QString command = "new \"" + name + "\" vod";
768     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
769     vlm_MessageDelete( message );
770     EditVod(  name, input, inputOptions, output, b_enabled, mux );
771 }
772
773 void VLMWrapper::EditVod( const QString& name, const QString& input,
774                           const QString& inputOptions, const QString& output,
775                           bool b_enabled,
776                           const QString& mux )
777 {
778     vlm_message_t *message;
779     QString command;
780
781     if( !input.isEmpty() )
782     {
783         command = "setup \"" + name + "\" input \"" + input + "\"";
784         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
785         vlm_MessageDelete( message );
786
787         QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
788         for( int i = 0; i < options.count(); i++ )
789         {
790             command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
791             vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
792             vlm_MessageDelete( message );
793         }
794     }
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     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
817 void VLMWrapper::AddSchedule( const QString& name, const QString& input,
818                               const QString& inputOptions, const QString& output,
819                               QDateTime _schetime, QDateTime _schedate,
820                               int _scherepeatnumber, int _repeatDays,
821                               bool b_enabled, const QString& mux )
822 {
823     vlm_message_t *message;
824     QString command = "new \"" + name + "\" schedule";
825     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
826     vlm_MessageDelete( message );
827     EditSchedule(  name, input, inputOptions, output, _schetime, _schedate,
828             _scherepeatnumber, _repeatDays, b_enabled, mux );
829 }
830
831 void VLMWrapper::EditSchedule( const QString& name, const QString& input,
832                                const QString& inputOptions, const QString& output,
833                                QDateTime _schetime, QDateTime _schedate,
834                                int _scherepeatnumber, int _repeatDays,
835                                bool b_enabled, const QString& mux )
836 {
837     vlm_message_t *message;
838     QString command;
839
840     if( !input.isEmpty() )
841     {
842         command = "setup \"" + name + "\" input \"" + input + "\"";
843         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
844         vlm_MessageDelete( message );
845
846         QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
847         for( int i = 0; i < options.count(); i++ )
848         {
849             command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
850             vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
851             vlm_MessageDelete( message );
852         }
853     }
854
855     if( !output.isEmpty() )
856     {
857         command = "setup \"" + name + "\" output \"" + output + "\"";
858         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
859         vlm_MessageDelete( message );
860     }
861
862     if( b_enabled )
863     {
864         command = "setup \"" + name + "\" enabled";
865         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
866         vlm_MessageDelete( message );
867     }
868
869     if( !mux.isEmpty() )
870     {
871         command = "setup \"" + name + "\" mux \"" + mux + "\"";
872         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
873         vlm_MessageDelete( message );
874     }
875
876     command = "setup \"" + name + "\" date \"" +
877         _schedate.toString( "yyyy/MM/dd" )+ "-" +
878         _schetime.toString( "hh:mm:ss" ) + "\"";
879     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
880     vlm_MessageDelete( message );
881
882     if( _scherepeatnumber > 0 )
883     {
884        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
885        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
886        vlm_MessageDelete( message );
887     }
888
889     if( _repeatDays > 0 )
890     {
891        command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
892        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
893        vlm_MessageDelete( message );
894     }
895 }
896
897 void VLMDialog::toggleVisible()
898 {
899     qDeleteAll( vlmItems );
900     vlmItems.clear();
901
902     ui.vlmListItem->clear();
903     mediasPopulator();
904     QVLCFrame::toggleVisible();
905 }
906
907
908 #endif