]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt: fix semantics and behaviour for chapters buttons
[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 <QSpinBox>
38 #include <assert.h>
39
40 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, const QString& inputMRL )
41            : QWizard( parent )
42 {
43     p_intf = _p_intf;
44
45     setWindowTitle( qtr( "Stream Output" ) );
46     setWindowRole( "vlc-stream-output" );
47
48     /* UI stuff */
49     ui.setupUi( this );
50     ui.inputBox->setMRL( inputMRL );
51     ui.helpEdit->setPlainText( qtr("This wizard will allow you to stream or "
52             "convert your media for use locally, on your private network, "
53             "or on the Internet.\n"
54             "You should start by checking that source matches what you want "
55             "your input to be and then press the \"Next\" "
56             "button to continue.\n") );
57
58     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
59                 "This is automatically generated "
60                  "when you change the above settings,\n"
61                  "but you can change it manually." ) ) ;
62
63     ui.destTab->setTabsClosable( true );
64     QTabBar* tb = ui.destTab->findChild<QTabBar*>();
65     if( tb != NULL ) tb->tabButton(0, QTabBar::RightSide)->hide();
66     CONNECT( ui.destTab, tabCloseRequested( int ), this, closeTab( int ) );
67     ui.destTab->setTabIcon( 0, QIcon( ":/buttons/playlist/playlist_add" ) );
68
69     ui.destBox->addItem( qtr( "File" ) );
70     ui.destBox->addItem( "HTTP" );
71     ui.destBox->addItem( "MS-WMSP (MMSH)" );
72     ui.destBox->addItem( "RTSP" );
73     ui.destBox->addItem( "RTP / MPEG Transport Stream" );
74     ui.destBox->addItem( "RTP Audio/Video Profile" );
75     ui.destBox->addItem( "UDP (legacy)" );
76     ui.destBox->addItem( "IceCast" );
77
78     BUTTONACT( ui.addButton, addDest() );
79
80 //     /* Connect everything to the updateMRL function */
81 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
82 #define CT( x ) CONNECT( ui.x, textChanged( const QString& ), this, updateMRL() );
83 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
84 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
85
86     /* Misc */
87     CB( soutAll );  CS( ttl ); CT( sapName ); CT( sapGroup );
88     CB( localOutput ); CB( transcodeBox );
89     CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
90
91     setButtonText( QWizard::FinishButton, "Stream" );
92
93 #undef CC
94 #undef CS
95 #undef CT
96 #undef CB
97 }
98
99 void SoutDialog::closeTab( int i )
100 {
101     if( i == 0 ) return;
102
103     QWidget* temp = ui.destTab->widget( i );
104     ui.destTab->removeTab( i );
105     delete temp;
106     updateMRL();
107 }
108
109 void SoutDialog::addDest( )
110 {
111     VirtualDestBox *db;
112     QString caption;
113
114     switch( ui.destBox->currentIndex() )
115     {
116         case 0:
117             db = new FileDestBox( this );
118             caption = qtr( "File" );
119             break;
120         case 1:
121             db = new HTTPDestBox( this );
122             caption = qfu( "HTTP" );
123             break;
124         case 2:
125             db = new MMSHDestBox( this );
126             caption = qfu( "WMSP" );
127             break;
128         case 3:
129             db = new RTSPDestBox( this );
130             caption = qfu( "RTSP" );
131             break;
132         case 4:
133             db = new RTPDestBox( this, "ts" );
134             caption = "RTP/TS";
135             break;
136         case 5:
137             db = new RTPDestBox( this );
138             caption = "RTP/AVP";
139             break;
140         case 6:
141             db = new UDPDestBox( this );
142             caption = "UDP";
143             break;
144         case 7:
145             db = new ICEDestBox( this );
146             caption = "Icecast";
147             break;
148         default:
149             assert(0);
150     }
151
152     int index = ui.destTab->addTab( db, caption );
153     CONNECT( db, mrlUpdated(), this, updateMRL() );
154     ui.destTab->setCurrentIndex( index );
155     updateMRL();
156 }
157
158 void SoutDialog::ok()
159 {
160     mrl = ui.mrlEdit->toPlainText();
161     accept();
162 }
163
164 void SoutDialog::cancel()
165 {
166     mrl.clear();
167     reject();
168 }
169
170 void SoutDialog::updateMRL()
171 {
172     QString qs_mux = ui.profileSelect->getMux();
173
174     SoutMrl smrl( ":sout=#" );
175     if( !ui.profileSelect->getTranscode().isEmpty() && ui.transcodeBox->isChecked() )
176     {
177         smrl.begin( ui.profileSelect->getTranscode() );
178         smrl.end();
179     }
180
181     bool multi = false;
182
183     if( ui.destTab->count() >= 3 ||
184         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
185         multi = true;
186
187     if( multi )
188         smrl.begin( "duplicate" );
189
190     for( int i = 1; i < ui.destTab->count(); i++ )
191     {
192         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
193         if( !vdb )
194             continue;
195
196         QString tempMRL = vdb->getMRL( qs_mux );
197         if( tempMRL.isEmpty() ) continue;
198
199         if( multi )
200             smrl.option( "dst", tempMRL );
201         else
202         {
203             smrl.begin( tempMRL);
204             smrl.end();
205         }
206     }
207     if( ui.localOutput->isChecked() )
208     {
209         if( multi )
210             smrl.option( "dst", "display" );
211         else
212         {
213             smrl.begin( "display" );
214             smrl.end();
215         }
216     }
217
218     if ( multi ) smrl.end();
219
220     mrl = smrl.getMrl();
221
222     if( ui.sap->isChecked() )
223     {
224         QString group = ui.sapGroup->text();
225         QString name = ui.sapName->text();
226
227         /* FIXME: This sucks. We should really return a QStringList instead of
228          * (mis)quoting, concatainating and split input item paramters. */
229         name = name.replace( " ", " " );
230         group = group.replace( " ", " " );
231
232         /* We need to add options for both standard and rtp targets */
233         /* This is inelegant but simple and functional */
234         mrl.append( qfu( " :sout-rtp-sap" ) );
235         mrl.append( qfu( " :sout-rtp-name=" ) + name );
236         mrl.append( qfu( " :sout-standard-sap" ) );
237         mrl.append( qfu( " :sout-standard-name=" ) + name );
238         mrl.append( qfu( " :sout-standard-group=" ) + group );
239     }
240     else
241     {
242         mrl.append( qfu( " :no-sout-rtp-sap" ) );
243         mrl.append( qfu( " :no-sout-standard-sap" ) );
244     }
245
246     if( ui.soutAll->isChecked() ) mrl.append( " :sout-all" );
247
248     mrl.append( qfu( " :ttl=" ) + QString::number( ui.ttl->value() ) );
249     mrl.append( " :sout-keep" );
250
251     ui.mrlEdit->setPlainText( mrl );
252 }
253