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"
29 #include <QFileDialog>
31 /**************************************************************************
33 **************************************************************************/
34 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
35 OpenPanel( _parent, _p_intf )
40 BUTTONACT( ui.fileBrowseButton, browseFile() );
41 BUTTONACT( ui.subBrowseButton, browseFileSub() );
43 BUTTONACT( ui.subGroupBox, updateMRL());
44 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
45 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
46 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
47 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
50 FileOpenPanel::~FileOpenPanel()
53 QStringList FileOpenPanel::browse(QString help)
55 return QFileDialog::getOpenFileNames( this, help, "", "" );
58 void FileOpenPanel::browseFile()
60 QString fileString = "";
61 QStringList files = browse( qtr("Open File") );
62 foreach( QString file, files) {
63 if( file.contains(" ") ) {
64 fileString += "\"" + file + "\"";
70 ui.fileInput->setEditText( fileString );
71 ui.fileInput->addItem( fileString );
72 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
77 void FileOpenPanel::browseFileSub()
79 ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
83 void FileOpenPanel::updateMRL()
85 QString mrl = ui.fileInput->currentText();
87 if( ui.subGroupBox->isChecked() ) {
88 mrl.append( " :sub-file=" + ui.subInput->currentText() );
89 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
90 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
93 emit methodChanged( "file-caching" );
96 void FileOpenPanel::clear()
98 ui.fileInput->setEditText( "");
99 ui.subInput->setEditText( "");
103 /**************************************************************************
105 **************************************************************************/
106 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
107 OpenPanel( _parent, _p_intf )
111 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
112 BUTTONACT( ui.dvdRadioButton, updateMRL());
113 BUTTONACT( ui.vcdRadioButton, updateMRL());
114 BUTTONACT( ui.audioCDRadioButton, updateMRL());
116 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
117 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
120 DiskOpenPanel::~DiskOpenPanel()
123 void DiskOpenPanel::clear()
125 ui.titleSpin->setValue(0);
126 ui.chapterSpin->setValue(0);
129 void DiskOpenPanel::updateMRL()
133 if( ui.dvdRadioButton->isChecked() ) {
134 mrl = "dvd://" + ui.deviceCombo->currentText();
135 emit methodChanged( "dvdnav-caching" );
137 if ( ui.titleSpin->value() > 0 ) {
138 mrl += QString("@%1").arg(ui.titleSpin->value());
139 if ( ui.chapterSpin->value() > 0 ) {
140 mrl+= QString(":%1").arg(ui.chapterSpin->value());
145 } else if (ui.vcdRadioButton->isChecked() ) {
146 mrl = "vcd://" + ui.deviceCombo->currentText();
147 emit methodChanged( "vcd-caching" );
149 if( ui.titleSpin->value() > 0 ) {
150 mrl += QString("@%1").arg(ui.titleSpin->value());
155 mrl = "cdda://" + ui.deviceCombo->currentText();
158 emit mrlUpdated(mrl);
163 /**************************************************************************
165 **************************************************************************/
166 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
167 OpenPanel( _parent, _p_intf )
171 CONNECT( ui.protocolCombo, currentIndexChanged(int),
172 this, updateProtocol(int) );
173 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
174 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
175 CONNECT( ui.timeShift, clicked(), this, updateMRL());
176 CONNECT( ui.ipv6, clicked(), this, updateMRL());
178 ui.protocolCombo->addItem("HTTP", QVariant("http"));
179 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
180 ui.protocolCombo->addItem("MMS", QVariant("mms"));
181 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
182 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
183 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
186 NetOpenPanel::~NetOpenPanel()
189 void NetOpenPanel::clear()
192 void NetOpenPanel::updateProtocol(int idx) {
193 QString addr = ui.addressText->text();
194 QString proto = ui.protocolCombo->itemData(idx).toString();
196 ui.timeShift->setEnabled( idx >= 4);
197 ui.ipv6->setEnabled( idx == 4 );
198 ui.addressText->setEnabled( idx != 4 );
199 ui.portSpin->setEnabled( idx >= 4 );
201 /* If we already have a protocol in the address, replace it */
202 if( addr.contains( "://")) {
203 msg_Err( p_intf, "replace");
204 addr.replace(QRegExp("^.*://"), proto + "://");
205 ui.addressText->setText(addr);
211 void NetOpenPanel::updateAddress() {
215 void NetOpenPanel::updateMRL() {
217 QString addr = ui.addressText->text();
218 int proto = ui.protocolCombo->currentIndex();
220 if( addr.contains( "://") && proto != 4 ) {
225 mrl = "http://" + addr;
226 emit methodChanged("http-caching");
229 mrl = "mms://" + addr;
230 emit methodChanged("mms-caching");
233 mrl = "ftp://" + addr;
234 emit methodChanged("ftp-caching");
237 mrl = "rtsp://" + addr;
238 emit methodChanged("rtsp-caching");
242 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
245 mrl += QString(":%1").arg(ui.portSpin->value());
246 emit methodChanged("udp-caching");
248 case 5: /* UDP multicast */
251 if ( addr.contains(':') && !addr.contains('[') ) {
252 mrl += "[" + addr + "]";
254 mrl += QString(":%1").arg(ui.portSpin->value());
255 emit methodChanged("udp-caching");
258 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
259 mrl += " :access-filter=timeshift";
261 emit mrlUpdated(mrl);