]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt4: missing qtr
[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( "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 #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     int index;
144     switch( ui.destBox->currentIndex() )
145     {
146         case 0:
147             {
148                 FileDestBox *fdb = new FileDestBox( this );
149                 index = ui.destTab->addTab( fdb, qtr( "File" ) );
150                 CONNECT( fdb, mrlUpdated(), this, updateMRL() );
151             }
152             break;
153         case 1:
154             {
155                 HTTPDestBox *hdb = new HTTPDestBox( this );
156                 index = ui.destTab->addTab( hdb, "HTTP" );
157                 CONNECT( hdb, mrlUpdated(), this, updateMRL() );
158             }
159             break;
160         case 2:
161             {
162                 MMSHDestBox *mdb = new MMSHDestBox( this );
163                 index = ui.destTab->addTab( mdb, "MMSH" );
164                 CONNECT( mdb, mrlUpdated(), this, updateMRL() );
165             }
166             break;
167         case 3:
168             {
169                 UDPDestBox *udb = new UDPDestBox( this );
170                 index = ui.destTab->addTab( udb, "UDP" );
171                 CONNECT( udb, mrlUpdated(), this, updateMRL() );
172             }
173             break;
174         case 4:
175             {
176                 RTPDestBox *rdb = new RTPDestBox( this );
177                 index = ui.destTab->addTab( rdb, "RTP" );
178                 CONNECT( rdb, mrlUpdated(), this, updateMRL() );
179             }
180             break;
181         case 5:
182             {
183                 ICEDestBox *idb = new ICEDestBox( this );
184                 index = ui.destTab->addTab( idb, "Icecast" );
185                 CONNECT( idb, mrlUpdated(), this, updateMRL() );
186             }
187             break;
188         default:
189             assert(0);
190     }
191
192     ui.destTab->setCurrentIndex( index );
193     updateMRL();
194 }
195
196 void SoutDialog::ok()
197 {
198     mrl = ui.mrlEdit->toPlainText();
199     accept();
200 }
201
202 void SoutDialog::cancel()
203 {
204     mrl.clear();
205     reject();
206 }
207
208 void SoutDialog::updateMRL()
209 {
210     QString qs_mux = ui.profileSelect->getMux();
211
212     SoutMrl smrl( ":sout=#" );
213     if( !ui.profileSelect->getTranscode().isEmpty() && ui.transcodeBox->isChecked() )
214     {
215         smrl.begin( ui.profileSelect->getTranscode() );
216         smrl.end();
217     }
218
219     bool multi = false;
220
221     if( ui.destTab->count() >= 3 ||
222         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
223         multi = true;
224
225     if( multi )
226         smrl.begin( "duplicate" );
227
228     for( int i = 1; i < ui.destTab->count(); i++ )
229     {
230         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
231         QString tempMRL = vdb->getMRL( qs_mux );
232
233         if( tempMRL.isEmpty() ) continue;
234         if( multi )
235             smrl.option( "dst", tempMRL );
236         else
237         {
238             smrl.begin( tempMRL);
239             smrl.end();
240         }
241     }
242     if( ui.localOutput->isChecked() )
243     {
244         if( multi )
245             smrl.option( "dst", "display" );
246         else
247         {
248             smrl.begin( "display" );
249             smrl.end();
250         }
251     }
252
253     if ( multi ) smrl.end();
254
255     mrl = smrl.getMrl();
256
257     /* FIXME, deal with SAP
258     sout.b_sap = ui.sap->isChecked();
259     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
260     sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
261
262     if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
263
264     if( ui.soutKeep->isChecked() ) mrl.append( " :sout-keep" );
265
266     ui.mrlEdit->setPlainText( mrl );
267 }
268