]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/sout/sout_widgets.cpp
Qt4: fix file headers
[vlc] / modules / gui / qt4 / components / sout / sout_widgets.cpp
1 /*****************************************************************************
2  * sout_widgets.cpp : Widgets for stream output destination boxes
3  ****************************************************************************
4  * Copyright (C) 2007-2009 the VideoLAN team
5  * Copyright (C) 2007 Société des arts technologiques
6  * Copyright (C) 2007 Savoir-faire Linux
7  * $Id$
8  *
9  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
10  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #include "components/sout/sout_widgets.hpp"
28 #include "dialogs/sout.hpp"
29 #include "util/qt_dirs.hpp"
30
31 #include <QGroupBox>
32 #include <QGridLayout>
33 #include <QLabel>
34 #include <QLineEdit>
35 #include <QFileDialog>
36
37 SoutInputBox::SoutInputBox( QWidget *_parent, const QString& mrl ) : QGroupBox( _parent )
38 {
39     /**
40      * Source Block
41      **/
42     setTitle( qtr( "Source" ) );
43     QGridLayout *sourceLayout = new QGridLayout( this );
44
45     QLabel *sourceLabel = new QLabel( qtr( "Source:" ) );
46     sourceLayout->addWidget( sourceLabel, 0, 0 );
47
48     sourceLine = new QLineEdit;
49     sourceLine->setReadOnly( true );
50     sourceLine->setText( mrl );
51     sourceLabel->setBuddy( sourceLine );
52     sourceLayout->addWidget( sourceLine, 0, 1 );
53
54     QLabel *sourceTypeLabel = new QLabel( qtr( "Type:" ) );
55     sourceLayout->addWidget( sourceTypeLabel, 1, 0 );
56     sourceValueLabel = new QLabel;
57     sourceLayout->addWidget( sourceValueLabel, 1, 1 );
58
59     /* Line */
60     QFrame *line = new QFrame;
61     line->setFrameStyle( QFrame::HLine |QFrame::Sunken );
62     sourceLayout->addWidget( line, 2, 0, 1, -1 );
63 }
64
65 void SoutInputBox::setMRL( const QString& mrl )
66 {
67     sourceLine->setText( mrl );
68     QString type;
69     int i = mrl.indexOf( "://" );
70     if( i != -1 )
71     {
72         type = mrl.left( i );
73     }
74     else
75         type = qtr( "File/Directory" );
76     sourceValueLabel->setText( type );
77 }
78
79 #define CT( x ) connect( x, SIGNAL( textChanged( const QString& ) ), this, SIGNAL( mrlUpdated() ) );
80 #define CS( x ) connect( x, SIGNAL( valueChanged( int ) ), this, SIGNAL( mrlUpdated() ) );
81
82 /* FileDest Box */
83 FileDestBox::FileDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
84 {
85     QPushButton *fileSelectButton;
86     QGridLayout *layout = new QGridLayout( this );
87
88     QLabel *fileOutput = new QLabel(
89          qtr( "This module writes the transcoded stream to a file."), this );
90     layout->addWidget(fileOutput, 0, 0, 1, -1);
91
92     QLabel *fileLabel = new QLabel( qtr( "Filename"), this );
93     layout->addWidget(fileLabel, 1, 0, 1, 1);
94
95     fileEdit = new QLineEdit(this);
96     layout->addWidget(fileEdit, 1, 4, 1, 1);
97
98     fileSelectButton = new QPushButton( qtr( "Browse..." ), this );
99     QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
100     fileSelectButton->setSizePolicy(sizePolicy);
101
102     layout->addWidget(fileSelectButton, 1, 5, 1, 1);
103     CT( fileEdit );
104     BUTTONACT( fileSelectButton, fileBrowse() );
105 }
106
107 QString FileDestBox::getMRL( const QString& mux )
108 {
109     if( fileEdit->text().isEmpty() ) return "";
110
111     SoutMrl m;
112     m.begin( "std" );
113     m.option( "access", "file" );
114     if( !mux.isEmpty() )
115         m.option( "mux", mux ); //FIXME: alert if ext doesn't match
116     m.option( "dst", fileEdit->text() );
117     m.end();
118
119     return m.getMrl();
120 }
121
122 void FileDestBox::fileBrowse()
123 {
124     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
125             "", qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
126     fileEdit->setText( toNativeSeparators( fileName ) );
127     emit mrlUpdated();
128 }
129
130
131
132 HTTPDestBox::HTTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
133 {
134     QGridLayout *layout = new QGridLayout( this );
135
136     QLabel *httpOutput = new QLabel(
137         qtr( "This module outputs the transcoded stream to a network via HTTP."),
138         this );
139     layout->addWidget(httpOutput, 0, 0, 1, -1);
140
141     QLabel *HTTPLabel = new QLabel( qtr("Path"), this );
142     QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
143     layout->addWidget(HTTPLabel, 2, 0, 1, 1);
144     layout->addWidget(HTTPPortLabel, 1, 0, 1, 1);
145
146     HTTPEdit = new QLineEdit(this);
147     HTTPEdit->setText( "/" );
148
149     HTTPPort = new QSpinBox(this);
150     HTTPPort->setMaximumSize(QSize(90, 16777215));
151     HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
152     HTTPPort->setMinimum(1);
153     HTTPPort->setMaximum(65535);
154     HTTPPort->setValue(8080);
155
156     layout->addWidget(HTTPEdit, 2, 1, 1, 1);
157     layout->addWidget(HTTPPort, 1, 1, 1, 1);
158     CS( HTTPPort );
159     CT( HTTPEdit );
160 }
161
162 QString HTTPDestBox::getMRL( const QString& mux )
163 {
164     if( HTTPEdit->text().isEmpty() ) return "";
165
166     QString path = HTTPEdit->text();
167     if( path[0] != '/' )
168         path.prepend( qfu("/") );
169     QString port;
170     port.setNum( HTTPPort->value() );
171     QString dst = ":" + port + path;
172
173     SoutMrl m;
174     m.begin( "std" );
175     m.option(  "access", "http" );
176     if( !mux.isEmpty() )
177         m.option( "mux", mux );
178     m.option( "dst", dst );
179     m.end();
180
181     return m.getMrl();
182 }
183
184 MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
185 {
186     QGridLayout *layout = new QGridLayout( this );
187
188     QLabel *mmshOutput = new QLabel(
189         qtr( "This module outputs the transcoded stream to a network "
190              " via the mms protocol." ), this );
191     layout->addWidget(mmshOutput, 0, 0, 1, -1);
192
193     QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
194     QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
195     layout->addWidget(MMSHLabel, 1, 0, 1, 1);
196     layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);
197
198     MMSHEdit = new QLineEdit(this);
199     MMSHEdit->setText( "0.0.0.0" );
200
201     MMSHPort = new QSpinBox(this);
202     MMSHPort->setMaximumSize(QSize(90, 16777215));
203     MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
204     MMSHPort->setMinimum(1);
205     MMSHPort->setMaximum(65535);
206     MMSHPort->setValue(8080);
207
208     layout->addWidget(MMSHEdit, 1, 1, 1, 1);
209     layout->addWidget(MMSHPort, 2, 1, 1, 1);
210     CS( MMSHPort );
211     CT( MMSHEdit );
212 }
213
214 QString MMSHDestBox::getMRL( const QString& mux )
215 {
216     if( MMSHEdit->text().isEmpty() ) return "";
217
218     SoutMrl m;
219     m.begin( "std" );
220     m.option(  "access", "mmsh" );
221     m.option( "mux", "asfh" );
222     m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
223     m.end();
224
225     return m.getMrl();
226 }
227
228
229 RTSPDestBox::RTSPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
230 {
231     QGridLayout *layout = new QGridLayout( this );
232
233     QLabel *rtspOutput = new QLabel(
234         qtr( "This module outputs the transcoded stream to a network via "
235              "RTSP." ), this );
236     layout->addWidget( rtspOutput, 0, 0, 1, -1 );
237
238     QLabel *RTSPLabel = new QLabel( qtr("Path"), this );
239     QLabel *RTSPPortLabel = new QLabel( qtr("Port"), this );
240     layout->addWidget( RTSPLabel, 2, 0, 1, 1 );
241     layout->addWidget( RTSPPortLabel, 1, 0, 1, 1 );
242
243     RTSPEdit = new QLineEdit( this );
244     RTSPEdit->setText( "/" );
245
246     RTSPPort = new QSpinBox( this );
247     RTSPPort->setMaximumSize( QSize( 90, 16777215 ) );
248     RTSPPort->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
249     RTSPPort->setMinimum( 1 );
250     RTSPPort->setMaximum( 65535 );
251     RTSPPort->setValue( 5544 );
252
253     layout->addWidget( RTSPEdit, 2, 1, 1, 1 );
254     layout->addWidget( RTSPPort, 1, 1, 1, 1 );
255     CS( RTSPPort );
256     CT( RTSPEdit );
257 }
258
259 QString RTSPDestBox::getMRL( const QString& mux )
260 {
261     if( RTSPEdit->text().isEmpty() ) return "";
262
263     QString path = RTSPEdit->text();
264     if( path[0] != '/' )
265         path.prepend( qfu("/") );
266     QString port;
267     port.setNum( RTSPPort->value() );
268     QString sdp = "rtsp://:" + port + path;
269
270     SoutMrl m;
271     m.begin( "rtp" );
272     m.option( "sdp", sdp );
273     m.option( "mux", "ts" );
274     m.end();
275
276     return m.getMrl();
277 }
278
279
280 UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
281 {
282     QGridLayout *layout = new QGridLayout( this );
283
284     QLabel *udpOutput = new QLabel(
285         qtr( "This module outputs the transcoded stream to a network via UDP."),
286         this );
287     layout->addWidget(udpOutput, 0, 0, 1, -1);
288
289     QLabel *UDPLabel = new QLabel( qtr("Address"), this );
290     QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
291     layout->addWidget(UDPLabel, 1, 0, 1, 1);
292     layout->addWidget(UDPPortLabel, 2, 0, 1, 1);
293
294     UDPEdit = new QLineEdit(this);
295
296     UDPPort = new QSpinBox(this);
297     UDPPort->setMaximumSize(QSize(90, 16777215));
298     UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
299     UDPPort->setMinimum(1);
300     UDPPort->setMaximum(65535);
301     UDPPort->setValue(1234);
302
303     layout->addWidget(UDPEdit, 1, 1, 1, 1);
304     layout->addWidget(UDPPort, 2, 1, 1, 1);
305     CS( UDPPort );
306     CT( UDPEdit );
307 }
308
309 QString UDPDestBox::getMRL( const QString& mux )
310 {
311     if( UDPEdit->text().isEmpty() ) return "";
312
313     SoutMrl m;
314     m.begin( "std" );
315     m.option(  "access", "udp" );
316     if( !mux.isEmpty() )
317         m.option( "mux", mux );
318     m.option( "dst", UDPEdit->text(), UDPPort->value() );
319     m.end();
320
321     return m.getMrl();
322 }
323
324
325
326 RTPDestBox::RTPDestBox( QWidget *_parent, const char *_mux )
327     : VirtualDestBox( _parent ), mux( _mux )
328 {
329     QGridLayout *layout = new QGridLayout( this );
330
331     QLabel *rtpOutput = new QLabel(
332         qtr( "This module outputs the transcoded stream to a network via RTP."),
333         this );
334     layout->addWidget(rtpOutput, 0, 0, 1, -1);
335
336     QLabel *RTPLabel = new QLabel( qtr("Address"), this );
337     QLabel *RTPPortLabel = new QLabel( qtr("Base port"), this );
338     layout->addWidget(RTPLabel, 1, 0, 1, 1);
339     layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
340
341     RTPEdit = new QLineEdit(this);
342
343     RTPPort = new QSpinBox(this);
344     RTPPort->setMaximumSize(QSize(90, 16777215));
345     RTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
346     RTPPort->setMinimum(1);
347     RTPPort->setMaximum(65535);
348     RTPPort->setValue(5004);
349
350     layout->addWidget(RTPEdit, 1, 1, 1, 1);
351     layout->addWidget(RTPPort, 2, 1, 1, 1);
352
353     CS( RTPPort );
354     CT( RTPEdit );
355 }
356
357 QString RTPDestBox::getMRL( const QString& )
358 {
359     if( RTPEdit->text().isEmpty() ) return "";
360
361     SoutMrl m;
362     m.begin( "rtp" );
363     m.option( "dst", RTPEdit->text() );
364     m.option( "port", RTPPort->value() );
365     if( mux != NULL )
366         m.option( "mux", qfu( mux ) );
367     m.end();
368
369     return m.getMrl();
370 }
371
372
373 ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
374 {
375     QGridLayout *layout = new QGridLayout( this );
376
377     QLabel *iceOutput = new QLabel(
378         qtr( "This module outputs the transcoded stream to an Icecast server."),
379         this );
380     layout->addWidget(iceOutput, 0, 0, 1, -1);
381
382     QLabel *ICELabel = new QLabel( qtr("Address"), this );
383     QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
384     layout->addWidget(ICELabel, 1, 0, 1, 1);
385     layout->addWidget(ICEPortLabel, 2, 0, 1, 1);
386
387     ICEEdit = new QLineEdit(this);
388
389     ICEPort = new QSpinBox(this);
390     ICEPort->setMaximumSize(QSize(90, 16777215));
391     ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
392     ICEPort->setMinimum(1);
393     ICEPort->setMaximum(65535);
394     ICEPort->setValue(8000);
395
396     layout->addWidget(ICEEdit, 1, 1, 1, 1);
397     layout->addWidget(ICEPort, 2, 1, 1, 1);
398
399     QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
400     QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
401     ICEMountEdit = new QLineEdit( this );
402     ICEPassEdit = new QLineEdit( this );
403     layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
404     layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
405     layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
406     layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );
407
408     CS( ICEPort );
409     CT( ICEEdit );
410     CT( ICEMountEdit );
411     CT( ICEPassEdit );
412 }
413
414 #undef CS
415 #undef CT
416
417 QString ICEDestBox::getMRL( const QString& mux )
418 {
419     if( ICEEdit->text().isEmpty() ) return "";
420
421     SoutMrl m;
422     m.begin( "std" );
423     m.option( "access", "shout" );
424     m.option( "mux", "ogg" );
425
426     QString url = ICEPassEdit->text() + "@"
427         + ICEEdit->text()
428         + ":" + QString::number( ICEPort->value(), 10 )
429         + "/" + ICEMountEdit->text();
430
431     m.option( "dst", url );
432     m.end();
433     return m.getMrl();
434 }
435