]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt: rework of the Sout Dialog
[vlc] / modules / gui / qt4 / dialogs / sout.cpp
1 /*****************************************************************************
2  * sout.cpp : Stream output dialog ( old-style )
3  ****************************************************************************
4  * Copyright (C) 2007-2008 the VideoLAN team
5  * Copyright (C) 2007 Société des arts technologiques
6  * Copyright (C) 2007 Savoir-faire Linux
7  *
8  * $Id$
9  *
10  * Authors: Clément Stenac <zorglub@videolan.org>
11  *          Jean-Baptiste Kempf <jb@videolan.org>
12  *          Jean-François Massol <jf.massol -at- gmail.com>
13  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * ( at your option ) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
28  *****************************************************************************/
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include "dialogs/sout.hpp"
35 #include "util/qt_dirs.hpp"
36 #include "components/sout/sout_widgets.hpp"
37
38 #include <QString>
39 #include <QFileDialog>
40 #include <QToolButton>
41
42 SoutDialog* SoutDialog::instance = NULL;
43
44 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, QString inputMRL )
45            : QVLCDialog( parent,  _p_intf )
46 {
47     setWindowTitle( qtr( "Stream Output" ) );
48
49     /* UI stuff */
50     ui.setupUi( this );
51     ui.inputBox->setMRL( inputMRL );
52     ui.helpEdit->setPlainText( "This dialog will allow you to stream or convert "
53             "your media, locally, on your private network or on the "
54             "Internet.\n"
55             "You should start by checking that your input matches what you "
56             "want and go on with the \"Next\" button.\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 #if 0
64     /* This needs Qt4.5 to be cool */
65     ui.destTab->setTabsClosable( true );
66 #else
67     closeTabButton = new QToolButton( this );
68     ui.destTab->setCornerWidget( closeTabButton );
69     closeTabButton->hide();
70     closeTabButton->setAutoRaise( true );
71     closeTabButton->setIcon( QIcon( ":/clear" ) );
72     BUTTONACT( closeTabButton, closeTab() );
73 #endif
74     CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
75     ui.destTab->setTabIcon( 0, QIcon( ":/playlist_add" ) );
76
77     ui.destBox->addItem( qtr( "File" ) );
78     ui.destBox->addItem( "HTTP" );
79     ui.destBox->addItem( "MMS" );
80     ui.destBox->addItem( "UDP" );
81     ui.destBox->addItem( "RTP" );
82     ui.destBox->addItem( "IceCast" );
83
84     BUTTONACT( ui.addButton, addDest() );
85
86 //     /* Connect everything to the updateMRL function */
87  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
88  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
89  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
90  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
91
92     /* Misc */
93     CB( soutAll ); CB( soutKeep );  CS( ttl ); CT( sapName ); CT( sapGroup );
94     CB( localOutput );
95     CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
96
97     okButton = new QPushButton( qtr( "&Stream" ) );
98     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
99
100     okButton->setDefault( true );
101     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
102     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
103
104     BUTTONACT( okButton, ok() );
105     BUTTONACT( cancelButton, cancel() );
106
107     BUTTONACT( ui.nextButton, next() );
108     BUTTONACT( ui.nextButton2, next() );
109     BUTTONACT( ui.prevButton, prev() );
110     BUTTONACT( ui.prevButton2, prev() );
111 }
112
113 void SoutDialog::next()
114 {
115     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
116 }
117
118 void SoutDialog::prev()
119 {
120     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
121 }
122
123 void SoutDialog::tabChanged( int i )
124 {
125     closeTabButton->setVisible( (i != 0) );
126 }
127
128 void SoutDialog::closeTab()
129 {
130     int i = ui.destTab->currentIndex();
131     if( i == 0 ) return;
132
133     QWidget *temp = ui.destTab->currentWidget();
134     ui.destTab->removeTab( i );
135     delete temp;
136     updateMRL();
137 }
138
139 void SoutDialog::addDest( )
140 {
141     int index;
142     switch( ui.destBox->currentIndex() )
143     {
144         case 0:
145             {
146                 FileDestBox *fdb = new FileDestBox( this );
147                 index = ui.destTab->addTab( fdb, "File" );
148                 CONNECT( fdb, mrlUpdated(), this, updateMRL() );
149             }
150             break;
151         case 1:
152             {
153                 HTTPDestBox *hdb = new HTTPDestBox( this );
154                 index = ui.destTab->addTab( hdb, "HTTP" );
155                 CONNECT( hdb, mrlUpdated(), this, updateMRL() );
156             }
157             break;
158         case 2:
159             {
160                 MMSHDestBox *mdb = new MMSHDestBox( this );
161                 index = ui.destTab->addTab( mdb, "MMSH" );
162                 CONNECT( mdb, mrlUpdated(), this, updateMRL() );
163             }
164             break;
165         case 3:
166             {
167                 UDPDestBox *udb = new UDPDestBox( this );
168                 index = ui.destTab->addTab( udb, "UDP" );
169                 CONNECT( udb, mrlUpdated(), this, updateMRL() );
170             }
171             break;
172         case 4:
173             {
174                 RTPDestBox *rdb = new RTPDestBox( this );
175                 index = ui.destTab->addTab( rdb, "RTP" );
176                 CONNECT( rdb, mrlUpdated(), this, updateMRL() );
177             }
178             break;
179         case 5:
180             {
181                 ICEDestBox *idb = new ICEDestBox( this );
182                 index = ui.destTab->addTab( idb, "Icecast" );
183                 CONNECT( idb, mrlUpdated(), this, updateMRL() );
184             }
185     }
186
187     ui.destTab->setCurrentIndex( index );
188     updateMRL();
189 }
190
191 void SoutDialog::ok()
192 {
193     mrl = ui.mrlEdit->toPlainText();
194     accept();
195 }
196
197 void SoutDialog::cancel()
198 {
199     mrl.clear();
200     reject();
201 }
202
203 void SoutDialog::updateMRL()
204 {
205     QString qs_mux = ui.profileSelect->getMux();
206
207     SoutMrl smrl( ":sout=#" );
208     if( !ui.profileSelect->getTranscode().isEmpty() )
209     {
210         smrl.begin( ui.profileSelect->getTranscode() );
211         smrl.end();
212     }
213
214     bool multi = false;
215
216     if( ui.destTab->count() >= 3 ||
217         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
218         multi = true;
219
220     if( multi )
221         smrl.begin( "duplicate" );
222
223     for( int i = 1; i < ui.destTab->count(); i++ )
224     {
225         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
226         QString tempMRL = vdb->getMRL( qs_mux );
227
228         if( tempMRL.isEmpty() ) continue;
229         if( multi )
230             smrl.option( "dst", tempMRL );
231         else
232         {
233             smrl.begin( tempMRL);
234             smrl.end();
235         }
236     }
237     if( ui.localOutput->isChecked() )
238     {
239         if( multi )
240             smrl.option( "dst", "display" );
241         else
242         {
243             smrl.begin( "display" );
244             smrl.end();
245         }
246     }
247
248     if ( multi ) smrl.end();
249
250     mrl = smrl.getMrl();
251
252     /* FIXME, deal with SAP 
253     sout.b_sap = ui.sap->isChecked();
254     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
255     sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
256
257     if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
258
259     if( ui.soutKeep->isChecked() ) mrl.append( " :sout-keep" );
260
261     ui.mrlEdit->setPlainText( mrl );
262 }
263