vlm.cpp 26 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 36

#include <QString>
37 38 39 40 41 42 43 44 45 46 47 48
#include <QComboBox>
#include <QVBoxLayout>
#include <QStackedWidget>
#include <QLabel>
#include <QWidget>
#include <QGridLayout>
#include <QLineEdit>
#include <QCheckBox>
#include <QToolButton>
#include <QGroupBox>
#include <QPushButton>
#include <QHBoxLayout>
49
#include <QDateTimeEdit>
50
#include <QDateTime>
51
#include <QSpinBox>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
52
#include <QHeaderView>
53
#include <QScrollArea>
54
#include <QFileDialog>
55

56
static const char *psz_type[] = { "Broadcast", "Schedule", "VOD" };
57

58
VLMDialog *VLMDialog::instance = NULL;
59

60
VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
61
{
62 63 64
    p_vlm = vlm_New( p_intf );

    if( !p_vlm )
65 66
    {
        msg_Warn( p_intf, "Couldn't build VLM object ");
67
        return;
68
    }
69
    vlmWrapper = new VLMWrapper( p_vlm );
70

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
75 76 77
#define ADDMEDIATYPES( str, type ) ui.mediaType->addItem( qtr( str ), QVariant( type ) );
    ADDMEDIATYPES( "Broadcast", QVLM_Broadcast );
    ADDMEDIATYPES( "Schedule", QVLM_Schedule );
78
    ADDMEDIATYPES( "Video On Demand ( VOD )", QVLM_VOD );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
79
#undef ADDMEDIATYPES
80 81 82

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

    time = new QDateTimeEdit( QTime::currentTime() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
93
    time->setAlignment( Qt::AlignRight );
94
    time->setDisplayFormat( "hh:mm:ss" );
95 96 97
    schetimelayout->addWidget( time, 0, 1, 1, 3 );

    date = new QDateTimeEdit( QDate::currentDate() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
98
    date->setAlignment( Qt::AlignRight );
99
    date->setCalendarPopup( true );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
100 101 102 103 104
#ifdef WIN32
    date->setDisplayFormat( "dd MM yyyy" );
#else
    date->setDisplayFormat( "dd MMMM yyyy" );
#endif
105
    schetimelayout->addWidget( date, 1, 1, 1, 3 );
106

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
107 108
    scherepeatnumber = new QSpinBox;
    scherepeatnumber->setAlignment( Qt::AlignRight );
109 110 111 112 113 114 115 116 117 118 119 120
    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" );

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

129 130
    QSpacerItem *spacer =
        new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
131
    vlmItemLayout->addItem( spacer );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
132

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
133
    QPushButton *importButton = new QPushButton( qtr( "Import" ) );
134 135
    ui.buttonBox->addButton( importButton, QDialogButtonBox::ActionRole );

136 137 138
    QPushButton *exportButton = new QPushButton( qtr( "Export" ) );
    ui.buttonBox->addButton( exportButton, QDialogButtonBox::ActionRole );

139
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
140 141
    ui.buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );

142

143
    showScheduleWidget( QVLM_Broadcast );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
144

145 146 147
    /* Connect the comboBox to show the right Widgets */
    CONNECT( ui.mediaType, currentIndexChanged( int ),
             this, showScheduleWidget( int ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
148

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

153
    BUTTONACT( closeButton, close() );
154
    BUTTONACT( exportButton, exportVLMConf() );
155
    BUTTONACT( importButton, importVLMConf() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
156
    BUTTONACT( ui.addButton, addVLMItem() );
157 158
    BUTTONACT( ui.clearButton, clearWidgets() );
    BUTTONACT( ui.saveButton, saveModifications() );
159
    BUTTONACT( ui.inputButton, selectInput() );
160
    BUTTONACT( ui.outputButton, selectOutput() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
161 162
}

163 164
VLMDialog::~VLMDialog()
{
165 166
    delete vlmWrapper;

167 168 169
   /* FIXME :you have to destroy vlm here to close
    * but we shouldn't destroy vlm here in case somebody else wants it */
    if( p_vlm )
170
    {
171
        vlm_Delete( p_vlm );
172
    }
173
}
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
174

175
void VLMDialog::showScheduleWidget( int i )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
176
{
177
    ui.schedBox->setVisible( ( i == QVLM_Schedule ) );
178 179
    ui.loopBCast->setVisible( ( i == QVLM_Broadcast ) );
    ui.vodBox->setVisible( ( i == QVLM_VOD ) );
180
}
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
181

182 183
void VLMDialog::selectVLMItem( int i )
{
184 185
    if( i >= 0 )
        ui.vlmItemScroll->ensureWidgetVisible( vlmItems.at( i ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
186 187
}

188
bool VLMDialog::isNameGenuine( QString name )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
189
{
190 191 192 193 194 195
    for( int i = 0; i < vlmItems.size(); i++ )
    {
        if( vlmItems.at( i )->name == name )
            return false;
    }
    return true;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
196 197 198 199
}

void VLMDialog::addVLMItem()
{
200
    int vlmItemCount = vlmItems.size();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
201

202 203 204 205
    /* 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
206
        msg_Err( p_intf, "VLM Name is empty or already exists, I can't do it" );
207 208 209 210
        return;
    }

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

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

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

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

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

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

262 263 264 265 266
// FIXME : VOD are not exported to the file
bool VLMDialog::exportVLMConf()
{
    QString saveVLMConfFileName = QFileDialog::getSaveFileName(
            this, qtr( "Choose a filename to save the VLM configuration..." ),
267
            qfu( config_GetHomeDir() ),
268 269 270 271 272 273 274 275 276 277 278 279 280
            qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );

    if( !saveVLMConfFileName.isEmpty() )
    {
        vlm_message_t *message;
        QString command = "save \"" + saveVLMConfFileName + "\"";
        vlm_ExecuteCommand( p_vlm , qtu( command ) , &message );
        vlm_MessageDelete( message );
        return true;
    }
    return false;
}

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
void VLMDialog::mediasPopulator()
{
    if( p_vlm )
    {
        int i_nMedias;
        QString typeShortName;
        int vlmItemCount;
        vlm_media_t ***ppp_dsc = (vlm_media_t ***)malloc( sizeof( vlm_media_t ) );

        /* Get medias informations and numbers */
        vlm_Control( p_vlm, VLM_GET_MEDIAS, ppp_dsc, &i_nMedias );

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

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

            QString outputText = qfu( (*ppp_dsc)[i]->psz_output );

            /* Schedule media is a quite especial, maybe there is another way to grab informations */
            if( (*ppp_dsc)[i]->b_vod )
            {
                typeShortName = "VOD";
                QString mux = qfu( (*ppp_dsc)[i]->vod.psz_mux );
                vlmAwidget = new VLMVod( mediaName, inputText, outputText,
                                    (*ppp_dsc)[i]->b_enabled, mux, this );
            }
            else
            {
                typeShortName = "Bcast";
                vlmAwidget = new VLMBroadcast( mediaName, inputText, outputText,
                                  (*ppp_dsc)[i]->b_enabled, (*ppp_dsc)[i]->broadcast.b_loop, this );
            }
            /* 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();
        }
        free( ppp_dsc );
    }
}
332

333 334
bool VLMDialog::importVLMConf()
{
335
    QString openVLMConfFileName = QFileDialog::getOpenFileName(
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
336
            this, qtr( "Open a VLM Configuration File" ),
337
            qfu( config_GetHomeDir() ),
338 339 340 341 342
            qtr( "VLM conf (*.vlm) ;; All (*.*)" ) );

    if( !openVLMConfFileName.isEmpty() )
    {
        vlm_message_t *message;
343
        int status;
344
        QString command = "load \"" + openVLMConfFileName + "\"";
345
        status = vlm_ExecuteCommand( p_vlm, qtu( command ) , &message );
346
        vlm_MessageDelete( message );
347 348 349 350 351 352
        if( status == 0 )
        {
            mediasPopulator();
        }
        else
        {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
353
            msg_Warn( p_intf, "Failed to import vlm configuration file : %s", qtu( command ) );
354 355
            return false;
        }
356 357 358
        return true;
    }
    return false;
359 360
}

361 362 363 364 365 366 367 368 369
void VLMDialog::clearWidgets()
{
    ui.nameLedit->clear();
    ui.inputLedit->clear();
    ui.outputLedit->clear();
    time->setTime( QTime::currentTime() );
    date->setDate( QDate::currentDate() );
    ui.enableCheck->setChecked( true );
    ui.nameLedit->setReadOnly( false );
370 371
    ui.loopBCast->setChecked( false );
    ui.muxLedit->clear();
372 373
    ui.saveButton->hide();
    ui.addButton->show();
374 375
}

376 377
void VLMDialog::selectInput()
{
378
    OpenDialog *o = OpenDialog::getInstance( this, p_intf, SELECT, true );
379 380 381 382
    o->exec();
    ui.inputLedit->setText( o->getMRL() );
}

383 384 385 386 387 388 389
void VLMDialog::selectOutput()
{
    SoutDialog *s = SoutDialog::getInstance( this, p_intf, false );
    if( s->exec() == QDialog::Accepted )
        ui.outputLedit->setText( s->getMrl() );
}

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

    /* HERE BE DRAGONS VLM REQUEST */
}

402
void VLMDialog::startModifyVLMItem( VLMAWidget *vlmObj )
403 404 405 406 407 408 409 410 411 412
{
    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 );

413 414 415 416 417 418 419 420 421
    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:
422 423
        time->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schetime );
        date->setDateTime( ( qobject_cast<VLMSchedule *>(vlmObj))->schedate );
424 425 426
        break;
    }

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

432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
void VLMDialog::saveModifications()
{
    VLMAWidget *vlmObj = vlmItems.at( currentIndex );
    if( vlmObj )
    {
        vlmObj->input = ui.inputLedit->text();
        vlmObj->output = ui.outputLedit->text();
        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:
450 451 452 453
            (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();
454 455 456 457 458 459 460 461
            break;
           //           vlmObj->
        }
        vlmObj->update(); /* It should call the correct function is VLMAWidget
                             is abstract, but I am far from sure... FIXME ? */
    }
    clearWidgets();
}
462 463

/*********************************
464
 * VLMAWidget - Abstract class
465
 ********************************/
466 467 468 469 470

VLMAWidget::VLMAWidget( QString _name,
                        QString _input,
                        QString _output,
                        bool _enabled,
471 472
                        VLMDialog *_parent,
                        int _type )
473
                      : QGroupBox( _name, _parent )
474 475 476 477 478 479
{
    parent = _parent;
    name = _name;
    input = _input;
    output = _output;
    b_enabled = _enabled;
480 481 482
    type = _type;

    setCheckable( true );
483 484
    setChecked( b_enabled );

485
    objLayout = new QGridLayout( this );
486 487
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );

488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    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;
    modifyButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_settings_16px.png" ) ) );
    objLayout->addWidget( modifyButton, 0, 5 );

    QToolButton *deleteButton = new QToolButton;
    deleteButton->setIcon( QIcon( QPixmap( ":/pixmaps/menus_quit_16px.png" ) ) );
    objLayout->addWidget( deleteButton, 0, 6 );

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

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

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

517 518 519 520 521
//FIXME, remove me before release
void VLMAWidget::enterEvent( QEvent *event )
{
    printf( "test" );
}
522

523 524 525 526 527
void VLMAWidget::toggleEnabled( bool b_enable )
{
    VLMWrapper::EnableItem( name, b_enable );
}

528
/****************
529
 * VLMBroadcast
530
 ****************/
531
VLMBroadcast::VLMBroadcast( QString _name, QString _input, QString _output,
532
                            bool _enabled, bool _looped, VLMDialog *_parent)
533
                          : VLMAWidget( _name, _input, _output,
534
                                        _enabled, _parent, QVLM_Broadcast )
535 536
{
    nameLabel->setText( "Broadcast: " + name );
537
    type = QVLM_Broadcast;
538 539 540
    b_looped = _looped;

    playButton = new QToolButton;
541 542
    playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
    objLayout->addWidget( playButton, 1, 0 );
543
    b_playing = true;
544

545 546 547
    QToolButton *stopButton = new QToolButton;
    stopButton->setIcon( QIcon( QPixmap( ":/pixmaps/stop_16px.png" ) ) );
    objLayout->addWidget( stopButton, 1, 1 );
548

549
    loopButton = new QToolButton;
550
    objLayout->addWidget( loopButton, 1, 2 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
551

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

556
    update();
557 558
}

559 560
void VLMBroadcast::update()
{
561
    VLMWrapper::EditBroadcast( name, input, output, b_enabled, b_looped );
562 563 564 565 566
    if( b_looped )
        loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_all.png" ) ) );
    else
        loopButton->setIcon( QIcon( QPixmap( ":/pixmaps/playlist_repeat_off.png" ) ) );
}
567 568

void VLMBroadcast::togglePlayPause()
569
{
570 571
    if( b_playing = true )
    {
572
        VLMWrapper::ControlBroadcast( name, ControlBroadcastPause );
573 574 575 576
        playButton->setIcon( QIcon( QPixmap( ":/pixmaps/pause_16px.png" ) ) );
    }
    else
    {
577
        VLMWrapper::ControlBroadcast( name, ControlBroadcastPlay );
578 579 580
        playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
    }
    b_playing = !b_playing;
581
}
582

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

589
void VLMBroadcast::stop()
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
590
{
591
    VLMWrapper::ControlBroadcast( name, ControlBroadcastStop );
592
    playButton->setIcon( QIcon( QPixmap( ":/pixmaps/play_16px.png" ) ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
593 594
}

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

613
void VLMSchedule::update()
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
614
{
615 616
   VLMWrapper::EditSchedule( name, input, output, schetime, schedate,
                             rNumber, rDays, b_enabled);
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
617
}
618

619 620 621
/****************
 * VLMVOD
 ****************/
622
VLMVod::VLMVod( QString name, QString input, QString output,
623 624
                bool enabled, QString _mux, VLMDialog *parent)
       : VLMAWidget( name, input, output, enabled, parent, QVLM_VOD )
625
{
626
    nameLabel->setText( "VOD:" + name );
627 628 629 630

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

632 633 634 635 636 637
    update();
}

void VLMVod::update()
{
    muxLabel->setText( mux );
638
    VLMWrapper::EditVod( name, input, output, b_enabled, mux );
639 640 641 642 643 644
}


/*******************
 * VLMWrapper
 *******************/
645
vlm_t * VLMWrapper::p_vlm = NULL;
646

647
VLMWrapper::VLMWrapper( vlm_t *_p_vlm )
648
{
649
    p_vlm = _p_vlm;
650 651
}

652
VLMWrapper::~VLMWrapper()
653 654 655
{
    p_vlm = NULL;
}
656

657
void VLMWrapper::AddBroadcast( const QString name, QString input,
658 659 660 661 662 663 664
                               QString output,
                               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 );
665
    EditBroadcast( name, input, output, b_enabled, b_loop );
666 667
}

668
void VLMWrapper::EditBroadcast( const QString name, const QString input,
669 670 671 672 673
                                const QString output,
                                bool b_enabled, bool b_loop  )
{
    vlm_message_t *message;
    QString command;
674

675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    command = "setup \"" + name + "\" inputdel all";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
    command = "setup \"" + name + "\" input \"" + input + "\"";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
    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 );
    }
}

701 702 703 704 705 706
void VLMWrapper::EnableItem( const QString name, bool b_enable )
{
    vlm_message_t *message;
    QString command = "setup \"" + name + ( b_enable ? " enable" : " disable" );
}

707
void VLMWrapper::ControlBroadcast( const QString name, int BroadcastStatus,
708 709 710 711
                                   unsigned int seek )
{
    vlm_message_t *message;

712
    QString command = "control \"" + name;
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
    switch( BroadcastStatus )
    {
    case ControlBroadcastPlay:
        command += " play";
        break;
    case ControlBroadcastPause:
        command += " pause";
        break;
    case ControlBroadcastStop:
        command += " stop";
        break;
    case ControlBroadcastSeek:
        command += " seek" + seek;
        break;
    }
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
}

732
void VLMWrapper::AddVod( const QString name, const QString input,
733 734 735 736 737 738 739
                         const QString output,
                         bool b_enabled, const QString mux )
{
    vlm_message_t *message;
    QString command = "new \"" + name + "\" vod";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
740
    EditVod(  name, input, output, b_enabled, mux );
741 742
}

743
void VLMWrapper::EditVod( const QString name, const QString input,
744
                          const QString output,
745 746 747 748 749 750 751
                          bool b_enabled,
                          const QString mux )
{
    vlm_message_t *message;
    QString command = "setup \"" + name + "\" input \"" + input + "\"";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
752

753 754 755 756 757 758
    if( !output.isEmpty() )
    {
        command = "setup \"" + name + "\" output \"" + output + "\"";
        vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
        vlm_MessageDelete( message );
    }
759

760 761 762 763 764 765 766 767 768 769 770 771
    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 );
    }
772
}
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833

void VLMWrapper::AddSchedule( const QString name, const QString input,
                              const QString output, QDateTime _schetime,
                              QDateTime _schedate,
                              int _scherepeatnumber, int _repeatDays,
                              bool b_enabled, const QString mux )
{
    vlm_message_t *message;
    QString command = "new \"" + name + "\" schedule";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );
    EditSchedule(  name, input, output, _schetime, _schedate,
            _scherepeatnumber, _repeatDays, b_enabled, mux );
}

void VLMWrapper::EditSchedule( const QString name, const QString input,
                          const QString output, QDateTime _schetime,
                          QDateTime _schedate, int _scherepeatnumber,
                          int _repeatDays, bool b_enabled,
                          const QString mux )
{
    vlm_message_t *message;
    QString command = "setup \"" + name + "\" input \"" + input + "\"";
    vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
    vlm_MessageDelete( message );

    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 );
    if( _scherepeatnumber > 0 )
    {
       command = "setup \"" + name + "\" repeat \"" + _scherepeatnumber + "\"";
       vlm_ExecuteCommand( p_vlm, qtu( command ), &message );
       vlm_MessageDelete( message );
    }
}


834
#endif