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