vlm.cpp 28.9 KB
Newer Older
1
/*****************************************************************************
2
 * vlm.cpp : VLM Management
3
 ****************************************************************************
4
 * Copyright © 2008 the VideoLAN team
Pierre's avatar
Pierre committed
5
 * $Id$
6
 *
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>
10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * ( at your option ) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * 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
 *****************************************************************************/
25

26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
29 30

#include "dialogs/vlm.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
31 32

#ifdef ENABLE_VLM
33
#include "dialogs/open.hpp"
34
#include "dialogs/sout.hpp"
35
#include "util/qt_dirs.hpp"
36 37

#include <QString>
38 39 40 41 42 43 44 45 46 47 48 49
#include <QComboBox>
#include <QVBoxLayout>
#include <QStackedWidget>
#include <QLabel>
#include <QWidget>
#include <QGridLayout>
#include <QLineEdit>
#include <QCheckBox>
#include <QToolButton>
#include <QGroupBox>
#include <QPushButton>
#include <QHBoxLayout>
50
#include <QDateTimeEdit>
51
#include <QDateTime>
52
#include <QSpinBox>
53
#include <QScrollArea>
54
#include <QFileDialog>
55 56


57
VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
58
{
59
    vlm_t *p_vlm = vlm_New( p_intf );
60 61

    if( !p_vlm )
62 63
    {
        msg_Warn( p_intf, "Couldn't build VLM object ");
64
        vlm = NULL;
65
        return;
66
    }
67
    vlm = new VLMWrapper( p_vlm );
68

69
    // UI stuff
70
    ui.setupUi( this );
71
    ui.saveButton->hide();
72

73
#define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
Christophe Mutricy's avatar
Christophe Mutricy committed
74 75 76
    ADDMEDIATYPES( N_("Broadcast"), QVLM_Broadcast );
    ADDMEDIATYPES( N_("Schedule"), QVLM_Schedule );
    ADDMEDIATYPES( N_("Video On Demand ( VOD )"), QVLM_VOD );
77
#undef ADDMEDIATYPES
78 79 80

    /* Schedule Stuffs */
    QGridLayout *schetimelayout = new QGridLayout( ui.schedBox );
81
    QLabel *schetimelabel = new QLabel( qtr( "Hours / Minutes / Seconds:" ) );
82
    schetimelayout->addWidget( schetimelabel, 0, 0 );
83
    QLabel *schedatelabel = new QLabel( qtr( "Day / Month / Year:" ) );
84 85 86
    schetimelayout->addWidget( schedatelabel, 1, 0 );
    QLabel *scherepeatLabel = new QLabel( qtr( "Repeat:" ) );
    schetimelayout->addWidget( scherepeatLabel, 2, 0 );
87 88 89 90
    QLabel *scherepeatTimeLabel = new QLabel( qtr( "Repeat delay:" ) );
    schetimelayout->addWidget( scherepeatTimeLabel, 3, 0 );

    time = new QDateTimeEdit( QTime::currentTime() );
91
    time->setAlignment( Qt::AlignRight );
92
    time->setDisplayFormat( "hh:mm:ss" );
93 94 95
    schetimelayout->addWidget( time, 0, 1, 1, 3 );

    date = new QDateTimeEdit( QDate::currentDate() );
96
    date->setAlignment( Qt::AlignRight );
97
    date->setCalendarPopup( true );
98
#ifdef _WIN32
99 100 101 102
    date->setDisplayFormat( "dd MM yyyy" );
#else
    date->setDisplayFormat( "dd MMMM yyyy" );
#endif
103
    schetimelayout->addWidget( date, 1, 1, 1, 3 );
104

105 106
    scherepeatnumber = new QSpinBox;
    scherepeatnumber->setAlignment( Qt::AlignRight );
107 108 109 110 111 112 113 114 115 116 117 118
    schetimelayout->addWidget( scherepeatnumber, 2, 1, 1, 3 );

    repeatDays = new QSpinBox;
    repeatDays->setAlignment( Qt::AlignRight );
    schetimelayout->addWidget( repeatDays, 3, 1, 1, 1 );
    repeatDays->setSuffix( qtr(" days") );

    repeatTime = new QDateTimeEdit;
    repeatTime->setAlignment( Qt::AlignRight );
    schetimelayout->addWidget( repeatTime, 3, 2, 1, 2 );
    repeatTime->setDisplayFormat( "hh:mm:ss" );

119 120 121 122 123 124 125 126
    /* scrollArea */
    ui.vlmItemScroll->setFrameStyle( QFrame::NoFrame );
    ui.vlmItemScroll->setWidgetResizable( true );
    vlmItemWidget = new QWidget;
    vlmItemLayout = new QVBoxLayout( vlmItemWidget );
    vlmItemWidget->setLayout( vlmItemLayout );
    ui.vlmItemScroll->setWidget( vlmItemWidget );

127 128
    QSpacerItem *spacer =
        new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
129
    vlmItemLayout->addItem( spacer );
130

131
    QPushButton *importButton = new QPushButton( qtr( "I&mport" ) );
132 133
    ui.buttonBox->addButton( importButton, QDialogButtonBox::ActionRole );

134
    QPushButton *exportButton = new QPushButton( qtr( "E&xport" ) );
135 136
    ui.buttonBox->addButton( exportButton, QDialogButtonBox::ActionRole );

137
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
138
    ui.buttonBox->addButton( closeButton, QDialogButtonBox::RejectRole );
139

140

141
    showScheduleWidget( QVLM_Broadcast );
142

143 144 145
    /* Connect the comboBox to show the right Widgets */
    CONNECT( ui.mediaType, currentIndexChanged( int ),
             this, showScheduleWidget( int ) );
146

147 148 149
    /* Connect the leftList to show the good VLMItem */
    CONNECT( ui.vlmListItem, currentRowChanged( int ),
             this, selectVLMItem( int ) );
150

151
    BUTTONACT( closeButton, close() );
152
    BUTTONACT( exportButton, exportVLMConf() );
153
    BUTTONACT( importButton, importVLMConf() );
154
    BUTTONACT( ui.addButton, addVLMItem() );
155 156
    BUTTONACT( ui.clearButton, clearWidgets() );
    BUTTONACT( ui.saveButton, saveModifications() );
157
    BUTTONACT( ui.inputButton, selectInput() );
158
    BUTTONACT( ui.outputButton, selectOutput() );
159 160 161 162 163

    if( !restoreGeometry( getSettings()->value("VLM/geometry").toByteArray() ) )
    {
        resize( QSize( 700, 500 ) );
    }
164 165
}

166 167
VLMDialog::~VLMDialog()
{
168
    delete vlm;
169

170
    getSettings()->setValue("VLM/geometry", saveGeometry());
171
}
172

173
void VLMDialog::showScheduleWidget( int i )
174
{
175
    ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
176 177
    ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
    ui.vodBox->setVisible( ( i == QVLM_VOD ) );
178
}
179

180 181
void VLMDialog::selectVLMItem( int i )
{
182 183
    if( i >= 0 )
        ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
184 185
}

186
bool VLMDialog::isNameGenuine( const QString& name )
187
{
188
    for( int i = 0; i < vlmItems.count(); i++ )
189 190 191 192 193
    {
        if( vlmItems.at( i )->name == name )
            return false;
    }
    return true;
194 195 196 197
}

void VLMDialog::addVLMItem()
{
198
    int vlmItemCount = vlmItems.count();
199

200 201 202 203
    /* Take the name and Check it */
    QString name = ui.nameLedit->text();
    if( name.isEmpty() || !isNameGenuine( name ) )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
204
        msg_Err( p_intf, "VLM Name is empty or already exists, I can't do it" );
205 206 207 208
        return;
    }

    int type = ui.mediaType->itemData( ui.mediaType->currentIndex() ).toInt();
209

210
    QString typeShortName;
211 212
    QString inputText = ui.inputLedit->text();
    QString outputText = ui.outputLedit->text();
213
    bool b_checked = ui.enableCheck->isChecked();
214
    bool b_looped = ui.loopBCast->isChecked();
215 216 217 218
    QDateTime schetime = time->dateTime();
    QDateTime schedate = date->dateTime();
    int repeatnum = scherepeatnumber->value();
    int repeatdays = repeatDays->value();
219
    VLMAWidget * vlmAwidget;
220
    outputText.remove( ":sout=" );
221

222 223 224
    switch( type )
    {
    case QVLM_Broadcast:
225
        typeShortName = "Bcast";
226
        vlmAwidget = new VLMBroadcast( vlm, name, inputText, inputOptions, outputText,
227
                                       b_checked, b_looped, this );
228 229
        vlm->AddBroadcast( name, inputText, inputOptions, outputText,
                           b_checked, b_looped );
230 231
    break;
    case QVLM_VOD:
232
        typeShortName = "VOD";
233
        vlmAwidget = new VLMVod( vlm, name, inputText, inputOptions, outputText,
234
                                 b_checked, ui.muxLedit->text(), this );
235
        vlm->AddVod( name, inputText, inputOptions, outputText, b_checked );
236 237
        break;
    case QVLM_Schedule:
238
        typeShortName = "Sched";
239
        vlmAwidget = new VLMSchedule( vlm, name, inputText, inputOptions, outputText,
240 241
                                      schetime, schedate, repeatnum,
                                      repeatdays, b_checked, this );
242 243
        vlm->AddSchedule( name, inputText, inputOptions, outputText, schetime,
                          schedate, repeatnum, repeatdays, b_checked);
244 245
        break;
    default:
246 247
        msg_Warn( p_intf, "Something bad happened" );
        return;
248 249
    }

250 251 252 253
    /* Add an Item of the Side List */
    ui.vlmListItem->addItem( typeShortName + " : " + name );
    ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );

254
    /* Add a new VLMAWidget on the main List */
255

256 257
    vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
    vlmItems.append( vlmAwidget );
258
    clearWidgets();
259 260
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
261
/* TODO : VOD are not exported to the file */
262 263
bool VLMDialog::exportVLMConf()
{
264 265
    QString saveVLMConfFileName = QFileDialog::getSaveFileName( this,
                                        qtr( "Save VLM configuration as..." ),
266
                                        QVLCUserDir( VLC_DOCUMENTS_DIR ),
267 268
                                        qtr( "VLM conf (*.vlm);;All (*)" ) );

269
    if( !saveVLMConfFileName.isEmpty() )
270
    {
271
        vlm->SaveConfig( saveVLMConfFileName );
272
        return true;
273
    }
274

275
    return false;
276 277
}

278 279
void VLMDialog::mediasPopulator()
{
280
    if( vlm != NULL )
281 282 283
    {
        QString typeShortName;
        int vlmItemCount;
284
        vlm_media_t **pp_dsc;
285

286
        /* Get medias information and numbers */
287
        int i_nMedias = vlm->GetMedias( pp_dsc );
288 289 290 291 292

        /* Loop on all of them */
        for( int i = 0; i < i_nMedias; i++ )
        {
            VLMAWidget * vlmAwidget;
293
            vlmItemCount = vlmItems.count();
294

295
            QString mediaName = qfu( pp_dsc[i]->psz_name );
296 297
            /* It may have several inputs, we take the first one by default
                 - an evolution will be to manage these inputs in the gui */
298
            QString inputText = qfu( pp_dsc[i]->ppsz_input[0] );
299

300
            QString outputText = qfu( pp_dsc[i]->psz_output );
301

302
            /* Schedule media is a quite especial, maybe there is another way to grab information */
303
            if( pp_dsc[i]->b_vod )
304 305
            {
                typeShortName = "VOD";
306
                QString mux = qfu( pp_dsc[i]->vod.psz_mux );
307 308 309
                vlmAwidget = new VLMVod( vlm, mediaName, inputText,
                                         inputOptions, outputText,
                                         pp_dsc[i]->b_enabled, mux, this );
310 311 312 313
            }
            else
            {
                typeShortName = "Bcast";
314
                vlmAwidget = new VLMBroadcast( vlm, mediaName, inputText, inputOptions,
315 316
                                               outputText, pp_dsc[i]->b_enabled,
                                               pp_dsc[i]->broadcast.b_loop, this );
317 318 319 320 321 322 323 324 325 326 327 328
            }
            /* Add an Item of the Side List */
            ui.vlmListItem->addItem( typeShortName + " : " + mediaName );
            ui.vlmListItem->setCurrentRow( vlmItemCount - 1 );

            /* Add a new VLMAWidget on the main List */
            vlmItemLayout->insertWidget( vlmItemCount, vlmAwidget );
            vlmItems.append( vlmAwidget );
            clearWidgets();
        }
    }
}
329

330 331
bool VLMDialog::importVLMConf()
{
332
    QString openVLMConfFileName = toNativeSeparators(
333
            QFileDialog::getOpenFileName(
334
            this, qtr( "Open VLM configuration..." ),
335
            QVLCUserDir( VLC_DOCUMENTS_DIR ),
336
            qtr( "VLM conf (*.vlm);;All (*)" ) ) );
337 338 339

    if( !openVLMConfFileName.isEmpty() )
    {
340
        if( vlm->LoadConfig( openVLMConfFileName ) )
341 342 343 344 345
        {
            mediasPopulator();
        }
        else
        {
346
            msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( openVLMConfFileName ) );
347 348
            return false;
        }
349 350 351
        return true;
    }
    return false;
352 353
}

354 355 356 357
void VLMDialog::clearWidgets()
{
    ui.nameLedit->clear();
    ui.inputLedit->clear();
Rémi Duraffort's avatar
Rémi Duraffort committed
358
    inputOptions.clear();
359 360 361 362 363
    ui.outputLedit->clear();
    time->setTime( QTime::currentTime() );
    date->setDate( QDate::currentDate() );
    ui.enableCheck->setChecked( true );
    ui.nameLedit->setReadOnly( false );
364 365
    ui.loopBCast->setChecked( false );
    ui.muxLedit->clear();
366 367
    ui.saveButton->hide();
    ui.addButton->show();
368 369
}

370 371
void VLMDialog::selectInput()
{
372
    OpenDialog *o = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
373
    o->exec();
Rémi Duraffort's avatar
Rémi Duraffort committed
374 375
    ui.inputLedit->setText( o->getMRL( false ) );
    inputOptions = o->getOptions();
376 377
}

378 379
void VLMDialog::selectOutput()
{
380
    SoutDialog *s = new SoutDialog( this, p_intf );
381
    if( s->exec() == QDialog::Accepted )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
382 383 384 385
    {
        int i = s->getMrl().indexOf( " " );
        ui.outputLedit->setText( s->getMrl().left( i ) );
    }
386 387
}

388
/* Object Modification */
389
void VLMDialog::removeVLMItem( VLMAWidget *vlmObj )
390 391 392 393
{
    int index = vlmItems.indexOf( vlmObj );
    if( index < 0 ) return;
    delete ui.vlmListItem->takeItem( index );
394
    vlmItems.removeAt( index );
395 396 397 398 399
    delete vlmObj;

    /* HERE BE DRAGONS VLM REQUEST */
}

400
void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
401 402 403 404 405 406 407 408 409 410
{
    currentIndex = vlmItems.indexOf( vlmObj );
    if( currentIndex < 0 ) return;

    ui.vlmListItem->setCurrentRow( currentIndex );
    ui.nameLedit->setText( vlmObj->name );
    ui.inputLedit->setText( vlmObj->input );
    ui.outputLedit->setText( vlmObj->output );
    ui.enableCheck->setChecked( vlmObj->b_enabled );

411 412 413 414 415 416 417 418 419
    switch( vlmObj->type )
    {
    case QVLM_Broadcast:
        ui.loopBCast->setChecked( (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped );
        break;
    case QVLM_VOD:
        ui.muxLedit->setText( (qobject_cast<VLMVod *>(vlmObj))->mux );
        break;
    case QVLM_Schedule:
420 421
        time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
        date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
422 423 424
        break;
    }

425 426 427 428 429
    ui.nameLedit->setReadOnly( true );
    ui.addButton->hide();
    ui.saveButton->show();
}

430 431 432 433 434 435
void VLMDialog::saveModifications()
{
    VLMAWidget *vlmObj = vlmItems.at( currentIndex );
    if( vlmObj )
    {
        vlmObj->input = ui.inputLedit->text();
436
        vlmObj->output = ui.outputLedit->text().remove( ":sout=" );
437 438 439 440 441 442 443 444 445 446 447
        vlmObj->setChecked( ui.enableCheck->isChecked() );
        vlmObj->b_enabled = ui.enableCheck->isChecked();
        switch( vlmObj->type )
        {
        case QVLM_Broadcast:
            (qobject_cast<VLMBroadcast *>(vlmObj))->b_looped = ui.loopBCast->isChecked();
            break;
        case QVLM_VOD:
            (qobject_cast<VLMVod *>(vlmObj))->mux = ui.muxLedit->text();
            break;
        case QVLM_Schedule:
448 449 450 451
            (qobject_cast<VLMSchedule *>(vlmObj))->schetime = time->dateTime();
            (qobject_cast<VLMSchedule *>(vlmObj))->schedate = date->dateTime();
            (qobject_cast<VLMSchedule *>(vlmObj))->rNumber = scherepeatnumber->value();
            (qobject_cast<VLMSchedule *>(vlmObj))->rDays = repeatDays->value();
452 453 454
            break;
           //           vlmObj->
        }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
455
        vlmObj->update();
456 457 458
    }
    clearWidgets();
}
459 460

/*********************************
461
 * VLMAWidget - Abstract class
462
 ********************************/
463

464 465 466 467
VLMAWidget::VLMAWidget( VLMWrapper *_vlm, const QString& _name,
                        const QString& _input, const QString& _inputOptions,
                        const QString& _output, bool _enabled,
                        VLMDialog *_parent, int _type )
468
                      : QGroupBox( _name, _parent )
469 470
{
    parent = _parent;
471
    vlm = _vlm;
472 473
    name = _name;
    input = _input;
Rémi Duraffort's avatar
Rémi Duraffort committed
474
    inputOptions = _inputOptions;
475 476
    output = _output;
    b_enabled = _enabled;
477 478 479
    type = _type;

    setCheckable( true );
480 481
    setChecked( b_enabled );

482
    objLayout = new QGridLayout( this );
483 484
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );

485 486 487 488 489 490 491
    nameLabel = new QLabel;
    objLayout->addWidget( nameLabel, 0, 0, 1, 4 );

    /*QLabel *time = new QLabel( "--:--/--:--" );
    objLayout->addWidget( time, 1, 3, 1, 2 );*/

    QToolButton *modifyButton = new QToolButton;
492
    modifyButton->setIcon( QIcon( ":/menu/settings.svg" ) );
493
    modifyButton->setToolTip( qtr("Change") );
494 495 496
    objLayout->addWidget( modifyButton, 0, 5 );

    QToolButton *deleteButton = new QToolButton;
497
    deleteButton->setIcon( QIcon( ":/toolbar/clear.svg" ) );
498
    deleteButton->setToolTip("Delete");
499 500 501 502
    objLayout->addWidget( deleteButton, 0, 6 );

    BUTTONACT( modifyButton, modify() );
    BUTTONACT( deleteButton, del() );
503
    CONNECT( this, clicked( bool ), this, toggleEnabled( bool ) );
504 505 506 507 508 509 510 511 512 513 514 515
}

void VLMAWidget::modify()
{
    parent->startModifyVLMItem( this );
}

void VLMAWidget::del()
{
    parent->removeVLMItem( this );
}

516 517
void VLMAWidget::toggleEnabled( bool b_enable )
{
518
    vlm->EnableItem( name, b_enable );
519 520
}

521
/****************
522
 * VLMBroadcast
523
 ****************/
524 525
VLMBroadcast::VLMBroadcast( VLMWrapper *vlm, const QString& _name,
                            const QString& _input,
Rémi Duraffort's avatar
Rémi Duraffort committed
526
                            const QString& _inputOptions,
527 528
                            const QString& _output, bool _enabled,
                            bool _looped, VLMDialog *_parent )
529 530 531
                          : VLMAWidget( vlm, _name, _input, _inputOptions,
                                        _output, _enabled, _parent,
                                        QVLM_Broadcast )
532
{
Christophe Mutricy's avatar
Christophe Mutricy committed
533
    nameLabel->setText( qtr("Broadcast: ") + name );
534
    type = QVLM_Broadcast;
535 536 537
    b_looped = _looped;

    playButton = new QToolButton;
538
    playButton->setIcon( QIcon( ":/toolbar/play_b.svg" ) );
539
    playButton->setToolTip( qtr("Play") );
540
    objLayout->addWidget( playButton, 1, 0 );
541
    b_playing = true;
542

543
    QToolButton *stopButton = new QToolButton;
544
    stopButton->setIcon( QIcon( ":/toolbar/stop_b.svg" ) );
545
    stopButton->setToolTip( qtr("Stop") );
546
    objLayout->addWidget( stopButton, 1, 1 );
547

548
    loopButton = new QToolButton;
549
    loopButton->setToolTip( qtr("Repeat") );
550
    objLayout->addWidget( loopButton, 1, 2 );
551

552 553 554
    BUTTONACT( playButton, togglePlayPause() );
    BUTTONACT( stopButton, stop() );
    BUTTONACT( loopButton, toggleLoop() );
555

556
    update();
557 558
}

559 560
void VLMBroadcast::update()
{
561
    vlm->EditBroadcast( name, input, inputOptions, output, b_enabled, b_looped );
562
    if( b_looped )
563
        loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_all.svg" ) );
564
    else
565
        loopButton->setIcon( QIcon( ":/buttons/playlist/repeat_off.svg" ) );
566
}
567 568

void VLMBroadcast::togglePlayPause()
569
{
Rémi Duraffort's avatar
Rémi Duraffort committed
570
    if( b_playing )
571
    {
572
        vlm->ControlBroadcast( name, ControlBroadcastPause );
573
        playButton->setIcon( QIcon( ":/toolbar/pause_b.svg" ) );
574 575 576
    }
    else
    {
577
        vlm->ControlBroadcast( name, ControlBroadcastPlay );
578
        playButton->setIcon( QIcon( ":/toolbar/play_b.svg" ) );
579 580
    }
    b_playing = !b_playing;
581
}
582

583
void VLMBroadcast::toggleLoop()
584
{
585 586
    b_enabled = !b_enabled;
    update();
587 588
}

589
void VLMBroadcast::stop()
590
{
591
    vlm->ControlBroadcast( name, ControlBroadcastStop );
592
    playButton->setIcon( QIcon( ":/menu/play.svg" ) );
593 594
}

595 596 597
/****************
 * VLMSchedule
 ****************/
598 599
VLMSchedule::VLMSchedule( VLMWrapper *vlm, const QString& name_,
                          const QString& input, const QString& inputOptions,
600 601 602
                          const QString& output, QDateTime _schetime,
                          QDateTime _schedate, int _scherepeatnumber,
                          int _repeatDays, bool enabled, VLMDialog *parent )
603 604
            : VLMAWidget( vlm, name_, input, inputOptions, output, enabled,
                          parent, QVLM_Schedule )
605
{
Christophe Mutricy's avatar
Christophe Mutricy committed
606
    nameLabel->setText( qtr("Schedule: ") + name );
607 608 609 610 611 612
    schetime = _schetime;
    schedate = _schedate;
    rNumber = _scherepeatnumber;
    rDays = _repeatDays;
    type = QVLM_Schedule;
    update();
613
}
614

615
void VLMSchedule::update()
616
{
617 618
    vlm->EditSchedule( name, input, inputOptions, output, schetime, schedate,
                       rNumber, rDays, b_enabled);
619
}
620

621 622 623
/****************
 * VLMVOD
 ****************/
624
VLMVod::VLMVod( VLMWrapper *vlm, const QString& name_, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
625
                const QString& inputOptions, const QString& output,
626
                bool enabled, const QString& _mux, VLMDialog *parent)
627
       : VLMAWidget( vlm, name_, input, inputOptions, output, enabled, parent,
Rémi Duraffort's avatar
Rémi Duraffort committed
628
                     QVLM_VOD )
629
{
Christophe Mutricy's avatar
Christophe Mutricy committed
630
    nameLabel->setText( qtr("VOD: ") + name );
631 632 633 634

    mux = _mux;
    muxLabel = new QLabel;
    objLayout->addWidget( muxLabel, 1, 0 );
635

636 637 638 639 640 641
    update();
}

void VLMVod::update()
{
    muxLabel->setText( mux );
642
    vlm->EditVod( name, input, inputOptions, output, b_enabled, mux );
643 644 645 646 647 648 649
}


/*******************
 * VLMWrapper
 *******************/

650
VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
651
{
652
    p_vlm = _p_vlm;
653 654
}

655
VLMWrapper::~VLMWrapper()
656
{
657
    vlm_Delete( p_vlm );
658
}
659

660 661 662 663 664 665 666 667
int VLMWrapper::GetMedias( vlm_media_t **& array )
{
    int count;

    vlm_Control( p_vlm, VLM_GET_MEDIAS, &array, &count );
    return count;
}

668
void VLMWrapper::AddBroadcast( const QString& name, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
669
                               const QString& inputOptions, const QString& output,
670 671 672 673 674 675
                               bool b_enabled, bool b_loop  )
{
    vlm_message_t *message;
    QString command = "new \"" + name + "\" broadcast";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
Rémi Duraffort's avatar
Rémi Duraffort committed
676
    EditBroadcast( name, input, inputOptions, output, b_enabled, b_loop );
677 678
}

679
void VLMWrapper::EditBroadcast( const QString& name, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
680
                                const QString& inputOptions, const QString& output,
681 682 683 684
                                bool b_enabled, bool b_loop  )
{
    vlm_message_t *message;
    QString command;
685

686 687 688
    command = "setup \"" + name + "\" inputdel all";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
689

Rémi Duraffort's avatar
Rémi Duraffort committed
690
    if( !input.isEmpty() )
691
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
692
        command = "setup \"" + name + "\" input \"" + input + "\"";
693 694 695
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );

Rémi Duraffort's avatar
Rémi Duraffort committed
696
        QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
697
        for( int i = 0; i < options.count(); i++ )
698
        {
Rémi Duraffort's avatar
Rémi Duraffort committed
699
            command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
700 701 702 703 704
            vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
            vlm_MessageDelete( message );
        }
    }

705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
    if( !output.isEmpty() )
    {
        command = "setup \"" + name + "\" output \"" + output + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
    if( b_enabled )
    {
        command = "setup \"" + name + "\" enabled";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
    if( b_loop )
    {
        command = "setup \"" + name + "\" loop";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
}

725
void VLMWrapper::EnableItem( const QString& name, bool b_enable )
726 727 728
{
    vlm_message_t *message;
    QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
729 730
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
731 732
}

733
void VLMWrapper::ControlBroadcast( const QString& name, int BroadcastStatus,
734 735 736 737
                                   unsigned int seek )
{
    vlm_message_t *message;

738
    QString command = "control \"" + name + "\"";
739 740 741 742 743 744 745 746 747 748 749 750
    switch( BroadcastStatus )
    {
    case ControlBroadcastPlay:
        command += " play";
        break;
    case ControlBroadcastPause:
        command += " pause";
        break;
    case ControlBroadcastStop:
        command += " stop";
        break;
    case ControlBroadcastSeek:
751
        command += " seek " + QString::number( seek );
752 753 754 755 756 757
        break;
    }
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
}

758
void VLMWrapper::AddVod( const QString& name, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
759
                         const QString& inputOptions, const QString& output,
760
                         bool b_enabled, const QString& mux )
761 762 763 764 765
{
    vlm_message_t *message;
    QString command = "new \"" + name + "\" vod";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
Rémi Duraffort's avatar
Rémi Duraffort committed
766
    EditVod(  name, input, inputOptions, output, b_enabled, mux );
767 768
}

769
void VLMWrapper::EditVod( const QString& name, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
770
                          const QString& inputOptions, const QString& output,
771
                          bool b_enabled,
772
                          const QString& mux )
773 774
{
    vlm_message_t *message;
775 776
    QString command;

Rémi Duraffort's avatar
Rémi Duraffort committed
777
    if( !input.isEmpty() )
778
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
779
        command = "setup \"" + name + "\" input \"" + input + "\"";
780 781 782
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );

Rémi Duraffort's avatar
Rémi Duraffort committed
783
        QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
784
        for( int i = 0; i < options.count(); i++ )
785
        {
Rémi Duraffort's avatar
Rémi Duraffort committed
786
            command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
787 788 789 790
            vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
            vlm_MessageDelete( message );
        }
    }
791

792 793 794 795 796 797
    if( !output.isEmpty() )
    {
        command = "setup \"" + name + "\" output \"" + output + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
798

799 800 801 802 803 804 805 806 807 808 809 810
    if( b_enabled )
    {
        command = "setup \"" + name + "\" enabled";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
    if( !mux.isEmpty() )
    {
        command = "setup \"" + name + "\" mux \"" + mux + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
811
}
812

813
void VLMWrapper::AddSchedule( const QString& name, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
814 815
                              const QString& inputOptions, const QString& output,
                              QDateTime _schetime, QDateTime _schedate,
816
                              int _scherepeatnumber, int _repeatDays,
817
                              bool b_enabled, const QString& mux )
818 819 820 821 822
{
    vlm_message_t *message;
    QString command = "new \"" + name + "\" schedule";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
Rémi Duraffort's avatar
Rémi Duraffort committed
823
    EditSchedule(  name, input, inputOptions, output, _schetime, _schedate,
824 825 826
            _scherepeatnumber, _repeatDays, b_enabled, mux );
}

827
void VLMWrapper::EditSchedule( const QString& name, const QString& input,
Rémi Duraffort's avatar
Rémi Duraffort committed
828 829 830 831
                               const QString& inputOptions, const QString& output,
                               QDateTime _schetime, QDateTime _schedate,
                               int _scherepeatnumber, int _repeatDays,
                               bool b_enabled, const QString& mux )
832 833
{
    vlm_message_t *message;
834 835
    QString command;

Rémi Duraffort's avatar
Rémi Duraffort committed
836
    if( !input.isEmpty() )
837
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
838
        command = "setup \"" + name + "\" input \"" + input + "\"";
839 840 841
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );

Rémi Duraffort's avatar
Rémi Duraffort committed
842
        QStringList options = inputOptions.split( " :", QString::SkipEmptyParts );
843
        for( int i = 0; i < options.count(); i++ )
844
        {
Rémi Duraffort's avatar
Rémi Duraffort committed
845
            command = "setup \"" + name + "\" option \"" + options[i].trimmed() + "\"";
846 847 848 849
            vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
            vlm_MessageDelete( message );
        }
    }
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876

    if( !output.isEmpty() )
    {
        command = "setup \"" + name + "\" output \"" + output + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }

    if( b_enabled )
    {
        command = "setup \"" + name + "\" enabled";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }

    if( !mux.isEmpty() )
    {
        command = "setup \"" + name + "\" mux \"" + mux + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }

    command = "setup \"" + name + "\" date \"" +
        _schedate.toString( "yyyy/MM/dd" )+ "-" +
        _schetime.toString( "hh:mm:ss" ) + "\"";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
877

878 879 880 881 882 883
    if( _scherepeatnumber > 0 )
    {
       command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
       vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
       vlm_MessageDelete( message );
    }
884 885 886 887 888 889 890

    if( _repeatDays > 0 )
    {
       command = "setup \"" + name + "\" period \"" + _repeatDays + "\"";
       vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
       vlm_MessageDelete( message );
    }
891 892
}

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
void VLMWrapper::SaveConfig( const QString& filename )
{
    /* FIXME: escaping */
    QString command = "save \"" + filename + "\"";
    vlm_message_t *message;

    vlm_ExecuteCommand( p_vlm , qtu( command ), &message );
    vlm_MessageDelete( message );
}

bool VLMWrapper::LoadConfig( const QString& filename )
{
    /* FIXME: escaping */
    QString command = "load \"" + filename + "\"";
    vlm_message_t *message;
    int status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
    vlm_MessageDelete( message );
    return status == 0;
}

913 914
void VLMDialog::toggleVisible()
{
915
    qDeleteAll( vlmItems );
916
    vlmItems.clear();
917

918 919
    ui.vlmListItem->clear();
    mediasPopulator();
920
    QVLCFrame::toggleVisible();
921 922
}

923

924
#endif