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