]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/vlm.cpp
Qt4 - Fix VLM-object not being checked. Add a type to be sure of the edition to do.
[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 = ui.enableCheck->isChecked();
174
175     VLMAWidget * vlmAwidget;
176
177     switch( type )
178     {
179     case QVLM_Broadcast:
180         typeShortName = "Bcast";
181         vlmAwidget = new VLMBroadcast( name, inputText, outputText,
182                                        b_checked, this );
183     break;
184     case QVLM_VOD:
185         typeShortName = "VOD";
186         vlmAwidget = new VLMVod( name, inputText, outputText,
187                                  b_checked, this );
188         break;
189     case QVLM_Schedule:
190         typeShortName = "Sched";
191         vlmAwidget = new VLMSchedule( name, inputText, outputText,
192                                       b_checked, this );
193         break;
194     default:
195         msg_Warn( p_intf, "Something bad happened" );
196         return;
197     }
198
199     /* Add an Item of the Side List */
200     ui.vlmListItem->addItem( typeShortName + " : " + name );
201     ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );
202
203     /* Add a new VLMAWidget on the main List */
204
205     vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
206     vlmItems.append( vlmAwidget );
207
208     /* HERE BE DRAGONS VLM REQUEST */
209 }
210
211 void VLMDialog::clearWidgets()
212 {
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();
222 }
223
224 void VLMDialog::saveModifications()
225 {
226     VLMAWidget *vlmObj = vlmItems.at( currentIndex );
227     if( vlmObj )
228     {
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();
233     }
234     clearWidgets();
235 }
236
237 /* Object Modification */
238 void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
239 {
240     int index = vlmItems.indexOf( vlmObj );
241     if( index < 0 ) return;
242
243     //FIXME, this is going to segfault if the focus in on the ListWidget
244     delete ui.vlmListItem->takeItem( index );
245     vlmItems.removeAt( index );
246     delete vlmObj;
247
248     /* HERE BE DRAGONS VLM REQUEST */
249 }
250
251 void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
252 {
253     currentIndex = vlmItems.indexOf( vlmObj );
254     if( currentIndex < 0 ) return;
255
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 );
262
263     ui.nameLedit->setReadOnly( true );
264     ui.addButton->hide();
265     ui.saveButton->show();
266 }
267
268
269 /*********************************
270  * VLMAWidget
271  ********************************/
272
273 VLMAWidget::VLMAWidget( QString _name,
274                         QString _input,
275                         QString _output,
276                         bool _enabled,
277                         VLMDialog *_parent,
278                         int _type )
279                       : QGroupBox( _name, _parent )
280 {
281     parent = _parent;
282     name = _name;
283     input = _input;
284     output = _output;
285     b_enabled = _enabled;
286     type = _type;
287
288     setCheckable( true );
289     setChecked( b_enabled );
290
291     objLayout = new QGridLayout( this );
292     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
293
294     nameLabel = new QLabel;
295     objLayout->addWidget( nameLabel, 0, 0, 1, 4 );
296
297     /*QLabel *time = new QLabel( "--:--/--:--" );
298     objLayout->addWidget( time, 1, 3, 1, 2 );*/
299
300     QToolButton *modifyButton = new QToolButton;
301     modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
302     objLayout->addWidget( modifyButton, 0, 5 );
303
304     QToolButton *deleteButton = new QToolButton;
305     deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
306     objLayout->addWidget( deleteButton, 0, 6 );
307
308     BUTTONACT( modifyButton, modify() );
309     BUTTONACT( deleteButton, del() );
310 }
311
312 void VLMAWidget::modify()
313 {
314     parent->startModifyVLMItem( this );
315 }
316
317 void VLMAWidget::del()
318 {
319     parent->removeVLMItem( this );
320 }
321
322
323 VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
324                             bool _enabled, VLMDialog *_parent)
325                           : VLMAWidget( _name, _input, _output,
326                                         _enabled, _parent, QVLM_Broadcast )
327 {
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 );
333
334     QToolButton *stopButton = new QToolButton;
335     stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
336     objLayout->addWidget( stopButton, 1, 1 );
337
338     QToolButton *loopButton = new QToolButton;
339     loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
340     objLayout->addWidget( loopButton, 1, 2 );
341
342     BUTTONACT( playButton, togglePlayPause() );
343     BUTTONACT( stopButton, stop() );
344     BUTTONACT( loopButton, toggleLoop() );
345 }
346
347
348 void VLMBroadcast::togglePlayPause()
349 {
350
351 }
352
353 void VLMBroadcast::toggleLoop()
354 {
355
356 }
357
358 void VLMBroadcast::stop()
359 {
360
361 }
362
363 void VLMAWidget::enterEvent( QEvent *event )
364 {
365     printf( "test" );
366 }
367
368
369 VLMSchedule::VLMSchedule( QString name, QString input, QString output,
370                             bool enabled, VLMDialog *parent) : VLMAWidget( name, input,
371                             output, enabled, parent, QVLM_Schedule )
372 {
373     nameLabel->setText( "Schedule: " + name );
374 }
375
376 VLMVod::VLMVod( QString name, QString input, QString output,
377                             bool enabled, VLMDialog *parent) : VLMAWidget( name, input,
378                             output, enabled, parent, QVLM_VOD )
379 {
380     nameLabel->setText( "VOD:" + name );
381 }