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