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