]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Assert against use of unitialized variable
[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
44     /* UI stuff */
45     ui.setupUi( this );
46     ui.inputBox->setMRL( inputMRL );
47     ui.helpEdit->setPlainText( qtr("This dialog will allow you to stream or "
48             "convert your media for use locally, on your private network, "
49             "or on the Internet.\n"
50             "You should start by checking that source matches what you want "
51             "your input to be and then press the \"Next\" "
52             "button to continue.\n") );
53
54     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
55                 "This is automatically generated "
56                  "when you change the above settings,\n"
57                  "but you can change it manually." ) ) ;
58
59 #if 0
60     /* This needs Qt4.5 to be cool */
61     ui.destTab->setTabsClosable( true );
62 #else
63     closeTabButton = new QToolButton( this );
64     ui.destTab->setCornerWidget( closeTabButton );
65     closeTabButton->hide();
66     closeTabButton->setAutoRaise( true );
67     closeTabButton->setIcon( QIcon( ":/toolbar/clear" ) );
68     BUTTONACT( closeTabButton, closeTab() );
69 #endif
70     CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
71     ui.destTab->setTabIcon( 0, QIcon( ":/buttons/playlist/playlist_add" ) );
72
73     ui.destBox->addItem( qtr( "File" ) );
74     ui.destBox->addItem( "HTTP" );
75     ui.destBox->addItem( "MMS" );
76     ui.destBox->addItem( "UDP" );
77     ui.destBox->addItem( "RTP" );
78     ui.destBox->addItem( "IceCast" );
79
80     BUTTONACT( ui.addButton, addDest() );
81
82 //     /* Connect everything to the updateMRL function */
83 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
84 #define CT( x ) CONNECT( ui.x, textChanged( const QString& ), this, updateMRL() );
85 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
86 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
87
88     /* Misc */
89     CB( soutAll ); CB( soutKeep );  CS( ttl ); CT( sapName ); CT( sapGroup );
90     CB( localOutput );
91     CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
92
93     okButton = new QPushButton( qtr( "&Stream" ) );
94     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
95
96     okButton->setDefault( true );
97     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
98     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
99
100     BUTTONACT( okButton, ok() );
101     BUTTONACT( cancelButton, cancel() );
102
103     BUTTONACT( ui.nextButton, next() );
104     BUTTONACT( ui.nextButton2, next() );
105     BUTTONACT( ui.prevButton, prev() );
106     BUTTONACT( ui.prevButton2, prev() );
107
108 #undef CC
109 #undef CS
110 #undef CT
111 #undef CB
112 }
113
114 void SoutDialog::next()
115 {
116     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
117 }
118
119 void SoutDialog::prev()
120 {
121     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
122 }
123
124 void SoutDialog::tabChanged( int i )
125 {
126     closeTabButton->setVisible( (i != 0) );
127 }
128
129 void SoutDialog::closeTab()
130 {
131     int i = ui.destTab->currentIndex();
132     if( i == 0 ) return;
133
134     QWidget *temp = ui.destTab->currentWidget();
135     ui.destTab->removeTab( i );
136     delete temp;
137     updateMRL();
138 }
139
140 void SoutDialog::addDest( )
141 {
142     int index;
143     switch( ui.destBox->currentIndex() )
144     {
145         case 0:
146             {
147                 FileDestBox *fdb = new FileDestBox( this );
148                 index = ui.destTab->addTab( fdb, "File" );
149                 CONNECT( fdb, mrlUpdated(), this, updateMRL() );
150             }
151             break;
152         case 1:
153             {
154                 HTTPDestBox *hdb = new HTTPDestBox( this );
155                 index = ui.destTab->addTab( hdb, "HTTP" );
156                 CONNECT( hdb, mrlUpdated(), this, updateMRL() );
157             }
158             break;
159         case 2:
160             {
161                 MMSHDestBox *mdb = new MMSHDestBox( this );
162                 index = ui.destTab->addTab( mdb, "MMSH" );
163                 CONNECT( mdb, mrlUpdated(), this, updateMRL() );
164             }
165             break;
166         case 3:
167             {
168                 UDPDestBox *udb = new UDPDestBox( this );
169                 index = ui.destTab->addTab( udb, "UDP" );
170                 CONNECT( udb, mrlUpdated(), this, updateMRL() );
171             }
172             break;
173         case 4:
174             {
175                 RTPDestBox *rdb = new RTPDestBox( this );
176                 index = ui.destTab->addTab( rdb, "RTP" );
177                 CONNECT( rdb, mrlUpdated(), this, updateMRL() );
178             }
179             break;
180         case 5:
181             {
182                 ICEDestBox *idb = new ICEDestBox( this );
183                 index = ui.destTab->addTab( idb, "Icecast" );
184                 CONNECT( idb, mrlUpdated(), this, updateMRL() );
185             }
186             break;
187         default:
188             assert(0);
189     }
190
191     ui.destTab->setCurrentIndex( index );
192     updateMRL();
193 }
194
195 void SoutDialog::ok()
196 {
197     mrl = ui.mrlEdit->toPlainText();
198     accept();
199 }
200
201 void SoutDialog::cancel()
202 {
203     mrl.clear();
204     reject();
205 }
206
207 void SoutDialog::updateMRL()
208 {
209     QString qs_mux = ui.profileSelect->getMux();
210
211     SoutMrl smrl( ":sout=#" );
212     if( !ui.profileSelect->getTranscode().isEmpty() && ui.transcodeBox->isChecked() )
213     {
214         smrl.begin( ui.profileSelect->getTranscode() );
215         smrl.end();
216     }
217
218     bool multi = false;
219
220     if( ui.destTab->count() >= 3 ||
221         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
222         multi = true;
223
224     if( multi )
225         smrl.begin( "duplicate" );
226
227     for( int i = 1; i < ui.destTab->count(); i++ )
228     {
229         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
230         QString tempMRL = vdb->getMRL( qs_mux );
231
232         if( tempMRL.isEmpty() ) continue;
233         if( multi )
234             smrl.option( "dst", tempMRL );
235         else
236         {
237             smrl.begin( tempMRL);
238             smrl.end();
239         }
240     }
241     if( ui.localOutput->isChecked() )
242     {
243         if( multi )
244             smrl.option( "dst", "display" );
245         else
246         {
247             smrl.begin( "display" );
248             smrl.end();
249         }
250     }
251
252     if ( multi ) smrl.end();
253
254     mrl = smrl.getMrl();
255
256     /* FIXME, deal with SAP
257     sout.b_sap = ui.sap->isChecked();
258     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
259     sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
260
261     if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
262
263     if( ui.soutKeep->isChecked() ) mrl.append( " :sout-keep" );
264
265     ui.mrlEdit->setPlainText( mrl );
266 }
267