]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
Qt: use count() iso size() on Qt Containers
[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 ) : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _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::AcceptRole );
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     //readSettings( "VLM", QSize( 700, 500 ) );
159 }
160
161 VLMDialog::~VLMDialog()
162 {
163     delete vlmWrapper;
164
165     //writeSettings( "VLM" );
166    /* TODO :you have to destroy vlm here to close
167     * but we shouldn't destroy vlm here in case somebody else wants it */
168     if( p_vlm )
169     {
170         vlm_Delete( p_vlm );
171     }
172 }
173
174 void VLMDialog::showScheduleWidget( int i )
175 {
176     ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
177     ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
178     ui.vodBox->setVisible( ( i == QVLM_VOD ) );
179 }
180
181 void VLMDialog::selectVLMItem( int i )
182 {
183     if( i >= 0 )
184         ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
185 }
186
187 bool VLMDialog::isNameGenuine( const QString& name )
188 {
189     for( int i = 0; i < vlmItems.count(); i++ )
190     {
191         if( vlmItems.at( i )->name == name )
192             return false;
193     }
194     return true;
195 }
196
197 void VLMDialog::addVLMItem()
198 {
199     int vlmItemCount = vlmItems.count();
200
201     /* Take the name and Check it */
202     QString name = ui.nameLedit->text();
203     if( name.isEmpty() || !isNameGenuine( name ) )
204     {
205         msg_Err( p_intf, "VLM Name is empty or already exists, I can't do it" );
206         return;
207     }
208
209     int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
210
211     QString typeShortName;
212     QString inputText = ui.inputLedit->text();
213     QString outputText = ui.outputLedit->text();
214     bool b_checked = ui.enableCheck->isChecked();
215     bool b_looped = ui.loopBCast->isChecked();
216     QDateTime schetime = time->dateTime();
217     QDateTime schedate = date->dateTime();
218     int repeatnum = scherepeatnumber->value();
219     int repeatdays = repeatDays->value();
220     VLMAWidget * vlmAwidget;
221     outputText.remove( ":sout=" );
222
223     switch( type )
224     {
225     case QVLM_Broadcast:
226         typeShortName = "Bcast";
227         vlmAwidget = new VLMBroadcast( name, inputText, inputOptions, outputText,
228                                        b_checked, b_looped, this );
229         VLMWrapper::AddBroadcast( name, inputText, inputOptions, outputText, b_checked,
230                                   b_looped );
231     break;
232     case QVLM_VOD:
233         typeShortName = "VOD";
234         vlmAwidget = new VLMVod( name, inputText, inputOptions, outputText,
235                                  b_checked, ui.muxLedit->text(), this );
236         VLMWrapper::AddVod( name, inputText, inputOptions, outputText, b_checked );
237         break;
238     case QVLM_Schedule:
239         typeShortName = "Sched";
240         vlmAwidget = new VLMSchedule( name, inputText, inputOptions, outputText,
241                                       schetime, schedate, repeatnum,
242                                       repeatdays, b_checked, this );
243         VLMWrapper::AddSchedule( name, inputText, inputOptions, outputText, schetime,
244                                  schedate, repeatnum, repeatdays, b_checked);
245         break;
246     default:
247         msg_Warn( p_intf, "Something bad happened" );
248         return;
249     }
250
251     /* Add an Item of the Side List */
252     ui.vlmListItem->addItem( typeShortName + " : " + name );
253     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
254
255     /* Add a new VLMAWidget on the main List */
256
257     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
258     vlmItems.append( vlmAwidget );
259     clearWidgets();
260 }
261
262 /* TODO : VOD are not exported to the file */
263 bool VLMDialog::exportVLMConf()
264 {
265     QString saveVLMConfFileName = QFileDialog::getSaveFileName( this,
266                                         qtr( "Save VLM configuration as..." ),
267                                         QVLCUserDir( VLC_DOCUMENTS_DIR ),
268                                         qtr( "VLM conf (*.vlm);;All (*)" ) );
269
270     if( !saveVLMConfFileName.isEmpty() )
271     {
272         vlm_message_t *message;
273         QString command = "save \"" + saveVLMConfFileName + "\"";
274         vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
275         vlm_MessageDelete( message );
276         return true;
277     }
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 information 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.count();
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 information */
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, inputOptions,
313                                          outputText, (*ppp_dsc)[i]->b_enabled,
314                                          mux, this );
315             }
316             else
317             {
318                 typeShortName = "Bcast";
319                 vlmAwidget = new VLMBroadcast( mediaName, inputText, inputOptions,
320                                                outputText, (*ppp_dsc)[i]->b_enabled,
321                                                (*ppp_dsc)[i]->broadcast.b_loop, this );
322             }
323             /* Add an Item of the Side List */
324             ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
325             ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
326
327             /* Add a new VLMAWidget on the main List */
328             vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
329             vlmItems.append( vlmAwidget );
330             clearWidgets();
331         }
332         free( ppp_dsc );
333     }
334 }
335
336 bool VLMDialog::importVLMConf()
337 {
338     QString openVLMConfFileName = toNativeSeparators(
339             QFileDialog::getOpenFileName(
340             this, qtr( "Open VLM configuration..." ),
341             QVLCUserDir( VLC_DOCUMENTS_DIR ),
342             qtr( "VLM conf (*.vlm);;All (*)" ) ) );
343
344     if( !openVLMConfFileName.isEmpty() )
345     {
346         vlm_message_t *message;
347         int status;
348         QString command = "load \"" + openVLMConfFileName + "\"";
349         status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
350         vlm_MessageDelete( message );
351         if( status == 0 )
352         {
353             mediasPopulator();
354         }
355         else
356         {
357             msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
358             return false;
359         }
360         return true;
361     }
362     return false;
363 }
364
365 void VLMDialog::clearWidgets()
366 {
367     ui.nameLedit->clear();
368     ui.inputLedit->clear();
369     inputOptions.clear();
370     ui.outputLedit->clear();
371     time->setTime( QTime::currentTime() );
372     date->setDate( QDate::currentDate() );
373     ui.enableCheck->setChecked( true );
374     ui.nameLedit->setReadOnly( false );
375     ui.loopBCast->setChecked( false );
376     ui.muxLedit->clear();
377     ui.saveButton->hide();
378     ui.addButton->show();
379 }
380
381 void VLMDialog::selectInput()
382 {
383     OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
384     o->exec();
385     ui.inputLedit->setText( o->getMRL( false ) );
386     inputOptions = o->getOptions();
387 }
388
389 void VLMDialog::selectOutput()
390 {
391     SoutDialog *s = new SoutDialog( this, p_intf );
392     if( s->exec() == QDialog::Accepted )
393     {
394         int i = s->getMrl().indexOf( " " );
395         ui.outputLedit->setText( s->getMrl().left( i ) );
396     }
397 }
398
399 /* Object Modification */
400 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
401 {
402     int index = vlmItems.indexOf( vlmObj );
403     if( index < 0 ) return;
404     delete ui.vlmListItem->takeItem( index );
405     vlmItems.removeAt( index );
406     delete vlmObj;
407
408     /* HERE BE DRAGONS VLM REQUEST */
409 }
410
411 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
412 {
413     currentIndex = vlmItems.indexOf( vlmObj );
414     if( currentIndex < 0 ) return;
415
416     ui.vlmListItem->setCurrentRow( currentIndex );
417     ui.nameLedit->setText( vlmObj->name );
418     ui.inputLedit->setText( vlmObj->input );
419     ui.outputLedit->setText( vlmObj->output );
420     ui.enableCheck->setChecked( vlmObj->b_enabled );
421
422     switch( vlmObj->type )
423     {
424     case QVLM_Broadcast:
425         ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
426         break;
427     case QVLM_VOD:
428         ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
429         break;
430     case QVLM_Schedule:
431         time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
432         date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
433         break;
434     }
435
436     ui.nameLedit->setReadOnly( true );
437     ui.addButton->hide();
438     ui.saveButton->show();
439 }
440
441 void VLMDialog::saveModifications()
442 {
443     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
444     if( vlmObj )
445     {
446         vlmObj->input = ui.inputLedit->text();
447         vlmObj->output = ui.outputLedit->text().remove( ":sout=" );
448         vlmObj->setChecked( ui.enableCheck->isChecked() );
449         vlmObj->b_enabled = ui.enableCheck->isChecked();
450         switch( vlmObj->type )
451         {
452         case QVLM_Broadcast:
453             (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
454             break;
455         case QVLM_VOD:
456             (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
457             break;
458         case QVLM_Schedule:
459             (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
460             (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
461             (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
462             (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
463             break;
464            //           vlmObj->
465         }
466         vlmObj->update();
467     }
468     clearWidgets();
469 }
470
471 /*********************************
472  * VLMAWidget - Abstract class
473  ********************************/
474
475 VLMAWidget::VLMAWidget( const QString& _name, const QString& _input,
476                         const QString& _inputOptions, const QString& _output,
477                         bool _enabled, VLMDialog *_parent, int _type )
478                       : QGroupBox( _name, _parent )
479 {
480     parent = _parent;
481     name = _name;
482     input = _input;
483     inputOptions = _inputOptions;
484     output = _output;
485     b_enabled = _enabled;
486     type = _type;
487
488     setCheckable( true );
489     setChecked( b_enabled );
490
491     objLayout = new QGridLayout( this );
492     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
493
494     nameLabel = new QLabel;
495     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
496
497     /*QLabel *time = new QLabel( "--:--/--:--" );
498     objLayout->addWidget( time, 1, 3, 1, 2 );*/
499
500     QToolButton *modifyButton = new QToolButton;
501     modifyButton->setIcon( QIcon( ":/menu/settings" ) );
502     modifyButton->setToolTip( qtr("Change") );
503     objLayout->addWidget( modifyButton, 0, 5 );
504
505     QToolButton *deleteButton = new QToolButton;
506     deleteButton->setIcon( QIcon( ":/menu/quit" ) );
507     deleteButton->setToolTip("Delete");
508     objLayout->addWidget( deleteButton, 0, 6 );
509
510     BUTTONACT( modifyButton, modify() );
511     BUTTONACT( deleteButton, del() );
512     CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
513 }
514
515 void VLMAWidget::modify()
516 {
517     parent->startModifyVLMItem( this );
518 }
519
520 void VLMAWidget::del()
521 {
522     parent->removeVLMItem( this );
523 }
524
525 void VLMAWidget::toggleEnabled( bool b_enable )
526 {
527     VLMWrapper::EnableItem( name, b_enable );
528 }
529
530 /****************
531  * VLMBroadcast
532  ****************/
533 VLMBroadcast::VLMBroadcast( const QString& _name, const QString& _input,
534                             const QString& _inputOptions,
535                             const QString& _output, bool _enabled,
536                             bool _looped, VLMDialog *_parent )
537                           : VLMAWidget( _name, _input, _inputOptions, _output,
538                                         _enabled, _parent, QVLM_Broadcast )
539 {
540     nameLabel->setText( qtr("Broadcast: ") + name );
541     type = QVLM_Broadcast;
542     b_looped = _looped;
543
544     playButton = new QToolButton;
545     playButton->setIcon( QIcon( ":/menu/play" ) );
546     playButton->setToolTip( qtr("Play") );
547     objLayout->addWidget( playButton, 1, 0 );
548     b_playing = true;
549
550     QToolButton *stopButton = new QToolButton;
551     stopButton->setIcon( QIcon( ":/toolbar/stop_b" ) );
552     stopButton->setToolTip( qtr("Stop") );
553     objLayout->addWidget( stopButton, 1, 1 );
554
555     loopButton = new QToolButton;
556     loopButton->setToolTip( qtr("Repeat") );
557     objLayout->addWidget( loopButton, 1, 2 );
558
559     BUTTONACT( playButton, togglePlayPause() );
560     BUTTONACT( stopButton, stop() );
561     BUTTONACT( loopButton, toggleLoop() );
562
563     update();
564 }
565
566 void VLMBroadcast::update()
567 {
568     VLMWrapper::EditBroadcast( name, input, inputOptions, output, b_enabled, b_looped );
569     if( b_looped )
570         loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
571     else
572         loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_off" ) );
573 }
574
575 void VLMBroadcast::togglePlayPause()
576 {
577     if( b_playing )
578     {
579         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
580         playButton->setIcon( QIcon( ":/menu/pause" ) );
581     }
582     else
583     {
584         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
585         playButton->setIcon( QIcon( ":/menu/play" ) );
586     }
587     b_playing = !b_playing;
588 }
589
590 void VLMBroadcast::toggleLoop()
591 {
592     b_enabled = !b_enabled;
593     update();
594 }
595
596 void VLMBroadcast::stop()
597 {
598     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
599     playButton->setIcon( QIcon( ":/menu/play" ) );
600 }
601
602 /****************
603  * VLMSchedule
604  ****************/
605 VLMSchedule::VLMSchedule( const QString& name, const QString& input,
606                           const QString& inputOptions,
607                           const QString& output, QDateTime _schetime,
608                           QDateTime _schedate, int _scherepeatnumber,
609                           int _repeatDays, bool enabled, VLMDialog *parent )
610             : VLMAWidget( name, input, inputOptions, output, enabled, parent,
611                           QVLM_Schedule )
612 {
613     nameLabel->setText( qtr("Schedule: ") + name );
614     schetime = _schetime;
615     schedate = _schedate;
616     rNumber = _scherepeatnumber;
617     rDays = _repeatDays;
618     type = QVLM_Schedule;
619     update();
620 }
621
622 void VLMSchedule::update()
623 {
624    VLMWrapper::EditSchedule( name, input, inputOptions, output, schetime, schedate,
625                              rNumber, rDays, b_enabled);
626 }
627
628 /****************
629  * VLMVOD
630  ****************/
631 VLMVod::VLMVod( const QString& name, const QString& input,
632                 const QString& inputOptions, const QString& output,
633                 bool enabled, const QString& _mux, VLMDialog *parent)
634        : VLMAWidget( name, input, inputOptions, output, enabled, parent,
635                      QVLM_VOD )
636 {
637     nameLabel->setText( qtr("VOD: ") + name );
638
639     mux = _mux;
640     muxLabel = new QLabel;
641     objLayout->addWidget( muxLabel, 1, 0 );
642
643     update();
644 }
645
646 void VLMVod::update()
647 {
648     muxLabel->setText( mux );
649     VLMWrapper::EditVod( name, input, inputOptions, output, b_enabled, mux );
650 }
651
652
653 /*******************
654  * VLMWrapper
655  *******************/
656 vlm_t * VLMWrapper::p_vlm = NULL;
657
658 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
659 {
660     p_vlm = _p_vlm;
661 }
662
663 VLMWrapper::~VLMWrapper()
664 {
665     p_vlm = NULL;
666 }
667
668 void VLMWrapper::AddBroadcast( const QString& name, const QString& input,
669                                const QString& inputOptions, const QString& output,
670                                bool b_enabled, bool b_loop  )
671 {
672     vlm_message_t *message;
673     QString command = "new \"" + name + "\" broadcast";
674     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
675     vlm_MessageDelete( message );
676     EditBroadcast( name, input, inputOptions, output, b_enabled, b_loop );
677 }
678
679 void VLMWrapper::EditBroadcast( const QString& name, const QString& input,
680                                 const QString& inputOptions, const QString& output,
681                                 bool b_enabled, bool b_loop  )
682 {
683     vlm_message_t *message;
684     QString command;
685
686     command = "setup \"" + name + "\" inputdel all";
687     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
688     vlm_MessageDelete( message );
689
690     if( !input.isEmpty() )
691     {
692         command = "setup \"" + name + "\" input \"" + input + "\"";
693         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
694         vlm_MessageDelete( message );
695
696         QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
697         for( int i = 0; i < options.count(); i++ )
698         {
699             command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
700             vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
701             vlm_MessageDelete( message );
702         }
703     }
704
705     if( !output.isEmpty() )
706     {
707         command = "setup \"" + name + "\" output \"" + output + "\"";
708         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
709         vlm_MessageDelete( message );
710     }
711     if( b_enabled )
712     {
713         command = "setup \"" + name + "\" enabled";
714         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
715         vlm_MessageDelete( message );
716     }
717     if( b_loop )
718     {
719         command = "setup \"" + name + "\" loop";
720         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
721         vlm_MessageDelete( message );
722     }
723 }
724
725 void VLMWrapper::EnableItem( const QString& name, bool b_enable )
726 {
727     vlm_message_t *message;
728     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
729     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
730     vlm_MessageDelete( message );
731 }
732
733 void VLMWrapper::ControlBroadcast( const QString& name, int BroadcastStatus,
734                                    unsigned int seek )
735 {
736     vlm_message_t *message;
737
738     QString command = "control \"" + name + "\"";
739     switch( BroadcastStatus )
740     {
741     case ControlBroadcastPlay:
742         command += " play";
743         break;
744     case ControlBroadcastPause:
745         command += " pause";
746         break;
747     case ControlBroadcastStop:
748         command += " stop";
749         break;
750     case ControlBroadcastSeek:
751         command += " seek" + seek;
752         break;
753     }
754     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
755     vlm_MessageDelete( message );
756 }
757
758 void VLMWrapper::AddVod( const QString& name, const QString& input,
759                          const QString& inputOptions, const QString& output,
760                          bool b_enabled, const QString& mux )
761 {
762     vlm_message_t *message;
763     QString command = "new \"" + name + "\" vod";
764     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
765     vlm_MessageDelete( message );
766     EditVod(  name, input, inputOptions, output, b_enabled, mux );
767 }
768
769 void VLMWrapper::EditVod( const QString& name, const QString& input,
770                           const QString& inputOptions, const QString& output,
771                           bool b_enabled,
772                           const QString& mux )
773 {
774     vlm_message_t *message;
775     QString command;
776
777     if( !input.isEmpty() )
778     {
779         command = "setup \"" + name + "\" input \"" + input + "\"";
780         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
781         vlm_MessageDelete( message );
782
783         QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
784         for( int i = 0; i < options.count(); i++ )
785         {
786             command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
787             vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
788             vlm_MessageDelete( message );
789         }
790     }
791
792     if( !output.isEmpty() )
793     {
794         command = "setup \"" + name + "\" output \"" + output + "\"";
795         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
796         vlm_MessageDelete( message );
797     }
798
799     if( b_enabled )
800     {
801         command = "setup \"" + name + "\" enabled";
802         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
803         vlm_MessageDelete( message );
804     }
805     if( !mux.isEmpty() )
806     {
807         command = "setup \"" + name + "\" mux \"" + mux + "\"";
808         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
809         vlm_MessageDelete( message );
810     }
811 }
812
813 void VLMWrapper::AddSchedule( const QString& name, const QString& input,
814                               const QString& inputOptions, const QString& output,
815                               QDateTime _schetime, QDateTime _schedate,
816                               int _scherepeatnumber, int _repeatDays,
817                               bool b_enabled, const QString& mux )
818 {
819     vlm_message_t *message;
820     QString command = "new \"" + name + "\" schedule";
821     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
822     vlm_MessageDelete( message );
823     EditSchedule(  name, input, inputOptions, output, _schetime, _schedate,
824             _scherepeatnumber, _repeatDays, b_enabled, mux );
825 }
826
827 void VLMWrapper::EditSchedule( const QString& name, const QString& input,
828                                const QString& inputOptions, const QString& output,
829                                QDateTime _schetime, QDateTime _schedate,
830                                int _scherepeatnumber, int _repeatDays,
831                                bool b_enabled, const QString& mux )
832 {
833     vlm_message_t *message;
834     QString command;
835
836     if( !input.isEmpty() )
837     {
838         command = "setup \"" + name + "\" input \"" + input + "\"";
839         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
840         vlm_MessageDelete( message );
841
842         QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
843         for( int i = 0; i < options.count(); i++ )
844         {
845             command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
846             vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
847             vlm_MessageDelete( message );
848         }
849     }
850
851     if( !output.isEmpty() )
852     {
853         command = "setup \"" + name + "\" output \"" + output + "\"";
854         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
855         vlm_MessageDelete( message );
856     }
857
858     if( b_enabled )
859     {
860         command = "setup \"" + name + "\" enabled";
861         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
862         vlm_MessageDelete( message );
863     }
864
865     if( !mux.isEmpty() )
866     {
867         command = "setup \"" + name + "\" mux \"" + mux + "\"";
868         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
869         vlm_MessageDelete( message );
870     }
871
872     command = "setup \"" + name + "\" date \"" +
873         _schedate.toString( "yyyy/MM/dd" )+ "-" +
874         _schetime.toString( "hh:mm:ss" ) + "\"";
875     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
876     vlm_MessageDelete( message );
877
878     if( _scherepeatnumber > 0 )
879     {
880        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
881        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
882        vlm_MessageDelete( message );
883     }
884
885     if( _repeatDays > 0 )
886     {
887        command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
888        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
889        vlm_MessageDelete( message );
890     }
891 }
892
893 void VLMDialog::toggleVisible()
894 {
895     QList<VLMAWidget *>::iterator it;
896     for( it = vlmItems.begin(); it != vlmItems.end(); ++it )
897     {
898         VLMAWidget *item =  *it;
899         delete item;
900         item = NULL;
901     }
902     vlmItems.clear();
903     ui.vlmListItem->clear();
904     mediasPopulator();
905     QVLCDialog::toggleVisible();
906 }
907
908
909 #endif