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