sout.cpp 7.69 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>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
37

38 39
SoutDialog* SoutDialog::instance = NULL;

40
SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, QString inputMRL )
41
           : QVLCDialog( parent,  _p_intf )
42
{
43
    setWindowTitle( qtr( "Stream Output" ) );
44

45
    /* UI stuff */
46
    ui.setupUi( this );
47
    ui.inputBox->setMRL( inputMRL );
48 49 50 51 52 53
    ui.helpEdit->setPlainText( "This dialog will allow you to stream or "
            "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\" "
            "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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#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 );
    closeTabButton->setIcon( QIcon( ":/clear" ) );
    BUTTONACT( closeTabButton, closeTab() );
#endif
    CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
    ui.destTab->setTabIcon( 0, QIcon( ":/playlist_add" ) );

    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 */
84
 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
85 86 87
 #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() );
108 109 110 111 112
}

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

115 116 117 118 119
void SoutDialog::prev()
{
    ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
}

120
void SoutDialog::tabChanged( int i )
121
{
122
    closeTabButton->setVisible( (i != 0) );
123 124
}

125
void SoutDialog::closeTab()
126
{
127 128
    int i = ui.destTab->currentIndex();
    if( i == 0 ) return;
129

130 131 132
    QWidget *temp = ui.destTab->currentWidget();
    ui.destTab->removeTab( i );
    delete temp;
133
    updateMRL();
134 135
}

136
void SoutDialog::addDest( )
137
{
138 139
    int index;
    switch( ui.destBox->currentIndex() )
140
    {
141 142 143 144 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
        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() );
            }
182
    }
183 184 185

    ui.destTab->setCurrentIndex( index );
    updateMRL();
186 187
}

188 189
void SoutDialog::ok()
{
190
    mrl = ui.mrlEdit->toPlainText();
191
    accept();
192
}
193

194 195
void SoutDialog::cancel()
{
196
    mrl.clear();
197
    reject();
198 199 200 201
}

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

204
    SoutMrl smrl( ":sout=#" );
205 206 207 208 209
    if( !ui.profileSelect->getTranscode().isEmpty() )
    {
        smrl.begin( ui.profileSelect->getTranscode() );
        smrl.end();
    }
210

211
    bool multi = false;
212

213 214 215
    if( ui.destTab->count() >= 3 ||
        ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
        multi = true;
216

217 218
    if( multi )
        smrl.begin( "duplicate" );
219

220 221 222 223
    for( int i = 1; i < ui.destTab->count(); i++ )
    {
        VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
        QString tempMRL = vdb->getMRL( qs_mux );
224

225 226 227 228
        if( tempMRL.isEmpty() ) continue;
        if( multi )
            smrl.option( "dst", tempMRL );
        else
229
        {
230 231
            smrl.begin( tempMRL);
            smrl.end();
232
        }
233 234 235 236 237 238
    }
    if( ui.localOutput->isChecked() )
    {
        if( multi )
            smrl.option( "dst", "display" );
        else
239
        {
240 241
            smrl.begin( "display" );
            smrl.end();
242
        }
243
    }
244

245
    if ( multi ) smrl.end();
246

247
    mrl = smrl.getMrl();
248

249 250 251 252
    /* FIXME, deal with SAP 
    sout.b_sap = ui.sap->isChecked();
    sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
    sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
253

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

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

258
    ui.mrlEdit->setPlainText( mrl );
259
}
260