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