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 *****************************************************************************/
26 #include "dialogs/vlm.hpp"
29 #include "dialogs/open.hpp"
30 #include "dialogs/sout.hpp"
34 #include <QVBoxLayout>
35 #include <QStackedWidget>
38 #include <QGridLayout>
41 #include <QToolButton>
43 #include <QPushButton>
44 #include <QHBoxLayout>
45 #include <QDateTimeEdit>
47 #include <QHeaderView>
48 #include <QScrollArea>
50 static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
52 VLMDialog *VLMDialog::instance = NULL;
54 VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
56 p_vlm = vlm_New( p_intf );
60 msg_Warn( p_intf, "Couldn't build VLM object ");
63 vlmWrapper = new VLMWrapper( p_vlm );
67 ui.saveButton->hide();
69 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
70 ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
71 ADDMEDIATYPES( "Schedule", QVLM_Schedule );
72 ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
76 QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
77 QLabel *schetimelabel = new QLabel( qtr( "Hours/Minutes/Seconds:" ) );
78 schetimelayout->addWidget( schetimelabel, 0, 0 );
79 QLabel *schedatelabel = new QLabel( qtr( "Day Month Year:" ) );
80 schetimelayout->addWidget( schedatelabel, 1, 0 );
81 QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
82 schetimelayout->addWidget( scherepeatLabel, 2, 0 );
83 QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
84 schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
86 time = new QDateTimeEdit( QTime::currentTime() );
87 time->setAlignment( Qt::AlignRight );
88 schetimelayout->addWidget( time, 0, 1, 1, 3 );
90 date = new QDateTimeEdit( QDate::currentDate() );
91 date->setAlignment( Qt::AlignRight );
92 date->setCalendarPopup( true );
94 date->setDisplayFormat( "dd MM yyyy" );
96 date->setDisplayFormat( "dd MMMM yyyy" );
98 schetimelayout->addWidget( date, 1, 1, 1, 3 );
100 scherepeatnumber = new QSpinBox;
101 scherepeatnumber->setAlignment( Qt::AlignRight );
102 schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
104 repeatDays = new QSpinBox;
105 repeatDays->setAlignment( Qt::AlignRight );
106 schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
107 repeatDays->setSuffix( qtr(" days") );
109 repeatTime = new QDateTimeEdit;
110 repeatTime->setAlignment( Qt::AlignRight );
111 schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
112 repeatTime->setDisplayFormat( "hh:mm:ss" );
115 ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
116 ui.vlmItemScroll->setWidgetResizable( true );
117 vlmItemWidget = new QWidget;
118 vlmItemLayout = new QVBoxLayout( vlmItemWidget );
119 vlmItemWidget->setLayout( vlmItemLayout );
120 ui.vlmItemScroll->setWidget( vlmItemWidget );
122 QSpacerItem *spacer =
123 new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
124 vlmItemLayout->addItem( spacer );
126 QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
127 ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
129 showScheduleWidget( QVLM_Broadcast );
131 /* Connect the comboBox to show the right Widgets */
132 CONNECT( ui.mediaType, currentIndexChanged( int ),
133 this, showScheduleWidget( int ) );
135 /* Connect the leftList to show the good VLMItem */
136 CONNECT( ui.vlmListItem, currentRowChanged( int ),
137 this, selectVLMItem( int ) );
139 BUTTONACT( closeButton, close() );
140 BUTTONACT( ui.addButton, addVLMItem() );
141 BUTTONACT( ui.clearButton, clearWidgets() );
142 BUTTONACT( ui.saveButton, saveModifications() );
143 BUTTONACT( ui.inputButton, selectInput() );
144 BUTTONACT( ui.outputButton, selectOutput() );
147 VLMDialog::~VLMDialog()
149 /* FIXME :you have to destroy vlm here to close
150 * but we shouldn't destroy vlm here in case somebody else wants it */
155 void VLMDialog::showScheduleWidget( int i )
157 ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
158 ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
159 ui.vodBox->setVisible( ( i == QVLM_VOD ) );
162 void VLMDialog::selectVLMItem( int i )
165 ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
168 bool VLMDialog::isNameGenuine( QString name )
170 for( int i = 0; i < vlmItems.size(); i++ )
172 if( vlmItems.at( i )->name == name )
178 void VLMDialog::addVLMItem()
180 int vlmItemCount = vlmItems.size();
182 /* Take the name and Check it */
183 QString name = ui.nameLedit->text();
184 if( name.isEmpty() || !isNameGenuine( name ) )
186 msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
190 int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
192 QString typeShortName;
193 QString inputText = ui.inputLedit->text();
194 QString outputText = ui.outputLedit->text();
195 bool b_checked = ui.enableCheck->isChecked();
196 bool b_looped = ui.loopBCast->isChecked();
198 VLMAWidget * vlmAwidget;
203 typeShortName = "Bcast";
204 vlmAwidget = new VLMBroadcast( name, inputText, outputText,
205 b_checked, b_looped, this );
206 VLMWrapper::AddBroadcast( name, inputText, outputText, b_checked, b_looped );
209 typeShortName = "VOD";
210 vlmAwidget = new VLMVod( name, inputText, outputText,
211 b_checked, ui.muxLedit->text(), this );
212 VLMWrapper::AddVod( name, inputText, outputText, b_checked );
215 typeShortName = "Sched";
216 vlmAwidget = new VLMSchedule( name, inputText, outputText,
220 msg_Warn( p_intf, "Something bad happened" );
224 /* Add an Item of the Side List */
225 ui.vlmListItem->addItem( typeShortName + " : " + name );
226 ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
228 /* Add a new VLMAWidget on the main List */
230 vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
231 vlmItems.append( vlmAwidget );
235 void VLMDialog::clearWidgets()
237 ui.nameLedit->clear();
238 ui.inputLedit->clear();
239 ui.outputLedit->clear();
240 time->setTime( QTime::currentTime() );
241 date->setDate( QDate::currentDate() );
242 ui.enableCheck->setChecked( true );
243 ui.nameLedit->setReadOnly( false );
244 ui.loopBCast->setChecked( false );
245 ui.muxLedit->clear();
246 ui.saveButton->hide();
247 ui.addButton->show();
250 void VLMDialog::selectInput()
252 OpenDialog *o = OpenDialog::getInstance( this, p_intf, 0, true );
254 ui.inputLedit->setText( o->getMRL() );
257 void VLMDialog::selectOutput()
259 SoutDialog *s = SoutDialog::getInstance( this, p_intf, false );
260 if( s->exec() == QDialog::Accepted )
261 ui.outputLedit->setText( s->getMrl() );
264 /* Object Modification */
265 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
267 int index = vlmItems.indexOf( vlmObj );
268 if( index < 0 ) return;
270 delete ui.vlmListItem->takeItem( index );
271 vlmItems.removeAt( index );
274 /* HERE BE DRAGONS VLM REQUEST */
277 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
279 currentIndex = vlmItems.indexOf( vlmObj );
280 if( currentIndex < 0 ) return;
282 msg_Dbg( p_intf, "Type: %i", vlmObj->type );
283 ui.vlmListItem->setCurrentRow( currentIndex );
284 ui.nameLedit->setText( vlmObj->name );
285 ui.inputLedit->setText( vlmObj->input );
286 ui.outputLedit->setText( vlmObj->output );
287 ui.enableCheck->setChecked( vlmObj->b_enabled );
289 switch( vlmObj->type )
292 ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
295 ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
298 //(qobject_cast<VLMSchedule *>)
302 ui.nameLedit->setReadOnly( true );
303 ui.addButton->hide();
304 ui.saveButton->show();
307 void VLMDialog::saveModifications()
309 VLMAWidget *vlmObj = vlmItems.at( currentIndex );
312 vlmObj->input = ui.inputLedit->text();
313 vlmObj->output = ui.outputLedit->text();
314 vlmObj->setChecked( ui.enableCheck->isChecked() );
315 vlmObj->b_enabled = ui.enableCheck->isChecked();
316 switch( vlmObj->type )
319 (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
322 (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
328 vlmObj->update(); /* It should call the correct function is VLMAWidget
329 is abstract, but I am far from sure... FIXME ? */
334 /*********************************
335 * VLMAWidget - Abstract class
336 ********************************/
338 VLMAWidget::VLMAWidget( QString _name,
344 : QGroupBox( _name, _parent )
350 b_enabled = _enabled;
353 setCheckable( true );
354 setChecked( b_enabled );
356 objLayout = new QGridLayout( this );
357 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
359 nameLabel = new QLabel;
360 objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
362 /*QLabel *time = new QLabel( "--:--/--:--" );
363 objLayout->addWidget( time, 1, 3, 1, 2 );*/
365 QToolButton *modifyButton = new QToolButton;
366 modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
367 objLayout->addWidget( modifyButton, 0, 5 );
369 QToolButton *deleteButton = new QToolButton;
370 deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
371 objLayout->addWidget( deleteButton, 0, 6 );
373 BUTTONACT( modifyButton, modify() );
374 BUTTONACT( deleteButton, del() );
375 CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
378 void VLMAWidget::modify()
380 parent->startModifyVLMItem( this );
383 void VLMAWidget::del()
385 parent->removeVLMItem( this );
388 //FIXME, remove me before release
389 void VLMAWidget::enterEvent( QEvent *event )
394 void VLMAWidget::toggleEnabled( bool b_enable )
396 VLMWrapper::EnableItem( name, b_enable );
402 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
403 bool _enabled, bool _looped, VLMDialog *_parent)
404 : VLMAWidget( _name, _input, _output,
405 _enabled, _parent, QVLM_Broadcast )
407 nameLabel->setText( "Broadcast: " + name );
408 type = QVLM_Broadcast;
411 playButton = new QToolButton;
412 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
413 objLayout->addWidget( playButton, 1, 0 );
416 QToolButton *stopButton = new QToolButton;
417 stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
418 objLayout->addWidget( stopButton, 1, 1 );
420 loopButton = new QToolButton;
421 objLayout->addWidget( loopButton, 1, 2 );
423 BUTTONACT( playButton, togglePlayPause() );
424 BUTTONACT( stopButton, stop() );
425 BUTTONACT( loopButton, toggleLoop() );
430 void VLMBroadcast::update()
432 VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
434 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_all.png" ) ) );
436 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
439 void VLMBroadcast::togglePlayPause()
441 if( b_playing = true )
443 VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
444 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/pause_16px.png" ) ) );
448 VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
449 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
451 b_playing = !b_playing;
454 void VLMBroadcast::toggleLoop()
456 b_enabled = !b_enabled;
460 void VLMBroadcast::stop()
462 VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
463 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
469 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
470 bool enabled, VLMDialog *parent)
471 : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
473 nameLabel->setText( "Schedule: " + name );
476 void VLMSchedule::update()
483 VLMVod::VLMVod( QString name, QString input, QString output,
484 bool enabled, QString _mux, VLMDialog *parent)
485 : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
487 nameLabel->setText( "VOD:" + name );
490 muxLabel = new QLabel;
491 objLayout->addWidget( muxLabel, 1, 0 );
496 void VLMVod::update()
498 muxLabel->setText( mux );
499 VLMWrapper::EditVod( name, input, output, b_enabled, mux );
506 vlm_t * VLMWrapper::p_vlm = NULL;
508 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
513 VLMWrapper::~VLMWrapper()
516 void VLMWrapper::AddBroadcast( const QString name, QString input,
518 bool b_enabled, bool b_loop )
520 vlm_message_t *message;
521 QString command = "new \"" + name + "\" broadcast";
522 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
523 vlm_MessageDelete( message );
524 EditBroadcast( name, input, output, b_enabled, b_loop );
527 void VLMWrapper::EditBroadcast( const QString name, const QString input,
528 const QString output,
529 bool b_enabled, bool b_loop )
531 vlm_message_t *message;
534 command = "setup \"" + name + "\" inputdel all";
535 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
536 vlm_MessageDelete( message );
537 command = "setup \"" + name + "\" input \"" + input + "\"";
538 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
539 vlm_MessageDelete( message );
540 if( !output.isEmpty() )
542 command = "setup \"" + name + "\" output \"" + output + "\"";
543 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
544 vlm_MessageDelete( message );
548 command = "setup \"" + name + "\" enabled";
549 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
550 vlm_MessageDelete( message );
554 command = "setup \"" + name + "\" loop";
555 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
556 vlm_MessageDelete( message );
560 void VLMWrapper::EnableItem( const QString name, bool b_enable )
562 vlm_message_t *message;
563 QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
566 void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
569 vlm_message_t *message;
571 QString command = "control \"" + name;
572 switch( BroadcastStatus )
574 case ControlBroadcastPlay:
577 case ControlBroadcastPause:
580 case ControlBroadcastStop:
583 case ControlBroadcastSeek:
584 command += " seek" + seek;
587 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
588 vlm_MessageDelete( message );
591 void VLMWrapper::AddVod( const QString name, const QString input,
592 const QString output,
593 bool b_enabled, const QString mux )
595 vlm_message_t *message;
596 QString command = "new \"" + name + "\" vod";
597 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
598 vlm_MessageDelete( message );
599 EditVod( name, input, output, b_enabled, mux );
602 void VLMWrapper::EditVod( const QString name, const QString input,
603 const QString output,
607 vlm_message_t *message;
608 QString command = "setup \"" + name + "\" input \"" + input + "\"";
609 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
610 vlm_MessageDelete( message );
611 if( !output.isEmpty() )
613 command = "setup \"" + name + "\" output \"" + output + "\"";
614 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
615 vlm_MessageDelete( message );
619 command = "setup \"" + name + "\" enabled";
620 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
621 vlm_MessageDelete( message );
625 command = "setup \"" + name + "\" mux \"" + mux + "\"";
626 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
627 vlm_MessageDelete( message );