]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
qt4_vlm: remove double call to VLMWrapper::Edit* functions (already called by the...
[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, outputText,
229                                        b_checked, b_looped, this );
230     break;
231     case QVLM_VOD:
232         typeShortName = "VOD";
233         vlmAwidget = new VLMVod( name, inputText, outputText,
234                                  b_checked, ui.muxLedit->text(), this );
235         break;
236     case QVLM_Schedule:
237         typeShortName = "Sched";
238         vlmAwidget = new VLMSchedule( name, inputText, outputText,
239                                       schetime, schedate, repeatnum,
240                                       repeatdays, b_checked, this );
241         break;
242     default:
243         msg_Warn( p_intf, "Something bad happened" );
244         return;
245     }
246
247     /* Add an Item of the Side List */
248     ui.vlmListItem->addItem( typeShortName + " : " + name );
249     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
250
251     /* Add a new VLMAWidget on the main List */
252
253     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
254     vlmItems.append( vlmAwidget );
255     clearWidgets();
256 }
257
258 /* TODO : VOD are not exported to the file */
259 bool VLMDialog::exportVLMConf()
260 {
261     QString saveVLMConfFileName = QFileDialog::getSaveFileName( this,
262                                         qtr( "Save VLM configuration as..." ),
263                                         QVLCUserDir( VLC_DOCUMENTS_DIR ),
264                                         qtr( "VLM conf (*.vlm);;All (*)" ) );
265
266     if( !saveVLMConfFileName.isEmpty() )
267     {
268         vlm_message_t *message;
269         QString command = "save \"" + saveVLMConfFileName + "\"";
270         vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
271         vlm_MessageDelete( message );
272         return true;
273     }
274
275     return false;
276 }
277
278 void VLMDialog::mediasPopulator()
279 {
280     if( p_vlm )
281     {
282         int i_nMedias;
283         QString typeShortName;
284         int vlmItemCount;
285         vlm_media_t ***ppp_dsc = (vlm_media_t ***)malloc( sizeof( vlm_media_t ) );
286
287         /* Get medias informations and numbers */
288         vlm_Control( p_vlm, VLM_GET_MEDIAS, ppp_dsc, &i_nMedias );
289
290         /* Loop on all of them */
291         for( int i = 0; i < i_nMedias; i++ )
292         {
293             VLMAWidget * vlmAwidget;
294             vlmItemCount = vlmItems.size();
295
296             QString mediaName = qfu( (*ppp_dsc)[i]->psz_name );
297             /* It may have several inputs, we take the first one by default
298                  - an evolution will be to manage these inputs in the gui */
299             QString inputText = qfu( (*ppp_dsc)[i]->ppsz_input[0] );
300
301             QString outputText = qfu( (*ppp_dsc)[i]->psz_output );
302
303             /* Schedule media is a quite especial, maybe there is another way to grab informations */
304             if( (*ppp_dsc)[i]->b_vod )
305             {
306                 typeShortName = "VOD";
307                 QString mux = qfu( (*ppp_dsc)[i]->vod.psz_mux );
308                 vlmAwidget = new VLMVod( mediaName, inputText, outputText,
309                                     (*ppp_dsc)[i]->b_enabled, mux, this );
310             }
311             else
312             {
313                 typeShortName = "Bcast";
314                 vlmAwidget = new VLMBroadcast( mediaName, inputText, outputText,
315                                   (*ppp_dsc)[i]->b_enabled, (*ppp_dsc)[i]->broadcast.b_loop, this );
316             }
317             /* Add an Item of the Side List */
318             ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
319             ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
320
321             /* Add a new VLMAWidget on the main List */
322             vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
323             vlmItems.append( vlmAwidget );
324             clearWidgets();
325         }
326         free( ppp_dsc );
327     }
328 }
329
330 bool VLMDialog::importVLMConf()
331 {
332     QString openVLMConfFileName = toNativeSeparators(
333             QFileDialog::getOpenFileName(
334             this, qtr( "Open VLM configuration..." ),
335             QVLCUserDir( VLC_DOCUMENTS_DIR ),
336             qtr( "VLM conf (*.vlm);;All (*)" ) ) );
337
338     if( !openVLMConfFileName.isEmpty() )
339     {
340         vlm_message_t *message;
341         int status;
342         QString command = "load \"" + openVLMConfFileName + "\"";
343         status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
344         vlm_MessageDelete( message );
345         if( status == 0 )
346         {
347             mediasPopulator();
348         }
349         else
350         {
351             msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
352             return false;
353         }
354         return true;
355     }
356     return false;
357 }
358
359 void VLMDialog::clearWidgets()
360 {
361     ui.nameLedit->clear();
362     ui.inputLedit->clear();
363     ui.outputLedit->clear();
364     time->setTime( QTime::currentTime() );
365     date->setDate( QDate::currentDate() );
366     ui.enableCheck->setChecked( true );
367     ui.nameLedit->setReadOnly( false );
368     ui.loopBCast->setChecked( false );
369     ui.muxLedit->clear();
370     ui.saveButton->hide();
371     ui.addButton->show();
372 }
373
374 void VLMDialog::selectInput()
375 {
376     OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
377     o->exec();
378     ui.inputLedit->setText( o->getMRL() );
379 }
380
381 void VLMDialog::selectOutput()
382 {
383     SoutDialog *s = new SoutDialog( this, p_intf );
384     if( s->exec() == QDialog::Accepted )
385         ui.outputLedit->setText( s->getMrl() );
386 }
387
388 /* Object Modification */
389 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
390 {
391     int index = vlmItems.indexOf( vlmObj );
392     if( index < 0 ) return;
393     delete ui.vlmListItem->takeItem( index );
394     vlmItems.removeAt( index );
395     delete vlmObj;
396
397     /* HERE BE DRAGONS VLM REQUEST */
398 }
399
400 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
401 {
402     currentIndex = vlmItems.indexOf( vlmObj );
403     if( currentIndex < 0 ) return;
404
405     ui.vlmListItem->setCurrentRow( currentIndex );
406     ui.nameLedit->setText( vlmObj->name );
407     ui.inputLedit->setText( vlmObj->input );
408     ui.outputLedit->setText( vlmObj->output );
409     ui.enableCheck->setChecked( vlmObj->b_enabled );
410
411     switch( vlmObj->type )
412     {
413     case QVLM_Broadcast:
414         ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
415         break;
416     case QVLM_VOD:
417         ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
418         break;
419     case QVLM_Schedule:
420         time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
421         date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
422         break;
423     }
424
425     ui.nameLedit->setReadOnly( true );
426     ui.addButton->hide();
427     ui.saveButton->show();
428 }
429
430 void VLMDialog::saveModifications()
431 {
432     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
433     if( vlmObj )
434     {
435         vlmObj->input = ui.inputLedit->text();
436         vlmObj->output = ui.outputLedit->text().remove( ":sout=" );
437         vlmObj->setChecked( ui.enableCheck->isChecked() );
438         vlmObj->b_enabled = ui.enableCheck->isChecked();
439         switch( vlmObj->type )
440         {
441         case QVLM_Broadcast:
442             (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
443             break;
444         case QVLM_VOD:
445             (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
446             break;
447         case QVLM_Schedule:
448             (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
449             (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
450             (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
451             (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
452             break;
453            //           vlmObj->
454         }
455         vlmObj->update();
456     }
457     clearWidgets();
458 }
459
460 /*********************************
461  * VLMAWidget - Abstract class
462  ********************************/
463
464 VLMAWidget::VLMAWidget( const QString& _name,
465                         const QString& _input,
466                         const QString& _output,
467                         bool _enabled,
468                         VLMDialog *_parent,
469                         int _type )
470                       : QGroupBox( _name, _parent )
471 {
472     parent = _parent;
473     name = _name;
474     input = _input;
475     output = _output;
476     b_enabled = _enabled;
477     type = _type;
478
479     setCheckable( true );
480     setChecked( b_enabled );
481
482     objLayout = new QGridLayout( this );
483     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
484
485     nameLabel = new QLabel;
486     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
487
488     /*QLabel *time = new QLabel( "--:--/--:--" );
489     objLayout->addWidget( time, 1, 3, 1, 2 );*/
490
491     QToolButton *modifyButton = new QToolButton;
492     modifyButton->setIcon( QIcon( ":/menu/settings" ) );
493     objLayout->addWidget( modifyButton, 0, 5 );
494
495     QToolButton *deleteButton = new QToolButton;
496     deleteButton->setIcon( QIcon( ":/menu/quit" ) );
497     objLayout->addWidget( deleteButton, 0, 6 );
498
499     BUTTONACT( modifyButton, modify() );
500     BUTTONACT( deleteButton, del() );
501     CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
502 }
503
504 void VLMAWidget::modify()
505 {
506     parent->startModifyVLMItem( this );
507 }
508
509 void VLMAWidget::del()
510 {
511     parent->removeVLMItem( this );
512 }
513
514 void VLMAWidget::toggleEnabled( bool b_enable )
515 {
516     VLMWrapper::EnableItem( name, b_enable );
517 }
518
519 /****************
520  * VLMBroadcast
521  ****************/
522 VLMBroadcast::VLMBroadcast( const QString& _name, const QString& _input,
523                             const QString& _output, bool _enabled,
524                             bool _looped, VLMDialog *_parent )
525                           : VLMAWidget( _name, _input, _output,
526                                         _enabled, _parent, QVLM_Broadcast )
527 {
528     nameLabel->setText( qtr("Broadcast: ") + name );
529     type = QVLM_Broadcast;
530     b_looped = _looped;
531
532     playButton = new QToolButton;
533     playButton->setIcon( QIcon( ":/menu/play" ) );
534     objLayout->addWidget( playButton, 1, 0 );
535     b_playing = true;
536
537     QToolButton *stopButton = new QToolButton;
538     stopButton->setIcon( QIcon( ":/toolbar/stop_b" ) );
539     objLayout->addWidget( stopButton, 1, 1 );
540
541     loopButton = new QToolButton;
542     objLayout->addWidget( loopButton, 1, 2 );
543
544     BUTTONACT( playButton, togglePlayPause() );
545     BUTTONACT( stopButton, stop() );
546     BUTTONACT( loopButton, toggleLoop() );
547
548     update();
549 }
550
551 void VLMBroadcast::update()
552 {
553     VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
554     if( b_looped )
555         loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
556     else
557         loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_off" ) );
558 }
559
560 void VLMBroadcast::togglePlayPause()
561 {
562     if( b_playing )
563     {
564         VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
565         playButton->setIcon( QIcon( ":/menu/pause" ) );
566     }
567     else
568     {
569         VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
570         playButton->setIcon( QIcon( ":/menu/play" ) );
571     }
572     b_playing = !b_playing;
573 }
574
575 void VLMBroadcast::toggleLoop()
576 {
577     b_enabled = !b_enabled;
578     update();
579 }
580
581 void VLMBroadcast::stop()
582 {
583     VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
584     playButton->setIcon( QIcon( ":/menu/play" ) );
585 }
586
587 /****************
588  * VLMSchedule
589  ****************/
590 VLMSchedule::VLMSchedule( const QString& name, const QString& input,
591                           const QString& output, QDateTime _schetime,
592                           QDateTime _schedate, int _scherepeatnumber,
593                           int _repeatDays, bool enabled, VLMDialog *parent )
594             : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
595 {
596     nameLabel->setText( qtr("Schedule: ") + name );
597     schetime = _schetime;
598     schedate = _schedate;
599     rNumber = _scherepeatnumber;
600     rDays = _repeatDays;
601     type = QVLM_Schedule;
602     update();
603 }
604
605 void VLMSchedule::update()
606 {
607    VLMWrapper::EditSchedule( name, input, output, schetime, schedate,
608                              rNumber, rDays, b_enabled);
609 }
610
611 /****************
612  * VLMVOD
613  ****************/
614 VLMVod::VLMVod( const QString& name, const QString& input, const QString& output,
615                 bool enabled, const QString& _mux, VLMDialog *parent)
616        : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
617 {
618     nameLabel->setText( qtr("VOD: ") + name );
619
620     mux = _mux;
621     muxLabel = new QLabel;
622     objLayout->addWidget( muxLabel, 1, 0 );
623
624     update();
625 }
626
627 void VLMVod::update()
628 {
629     muxLabel->setText( mux );
630     VLMWrapper::EditVod( name, input, output, b_enabled, mux );
631 }
632
633
634 /*******************
635  * VLMWrapper
636  *******************/
637 vlm_t * VLMWrapper::p_vlm = NULL;
638
639 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
640 {
641     p_vlm = _p_vlm;
642 }
643
644 VLMWrapper::~VLMWrapper()
645 {
646     p_vlm = NULL;
647 }
648
649 void VLMWrapper::AddBroadcast( const QString& name, const QString& input,
650                                const QString& output,
651                                bool b_enabled, bool b_loop  )
652 {
653     vlm_message_t *message;
654     QString command = "new \"" + name + "\" broadcast";
655     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
656     vlm_MessageDelete( message );
657     EditBroadcast( name, input, output, b_enabled, b_loop );
658 }
659
660 void VLMWrapper::EditBroadcast( const QString& name, const QString& input,
661                                 const QString& output,
662                                 bool b_enabled, bool b_loop  )
663 {
664     vlm_message_t *message;
665     QString command;
666
667     command = "setup \"" + name + "\" inputdel all";
668     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
669     vlm_MessageDelete( message );
670     command = "setup \"" + name + "\" input \"" + input + "\"";
671     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
672     vlm_MessageDelete( message );
673     if( !output.isEmpty() )
674     {
675         command = "setup \"" + name + "\" output \"" + output + "\"";
676         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
677         vlm_MessageDelete( message );
678     }
679     if( b_enabled )
680     {
681         command = "setup \"" + name + "\" enabled";
682         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
683         vlm_MessageDelete( message );
684     }
685     if( b_loop )
686     {
687         command = "setup \"" + name + "\" loop";
688         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
689         vlm_MessageDelete( message );
690     }
691 }
692
693 void VLMWrapper::EnableItem( const QString& name, bool b_enable )
694 {
695     vlm_message_t *message;
696     QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
697     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
698     vlm_MessageDelete( message );
699 }
700
701 void VLMWrapper::ControlBroadcast( const QString& name, int BroadcastStatus,
702                                    unsigned int seek )
703 {
704     vlm_message_t *message;
705
706     QString command = "control \"" + name + "\"";
707     switch( BroadcastStatus )
708     {
709     case ControlBroadcastPlay:
710         command += " play";
711         break;
712     case ControlBroadcastPause:
713         command += " pause";
714         break;
715     case ControlBroadcastStop:
716         command += " stop";
717         break;
718     case ControlBroadcastSeek:
719         command += " seek" + seek;
720         break;
721     }
722     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
723     vlm_MessageDelete( message );
724 }
725
726 void VLMWrapper::AddVod( const QString& name, const QString& input,
727                          const QString& output,
728                          bool b_enabled, const QString& mux )
729 {
730     vlm_message_t *message;
731     QString command = "new \"" + name + "\" vod";
732     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
733     vlm_MessageDelete( message );
734     EditVod(  name, input, output, b_enabled, mux );
735 }
736
737 void VLMWrapper::EditVod( const QString& name, const QString& input,
738                           const QString& output,
739                           bool b_enabled,
740                           const QString& mux )
741 {
742     vlm_message_t *message;
743     QString command = "setup \"" + name + "\" input \"" + input + "\"";
744     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
745     vlm_MessageDelete( message );
746
747     if( !output.isEmpty() )
748     {
749         command = "setup \"" + name + "\" output \"" + output + "\"";
750         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
751         vlm_MessageDelete( message );
752     }
753
754     if( b_enabled )
755     {
756         command = "setup \"" + name + "\" enabled";
757         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
758         vlm_MessageDelete( message );
759     }
760     if( !mux.isEmpty() )
761     {
762         command = "setup \"" + name + "\" mux \"" + mux + "\"";
763         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
764         vlm_MessageDelete( message );
765     }
766 }
767
768 void VLMWrapper::AddSchedule( const QString& name, const QString& input,
769                               const QString& output, QDateTime _schetime,
770                               QDateTime _schedate,
771                               int _scherepeatnumber, int _repeatDays,
772                               bool b_enabled, const QString& mux )
773 {
774     vlm_message_t *message;
775     QString command = "new \"" + name + "\" schedule";
776     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
777     vlm_MessageDelete( message );
778     EditSchedule(  name, input, output, _schetime, _schedate,
779             _scherepeatnumber, _repeatDays, b_enabled, mux );
780 }
781
782 void VLMWrapper::EditSchedule( const QString& name, const QString& input,
783                                const QString& output, QDateTime _schetime,
784                                QDateTime _schedate, int _scherepeatnumber,
785                                int _repeatDays, bool b_enabled,
786                                const QString& mux )
787 {
788     vlm_message_t *message;
789     QString command = "setup \"" + name + "\" input \"" + input + "\"";
790     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
791     vlm_MessageDelete( message );
792
793     if( !output.isEmpty() )
794     {
795         command = "setup \"" + name + "\" output \"" + output + "\"";
796         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
797         vlm_MessageDelete( message );
798     }
799
800     if( b_enabled )
801     {
802         command = "setup \"" + name + "\" enabled";
803         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
804         vlm_MessageDelete( message );
805     }
806
807     if( !mux.isEmpty() )
808     {
809         command = "setup \"" + name + "\" mux \"" + mux + "\"";
810         vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
811         vlm_MessageDelete( message );
812     }
813
814     command = "setup \"" + name + "\" date \"" +
815         _schedate.toString( "yyyy/MM/dd" )+ "-" +
816         _schetime.toString( "hh:mm:ss" ) + "\"";
817     vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
818     vlm_MessageDelete( message );
819
820     if( _scherepeatnumber > 0 )
821     {
822        command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
823        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
824        vlm_MessageDelete( message );
825     }
826
827     if( _repeatDays > 0 )
828     {
829        command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
830        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
831        vlm_MessageDelete( message );
832     }
833 }
834
835 void VLMDialog::toggleVisible()
836 {
837     QList<VLMAWidget *>::iterator it;
838     for( it = vlmItems.begin(); it != vlmItems.end(); it++ )
839     {
840         VLMAWidget *item =  *it;
841         delete item;
842         item = NULL;
843     }
844     vlmItems.clear();
845     ui.vlmListItem->clear();
846     mediasPopulator();
847     QVLCDialog::toggleVisible();
848 }
849
850
851 #endif