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