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>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "dialogs/vlm.hpp"
29 #include <QVBoxLayout>
30 #include <QStackedWidget>
33 #include <QGridLayout>
36 #include <QToolButton>
38 #include <QPushButton>
39 #include <QHBoxLayout>
40 #include <QDateTimeEdit>
42 #include <QHeaderView>
43 #include <QScrollArea>
45 static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
47 VLMDialog *VLMDialog::instance = NULL;
49 VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
51 p_vlm = vlm_New( p_intf );
55 msg_Warn( p_intf, "Couldn't build VLM object ");
58 vlmWrapper = new VLMWrapper( p_vlm );
62 ui.saveButton->hide();
64 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
65 ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
66 ADDMEDIATYPES( "Schedule", QVLM_Schedule );
67 ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
71 QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
72 QLabel *schetimelabel = new QLabel( qtr( "Hours/Minutes/Seconds:" ) );
73 schetimelayout->addWidget( schetimelabel, 0, 0 );
74 QLabel *schedatelabel = new QLabel( qtr( "Day Month Year:" ) );
75 schetimelayout->addWidget( schedatelabel, 1, 0 );
76 QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
77 schetimelayout->addWidget( scherepeatLabel, 2, 0 );
78 QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
79 schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
81 time = new QDateTimeEdit( QTime::currentTime() );
82 time->setAlignment( Qt::AlignRight );
83 schetimelayout->addWidget( time, 0, 1, 1, 3 );
85 date = new QDateTimeEdit( QDate::currentDate() );
86 date->setAlignment( Qt::AlignRight );
87 date->setCalendarPopup( true );
89 date->setDisplayFormat( "dd MM yyyy" );
91 date->setDisplayFormat( "dd MMMM yyyy" );
93 schetimelayout->addWidget( date, 1, 1, 1, 3 );
95 scherepeatnumber = new QSpinBox;
96 scherepeatnumber->setAlignment( Qt::AlignRight );
97 schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
99 repeatDays = new QSpinBox;
100 repeatDays->setAlignment( Qt::AlignRight );
101 schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
102 repeatDays->setSuffix( qtr(" days") );
104 repeatTime = new QDateTimeEdit;
105 repeatTime->setAlignment( Qt::AlignRight );
106 schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
107 repeatTime->setDisplayFormat( "hh:mm:ss" );
110 ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
111 ui.vlmItemScroll->setWidgetResizable( true );
112 vlmItemWidget = new QWidget;
113 vlmItemLayout = new QVBoxLayout( vlmItemWidget );
114 vlmItemWidget->setLayout( vlmItemLayout );
115 ui.vlmItemScroll->setWidget( vlmItemWidget );
117 QSpacerItem *spacer =
118 new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
119 vlmItemLayout->addItem( spacer );
121 QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
122 ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
124 showScheduleWidget( QVLM_Broadcast );
126 /* Connect the comboBox to show the right Widgets */
127 CONNECT( ui.mediaType, currentIndexChanged( int ),
128 this, showScheduleWidget( int ) );
130 /* Connect the leftList to show the good VLMItem */
131 CONNECT( ui.vlmListItem, currentRowChanged( int ),
132 this, selectVLMItem( int ) );
134 BUTTONACT( closeButton, close() );
135 BUTTONACT( ui.addButton, addVLMItem() );
136 BUTTONACT( ui.clearButton, clearWidgets() );
137 BUTTONACT( ui.saveButton, saveModifications() );
140 VLMDialog::~VLMDialog()
142 /* FIXME :you have to destroy vlm here to close
143 * but we shouldn't destroy vlm here in case somebody else wants it */
148 void VLMDialog::showScheduleWidget( int i )
150 ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
151 ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
152 ui.vodBox->setVisible( ( i == QVLM_VOD ) );
155 void VLMDialog::selectVLMItem( int i )
157 ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
160 bool VLMDialog::isNameGenuine( QString name )
162 for( int i = 0; i < vlmItems.size(); i++ )
164 if( vlmItems.at( i )->name == name )
170 void VLMDialog::addVLMItem()
172 int vlmItemCount = vlmItems.size();
174 /* Take the name and Check it */
175 QString name = ui.nameLedit->text();
176 if( name.isEmpty() || !isNameGenuine( name ) )
178 msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
182 int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
184 QString typeShortName;
185 QString inputText = ui.inputLedit->text();
186 QString outputText = ui.outputLedit->text();
187 bool b_checked = ui.enableCheck->isChecked();
188 bool b_looped = ui.loopBCast->isChecked();
190 VLMAWidget * vlmAwidget;
195 typeShortName = "Bcast";
196 vlmAwidget = new VLMBroadcast( name, inputText, outputText,
197 b_checked, b_looped, this );
198 //VLMWrapper::AddBroadcast( vlmWrapper->p_vlc, name, inputText, outputText, b_checked, b_looped );
201 typeShortName = "VOD";
202 vlmAwidget = new VLMVod( name, inputText, outputText,
203 b_checked, ui.muxLedit->text(), this );
204 ///VLMWrapper::AddVod( vlmWrapper->GetVLM(), name, inputText, outputText, b_checked );
207 typeShortName = "Sched";
208 vlmAwidget = new VLMSchedule( name, inputText, outputText,
212 msg_Warn( p_intf, "Something bad happened" );
216 /* Add an Item of the Side List */
217 ui.vlmListItem->addItem( typeShortName + " : " + name );
218 ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
220 /* Add a new VLMAWidget on the main List */
222 vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
223 vlmItems.append( vlmAwidget );
225 /* HERE BE DRAGONS VLM REQUEST */
228 void VLMDialog::clearWidgets()
230 ui.nameLedit->clear();
231 ui.inputLedit->clear();
232 ui.outputLedit->clear();
233 time->setTime( QTime::currentTime() );
234 date->setDate( QDate::currentDate() );
235 ui.enableCheck->setChecked( true );
236 ui.nameLedit->setReadOnly( false );
237 ui.loopBCast->setChecked( false );
238 ui.muxLedit->clear();
239 ui.saveButton->hide();
240 ui.addButton->show();
243 /* Object Modification */
244 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
246 int index = vlmItems.indexOf( vlmObj );
247 if( index < 0 ) return;
249 //FIXME, this is going to segfault if the focus in on the ListWidget
250 delete ui.vlmListItem->takeItem( index );
251 vlmItems.removeAt( index );
254 /* HERE BE DRAGONS VLM REQUEST */
257 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
259 currentIndex = vlmItems.indexOf( vlmObj );
260 if( currentIndex < 0 ) return;
262 msg_Dbg( p_intf, "Type: %i", vlmObj->type );
263 ui.vlmListItem->setCurrentRow( currentIndex );
264 ui.nameLedit->setText( vlmObj->name );
265 ui.inputLedit->setText( vlmObj->input );
266 ui.outputLedit->setText( vlmObj->output );
267 ui.enableCheck->setChecked( vlmObj->b_enabled );
269 switch( vlmObj->type )
272 ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
275 ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
278 //(qobject_cast<VLMSchedule *>)
282 ui.nameLedit->setReadOnly( true );
283 ui.addButton->hide();
284 ui.saveButton->show();
287 void VLMDialog::saveModifications()
289 VLMAWidget *vlmObj = vlmItems.at( currentIndex );
292 vlmObj->input = ui.inputLedit->text();
293 vlmObj->output = ui.outputLedit->text();
294 vlmObj->setChecked( ui.enableCheck->isChecked() );
295 vlmObj->b_enabled = ui.enableCheck->isChecked();
296 switch( vlmObj->type )
299 (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
302 (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
308 vlmObj->update(); /* It should call the correct function is VLMAWidget
309 is abstract, but I am far from sure... FIXME ? */
314 /*********************************
315 * VLMAWidget - Abstract class
316 ********************************/
318 VLMAWidget::VLMAWidget( QString _name,
324 : QGroupBox( _name, _parent )
330 b_enabled = _enabled;
333 setCheckable( true );
334 setChecked( b_enabled );
336 objLayout = new QGridLayout( this );
337 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
339 nameLabel = new QLabel;
340 objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
342 /*QLabel *time = new QLabel( "--:--/--:--" );
343 objLayout->addWidget( time, 1, 3, 1, 2 );*/
345 QToolButton *modifyButton = new QToolButton;
346 modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
347 objLayout->addWidget( modifyButton, 0, 5 );
349 QToolButton *deleteButton = new QToolButton;
350 deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
351 objLayout->addWidget( deleteButton, 0, 6 );
353 BUTTONACT( modifyButton, modify() );
354 BUTTONACT( deleteButton, del() );
357 void VLMAWidget::modify()
359 parent->startModifyVLMItem( this );
362 void VLMAWidget::del()
364 parent->removeVLMItem( this );
367 //FIXME, remove me before release
368 void VLMAWidget::enterEvent( QEvent *event )
376 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
377 bool _enabled, bool _looped, VLMDialog *_parent)
378 : VLMAWidget( _name, _input, _output,
379 _enabled, _parent, QVLM_Broadcast )
381 nameLabel->setText( "Broadcast: " + name );
382 type = QVLM_Broadcast;
385 playButton = new QToolButton;
386 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
387 objLayout->addWidget( playButton, 1, 0 );
390 QToolButton *stopButton = new QToolButton;
391 stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
392 objLayout->addWidget( stopButton, 1, 1 );
394 loopButton = new QToolButton;
395 objLayout->addWidget( loopButton, 1, 2 );
397 BUTTONACT( playButton, togglePlayPause() );
398 BUTTONACT( stopButton, stop() );
399 BUTTONACT( loopButton, toggleLoop() );
404 void VLMBroadcast::update()
406 //VLMWrapper::EditBroadcast( VLMWrapper::p_vlm, name, input, output, b_enabled, b_looped );
408 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_all.png" ) ) );
410 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
413 void VLMBroadcast::togglePlayPause()
415 if( b_playing = true )
417 // VLMWrapper::ControlBroadcast( VLMWrapper::p_vlm, name, ControlBroadcastPause );
418 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/pause_16px.png" ) ) );
422 //VLMWrapper::ControlBroadcast( VLMWrapper::p_vlm, name, ControlBroadcastPlay );
423 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
425 b_playing = !b_playing;
428 void VLMBroadcast::toggleLoop()
430 b_enabled = !b_enabled;
434 void VLMBroadcast::stop()
436 //VLMWrapper::ControlBroadcast( VLMWrapper::p_vlm, name, ControlBroadcastStop );
437 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
443 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
444 bool enabled, VLMDialog *parent)
445 : VLMAWidget( name, input, output, enabled, parent, QVLM_Schedule )
447 nameLabel->setText( "Schedule: " + name );
450 void VLMSchedule::update()
457 VLMVod::VLMVod( QString name, QString input, QString output,
458 bool enabled, QString _mux, VLMDialog *parent)
459 : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
461 nameLabel->setText( "VOD:" + name );
464 muxLabel = new QLabel;
465 objLayout->addWidget( muxLabel, 1, 0 );
470 void VLMVod::update()
472 muxLabel->setText( mux );
473 //VLMWrapper::EditVod( p_vlm, name, input, output, b_enabled, mux );
480 vlm_t * VLMWrapper::p_vlm = NULL;
482 VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
487 VLMWrapper::~VLMWrapper()
490 void VLMWrapper::AddBroadcast( const QString name, QString input,
492 bool b_enabled, bool b_loop )
494 vlm_message_t *message;
495 QString command = "new \"" + name + "\" broadcast";
496 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
497 vlm_MessageDelete( message );
498 EditBroadcast( name, input, output, b_enabled, b_loop );
501 void VLMWrapper::EditBroadcast( const QString name, const QString input,
502 const QString output,
503 bool b_enabled, bool b_loop )
505 vlm_message_t *message;
508 command = "setup \"" + name + "\" inputdel all";
509 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
510 vlm_MessageDelete( message );
511 command = "setup \"" + name + "\" input \"" + input + "\"";
512 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
513 vlm_MessageDelete( message );
514 if( !output.isEmpty() )
516 command = "setup \"" + name + "\" output \"" + output + "\"";
517 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
518 vlm_MessageDelete( message );
522 command = "setup \"" + name + "\" enabled";
523 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
524 vlm_MessageDelete( message );
528 command = "setup \"" + name + "\" loop";
529 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
530 vlm_MessageDelete( message );
534 void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
537 vlm_message_t *message;
539 QString command = "setup \"" + name;
540 switch( BroadcastStatus )
542 case ControlBroadcastPlay:
545 case ControlBroadcastPause:
548 case ControlBroadcastStop:
551 case ControlBroadcastSeek:
552 command += " seek" + seek;
555 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
556 vlm_MessageDelete( message );
559 void VLMWrapper::AddVod( const QString name, const QString input,
560 const QString output,
561 bool b_enabled, const QString mux )
563 vlm_message_t *message;
564 QString command = "new \"" + name + "\" vod";
565 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
566 vlm_MessageDelete( message );
567 EditVod( name, input, output, b_enabled, mux );
570 void VLMWrapper::EditVod( const QString name, const QString input,
571 const QString output,
575 vlm_message_t *message;
576 QString command = "setup \"" + name + "\" input \"" + input + "\"";
577 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
578 vlm_MessageDelete( message );
579 if( !output.isEmpty() )
581 command = "setup \"" + name + "\" output \"" + output + "\"";
582 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
583 vlm_MessageDelete( message );
587 command = "setup \"" + name + "\" enabled";
588 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
589 vlm_MessageDelete( message );
593 command = "setup \"" + name + "\" mux \"" + mux + "\"";
594 vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
595 vlm_MessageDelete( message );