sout.cpp 7.87 KB
Newer Older
1
/*****************************************************************************
2
 * sout.cpp : Stream output dialog ( old-style )
3
 ****************************************************************************
4
 * Copyright (C) 2007-2009 the VideoLAN team
5
 *
6
 * $Id$
7 8
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
10 11 12 13
 *
 * 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
14
 * ( at your option ) any later version.
15 16 17 18 19 20 21 22 23 24
 *
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
25

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

#include "dialogs/sout.hpp"
31
#include "util/qt_dirs.hpp"
32
#include "components/sout/sout_widgets.hpp"
33

34
#include <QString>
35
#include <QFileDialog>
36
#include <QToolButton>
37
#include <assert.h>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
38

39
SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, const QString& inputMRL )
40
           : QVLCDialog( parent,  _p_intf )
41
{
42
    setWindowTitle( qtr( "Stream Output" ) );
Nick Pope's avatar
Nick Pope committed
43
    setWindowRole( "vlc-stream-output" );
44

45
    /* UI stuff */
46
    ui.setupUi( this );
47
    ui.inputBox->setMRL( inputMRL );
Eric Lassauge's avatar
Eric Lassauge committed
48
    ui.helpEdit->setPlainText( qtr("This dialog will allow you to stream or "
49 50 51 52
            "convert your media for use locally, on your private network, "
            "or on the Internet.\n"
            "You should start by checking that source matches what you want "
            "your input to be and then press the \"Next\" "
Eric Lassauge's avatar
Eric Lassauge committed
53
            "button to continue.\n") );
54

55 56 57
    ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
                "This is automatically generated "
                 "when you change the above settings,\n"
58
                 "but you can change it manually." ) ) ;
59

60 61 62 63 64 65 66 67
#if 0
    /* This needs Qt4.5 to be cool */
    ui.destTab->setTabsClosable( true );
#else
    closeTabButton = new QToolButton( this );
    ui.destTab->setCornerWidget( closeTabButton );
    closeTabButton->hide();
    closeTabButton->setAutoRaise( true );
68
    closeTabButton->setIcon( QIcon( ":/toolbar/clear" ) );
69 70 71
    BUTTONACT( closeTabButton, closeTab() );
#endif
    CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
72
    ui.destTab->setTabIcon( 0, QIcon( ":/buttons/playlist/playlist_add" ) );
73 74 75 76 77 78 79 80 81 82

    ui.destBox->addItem( qtr( "File" ) );
    ui.destBox->addItem( "HTTP" );
    ui.destBox->addItem( "MMS" );
    ui.destBox->addItem( "UDP" );
    ui.destBox->addItem( "RTP" );
    ui.destBox->addItem( "IceCast" );

    BUTTONACT( ui.addButton, addDest() );

83
//     /* Connect everything to the updateMRL function */
Rémi Duraffort's avatar
Rémi Duraffort committed
84 85 86 87
#define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
#define CT( x ) CONNECT( ui.x, textChanged( const QString& ), this, updateMRL() );
#define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
#define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
88

89
    /* Misc */
90
    CB( soutAll ); CB( soutKeep );  CS( ttl ); CT( sapName ); CT( sapGroup );
91 92
    CB( localOutput );
    CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
93

94
    okButton = new QPushButton( qtr( "&Stream" ) );
95 96 97 98 99 100
    QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );

    okButton->setDefault( true );
    ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
    ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );

101 102
    BUTTONACT( okButton, ok() );
    BUTTONACT( cancelButton, cancel() );
103

104 105
    BUTTONACT( ui.nextButton, next() );
    BUTTONACT( ui.nextButton2, next() );
106 107
    BUTTONACT( ui.prevButton, prev() );
    BUTTONACT( ui.prevButton2, prev() );
Rémi Duraffort's avatar
Rémi Duraffort committed
108 109 110 111 112

#undef CC
#undef CS
#undef CT
#undef CB
113 114 115 116 117
}

void SoutDialog::next()
{
    ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
118
}
119

120 121 122 123 124
void SoutDialog::prev()
{
    ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
}

125
void SoutDialog::tabChanged( int i )
126
{
127
    closeTabButton->setVisible( (i != 0) );
128 129
}

130
void SoutDialog::closeTab()
131
{
132 133
    int i = ui.destTab->currentIndex();
    if( i == 0 ) return;
134

135 136 137
    QWidget *temp = ui.destTab->currentWidget();
    ui.destTab->removeTab( i );
    delete temp;
138
    updateMRL();
139 140
}

141
void SoutDialog::addDest( )
142
{
143 144
    int index;
    switch( ui.destBox->currentIndex() )
145
    {
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
        case 0:
            {
                FileDestBox *fdb = new FileDestBox( this );
                index = ui.destTab->addTab( fdb, "File" );
                CONNECT( fdb, mrlUpdated(), this, updateMRL() );
            }
            break;
        case 1:
            {
                HTTPDestBox *hdb = new HTTPDestBox( this );
                index = ui.destTab->addTab( hdb, "HTTP" );
                CONNECT( hdb, mrlUpdated(), this, updateMRL() );
            }
            break;
        case 2:
            {
                MMSHDestBox *mdb = new MMSHDestBox( this );
                index = ui.destTab->addTab( mdb, "MMSH" );
                CONNECT( mdb, mrlUpdated(), this, updateMRL() );
            }
            break;
        case 3:
            {
                UDPDestBox *udb = new UDPDestBox( this );
                index = ui.destTab->addTab( udb, "UDP" );
                CONNECT( udb, mrlUpdated(), this, updateMRL() );
            }
            break;
        case 4:
            {
                RTPDestBox *rdb = new RTPDestBox( this );
                index = ui.destTab->addTab( rdb, "RTP" );
                CONNECT( rdb, mrlUpdated(), this, updateMRL() );
            }
            break;
        case 5:
            {
                ICEDestBox *idb = new ICEDestBox( this );
                index = ui.destTab->addTab( idb, "Icecast" );
                CONNECT( idb, mrlUpdated(), this, updateMRL() );
            }
187 188 189
            break;
        default:
            assert(0);
190
    }
191 192 193

    ui.destTab->setCurrentIndex( index );
    updateMRL();
194 195
}

196 197
void SoutDialog::ok()
{
198
    mrl = ui.mrlEdit->toPlainText();
199
    accept();
200
}
201

202 203
void SoutDialog::cancel()
{
204
    mrl.clear();
205
    reject();
206 207 208 209
}

void SoutDialog::updateMRL()
{
210
    QString qs_mux = ui.profileSelect->getMux();
211

212
    SoutMrl smrl( ":sout=#" );
213
    if( !ui.profileSelect->getTranscode().isEmpty() && ui.transcodeBox->isChecked() )
214 215 216 217
    {
        smrl.begin( ui.profileSelect->getTranscode() );
        smrl.end();
    }
218

219
    bool multi = false;
220

221 222 223
    if( ui.destTab->count() >= 3 ||
        ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
        multi = true;
224

225 226
    if( multi )
        smrl.begin( "duplicate" );
227

228 229 230 231
    for( int i = 1; i < ui.destTab->count(); i++ )
    {
        VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
        QString tempMRL = vdb->getMRL( qs_mux );
232

233 234 235 236
        if( tempMRL.isEmpty() ) continue;
        if( multi )
            smrl.option( "dst", tempMRL );
        else
237
        {
238 239
            smrl.begin( tempMRL);
            smrl.end();
240
        }
241 242 243 244 245 246
    }
    if( ui.localOutput->isChecked() )
    {
        if( multi )
            smrl.option( "dst", "display" );
        else
247
        {
248 249
            smrl.begin( "display" );
            smrl.end();
250
        }
251
    }
252

253
    if ( multi ) smrl.end();
254

255
    mrl = smrl.getMrl();
256

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
257
    /* FIXME, deal with SAP
258 259 260
    sout.b_sap = ui.sap->isChecked();
    sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
    sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
261

262
    if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
263

264
    if( ui.soutKeep->isChecked() ) mrl.append( " :sout-keep" );
265

266
    ui.mrlEdit->setPlainText( mrl );
267
}
268