]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
* Only allow playlist files in open playlist (Refs:#940)
[vlc] / modules / gui / qt4 / components / open.cpp
1 /*****************************************************************************
2  * open.cpp : Panels for the open dialogs
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25
26 #include "qt4.hpp"
27 #include "components/open.hpp"
28 #include "dialogs_provider.hpp"
29
30 /**************************************************************************
31  * File open
32  **************************************************************************/
33 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
34                                 OpenPanel( _parent, _p_intf )
35 {
36     ui.setupUi( this );
37
38
39     BUTTONACT( ui.fileBrowseButton, browseFile() );
40     BUTTONACT( ui.subBrowseButton, browseFileSub() );
41
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());
47 }
48
49 FileOpenPanel::~FileOpenPanel()
50 {}
51
52 QStringList FileOpenPanel::browse(QString help)
53 {
54     return THEDP->showSimpleOpen( help );
55 }
56
57 void FileOpenPanel::browseFile()
58 {
59     QString fileString = "";
60     QStringList files = browse( qtr("Open File") );
61     foreach( QString file, files) {
62         if( file.contains(" ") ) {
63             fileString += "\"" + file + "\"";
64         } else {
65             fileString += file;
66         }
67     }
68
69     ui.fileInput->setEditText( fileString );
70     ui.fileInput->addItem( fileString );
71     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
72
73     updateMRL();
74 }
75
76 void FileOpenPanel::browseFileSub()
77 {
78     ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
79     updateMRL();
80 }
81
82 void FileOpenPanel::updateMRL()
83 {
84     QString mrl = ui.fileInput->currentText();
85
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() );
90     }
91     emit mrlUpdated(mrl);
92     emit methodChanged( "file-caching" );
93 }
94
95 void FileOpenPanel::clear()
96 {
97     ui.fileInput->setEditText( "");
98     ui.subInput->setEditText( "");
99 }
100
101
102 /**************************************************************************
103  * Disk open
104  **************************************************************************/
105 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
106                                 OpenPanel( _parent, _p_intf )
107 {
108     ui.setupUi( this );
109
110     CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
111     BUTTONACT( ui.dvdRadioButton, updateMRL());
112     BUTTONACT( ui.vcdRadioButton, updateMRL());
113     BUTTONACT( ui.audioCDRadioButton, updateMRL());
114
115     CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
116     CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
117 }
118
119 DiskOpenPanel::~DiskOpenPanel()
120 {}
121
122 void DiskOpenPanel::clear()
123 {
124     ui.titleSpin->setValue(0);
125     ui.chapterSpin->setValue(0);
126 }
127
128 void DiskOpenPanel::updateMRL()
129 {
130     QString mrl = "";
131     /* DVD */
132     if( ui.dvdRadioButton->isChecked() ) {
133         mrl = "dvd://" + ui.deviceCombo->currentText();
134         emit methodChanged( "dvdnav-caching" );
135
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());
140             }
141         }
142
143     /* VCD */
144     } else if (ui.vcdRadioButton->isChecked() ) {
145         mrl = "vcd://" + ui.deviceCombo->currentText();
146         emit methodChanged( "vcd-caching" );
147
148         if( ui.titleSpin->value() > 0 ) {
149             mrl += QString("@%1").arg(ui.titleSpin->value());
150         }
151
152     /* CDDA */
153     } else {
154         mrl = "cdda://" + ui.deviceCombo->currentText();
155     }
156
157     emit mrlUpdated(mrl);
158 }
159
160
161
162 /**************************************************************************
163  * Net open
164  **************************************************************************/
165 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
166                                 OpenPanel( _parent, _p_intf )
167 {
168     ui.setupUi( this );
169
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());
176
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"));
183 }
184
185 NetOpenPanel::~NetOpenPanel()
186 {}
187
188 void NetOpenPanel::clear()
189 {}
190
191 void NetOpenPanel::updateProtocol(int idx) {
192     QString addr = ui.addressText->text();
193     QString proto = ui.protocolCombo->itemData(idx).toString();
194
195     ui.timeShift->setEnabled( idx >= 4);
196     ui.ipv6->setEnabled( idx == 4 );
197     ui.addressText->setEnabled( idx != 4 );
198     ui.portSpin->setEnabled( idx >= 4 );
199
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);
205     }
206
207     updateMRL();
208 }
209
210 void NetOpenPanel::updateAddress() {
211     updateMRL();
212 }
213
214 void NetOpenPanel::updateMRL() {
215     QString mrl = "";
216     QString addr = ui.addressText->text();
217     int proto = ui.protocolCombo->currentIndex();
218
219     if( addr.contains( "://") && proto != 4 ) {
220         mrl = addr;
221     } else {
222         switch(proto) {
223         case 0:
224             mrl = "http://" + addr;
225             emit methodChanged("http-caching");
226             break;
227         case 2:
228             mrl = "mms://" + addr;
229             emit methodChanged("mms-caching");
230             break;
231         case 1:
232             mrl = "ftp://" + addr;
233             emit methodChanged("ftp-caching");
234             break;
235         case 3: /* RTSP */
236             mrl = "rtsp://" + addr;
237             emit methodChanged("rtsp-caching");
238             break;
239         case 4:
240             mrl = "udp://@";
241             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
242                 mrl += "[::]";
243             }
244             mrl += QString(":%1").arg(ui.portSpin->value());
245             emit methodChanged("udp-caching");
246             break;
247         case 5: /* UDP multicast */
248             mrl = "udp://@";
249             /* Add [] to IPv6 */
250             if ( addr.contains(':') && !addr.contains('[') ) {
251                 mrl += "[" + addr + "]";
252             } else mrl += addr;
253             mrl += QString(":%1").arg(ui.portSpin->value());
254             emit methodChanged("udp-caching");
255         }
256     }
257     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
258         mrl += " :access-filter=timeshift";
259     }
260     emit mrlUpdated(mrl);
261 }