]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Code factorization
[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 / Transport Stream" );
78     ui.destBox->addItem( "UDP (legacy)" );
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 );  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 #undef CC
110 #undef CS
111 #undef CT
112 #undef CB
113 }
114
115 void SoutDialog::next()
116 {
117     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
118 }
119
120 void SoutDialog::prev()
121 {
122     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
123 }
124
125 void SoutDialog::tabChanged( int i )
126 {
127     closeTabButton->setVisible( (i != 0) );
128 }
129
130 void SoutDialog::closeTab()
131 {
132     int i = ui.destTab->currentIndex();
133     if( i == 0 ) return;
134
135     QWidget *temp = ui.destTab->currentWidget();
136     ui.destTab->removeTab( i );
137     delete temp;
138     updateMRL();
139 }
140
141 void SoutDialog::addDest( )
142 {
143     VirtualDestBox *db;
144     QString caption;
145
146     switch( ui.destBox->currentIndex() )
147     {
148         case 0:
149             db = new FileDestBox( this );
150             caption = qtr( "File" );
151             break;
152         case 1:
153             db = new HTTPDestBox( this );
154             caption = qfu( "HTTP" );
155             break;
156         case 2:
157             db = new MMSHDestBox( this );
158             caption = qfu( "WMSP" );
159             break;
160         case 3:
161             db = new RTPDestBox( this );
162             caption = "RTP/TS";
163             break;
164         case 4:
165             db = new UDPDestBox( this );
166             caption = "UDP";
167             break;
168         case 5:
169             db = new ICEDestBox( this );
170             caption = "Icecast";
171             break;
172         default:
173             assert(0);
174     }
175
176     int index = ui.destTab->addTab( db, caption );
177     CONNECT( db, mrlUpdated(), this, updateMRL() );
178     ui.destTab->setCurrentIndex( index );
179     updateMRL();
180 }
181
182 void SoutDialog::ok()
183 {
184     mrl = ui.mrlEdit->toPlainText();
185     accept();
186 }
187
188 void SoutDialog::cancel()
189 {
190     mrl.clear();
191     reject();
192 }
193
194 void SoutDialog::updateMRL()
195 {
196     QString qs_mux = ui.profileSelect->getMux();
197
198     SoutMrl smrl( ":sout=#" );
199     if( !ui.profileSelect->getTranscode().isEmpty() && ui.transcodeBox->isChecked() )
200     {
201         smrl.begin( ui.profileSelect->getTranscode() );
202         smrl.end();
203     }
204
205     bool multi = false;
206
207     if( ui.destTab->count() >= 3 ||
208         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
209         multi = true;
210
211     if( multi )
212         smrl.begin( "duplicate" );
213
214     for( int i = 1; i < ui.destTab->count(); i++ )
215     {
216         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
217         QString tempMRL = vdb->getMRL( qs_mux );
218
219         if( tempMRL.isEmpty() ) continue;
220         if( multi )
221             smrl.option( "dst", tempMRL );
222         else
223         {
224             smrl.begin( tempMRL);
225             smrl.end();
226         }
227     }
228     if( ui.localOutput->isChecked() )
229     {
230         if( multi )
231             smrl.option( "dst", "display" );
232         else
233         {
234             smrl.begin( "display" );
235             smrl.end();
236         }
237     }
238
239     if ( multi ) smrl.end();
240
241     mrl = smrl.getMrl();
242
243     /* FIXME, deal with SAP
244     sout.b_sap = ui.sap->isChecked();
245     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
246     sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
247
248     if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
249
250     mrl.append( " :sout-keep" );
251
252     ui.mrlEdit->setPlainText( mrl );
253 }
254