]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
Qt4 - VLM improvements... Classing for the three kind of objects, more property editi...
[vlc] / modules / gui / qt4 / dialogs / vlm.cpp
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 $
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *          Jean-François Massol <jf.massol -at- gmail.com>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "dialogs/vlm.hpp"
26 #include <vlc_streaming.h>
27
28 #include <QString>
29 #include <QComboBox>
30 #include <QVBoxLayout>
31 #include <QStackedWidget>
32 #include <QLabel>
33 #include <QWidget>
34 #include <QGridLayout>
35 #include <QLineEdit>
36 #include <QCheckBox>
37 #include <QToolButton>
38 #include <QGroupBox>
39 #include <QPushButton>
40 #include <QHBoxLayout>
41 #include <QDateTimeEdit>
42 #include <QSpinBox>
43 #include <QHeaderView>
44 #include <QScrollArea>
45
46 static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
47
48 VLMDialog *VLMDialog::instance = NULL;
49
50 VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
51 {
52     // UI stuff
53     ui.setupUi( this );
54     ui.saveButton->hide();
55
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 );
60 #undef ADDMEDIATYPES
61
62     /* Schedule Stuffs */
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 );
72
73     time = new QDateTimeEdit( QTime::currentTime() );
74     time->setAlignment( Qt::AlignRight );
75     schetimelayout->addWidget( time, 0, 1, 1, 3 );
76
77     date = new QDateTimeEdit( QDate::currentDate() );
78     date->setAlignment( Qt::AlignRight );
79     date->setCalendarPopup( true );
80 #ifdef WIN32
81     date->setDisplayFormat( "dd MM yyyy" );
82 #else
83     date->setDisplayFormat( "dd MMMM yyyy" );
84 #endif
85     schetimelayout->addWidget( date, 1, 1, 1, 3 );
86
87     scherepeatnumber = new QSpinBox;
88     scherepeatnumber->setAlignment( Qt::AlignRight );
89     schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );
90
91     repeatDays = new QSpinBox;
92     repeatDays->setAlignment( Qt::AlignRight );
93     schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
94     repeatDays->setSuffix( qtr(" days") );
95
96     repeatTime = new QDateTimeEdit;
97     repeatTime->setAlignment( Qt::AlignRight );
98     schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
99     repeatTime->setDisplayFormat( "hh:mm:ss" );
100
101     /* scrollArea */
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 );
108
109     QSpacerItem *spacer =
110         new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
111     vlmItemLayout->addItem( spacer );
112
113     QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
114     ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
115
116     showScheduleWidget( QVLM_Broadcast );
117
118     /* Connect the comboBox to show the right Widgets */
119     CONNECT( ui.mediaType, currentIndexChanged( int ),
120              this, showScheduleWidget( int ) );
121
122     /* Connect the leftList to show the good VLMItem */
123     CONNECT( ui.vlmListItem, currentRowChanged( int ),
124              this, selectVLMItem( int ) );
125
126     BUTTONACT( closeButton, close() );
127     BUTTONACT( ui.addButton, addVLMItem() );
128     BUTTONACT( ui.clearButton, clearWidgets() );
129     BUTTONACT( ui.saveButton, saveModifications() );
130 }
131
132 VLMDialog::~VLMDialog(){}
133
134 void VLMDialog::showScheduleWidget( int i )
135 {
136     ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
137     ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
138     ui.vodBox->setVisible( ( i == QVLM_VOD ) );
139 }
140
141 void VLMDialog::selectVLMItem( int i )
142 {
143     ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
144 }
145
146 bool VLMDialog::isNameGenuine( QString name )
147 {
148     for( int i = 0; i < vlmItems.size(); i++ )
149     {
150         if( vlmItems.at( i )->name == name )
151             return false;
152     }
153     return true;
154 }
155
156 void VLMDialog::addVLMItem()
157 {
158     int vlmItemCount = vlmItems.size();
159
160     /* Take the name and Check it */
161     QString name = ui.nameLedit->text();
162     if( name.isEmpty() || !isNameGenuine( name ) )
163     {
164         msg_Dbg( p_intf, "VLM Name is empty or already exists, I can't do it" );
165         return;
166     }
167
168     int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
169
170     QString typeShortName;
171     QString inputText = ui.inputLedit->text();
172     QString outputText = ui.outputLedit->text();
173     bool b_checked;
174
175     VLMAWidget * vlmAwidget;
176
177     switch( type )
178     {
179     case QVLM_Broadcast:
180         typeShortName = "Bcast";
181         vlmAwidget = new VLMBroadcast( name, inputText, outputText, b_checked, this );
182     break;
183     case QVLM_VOD:
184         typeShortName = "VOD";
185         vlmAwidget = new VLMVod( name, inputText, outputText, b_checked, this );
186         break;
187     case QVLM_Schedule:
188         typeShortName = "Sched";
189         vlmAwidget = new VLMSchedule( name, inputText, outputText, b_checked, this );
190         break;
191     default:
192         msg_Warn( p_intf, "Something bad happened" );
193         return;
194     }
195
196     /* Add an Item of the Side List */
197     ui.vlmListItem->addItem( typeShortName + " : " + name );
198     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
199
200     /* Add a new VLMAWidget on the main List */
201
202     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
203     vlmItems.append( vlmAwidget );
204
205     /* HERE BE DRAGONS VLM REQUEST */
206 }
207
208 void VLMDialog::clearWidgets()
209 {
210     ui.nameLedit->clear();
211     ui.inputLedit->clear();
212     ui.outputLedit->clear();
213     time->setTime( QTime::currentTime() );
214     date->setDate( QDate::currentDate() );
215     ui.enableCheck->setChecked( true );
216     ui.nameLedit->setReadOnly( false );
217 }
218
219 void VLMDialog::saveModifications()
220 {
221     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
222     if( vlmObj )
223     {
224         vlmObj->input = ui.inputLedit->text();
225         vlmObj->output = ui.outputLedit->text();
226         vlmObj->setChecked( ui.enableCheck->isChecked() );
227         vlmObj->b_enabled = ui.enableCheck->isChecked();
228     }
229     ui.saveButton->hide();
230     ui.addButton->show();
231     clearWidgets();
232 }
233
234 /* Object Modification */
235 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
236 {
237     int index = vlmItems.indexOf( vlmObj );
238     if( index < 0 ) return;
239
240     //FIXME, this is going to segfault if the focus in on the ListWidget
241     delete ui.vlmListItem->takeItem( index );
242     vlmItems.removeAt( index );
243     delete vlmObj;
244
245     /* HERE BE DRAGONS VLM REQUEST */
246 }
247
248 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
249 {
250     currentIndex = vlmItems.indexOf( vlmObj );
251     if( currentIndex < 0 ) return;
252
253     ui.vlmListItem->setCurrentRow( currentIndex );
254     ui.nameLedit->setText( vlmObj->name );
255     ui.inputLedit->setText( vlmObj->input );
256     ui.outputLedit->setText( vlmObj->output );
257     ui.enableCheck->setChecked( vlmObj->b_enabled );
258
259     ui.nameLedit->setReadOnly( true );
260     ui.addButton->hide();
261     ui.saveButton->show();
262 }
263
264
265 /*********************************
266  * VLMAWidget
267  ********************************/
268
269 VLMAWidget::VLMAWidget( QString _name,
270                         QString _input,
271                         QString _output,
272                         bool _enabled,
273                         VLMDialog *_parent )
274                       : QGroupBox( _name, _parent )
275 {
276     parent = _parent;
277     name = _name;
278     input = _input;
279     output = _output;
280     b_enabled = _enabled;
281     setChecked( b_enabled );
282
283     objLayout = new QGridLayout( this );
284     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
285
286     nameLabel = new QLabel;
287     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
288
289     /*QLabel *time = new QLabel( "--:--/--:--" );
290     objLayout->addWidget( time, 1, 3, 1, 2 );*/
291
292     QToolButton *modifyButton = new QToolButton;
293     modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
294     objLayout->addWidget( modifyButton, 0, 5 );
295
296     QToolButton *deleteButton = new QToolButton;
297     deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
298     objLayout->addWidget( deleteButton, 0, 6 );
299
300     BUTTONACT( modifyButton, modify() );
301     BUTTONACT( deleteButton, del() );
302 }
303
304 void VLMAWidget::modify()
305 {
306     parent->startModifyVLMItem( this );
307 }
308
309 void VLMAWidget::del()
310 {
311     parent->removeVLMItem( this );
312 }
313
314
315 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
316                             bool _enabled, VLMDialog *_parent)
317                           : VLMAWidget( _name, _input, _output,
318                                         _enabled, _parent)
319 {
320     nameLabel->setText( "Broadcast: " + name );
321     QToolButton *playButton = new QToolButton;
322     playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
323     objLayout->addWidget( playButton, 1, 0 );
324
325     QToolButton *stopButton = new QToolButton;
326     stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
327     objLayout->addWidget( stopButton, 1, 1 );
328
329     QToolButton *loopButton = new QToolButton;
330     loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
331     objLayout->addWidget( loopButton, 1, 2 );
332
333     BUTTONACT( playButton, togglePlayPause() );
334     BUTTONACT( stopButton, stop() );
335     BUTTONACT( loopButton, toggleLoop() );
336 }
337
338
339 void VLMBroadcast::togglePlayPause()
340 {
341
342 }
343
344 void VLMBroadcast::toggleLoop()
345 {
346
347 }
348
349 void VLMBroadcast::stop()
350 {
351
352 }
353
354 void VLMAWidget::enterEvent( QEvent *event )
355 {
356     printf( "test" );
357 }
358
359
360 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
361                             bool enabled, VLMDialog *parent) : VLMAWidget( name, input,
362                             output, enabled, parent)
363 {
364     nameLabel->setText( "Schedule: " + name );
365 }
366
367 VLMVod::VLMVod( QString name, QString input, QString output,
368                             bool enabled, VLMDialog *parent) : VLMAWidget( name, input,
369                             output, enabled, parent)
370 {
371     nameLabel->setText( "VOD:" + name );
372 }