]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt4: implement SAP in the streaming wizard
[vlc] / modules / gui / qt4 / dialogs / sout.cpp
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  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * ( at your option ) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * 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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #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>
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" ) );
43     setWindowRole( "vlc-stream-output" );
44
45     /* UI stuff */
46     ui.setupUi( this );
47     ui.inputBox->setMRL( inputMRL );
48     ui.helpEdit->setPlainText( qtr("This dialog will allow you to stream or "
49             "convert your media for use locally, on your private network, "
50             "or on the Internet.\n"
51             "You should start by checking that source matches what you want "
52             "your input to be and then press the \"Next\" "
53             "button to continue.\n") );
54
55     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
56                 "This is automatically generated "
57                  "when you change the above settings,\n"
58                  "but you can change it manually." ) ) ;
59
60 #if 0
61     /* This needs Qt4.5 to be cool */
62     ui.destTab->setTabsClosable( true );
63 #else
64     closeTabButton = new QToolButton( this );
65     ui.destTab->setCornerWidget( closeTabButton );
66     closeTabButton->hide();
67     closeTabButton->setAutoRaise( true );
68     closeTabButton->setIcon( QIcon( ":/toolbar/clear" ) );
69     BUTTONACT( closeTabButton, closeTab() );
70 #endif
71     CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
72     ui.destTab->setTabIcon( 0, QIcon( ":/buttons/playlist/playlist_add" ) );
73
74     ui.destBox->addItem( qtr( "File" ) );
75     ui.destBox->addItem( "HTTP" );
76     ui.destBox->addItem( "MS-WMSP (MMSH)" );
77     ui.destBox->addItem( "RTP / MPEG Transport Stream" );
78     ui.destBox->addItem( "RTP Audio/Video Profile" );
79     ui.destBox->addItem( "UDP (legacy)" );
80     ui.destBox->addItem( "IceCast" );
81
82     BUTTONACT( ui.addButton, addDest() );
83
84 //     /* Connect everything to the updateMRL function */
85 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
86 #define CT( x ) CONNECT( ui.x, textChanged( const QString& ), this, updateMRL() );
87 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
88 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
89
90     /* Misc */
91     CB( soutAll );  CS( ttl ); CT( sapName ); CT( sapGroup );
92     CB( localOutput );
93     CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
94
95     okButton = new QPushButton( qtr( "&Stream" ) );
96     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
97
98     okButton->setDefault( true );
99     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
100     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
101
102     BUTTONACT( okButton, ok() );
103     BUTTONACT( cancelButton, cancel() );
104
105     BUTTONACT( ui.nextButton, next() );
106     BUTTONACT( ui.nextButton2, next() );
107     BUTTONACT( ui.prevButton, prev() );
108     BUTTONACT( ui.prevButton2, prev() );
109
110 #undef CC
111 #undef CS
112 #undef CT
113 #undef CB
114 }
115
116 void SoutDialog::next()
117 {
118     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
119 }
120
121 void SoutDialog::prev()
122 {
123     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
124 }
125
126 void SoutDialog::tabChanged( int i )
127 {
128     closeTabButton->setVisible( (i != 0) );
129 }
130
131 void SoutDialog::closeTab()
132 {
133     int i = ui.destTab->currentIndex();
134     if( i == 0 ) return;
135
136     QWidget *temp = ui.destTab->currentWidget();
137     ui.destTab->removeTab( i );
138     delete temp;
139     updateMRL();
140 }
141
142 void SoutDialog::addDest( )
143 {
144     VirtualDestBox *db;
145     QString caption;
146
147     switch( ui.destBox->currentIndex() )
148     {
149         case 0:
150             db = new FileDestBox( this );
151             caption = qtr( "File" );
152             break;
153         case 1:
154             db = new HTTPDestBox( this );
155             caption = qfu( "HTTP" );
156             break;
157         case 2:
158             db = new MMSHDestBox( this );
159             caption = qfu( "WMSP" );
160             break;
161         case 3:
162             db = new RTPDestBox( this, "ts" );
163             caption = "RTP/TS";
164             break;
165         case 4:
166             db = new RTPDestBox( this );
167             caption = "RTP/AVP";
168             break;
169         case 5:
170             db = new UDPDestBox( this );
171             caption = "UDP";
172             break;
173         case 6:
174             db = new ICEDestBox( this );
175             caption = "Icecast";
176             break;
177         default:
178             assert(0);
179     }
180
181     int index = ui.destTab->addTab( db, caption );
182     CONNECT( db, mrlUpdated(), this, updateMRL() );
183     ui.destTab->setCurrentIndex( index );
184     updateMRL();
185 }
186
187 void SoutDialog::ok()
188 {
189     mrl = ui.mrlEdit->toPlainText();
190     accept();
191 }
192
193 void SoutDialog::cancel()
194 {
195     mrl.clear();
196     reject();
197 }
198
199 void SoutDialog::updateMRL()
200 {
201     QString qs_mux = ui.profileSelect->getMux();
202
203     SoutMrl smrl( ":sout=#" );
204     if( !ui.profileSelect->getTranscode().isEmpty() && ui.transcodeBox->isChecked() )
205     {
206         smrl.begin( ui.profileSelect->getTranscode() );
207         smrl.end();
208     }
209
210     bool multi = false;
211
212     if( ui.destTab->count() >= 3 ||
213         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
214         multi = true;
215
216     if( multi )
217         smrl.begin( "duplicate" );
218
219     for( int i = 1; i < ui.destTab->count(); i++ )
220     {
221         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
222         QString tempMRL = vdb->getMRL( qs_mux );
223
224         if( tempMRL.isEmpty() ) continue;
225         if( multi )
226             smrl.option( "dst", tempMRL );
227         else
228         {
229             smrl.begin( tempMRL);
230             smrl.end();
231         }
232     }
233     if( ui.localOutput->isChecked() )
234     {
235         if( multi )
236             smrl.option( "dst", "display" );
237         else
238         {
239             smrl.begin( "display" );
240             smrl.end();
241         }
242     }
243
244     if ( multi ) smrl.end();
245
246     mrl = smrl.getMrl();
247
248     if( ui.sap->isChecked() )
249     {
250         QString group = ui.sapGroup->text();
251         QString name = ui.sapName->text();
252
253         /* FIXME: This sucks. We should really return a QStringList instead of
254          * (mis)quoting, concatainating and split input item paramters. */
255         name = name.replace( " ", " " );
256         group = group.replace( " ", " " );
257
258         /* We need to add options for both standard and rtp targets */
259         /* This is inelegant but simple and functional */
260         mrl.append( qfu( " :sout-rtp-sap" ) );
261         mrl.append( qfu( " :sout-rtp-name=" ) + name );
262         mrl.append( qfu( " :sout-standard-sap" ) );
263         mrl.append( qfu( " :sout-standard-name=" ) + name );
264         mrl.append( qfu( " :sout-standard-group=" ) + group );
265     }
266     else
267     {
268         mrl.append( qfu( " :no-sout-rtp-sap" ) );
269         mrl.append( qfu( " :no-sout-standard-sap" ) );
270     }
271
272     if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
273
274     mrl.append( " :sout-keep" );
275
276     ui.mrlEdit->setPlainText( mrl );
277 }
278