]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/sout/sout_widgets.cpp
9dfb940a8190b5be60e5b440c918f7a03e452651
[vlc] / modules / gui / qt4 / components / sout / sout_widgets.cpp
1 /*****************************************************************************
2  * profile_selector.cpp : A small profile selector and editor
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, 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( 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 modules outputs to a file on your disk."), 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( 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 modules streams on the networks with the HTTP protocol."), this );
138     layout->addWidget(httpOutput, 0, 0, 1, -1);
139
140     QLabel *HTTPLabel = new QLabel( qtr("Address"), this );
141     QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
142     layout->addWidget(HTTPLabel, 1, 0, 1, 1);
143     layout->addWidget(HTTPPortLabel, 2, 0, 1, 1);
144
145     HTTPEdit = new QLineEdit(this);
146
147     HTTPPort = new QSpinBox(this);
148     HTTPPort->setMaximumSize(QSize(90, 16777215));
149     HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
150     HTTPPort->setMinimum(1);
151     HTTPPort->setMaximum(65535);
152     HTTPPort->setValue(8080);
153
154     layout->addWidget(HTTPEdit, 1, 1, 1, 1);
155     layout->addWidget(HTTPPort, 2, 1, 1, 1);
156     CS( HTTPPort );
157     CT( HTTPEdit );
158 }
159
160 QString HTTPDestBox::getMRL( QString mux )
161 {
162     if( HTTPEdit->text().isEmpty() ) return "";
163
164     SoutMrl m;
165     m.begin( "std" );
166     m.option(  "access", "http" );
167     if( !mux.isEmpty() )
168         m.option( "mux", mux );
169     m.option( "dst", HTTPEdit->text(), HTTPPort->value() );
170     m.end();
171
172     return m.getMrl();
173 }
174
175 MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
176 {
177     QGridLayout *layout = new QGridLayout( this );
178
179     QLabel *mmshOutput = new QLabel(
180          qtr( "This modules streams on the networks with the mms: protocol."), this );
181     layout->addWidget(mmshOutput, 0, 0, 1, -1);
182
183     QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
184     QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
185     layout->addWidget(MMSHLabel, 1, 0, 1, 1);
186     layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);
187
188     MMSHEdit = new QLineEdit(this);
189
190     MMSHPort = new QSpinBox(this);
191     MMSHPort->setMaximumSize(QSize(90, 16777215));
192     MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
193     MMSHPort->setMinimum(1);
194     MMSHPort->setMaximum(65535);
195     MMSHPort->setValue(1234);
196
197     layout->addWidget(MMSHEdit, 1, 1, 1, 1);
198     layout->addWidget(MMSHPort, 2, 1, 1, 1);
199     CS( MMSHPort );
200     CT( MMSHEdit );
201 }
202
203 QString MMSHDestBox::getMRL( QString mux )
204 {
205     if( MMSHEdit->text().isEmpty() ) return "";
206
207     SoutMrl m;
208     m.begin( "std" );
209     m.option(  "access", "mmsh" );
210     m.option( "mux", "asfh" );
211     m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
212     m.end();
213
214     return m.getMrl();
215 }
216
217
218 UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
219 {
220     QGridLayout *layout = new QGridLayout( this );
221
222     QLabel *udpOutput = new QLabel(
223          qtr( "This modules streams on the networks with the UDP protocol."), this );
224     layout->addWidget(udpOutput, 0, 0, 1, -1);
225
226     QLabel *UDPLabel = new QLabel( qtr("Address"), this );
227     QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
228     layout->addWidget(UDPLabel, 1, 0, 1, 1);
229     layout->addWidget(UDPPortLabel, 2, 0, 1, 1);
230
231     UDPEdit = new QLineEdit(this);
232
233     UDPPort = new QSpinBox(this);
234     UDPPort->setMaximumSize(QSize(90, 16777215));
235     UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
236     UDPPort->setMinimum(1);
237     UDPPort->setMaximum(65535);
238     UDPPort->setValue(1234);
239
240     layout->addWidget(UDPEdit, 1, 1, 1, 1);
241     layout->addWidget(UDPPort, 2, 1, 1, 1);
242     CS( UDPPort );
243     CT( UDPEdit );
244 }
245
246 QString UDPDestBox::getMRL( QString mux )
247 {
248     if( UDPEdit->text().isEmpty() ) return "";
249
250     SoutMrl m;
251     m.begin( "std" );
252     m.option(  "access", "udp" );
253     if( !mux.isEmpty() )
254         m.option( "mux", mux );
255     m.option( "dst", UDPEdit->text(), UDPPort->value() );
256     m.end();
257
258     return m.getMrl();
259 }
260
261
262
263 RTPDestBox::RTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
264 {
265     QGridLayout *layout = new QGridLayout( this );
266
267     QLabel *rtpOutput = new QLabel(
268          qtr( "This modules streams on the networks with the RTP protocol."), this );
269     layout->addWidget(rtpOutput, 0, 0, 1, -1);
270
271     QLabel *RTPLabel = new QLabel( qtr("Address"), this );
272     QLabel *RTPPortLabel = new QLabel( qtr("Port"), this );
273     layout->addWidget(RTPLabel, 1, 0, 1, 1);
274     layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
275
276     RTPEdit = new QLineEdit(this);
277
278     RTPPort = new QSpinBox(this);
279     RTPPort->setMaximumSize(QSize(90, 16777215));
280     RTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
281     RTPPort->setMinimum(1);
282     RTPPort->setMaximum(65535);
283     RTPPort->setValue(1234);
284
285     RTPPortAudio = new QSpinBox(this);
286     RTPPortAudio->setMaximumSize(QSize(90, 16777215));
287     RTPPortAudio->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
288     RTPPortAudio->setMinimum(-1);
289     RTPPortAudio->setMaximum(65535);
290     RTPPortAudio->setValue(-1);
291
292     RTPPortVideo = new QSpinBox(this);
293     RTPPortVideo->setMaximumSize(QSize(90, 16777215));
294     RTPPortVideo->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
295     RTPPortVideo->setMinimum(-1);
296     RTPPortVideo->setMaximum(65535);
297     RTPPortVideo->setValue(-1);
298
299     layout->addWidget(RTPEdit, 1, 1, 1, 1);
300     layout->addWidget(RTPPort, 2, 1, 1, 1);
301
302     QLabel *RTPPortAudioLabel = new QLabel( qtr("Audio Port"), this );
303     QLabel *RTPPortVideoLabel = new QLabel( qtr("Video Port"), this );
304     layout->addWidget(RTPPortAudioLabel, 3, 0, 1, 1);
305     layout->addWidget(RTPPortAudio, 3, 1, 1, 1);
306     layout->addWidget(RTPPortVideoLabel, 3, 2, 1, 1);
307     layout->addWidget(RTPPortVideo, 3, 3, 1, 1);
308
309
310     CS( RTPPort );
311     CS( RTPPortAudio );
312     CS( RTPPortVideo );
313     CT( RTPEdit );
314 }
315
316 QString RTPDestBox::getMRL( QString mux )
317 {
318     if( RTPEdit->text().isEmpty() ) return "";
319
320     SoutMrl m;
321     m.begin( "rtp" );
322     m.option( "dst", RTPEdit->text() );
323     m.option( "port", RTPPort->value() );
324     if( !mux.isEmpty() )
325         m.option( "mux", mux );
326     if( mux.isEmpty() || mux.compare( "ts", Qt::CaseInsensitive ) )
327     {
328
329         m.option( "port-audio", RTPPortAudio->value() );
330         m.option( "port-video", RTPPortVideo->value() );
331     }
332     m.end();
333
334     return m.getMrl();
335 }
336
337
338 ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
339 {
340     QGridLayout *layout = new QGridLayout( this );
341
342     QLabel *iceOutput = new QLabel(
343          qtr( "This modules streams using IceCast."), this );
344     layout->addWidget(iceOutput, 0, 0, 1, -1);
345
346     QLabel *ICELabel = new QLabel( qtr("Address"), this );
347     QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
348     layout->addWidget(ICELabel, 1, 0, 1, 1);
349     layout->addWidget(ICEPortLabel, 2, 0, 1, 1);
350
351     ICEEdit = new QLineEdit(this);
352
353     ICEPort = new QSpinBox(this);
354     ICEPort->setMaximumSize(QSize(90, 16777215));
355     ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
356     ICEPort->setMinimum(1);
357     ICEPort->setMaximum(65535);
358     ICEPort->setValue(1234);
359
360     layout->addWidget(ICEEdit, 1, 1, 1, 1);
361     layout->addWidget(ICEPort, 2, 1, 1, 1);
362
363     QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
364     QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
365     ICEMountEdit = new QLineEdit( this );
366     ICEPassEdit = new QLineEdit( this );
367     layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
368     layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
369     layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
370     layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );
371
372     CS( ICEPort );
373     CT( ICEEdit );
374     CT( ICEMountEdit );
375     CT( ICEPassEdit );
376 }
377
378 QString ICEDestBox::getMRL( QString mux )
379 {
380     if( ICEEdit->text().isEmpty() ) return "";
381
382     SoutMrl m;
383     m.begin( "std" );
384     m.option( "access", "shout" );
385     m.option( "mux", "ogg" );
386
387     QString url = ICEPassEdit->text() + "@"
388         + ICEEdit->text()
389         + ":" + QString::number( ICEPort->value(), 10 )
390         + "/" + ICEMountEdit->text();
391
392     m.option( "dst", url );
393     m.end();
394     return m.getMrl();
395 }
396