1 /*****************************************************************************
2 * open.cpp : Panels for the open dialogs
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 #include "components/open.hpp"
28 #include "dialogs_provider.hpp"
30 /**************************************************************************
32 **************************************************************************/
33 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
34 OpenPanel( _parent, _p_intf )
39 BUTTONACT( ui.fileBrowseButton, browseFile() );
40 BUTTONACT( ui.subBrowseButton, browseFileSub() );
42 BUTTONACT( ui.subGroupBox, updateMRL());
43 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
44 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
45 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
46 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
49 FileOpenPanel::~FileOpenPanel()
52 QStringList FileOpenPanel::browse(QString help)
54 return THEDP->showSimpleOpen( help );
57 void FileOpenPanel::browseFile()
59 QString fileString = "";
60 QStringList files = browse( qtr("Open File") );
61 foreach( QString file, files) {
62 if( file.contains(" ") ) {
63 fileString += "\"" + file + "\"";
69 ui.fileInput->setEditText( fileString );
70 ui.fileInput->addItem( fileString );
71 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
76 void FileOpenPanel::browseFileSub()
78 ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
82 void FileOpenPanel::updateMRL()
84 QString mrl = ui.fileInput->currentText();
86 if( ui.subGroupBox->isChecked() ) {
87 mrl.append( " :sub-file=" + ui.subInput->currentText() );
88 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
89 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
92 emit methodChanged( "file-caching" );
95 void FileOpenPanel::clear()
97 ui.fileInput->setEditText( "");
98 ui.subInput->setEditText( "");
102 /**************************************************************************
104 **************************************************************************/
105 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
106 OpenPanel( _parent, _p_intf )
110 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
111 BUTTONACT( ui.dvdRadioButton, updateMRL());
112 BUTTONACT( ui.vcdRadioButton, updateMRL());
113 BUTTONACT( ui.audioCDRadioButton, updateMRL());
115 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
116 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
119 DiskOpenPanel::~DiskOpenPanel()
122 void DiskOpenPanel::clear()
124 ui.titleSpin->setValue(0);
125 ui.chapterSpin->setValue(0);
128 void DiskOpenPanel::updateMRL()
132 if( ui.dvdRadioButton->isChecked() ) {
133 mrl = "dvd://" + ui.deviceCombo->currentText();
134 emit methodChanged( "dvdnav-caching" );
136 if ( ui.titleSpin->value() > 0 ) {
137 mrl += QString("@%1").arg(ui.titleSpin->value());
138 if ( ui.chapterSpin->value() > 0 ) {
139 mrl+= QString(":%1").arg(ui.chapterSpin->value());
144 } else if (ui.vcdRadioButton->isChecked() ) {
145 mrl = "vcd://" + ui.deviceCombo->currentText();
146 emit methodChanged( "vcd-caching" );
148 if( ui.titleSpin->value() > 0 ) {
149 mrl += QString("@%1").arg(ui.titleSpin->value());
154 mrl = "cdda://" + ui.deviceCombo->currentText();
157 emit mrlUpdated(mrl);
162 /**************************************************************************
164 **************************************************************************/
165 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
166 OpenPanel( _parent, _p_intf )
170 CONNECT( ui.protocolCombo, currentIndexChanged(int),
171 this, updateProtocol(int) );
172 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
173 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
174 CONNECT( ui.timeShift, clicked(), this, updateMRL());
175 CONNECT( ui.ipv6, clicked(), this, updateMRL());
177 ui.protocolCombo->addItem("HTTP", QVariant("http"));
178 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
179 ui.protocolCombo->addItem("MMS", QVariant("mms"));
180 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
181 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
182 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
185 NetOpenPanel::~NetOpenPanel()
188 void NetOpenPanel::clear()
191 void NetOpenPanel::updateProtocol(int idx) {
192 QString addr = ui.addressText->text();
193 QString proto = ui.protocolCombo->itemData(idx).toString();
195 ui.timeShift->setEnabled( idx >= 4);
196 ui.ipv6->setEnabled( idx == 4 );
197 ui.addressText->setEnabled( idx != 4 );
198 ui.portSpin->setEnabled( idx >= 4 );
200 /* If we already have a protocol in the address, replace it */
201 if( addr.contains( "://")) {
202 msg_Err( p_intf, "replace");
203 addr.replace(QRegExp("^.*://"), proto + "://");
204 ui.addressText->setText(addr);
210 void NetOpenPanel::updateAddress() {
214 void NetOpenPanel::updateMRL() {
216 QString addr = ui.addressText->text();
217 int proto = ui.protocolCombo->currentIndex();
219 if( addr.contains( "://") && proto != 4 ) {
224 mrl = "http://" + addr;
225 emit methodChanged("http-caching");
228 mrl = "mms://" + addr;
229 emit methodChanged("mms-caching");
232 mrl = "ftp://" + addr;
233 emit methodChanged("ftp-caching");
236 mrl = "rtsp://" + addr;
237 emit methodChanged("rtsp-caching");
241 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
244 mrl += QString(":%1").arg(ui.portSpin->value());
245 emit methodChanged("udp-caching");
247 case 5: /* UDP multicast */
250 if ( addr.contains(':') && !addr.contains('[') ) {
251 mrl += "[" + addr + "]";
253 mrl += QString(":%1").arg(ui.portSpin->value());
254 emit methodChanged("udp-caching");
257 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
258 mrl += " :access-filter=timeshift";
260 emit mrlUpdated(mrl);