1 /*****************************************************************************
2 * vlm.cpp : VLM Management
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
5 * $Id: sout.cpp 21875 2007-09-08 16:01:33Z jb $
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>
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.
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.
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 *****************************************************************************/
29 #include "dialogs/vlm.hpp"
32 #include "dialogs/open.hpp"
33 #include "dialogs/sout.hpp"
37 #include <QVBoxLayout>
38 #include <QStackedWidget>
41 #include <QGridLayout>
44 #include <QToolButton>
46 #include <QPushButton>
47 #include <QHBoxLayout>
48 #include <QDateTimeEdit>
50 #include <QHeaderView>
51 #include <QScrollArea>
53 static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
55 VLMDialog *VLMDialog::instance = NULL;
57 VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
59 p_vlm = vlm_New( p_intf );
63 msg_Warn( p_intf, "Couldn't build VLM object ");
66 vlmWrapper = new VLMWrapper( p_vlm );
70 ui.saveButton->hide();
72 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
73 ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
74 ADDMEDIATYPES( "Schedule", QVLM_Schedule );
75 ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
79 QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
80 QLabel *schetimelabel = new QLabel( qtr( "Hours/Minutes/Seconds:" ) );
81 schetimelayout->addWidget( schetimelabel, 0, 0 );
82 QLabel *schedatelabel = new QLabel( qtr( "Day Month Year:" ) );
83 schetimelayout->addWidget( schedatelabel, 1, 0 );
84 QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
85 schetimelayout->addWidget( scherepeatLabel, 2, 0 );
86 QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
87 schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
89 time = new QDateTimeEdit( QTime::currentTime() );
90 time->setAlignment( Qt::AlignRight );
91 schetimelayout->addWidget( time, 0, 1, 1, 3 );
93 date = new QDateTimeEdit( QDate::currentDate() );
94 date->setAlignment( Qt::AlignRight );
95 date->setCalendarPopup( true );
97 date->setDisplayFormat( "dd MM yyyy" );
99 date->setDisplayFormat( "dd MMMM yyyy" );
101 schetimelayout->addWidget( date, 1, 1, 1, 3 );
103 scherepeatnumber = new QSpinBox;
104 scherepeatnumber->setAlignment( Qt::AlignRight );
105 schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
107 repeatDays = new QSpinBox;
108 repeatDays->setAlignment( Qt::AlignRight );
109 schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
110 repeatDays->setSuffix( qtr(" days") );
112 repeatTime = new QDateTimeEdit;
113 repeatTime->setAlignment( Qt::AlignRight );
114 schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
115 repeatTime->setDisplayFormat( "hh:mm:ss" );
118 ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
119 ui.vlmItemScroll->setWidgetResizable( true );
120 vlmItemWidget = new QWidget;
121 vlmItemLayout = new QVBoxLayout( vlmItemWidget );
122 vlmItemWidget->setLayout( vlmItemLayout );
123 ui.vlmItemScroll->setWidget( vlmItemWidget );
125 QSpacerItem *spacer =
126 new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
127 vlmItemLayout->addItem( spacer );
129 QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
130 ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
132 showScheduleWidget( QVLM_Broadcast );
134 /* Connect the comboBox to show the right Widgets */
135 CONNECT( ui.mediaType, currentIndexChanged( int ),
136 this, showScheduleWidget( int ) );
138 /* Connect the leftList to show the good VLMItem */
139 CONNECT( ui.vlmListItem, currentRowChanged( int ),
140 this, selectVLMItem( int ) );
142 BUTTONACT( closeButton, close() );
143 BUTTONACT( ui.addButton, addVLMItem() );
144 BUTTONACT( ui.clearButton, clearWidgets() );
145 BUTTONACT( ui.saveButton, saveModifications() );
146 BUTTONACT( ui.inputButton, selectInput() );
147 BUTTONACT( ui.outputButton, selectOutput() );
150 VLMDialog::~VLMDialog()
152 /* FIXME :you have to destroy vlm here to close
153 * but we shouldn't destroy vlm here in case somebody else wants it */
158 void VLMDialog::showScheduleWidget( int i )
160 ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
161 ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
162 ui.vodBox->setVisible( ( i == QVLM_VOD ) );
165 void VLMDialog::selectVLMItem( int i )
168 ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
171 bool VLMDialog::isNameGenuine( QString name )
173 for( int i = 0; i < vlmItems.size(); i++ )
175 if( vlmItems.at( i )->name == name )
181 void VLMDialog::addVLMItem()
183 int vlmItemCount = vlmItems.size();
185 /* Take the name and Check it */
186 QString name = ui.nameLedit->text();
187 if( name.isEmpty() || !isNameGenuine( name ) )
189 msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
193 int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
195 QString typeShortName;
196 QString inputText = ui.inputLedit->text();
197 QString outputText = ui.outputLedit->text();
198 bool b_checked = ui.enableCheck->isChecked();
199 bool b_looped = ui.loopBCast->isChecked();
201 VLMAWidget * vlmAwidget;
206 typeShortName = "Bcast";
207 vlmAwidget = new VLMBroadcast( name, inputText, outputText,
208 b_checked, b_looped, this );
209 VLMWrapper::AddBroadcast( name, inputText, outputText, b_checked, b_looped );
212 typeShortName = "VOD";
213 vlmAwidget = new VLMVod( name, inputText, outputText,
214 b_checked, ui.muxLedit->text(), this );
215 VLMWrapper::AddVod( name, inputText, outputText, b_checked );
218 typeShortName = "Sched";
219 vlmAwidget = new VLMSchedule( name, inputText, outputText,
223 msg_Warn( p_intf, "Something bad happened" );
227 /* Add an Item of the Side List */
228 ui.vlmListItem->addItem( typeShortName + " : " + name );
229 ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
231 /* Add a new VLMAWidget on the main List */
233 vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
234 vlmItems.append( vlmAwidget );
238 void VLMDialog::clearWidgets()
240 ui.nameLedit->clear();
241 ui.inputLedit->clear();
242 ui.outputLedit->clear();
243 time->setTime( QTime::currentTime() );
244 date->setDate( QDate::currentDate() );
245 ui.enableCheck->setChecked( true );
246 ui.nameLedit->setReadOnly( false );
247 ui.loopBCast->setChecked( false );
248 ui.muxLedit->clear();
249 ui.saveButton->hide();
250 ui.addButton->show();
253 void VLMDialog::selectInput()
255 OpenDialog *o = OpenDialog::getInstance( this, p_intf, 0, true );
257 ui.inputLedit->setText( o->getMRL() );
260 void VLMDialog::selectOutput()
262 SoutDialog *s = SoutDialog::getInstance( this, p_intf, false );
263 if( s->exec() == QDialog::Accepted )
264 ui.outputLedit->setText( s->getMrl() );
267 /* Object Modification */
268 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
270 int index = vlmItems.indexOf( vlmObj );
271 if( index < 0 ) return;
273 delete ui.vlmListItem->takeItem( index );
274 vlmItems.removeAt( index );
277 /* HERE BE DRAGONS VLM REQUEST */
280 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
282 currentIndex = vlmItems.indexOf( vlmObj );
283 if( currentIndex < 0 ) return;
285 msg_Dbg( p_intf, "Type: %i", vlmObj->type );
286 ui.vlmListItem->setCurrentRow( currentIndex );
287 ui.nameLedit->setText( vlmObj->name );
288 ui.inputLedit->setText( vlmObj->input );
289 ui.outputLedit->setText( vlmObj->output );
290 ui.enableCheck->setChecked( vlmObj->b_enabled );
292 switch( vlmObj->type )
295 ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
298 ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
301 //(qobject_cast<VLMSchedule *>)
305 ui.nameLedit->setReadOnly( true );
306 ui.addButton->hide();
307 ui.saveButton->show();
310 void VLMDialog::saveModifications()
312 VLMAWidget *vlmObj = vlmItems.at( currentIndex );
315 vlmObj->input = ui.inputLedit->text();
316 vlmObj->output = ui.outputLedit->text();
317 vlmObj->setChecked( ui.enableCheck->isChecked() );
318 vlmObj->b_enabled = ui.enableCheck->isChecked();
319 switch( vlmObj->type )
322 (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
325 (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
331 vlmObj->update(); /* It should call the correct function is VLMAWidget
332 is abstract, but I am far from sure... FIXME ? */
337 /*********************************
338 * VLMAWidget - Abstract class
339 ********************************/
341 VLMAWidget::VLMAWidget( QString _name,
347 : QGroupBox( _name, _parent )
353 b_enabled = _enabled;
356 setCheckable( true );
357 setChecked( b_enabled );
359 objLayout = new QGridLayout( this );
360 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
362 nameLabel = new QLabel;
363 objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
365 /*QLabel *time = new QLabel( "--:--/--:--" );
366 objLayout->addWidget( time, 1, 3, 1, 2 );*/
368 QToolButton *modifyButton = new QToolButton;
369 modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
370 objLayout->addWidget( modifyButton, 0, 5 );
372 QToolButton *deleteButton = new QToolButton;
373 deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
374 objLayout->addWidget( deleteButton, 0, 6 );
376 BUTTONACT( modifyButton, modify() );
377 BUTTONACT( deleteButton, del() );
378 CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
381 void VLMAWidget::modify()
383 parent->startModifyVLMItem( this );
386 void VLMAWidget::del()
388 parent->removeVLMItem( this );
391 //FIXME, remove me before release
392 void VLMAWidget::enterEvent( QEvent *event )
397 void VLMAWidget::toggleEnabled( bool b_enable )
399 VLMWrapper::EnableItem( name, b_enable );
405 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
406 bool _enabled, bool _looped, VLMDialog *_parent)
407 : VLMAWidget( _name, _input, _output,
408 _enabled, _parent, QVLM_Broadcast )
410 nameLabel->setText( "Broadcast: " + name );
411 type = QVLM_Broadcast;
414 playButton = new QToolButton;
415 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
416 objLayout->addWidget( playButton, 1, 0 );
419 QToolButton *stopButton = new QToolButton;
420 stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
421 objLayout->addWidget( stopButton, 1, 1 );
423 loopButton = new QToolButton;
424 objLayout->addWidget( loopButton, 1, 2 );
426 BUTTONACT( playButton, togglePlayPause() );
427 BUTTONACT( stopButton, stop() );
428 BUTTONACT( loopButton, toggleLoop() );
433 void VLMBroadcast::update()
435 VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
437 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_all.png" ) ) );
439 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
442 void VLMBroadcast::togglePlayPause()
444 if( b_playing = true )
446 VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
447 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/pause_16px.png" ) ) );
451 VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
452 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
454 b_playing = !b_playing;
457 void VLMBroadcast::toggleLoop()
459 b_enabled = !b_enabled;
463 void VLMBroadcast::stop()
465 VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
466 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
472 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
473 bool enabled, VLMDialog *parent)
474 : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
476 nameLabel->setText( "Schedule: " + name );
479 void VLMSchedule::update()
486 VLMVod::VLMVod( QString name, QString input, QString output,
487 bool enabled, QString _mux, VLMDialog *parent)
488 : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
490 nameLabel->setText( "VOD:" + name );
493 muxLabel = new QLabel;
494 objLayout->addWidget( muxLabel, 1, 0 );
499 void VLMVod::update()
501 muxLabel->setText( mux );
502 VLMWrapper::EditVod( name, input, output, b_enabled, mux );
509 vlm_t * VLMWrapper::p_vlm = NULL;
511 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
516 VLMWrapper::~VLMWrapper()
519 void VLMWrapper::AddBroadcast( const QString name, QString input,
521 bool b_enabled, bool b_loop )
523 vlm_message_t *message;
524 QString command = "new \"" + name + "\" broadcast";
525 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
526 vlm_MessageDelete( message );
527 EditBroadcast( name, input, output, b_enabled, b_loop );
530 void VLMWrapper::EditBroadcast( const QString name, const QString input,
531 const QString output,
532 bool b_enabled, bool b_loop )
534 vlm_message_t *message;
537 command = "setup \"" + name + "\" inputdel all";
538 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
539 vlm_MessageDelete( message );
540 command = "setup \"" + name + "\" input \"" + input + "\"";
541 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
542 vlm_MessageDelete( message );
543 if( !output.isEmpty() )
545 command = "setup \"" + name + "\" output \"" + output + "\"";
546 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
547 vlm_MessageDelete( message );
551 command = "setup \"" + name + "\" enabled";
552 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
553 vlm_MessageDelete( message );
557 command = "setup \"" + name + "\" loop";
558 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
559 vlm_MessageDelete( message );
563 void VLMWrapper::EnableItem( const QString name, bool b_enable )
565 vlm_message_t *message;
566 QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
569 void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
572 vlm_message_t *message;
574 QString command = "control \"" + name;
575 switch( BroadcastStatus )
577 case ControlBroadcastPlay:
580 case ControlBroadcastPause:
583 case ControlBroadcastStop:
586 case ControlBroadcastSeek:
587 command += " seek" + seek;
590 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
591 vlm_MessageDelete( message );
594 void VLMWrapper::AddVod( const QString name, const QString input,
595 const QString output,
596 bool b_enabled, const QString mux )
598 vlm_message_t *message;
599 QString command = "new \"" + name + "\" vod";
600 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
601 vlm_MessageDelete( message );
602 EditVod( name, input, output, b_enabled, mux );
605 void VLMWrapper::EditVod( const QString name, const QString input,
606 const QString output,
610 vlm_message_t *message;
611 QString command = "setup \"" + name + "\" input \"" + input + "\"";
612 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
613 vlm_MessageDelete( message );
614 if( !output.isEmpty() )
616 command = "setup \"" + name + "\" output \"" + output + "\"";
617 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
618 vlm_MessageDelete( message );
622 command = "setup \"" + name + "\" enabled";
623 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
624 vlm_MessageDelete( message );
628 command = "setup \"" + name + "\" mux \"" + mux + "\"";
629 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
630 vlm_MessageDelete( message );