]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt: correctly handle cancelling of sout/convert dialogs. Update copyrights.
[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 convert "
49             "your media, locally, on your private network or on the "
50             "Internet.\n"
51             "You should start by checking that your input matches what you "
52             "want and go on with the \"Next\" button.\n" );
53
54     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
55                 "This is automatically generated "
56                  "when you change the above settings,\n"
57                  "but you can change it manually." ) ) ;
58
59 #if 0
60     /* This needs Qt4.5 to be cool */
61     ui.destTab->setTabsClosable( true );
62 #else
63     closeTabButton = new QToolButton( this );
64     ui.destTab->setCornerWidget( closeTabButton );
65     closeTabButton->hide();
66     closeTabButton->setAutoRaise( true );
67     closeTabButton->setIcon( QIcon( ":/clear" ) );
68     BUTTONACT( closeTabButton, closeTab() );
69 #endif
70     CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) );
71     ui.destTab->setTabIcon( 0, QIcon( ":/playlist_add" ) );
72
73     ui.destBox->addItem( qtr( "File" ) );
74     ui.destBox->addItem( "HTTP" );
75     ui.destBox->addItem( "MMS" );
76     ui.destBox->addItem( "UDP" );
77     ui.destBox->addItem( "RTP" );
78     ui.destBox->addItem( "IceCast" );
79
80     BUTTONACT( ui.addButton, addDest() );
81
82 //     /* Connect everything to the updateMRL function */
83  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
84  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
85  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
86  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
87
88     /* Misc */
89     CB( soutAll ); CB( soutKeep );  CS( ttl ); CT( sapName ); CT( sapGroup );
90     CB( localOutput );
91     CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
92
93     okButton = new QPushButton( qtr( "&Stream" ) );
94     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
95
96     okButton->setDefault( true );
97     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
98     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
99
100     BUTTONACT( okButton, ok() );
101     BUTTONACT( cancelButton, cancel() );
102
103     BUTTONACT( ui.nextButton, next() );
104     BUTTONACT( ui.nextButton2, next() );
105     BUTTONACT( ui.prevButton, prev() );
106     BUTTONACT( ui.prevButton2, prev() );
107 }
108
109 void SoutDialog::next()
110 {
111     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
112 }
113
114 void SoutDialog::prev()
115 {
116     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
117 }
118
119 void SoutDialog::tabChanged( int i )
120 {
121     closeTabButton->setVisible( (i != 0) );
122 }
123
124 void SoutDialog::closeTab()
125 {
126     int i = ui.destTab->currentIndex();
127     if( i == 0 ) return;
128
129     QWidget *temp = ui.destTab->currentWidget();
130     ui.destTab->removeTab( i );
131     delete temp;
132     updateMRL();
133 }
134
135 void SoutDialog::addDest( )
136 {
137     int index;
138     switch( ui.destBox->currentIndex() )
139     {
140         case 0:
141             {
142                 FileDestBox *fdb = new FileDestBox( this );
143                 index = ui.destTab->addTab( fdb, "File" );
144                 CONNECT( fdb, mrlUpdated(), this, updateMRL() );
145             }
146             break;
147         case 1:
148             {
149                 HTTPDestBox *hdb = new HTTPDestBox( this );
150                 index = ui.destTab->addTab( hdb, "HTTP" );
151                 CONNECT( hdb, mrlUpdated(), this, updateMRL() );
152             }
153             break;
154         case 2:
155             {
156                 MMSHDestBox *mdb = new MMSHDestBox( this );
157                 index = ui.destTab->addTab( mdb, "MMSH" );
158                 CONNECT( mdb, mrlUpdated(), this, updateMRL() );
159             }
160             break;
161         case 3:
162             {
163                 UDPDestBox *udb = new UDPDestBox( this );
164                 index = ui.destTab->addTab( udb, "UDP" );
165                 CONNECT( udb, mrlUpdated(), this, updateMRL() );
166             }
167             break;
168         case 4:
169             {
170                 RTPDestBox *rdb = new RTPDestBox( this );
171                 index = ui.destTab->addTab( rdb, "RTP" );
172                 CONNECT( rdb, mrlUpdated(), this, updateMRL() );
173             }
174             break;
175         case 5:
176             {
177                 ICEDestBox *idb = new ICEDestBox( this );
178                 index = ui.destTab->addTab( idb, "Icecast" );
179                 CONNECT( idb, mrlUpdated(), this, updateMRL() );
180             }
181     }
182
183     ui.destTab->setCurrentIndex( index );
184     updateMRL();
185 }
186
187 void SoutDialog::ok()
188 {
189     mrl = ui.mrlEdit->toPlainText();
190     accept();
191 }
192
193 void SoutDialog::cancel()
194 {
195     mrl.clear();
196     reject();
197 }
198
199 void SoutDialog::updateMRL()
200 {
201     QString qs_mux = ui.profileSelect->getMux();
202
203     SoutMrl smrl( ":sout=#" );
204     if( !ui.profileSelect->getTranscode().isEmpty() )
205     {
206         smrl.begin( ui.profileSelect->getTranscode() );
207         smrl.end();
208     }
209
210     bool multi = false;
211
212     if( ui.destTab->count() >= 3 ||
213         ( ui.destTab->count() == 2 && ui.localOutput->isChecked() ) )
214         multi = true;
215
216     if( multi )
217         smrl.begin( "duplicate" );
218
219     for( int i = 1; i < ui.destTab->count(); i++ )
220     {
221         VirtualDestBox *vdb = qobject_cast<VirtualDestBox *>(ui.destTab->widget( i ));
222         QString tempMRL = vdb->getMRL( qs_mux );
223
224         if( tempMRL.isEmpty() ) continue;
225         if( multi )
226             smrl.option( "dst", tempMRL );
227         else
228         {
229             smrl.begin( tempMRL);
230             smrl.end();
231         }
232     }
233     if( ui.localOutput->isChecked() )
234     {
235         if( multi )
236             smrl.option( "dst", "display" );
237         else
238         {
239             smrl.begin( "display" );
240             smrl.end();
241         }
242     }
243
244     if ( multi ) smrl.end();
245
246     mrl = smrl.getMrl();
247
248     /* FIXME, deal with SAP 
249     sout.b_sap = ui.sap->isChecked();
250     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
251     sout.psz_name = strdup( qtu( ui.sapName->text() ) ); */
252
253     if( ui.soutAll->isChecked() )  mrl.append( " :sout-all" );
254
255     if( ui.soutKeep->isChecked() ) mrl.append( " :sout-keep" );
256
257     ui.mrlEdit->setPlainText( mrl );
258 }
259