]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
Qt4 - Open: New way and interface for File Open using an integration of QFileDialog...
[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 #include "util/customwidgets.hpp"
30
31 #include <QFileDialog>
32 #include <QDialogButtonBox>
33 #include <QLineEdit>
34
35 /**************************************************************************
36  * File open
37  **************************************************************************/
38 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
39                                 OpenPanel( _parent, _p_intf )
40 {
41     /* Classic UI Setup */
42     ui.setupUi( this );
43
44     /* Use a QFileDialog and customize it because we don't want to
45        rewrite it all. Be careful to your eyes cause there are a few hacks.
46        Be very careful and test correctly when you modify this. */
47
48     // Make this QFileDialog a child of tempWidget from the ui.
49     dialogBox = new QFileDialog( ui.tempWidget );
50     dialogBox->setFileMode( QFileDialog::ExistingFiles );
51     dialogBox->setDirectory( qfu( p_intf->p_libvlc->psz_homedir ) );
52     /* We don't want to see a grip in the middle of the window, do we? */
53     dialogBox->setSizeGripEnabled( false );
54
55     // Add it to the layout
56     ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
57
58     // But hide the two OK/Cancel buttons. Enable them for debug.
59     findChild<QDialogButtonBox*>()->hide();
60
61     /* Ugly hacks to get the good Widget */
62     //This lineEdit is the normal line in the fileDialog.
63     lineFileEdit = findChildren<QLineEdit*>()[3];
64     lineFileEdit->hide();
65
66     /* Make a list of QLabel inside the QFileDialog to access the good ones */
67     QList<QLabel *> listLabel = findChildren<QLabel*>();
68
69     /* Hide the FileNames one. Enable it for debug */
70     listLabel[4]->hide();
71     /* Change the text that was uncool in the usual box */
72     listLabel[5]->setText( qtr( "Filter:" ) );
73
74     BUTTONACT( ui.subBrowseButton, browseFileSub() );
75
76     BUTTONACT( ui.subGroupBox, updateMRL());
77     CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
78     CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
79     CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
80     CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
81     CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
82 }
83
84 FileOpenPanel::~FileOpenPanel()
85 {}
86
87 QStringList FileOpenPanel::browse(QString help)
88 {
89     return THEDP->showSimpleOpen( help );
90 }
91
92 void FileOpenPanel::browseFile()
93 {
94     QString fileString = "";
95     foreach( QString file, dialogBox->selectedFiles() ) { 
96          fileString += "\"" + file + "\" ";
97     }
98     ui.fileInput->setEditText( fileString );
99     updateMRL();
100 }
101
102 void FileOpenPanel::browseFileSub()
103 {
104     ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
105     updateMRL();
106 }
107
108 void FileOpenPanel::updateMRL()
109 {
110     QString mrl = ui.fileInput->currentText();
111
112     if( ui.subGroupBox->isChecked() ) {
113         mrl.append( " :sub-file=" + ui.subInput->currentText() );
114         mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
115         mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
116     }
117     emit mrlUpdated( mrl );
118     emit methodChanged( "file-caching" );
119 }
120
121
122 /* Function called by Open Dialog when clicke on Play/Enqueue */
123 void FileOpenPanel::accept()
124 {
125     ui.fileInput->addItem(ui.fileInput->currentText());
126     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
127 }
128
129
130 /* Function called by Open Dialog when clicked on cancel */
131 void FileOpenPanel::clear()
132 {
133     ui.fileInput->setEditText( "" );
134     ui.subInput->setEditText( "" );
135 }
136
137
138 /**************************************************************************
139  * Disk open
140  **************************************************************************/
141 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
142                                 OpenPanel( _parent, _p_intf )
143 {
144     ui.setupUi( this );
145
146     CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
147     BUTTONACT( ui.dvdRadioButton, updateMRL());
148     BUTTONACT( ui.vcdRadioButton, updateMRL());
149     BUTTONACT( ui.audioCDRadioButton, updateMRL());
150
151     CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
152     CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
153 }
154
155 DiskOpenPanel::~DiskOpenPanel()
156 {}
157
158 void DiskOpenPanel::clear()
159 {
160     ui.titleSpin->setValue(0);
161     ui.chapterSpin->setValue(0);
162 }
163
164 void DiskOpenPanel::updateMRL()
165 {
166     QString mrl = "";
167     /* DVD */
168     if( ui.dvdRadioButton->isChecked() ) {
169         mrl = "dvd://" + ui.deviceCombo->currentText();
170         emit methodChanged( "dvdnav-caching" );
171
172         if ( ui.titleSpin->value() > 0 ) {
173             mrl += QString("@%1").arg(ui.titleSpin->value());
174             if ( ui.chapterSpin->value() > 0 ) {
175                 mrl+= QString(":%1").arg(ui.chapterSpin->value());
176             }
177         }
178
179     /* VCD */
180     } else if (ui.vcdRadioButton->isChecked() ) {
181         mrl = "vcd://" + ui.deviceCombo->currentText();
182         emit methodChanged( "vcd-caching" );
183
184         if( ui.titleSpin->value() > 0 ) {
185             mrl += QString("@%1").arg(ui.titleSpin->value());
186         }
187
188     /* CDDA */
189     } else {
190         mrl = "cdda://" + ui.deviceCombo->currentText();
191     }
192
193     emit mrlUpdated(mrl);
194 }
195
196
197
198 /**************************************************************************
199  * Net open
200  **************************************************************************/
201 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
202                                 OpenPanel( _parent, _p_intf )
203 {
204     ui.setupUi( this );
205
206     CONNECT( ui.protocolCombo, currentIndexChanged(int),
207              this, updateProtocol(int) );
208     CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
209     CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
210     CONNECT( ui.timeShift, clicked(), this, updateMRL());
211     CONNECT( ui.ipv6, clicked(), this, updateMRL());
212
213     ui.protocolCombo->addItem("HTTP", QVariant("http"));
214     ui.protocolCombo->addItem("FTP", QVariant("ftp"));
215     ui.protocolCombo->addItem("MMS", QVariant("mms"));
216     ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
217     ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
218     ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
219 }
220
221 NetOpenPanel::~NetOpenPanel()
222 {}
223
224 void NetOpenPanel::clear()
225 {}
226
227 void NetOpenPanel::updateProtocol(int idx) {
228     QString addr = ui.addressText->text();
229     QString proto = ui.protocolCombo->itemData(idx).toString();
230
231     ui.timeShift->setEnabled( idx >= 4);
232     ui.ipv6->setEnabled( idx == 4 );
233     ui.addressText->setEnabled( idx != 4 );
234     ui.portSpin->setEnabled( idx >= 4 );
235
236     /* If we already have a protocol in the address, replace it */
237     if( addr.contains( "://")) {
238         msg_Err( p_intf, "replace");
239         addr.replace(QRegExp("^.*://"), proto + "://");
240         ui.addressText->setText(addr);
241     }
242
243     updateMRL();
244 }
245
246 void NetOpenPanel::updateAddress() {
247     updateMRL();
248 }
249
250 void NetOpenPanel::updateMRL() {
251     QString mrl = "";
252     QString addr = ui.addressText->text();
253     int proto = ui.protocolCombo->currentIndex();
254
255     if( addr.contains( "://") && proto != 4 ) {
256         mrl = addr;
257     } else {
258         switch(proto) {
259         case 0:
260             mrl = "http://" + addr;
261             emit methodChanged("http-caching");
262             break;
263         case 2:
264             mrl = "mms://" + addr;
265             emit methodChanged("mms-caching");
266             break;
267         case 1:
268             mrl = "ftp://" + addr;
269             emit methodChanged("ftp-caching");
270             break;
271         case 3: /* RTSP */
272             mrl = "rtsp://" + addr;
273             emit methodChanged("rtsp-caching");
274             break;
275         case 4:
276             mrl = "udp://@";
277             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
278                 mrl += "[::]";
279             }
280             mrl += QString(":%1").arg(ui.portSpin->value());
281             emit methodChanged("udp-caching");
282             break;
283         case 5: /* UDP multicast */
284             mrl = "udp://@";
285             /* Add [] to IPv6 */
286             if ( addr.contains(':') && !addr.contains('[') ) {
287                 mrl += "[" + addr + "]";
288             } else mrl += addr;
289             mrl += QString(":%1").arg(ui.portSpin->value());
290             emit methodChanged("udp-caching");
291         }
292     }
293     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
294         mrl += " :access-filter=timeshift";
295     }
296     emit mrlUpdated(mrl);
297 }
298
299 /**************************************************************************
300  * Capture open
301  **************************************************************************/
302 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
303                                 OpenPanel( _parent, _p_intf )
304 {
305     ui.setupUi( this );
306 }
307
308 CaptureOpenPanel::~CaptureOpenPanel()
309 {}
310
311 void CaptureOpenPanel::clear()
312 {}
313
314 void CaptureOpenPanel::updateMRL()
315 {
316     QString mrl = "";
317     emit mrlUpdated(mrl);
318 }