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"
26 #include <vlc_streaming.h>
30 #include <QVBoxLayout>
31 #include <QStackedWidget>
34 #include <QGridLayout>
37 #include <QToolButton>
39 #include <QPushButton>
40 #include <QHBoxLayout>
41 #include <QDateTimeEdit>
43 #include <QHeaderView>
44 #include <QScrollArea>
46 static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
48 VLMDialog *VLMDialog::instance = NULL;
50 VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
54 ui.saveButton->hide();
56 #define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
57 ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
58 ADDMEDIATYPES( "Schedule", QVLM_Schedule );
59 ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
63 QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
64 QLabel *schetimelabel = new QLabel( qtr( "Hours/Minutes/Seconds:" ) );
65 schetimelayout->addWidget( schetimelabel, 0, 0 );
66 QLabel *schedatelabel = new QLabel( qtr( "Day Month Year:" ) );
67 schetimelayout->addWidget( schedatelabel, 1, 0 );
68 QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
69 schetimelayout->addWidget( scherepeatLabel, 2, 0 );
70 QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
71 schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );
73 time = new QDateTimeEdit( QTime::currentTime() );
74 time->setAlignment( Qt::AlignRight );
75 schetimelayout->addWidget( time, 0, 1, 1, 3 );
77 date = new QDateTimeEdit( QDate::currentDate() );
78 date->setAlignment( Qt::AlignRight );
79 date->setCalendarPopup( true );
81 date->setDisplayFormat( "dd MM yyyy" );
83 date->setDisplayFormat( "dd MMMM yyyy" );
85 schetimelayout->addWidget( date, 1, 1, 1, 3 );
87 scherepeatnumber = new QSpinBox;
88 scherepeatnumber->setAlignment( Qt::AlignRight );
89 schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
91 repeatDays = new QSpinBox;
92 repeatDays->setAlignment( Qt::AlignRight );
93 schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
94 repeatDays->setSuffix( qtr(" days") );
96 repeatTime = new QDateTimeEdit;
97 repeatTime->setAlignment( Qt::AlignRight );
98 schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
99 repeatTime->setDisplayFormat( "hh:mm:ss" );
102 ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
103 ui.vlmItemScroll->setWidgetResizable( true );
104 vlmItemWidget = new QWidget;
105 vlmItemLayout = new QVBoxLayout( vlmItemWidget );
106 vlmItemWidget->setLayout( vlmItemLayout );
107 ui.vlmItemScroll->setWidget( vlmItemWidget );
109 QSpacerItem *spacer =
110 new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
111 vlmItemLayout->addItem( spacer );
113 QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
114 ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
116 showScheduleWidget( QVLM_Broadcast );
118 /* Connect the comboBox to show the right Widgets */
119 CONNECT( ui.mediaType, currentIndexChanged( int ),
120 this, showScheduleWidget( int ) );
122 /* Connect the leftList to show the good VLMItem */
123 CONNECT( ui.vlmListItem, currentRowChanged( int ),
124 this, selectVLMItem( int ) );
126 BUTTONACT( closeButton, close() );
127 BUTTONACT( ui.addButton, addVLMItem() );
128 BUTTONACT( ui.clearButton, clearWidgets() );
129 BUTTONACT( ui.saveButton, saveModifications() );
132 VLMDialog::~VLMDialog(){}
134 void VLMDialog::showScheduleWidget( int i )
136 ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
137 ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
138 ui.vodBox->setVisible( ( i == QVLM_VOD ) );
141 void VLMDialog::selectVLMItem( int i )
143 ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
146 bool VLMDialog::isNameGenuine( QString name )
148 for( int i = 0; i < vlmItems.size(); i++ )
150 if( vlmItems.at( i )->name == name )
156 void VLMDialog::addVLMItem()
158 int vlmItemCount = vlmItems.size();
160 /* Take the name and Check it */
161 QString name = ui.nameLedit->text();
162 if( name.isEmpty() || !isNameGenuine( name ) )
164 msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
168 int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
170 QString typeShortName;
171 QString inputText = ui.inputLedit->text();
172 QString outputText = ui.outputLedit->text();
173 bool b_checked = ui.enableCheck->isChecked();
175 VLMAWidget * vlmAwidget;
180 typeShortName = "Bcast";
181 vlmAwidget = new VLMBroadcast( name, inputText, outputText,
185 typeShortName = "VOD";
186 vlmAwidget = new VLMVod( name, inputText, outputText,
190 typeShortName = "Sched";
191 vlmAwidget = new VLMSchedule( name, inputText, outputText,
195 msg_Warn( p_intf, "Something bad happened" );
199 /* Add an Item of the Side List */
200 ui.vlmListItem->addItem( typeShortName + " : " + name );
201 ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
203 /* Add a new VLMAWidget on the main List */
205 vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
206 vlmItems.append( vlmAwidget );
208 /* HERE BE DRAGONS VLM REQUEST */
211 void VLMDialog::clearWidgets()
213 ui.nameLedit->clear();
214 ui.inputLedit->clear();
215 ui.outputLedit->clear();
216 time->setTime( QTime::currentTime() );
217 date->setDate( QDate::currentDate() );
218 ui.enableCheck->setChecked( true );
219 ui.nameLedit->setReadOnly( false );
220 ui.saveButton->hide();
221 ui.addButton->show();
224 void VLMDialog::saveModifications()
226 VLMAWidget *vlmObj = vlmItems.at( currentIndex );
229 vlmObj->input = ui.inputLedit->text();
230 vlmObj->output = ui.outputLedit->text();
231 vlmObj->setChecked( ui.enableCheck->isChecked() );
232 vlmObj->b_enabled = ui.enableCheck->isChecked();
237 /* Object Modification */
238 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
240 int index = vlmItems.indexOf( vlmObj );
241 if( index < 0 ) return;
243 //FIXME, this is going to segfault if the focus in on the ListWidget
244 delete ui.vlmListItem->takeItem( index );
245 vlmItems.removeAt( index );
248 /* HERE BE DRAGONS VLM REQUEST */
251 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
253 currentIndex = vlmItems.indexOf( vlmObj );
254 if( currentIndex < 0 ) return;
256 msg_Dbg( p_intf, "Type: %i", vlmObj->type );
257 ui.vlmListItem->setCurrentRow( currentIndex );
258 ui.nameLedit->setText( vlmObj->name );
259 ui.inputLedit->setText( vlmObj->input );
260 ui.outputLedit->setText( vlmObj->output );
261 ui.enableCheck->setChecked( vlmObj->b_enabled );
263 ui.nameLedit->setReadOnly( true );
264 ui.addButton->hide();
265 ui.saveButton->show();
269 /*********************************
271 ********************************/
273 VLMAWidget::VLMAWidget( QString _name,
279 : QGroupBox( _name, _parent )
285 b_enabled = _enabled;
288 setCheckable( true );
289 setChecked( b_enabled );
291 objLayout = new QGridLayout( this );
292 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
294 nameLabel = new QLabel;
295 objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
297 /*QLabel *time = new QLabel( "--:--/--:--" );
298 objLayout->addWidget( time, 1, 3, 1, 2 );*/
300 QToolButton *modifyButton = new QToolButton;
301 modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
302 objLayout->addWidget( modifyButton, 0, 5 );
304 QToolButton *deleteButton = new QToolButton;
305 deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
306 objLayout->addWidget( deleteButton, 0, 6 );
308 BUTTONACT( modifyButton, modify() );
309 BUTTONACT( deleteButton, del() );
312 void VLMAWidget::modify()
314 parent->startModifyVLMItem( this );
317 void VLMAWidget::del()
319 parent->removeVLMItem( this );
323 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
324 bool _enabled, VLMDialog *_parent)
325 : VLMAWidget( _name, _input, _output,
326 _enabled, _parent, QVLM_Broadcast )
328 nameLabel->setText( "Broadcast: " + name );
329 type = QVLM_Broadcast;
330 QToolButton *playButton = new QToolButton;
331 playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
332 objLayout->addWidget( playButton, 1, 0 );
334 QToolButton *stopButton = new QToolButton;
335 stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
336 objLayout->addWidget( stopButton, 1, 1 );
338 QToolButton *loopButton = new QToolButton;
339 loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
340 objLayout->addWidget( loopButton, 1, 2 );
342 BUTTONACT( playButton, togglePlayPause() );
343 BUTTONACT( stopButton, stop() );
344 BUTTONACT( loopButton, toggleLoop() );
348 void VLMBroadcast::togglePlayPause()
353 void VLMBroadcast::toggleLoop()
358 void VLMBroadcast::stop()
363 void VLMAWidget::enterEvent( QEvent *event )
369 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
370 bool enabled, VLMDialog *parent) : VLMAWidget( name, input,
371 output, enabled, parent, QVLM_Schedule )
373 nameLabel->setText( "Schedule: " + name );
376 VLMVod::VLMVod( QString name, QString input, QString output,
377 bool enabled, VLMDialog *parent) : VLMAWidget( name, input,
378 output, enabled, parent, QVLM_VOD )
380 nameLabel->setText( "VOD:" + name );