sout.cpp 7.69 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1
/*****************************************************************************
2
 * sout.cpp : Stream output dialog ( old-style )
Clément Stenac's avatar
Clément Stenac committed
3
 ****************************************************************************
4
 * Copyright (C) 2007-2009 the VideoLAN team
5
 *
6
 * $Id$
Clément Stenac's avatar
Clément Stenac committed
7 8
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
Clément Stenac's avatar
Clément Stenac committed
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.
Clément Stenac's avatar
Clément Stenac committed
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
Clément Stenac's avatar
Clément Stenac committed
29 30

#include "dialogs/sout.hpp"
31
#include "util/qt_dirs.hpp"
32
#include "components/sout/sout_widgets.hpp"
Clément Stenac's avatar
Clément Stenac committed
33

34
#include <QString>
Clément Stenac's avatar
Clément Stenac committed
35
#include <QFileDialog>
36
#include <QToolButton>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
37

38
SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, const QString& inputMRL )
39
           : QVLCDialog( parent,  _p_intf )
Clément Stenac's avatar
Clément Stenac committed
40
{
41
    setWindowTitle( qtr( "Stream Output" ) );
42

Clément Stenac's avatar
Clément Stenac committed
43
    /* UI stuff */
44
    ui.setupUi( this );
45
    ui.inputBox->setMRL( inputMRL );
46 47 48 49 50 51
    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" );
52

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

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#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() );

81
//     /* Connect everything to the updateMRL function */
82
 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
83
 #define CT( x ) CONNECT( ui.x, textChanged( const QString& ), this, updateMRL() );
84 85
 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
86

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

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

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

99 100
    BUTTONACT( okButton, ok() );
    BUTTONACT( cancelButton, cancel() );
101

102 103
    BUTTONACT( ui.nextButton, next() );
    BUTTONACT( ui.nextButton2, next() );
104 105
    BUTTONACT( ui.prevButton, prev() );
    BUTTONACT( ui.prevButton2, prev() );
106 107 108 109 110
}

void SoutDialog::next()
{
    ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
111
}
Clément Stenac's avatar
Clément Stenac committed
112

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

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

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

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

134
void SoutDialog::addDest( )
135
{
136 137
    int index;
    switch( ui.destBox->currentIndex() )
138
    {
139 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
        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() );
            }
180
    }
181 182 183

    ui.destTab->setCurrentIndex( index );
    updateMRL();
184 185
}

Clément Stenac's avatar
Clément Stenac committed
186 187
void SoutDialog::ok()
{
188
    mrl = ui.mrlEdit->toPlainText();
189
    accept();
Clément Stenac's avatar
Clément Stenac committed
190
}
191

Clément Stenac's avatar
Clément Stenac committed
192 193
void SoutDialog::cancel()
{
194
    mrl.clear();
195
    reject();
Clément Stenac's avatar
Clément Stenac committed
196 197 198 199
}

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

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

209
    bool multi = false;
210

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

215 216
    if( multi )
        smrl.begin( "duplicate" );
217

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

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

243
    if ( multi ) smrl.end();
244

245
    mrl = smrl.getMrl();
246

247 248 249 250
    /* 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() ) ); */
251

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

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

256
    ui.mrlEdit->setPlainText( mrl );
257
}
258