]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
d41402bf021fa5d5ba8ba0f6a2cb44078ec89c68
[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::instance = NULL;
39
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     ui.helpEdit->setPlainText( "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( ":/clear" ) );
69     BUTTONACT( closeTabButton, closeTab() );
70 #endif
71     CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
72     ui.destTab->setTabIcon( 0, QIcon( ":/playlist_add" ) );
73
74     ui.destBox->addItem( qtr( "File" ) );
75     ui.destBox->addItem( "HTTP" );
76     ui.destBox->addItem( "MMS" );
77     ui.destBox->addItem( "UDP" );
78     ui.destBox->addItem( "RTP" );
79     ui.destBox->addItem( "IceCast" );
80
81     BUTTONACT( ui.addButton, addDest() );
82
83 //     /* Connect everything to the updateMRL function */
84  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
85  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
86  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
87  #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     CB( localOutput );
92     CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
93
94     okButton = new QPushButton( qtr( "&Stream" ) );
95     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
96
97     okButton->setDefault( true );
98     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
99     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
100
101     BUTTONACT( okButton, ok() );
102     BUTTONACT( cancelButton, cancel() );
103
104     BUTTONACT( ui.nextButton, next() );
105     BUTTONACT( ui.nextButton2, next() );
106     BUTTONACT( ui.prevButton, prev() );
107     BUTTONACT( ui.prevButton2, prev() );
108 }
109
110 void SoutDialog::next()
111 {
112     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
113 }
114
115 void SoutDialog::prev()
116 {
117     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
118 }
119
120 void SoutDialog::tabChanged( int i )
121 {
122     closeTabButton->setVisible( (i != 0) );
123 }
124
125 void SoutDialog::closeTab()
126 {
127     int i = ui.destTab->currentIndex();
128     if( i == 0 ) return;
129
130     QWidget *temp = ui.destTab->currentWidget();
131     ui.destTab->removeTab( i );
132     delete temp;
133     updateMRL();
134 }
135
136 void SoutDialog::addDest( )
137 {
138     int index;
139     switch( ui.destBox->currentIndex() )
140     {
141         case 0:
142             {
143                 FileDestBox *fdb = new FileDestBox( this );
144                 index = ui.destTab->addTab( fdb, "File" );
145                 CONNECT( fdb, mrlUpdated(), this, updateMRL() );
146             }
147             break;
148         case 1:
149             {
150                 HTTPDestBox *hdb = new HTTPDestBox( this );
151                 index = ui.destTab->addTab( hdb, "HTTP" );
152                 CONNECT( hdb, mrlUpdated(), this, updateMRL() );
153             }
154             break;
155         case 2:
156             {
157                 MMSHDestBox *mdb = new MMSHDestBox( this );
158                 index = ui.destTab->addTab( mdb, "MMSH" );
159                 CONNECT( mdb, mrlUpdated(), this, updateMRL() );
160             }
161             break;
162         case 3:
163             {
164                 UDPDestBox *udb = new UDPDestBox( this );
165                 index = ui.destTab->addTab( udb, "UDP" );
166                 CONNECT( udb, mrlUpdated(), this, updateMRL() );
167             }
168             break;
169         case 4:
170             {
171                 RTPDestBox *rdb = new RTPDestBox( this );
172                 index = ui.destTab->addTab( rdb, "RTP" );
173                 CONNECT( rdb, mrlUpdated(), this, updateMRL() );
174             }
175             break;
176         case 5:
177             {
178                 ICEDestBox *idb = new ICEDestBox( this );
179                 index = ui.destTab->addTab( idb, "Icecast" );
180                 CONNECT( idb, mrlUpdated(), this, updateMRL() );
181             }
182     }
183
184     ui.destTab->setCurrentIndex( index );
185     updateMRL();
186 }
187
188 void SoutDialog::ok()
189 {
190     mrl = ui.mrlEdit->toPlainText();
191     accept();
192 }
193
194 void SoutDialog::cancel()
195 {
196     mrl.clear();
197     reject();
198 }
199
200 void SoutDialog::updateMRL()
201 {
202     QString qs_mux = ui.profileSelect->getMux();
203
204     SoutMrl smrl( ":sout=#" );
205     if( !ui.profileSelect->getTranscode().isEmpty() )
206     {
207         smrl.begin( ui.profileSelect->getTranscode() );
208         smrl.end();
209     }
210
211     bool multi = false;
212
213     if( ui.destTab->count() >= 3 ||
214         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
215         multi = true;
216
217     if( multi )
218         smrl.begin( "duplicate" );
219
220     for( int i = 1; i < ui.destTab->count(); i++ )
221     {
222         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
223         QString tempMRL = vdb->getMRL( qs_mux );
224
225         if( tempMRL.isEmpty() ) continue;
226         if( multi )
227             smrl.option( "dst", tempMRL );
228         else
229         {
230             smrl.begin( tempMRL);
231             smrl.end();
232         }
233     }
234     if( ui.localOutput->isChecked() )
235     {
236         if( multi )
237             smrl.option( "dst", "display" );
238         else
239         {
240             smrl.begin( "display" );
241             smrl.end();
242         }
243     }
244
245     if ( multi ) smrl.end();
246
247     mrl = smrl.getMrl();
248
249     /* FIXME, deal with SAP 
250     sout.b_sap = ui.sap->isChecked();
251     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
252     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