]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
Qt4 - Open. Use a Frame and not a QComboBox for subtitles. (lacks still some toggle...
[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     /* Hacks Continued Catch the close event */
75     dialogBox->installEventFilter( this );
76
77     // Hide the subtitles control by default.
78     ui.subFrame->hide();
79
80
81     BUTTONACT( ui.subBrowseButton, browseFileSub() );
82     BUTTONACT( ui.subCheckBox, updateMRL());
83
84     CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
85     CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
86     CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
87     CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
88     CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
89 }
90
91 FileOpenPanel::~FileOpenPanel()
92 {}
93
94 QStringList FileOpenPanel::browse(QString help)
95 {
96     return THEDP->showSimpleOpen( help );
97 }
98
99 void FileOpenPanel::browseFile()
100 {
101     QString fileString = "";
102     foreach( QString file, dialogBox->selectedFiles() ) { 
103          fileString += "\"" + file + "\" ";
104     }
105     ui.fileInput->setEditText( fileString );
106     updateMRL();
107 }
108
109 void FileOpenPanel::browseFileSub()
110 {
111     ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
112     updateMRL();
113 }
114
115 void FileOpenPanel::updateMRL()
116 {
117     QString mrl = ui.fileInput->currentText();
118
119     if( ui.subCheckBox->isChecked() ) {
120         mrl.append( " :sub-file=" + ui.subInput->currentText() );
121         mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
122         mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
123     }
124     emit mrlUpdated( mrl );
125     emit methodChanged( "file-caching" );
126 }
127
128
129 /* Function called by Open Dialog when clicke on Play/Enqueue */
130 void FileOpenPanel::accept()
131 {
132     ui.fileInput->addItem(ui.fileInput->currentText());
133     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
134 }
135
136
137 /* Function called by Open Dialog when clicked on cancel */
138 void FileOpenPanel::clear()
139 {
140     ui.fileInput->setEditText( "" );
141     ui.subInput->setEditText( "" );
142 }
143
144 bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
145 {
146     printf( "coin\n" );
147     if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
148     {
149          event->ignore();
150          return true;
151     }
152     // standard event processing
153     else
154         return QObject::eventFilter(object, event);
155 }
156
157 /**************************************************************************
158  * Disk open
159  **************************************************************************/
160 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
161                                 OpenPanel( _parent, _p_intf )
162 {
163     ui.setupUi( this );
164
165     CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
166     BUTTONACT( ui.dvdRadioButton, updateMRL());
167     BUTTONACT( ui.vcdRadioButton, updateMRL());
168     BUTTONACT( ui.audioCDRadioButton, updateMRL());
169
170     CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
171     CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
172 }
173
174 DiskOpenPanel::~DiskOpenPanel()
175 {}
176
177 void DiskOpenPanel::clear()
178 {
179     ui.titleSpin->setValue(0);
180     ui.chapterSpin->setValue(0);
181 }
182
183 void DiskOpenPanel::updateMRL()
184 {
185     QString mrl = "";
186     /* DVD */
187     if( ui.dvdRadioButton->isChecked() ) {
188         mrl = "dvd://" + ui.deviceCombo->currentText();
189         emit methodChanged( "dvdnav-caching" );
190
191         if ( ui.titleSpin->value() > 0 ) {
192             mrl += QString("@%1").arg(ui.titleSpin->value());
193             if ( ui.chapterSpin->value() > 0 ) {
194                 mrl+= QString(":%1").arg(ui.chapterSpin->value());
195             }
196         }
197
198     /* VCD */
199     } else if (ui.vcdRadioButton->isChecked() ) {
200         mrl = "vcd://" + ui.deviceCombo->currentText();
201         emit methodChanged( "vcd-caching" );
202
203         if( ui.titleSpin->value() > 0 ) {
204             mrl += QString("@%1").arg(ui.titleSpin->value());
205         }
206
207     /* CDDA */
208     } else {
209         mrl = "cdda://" + ui.deviceCombo->currentText();
210     }
211
212     emit mrlUpdated(mrl);
213 }
214
215
216
217 /**************************************************************************
218  * Net open
219  **************************************************************************/
220 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
221                                 OpenPanel( _parent, _p_intf )
222 {
223     ui.setupUi( this );
224
225     CONNECT( ui.protocolCombo, currentIndexChanged(int),
226              this, updateProtocol(int) );
227     CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
228     CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
229     CONNECT( ui.timeShift, clicked(), this, updateMRL());
230     CONNECT( ui.ipv6, clicked(), this, updateMRL());
231
232     ui.protocolCombo->addItem("HTTP", QVariant("http"));
233     ui.protocolCombo->addItem("FTP", QVariant("ftp"));
234     ui.protocolCombo->addItem("MMS", QVariant("mms"));
235     ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
236     ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
237     ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
238 }
239
240 NetOpenPanel::~NetOpenPanel()
241 {}
242
243 void NetOpenPanel::clear()
244 {}
245
246 void NetOpenPanel::updateProtocol(int idx) {
247     QString addr = ui.addressText->text();
248     QString proto = ui.protocolCombo->itemData(idx).toString();
249
250     ui.timeShift->setEnabled( idx >= 4);
251     ui.ipv6->setEnabled( idx == 4 );
252     ui.addressText->setEnabled( idx != 4 );
253     ui.portSpin->setEnabled( idx >= 4 );
254
255     /* If we already have a protocol in the address, replace it */
256     if( addr.contains( "://")) {
257         msg_Err( p_intf, "replace");
258         addr.replace(QRegExp("^.*://"), proto + "://");
259         ui.addressText->setText(addr);
260     }
261
262     updateMRL();
263 }
264
265 void NetOpenPanel::updateAddress() {
266     updateMRL();
267 }
268
269 void NetOpenPanel::updateMRL() {
270     QString mrl = "";
271     QString addr = ui.addressText->text();
272     int proto = ui.protocolCombo->currentIndex();
273
274     if( addr.contains( "://") && proto != 4 ) {
275         mrl = addr;
276     } else {
277         switch(proto) {
278         case 0:
279             mrl = "http://" + addr;
280             emit methodChanged("http-caching");
281             break;
282         case 2:
283             mrl = "mms://" + addr;
284             emit methodChanged("mms-caching");
285             break;
286         case 1:
287             mrl = "ftp://" + addr;
288             emit methodChanged("ftp-caching");
289             break;
290         case 3: /* RTSP */
291             mrl = "rtsp://" + addr;
292             emit methodChanged("rtsp-caching");
293             break;
294         case 4:
295             mrl = "udp://@";
296             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
297                 mrl += "[::]";
298             }
299             mrl += QString(":%1").arg(ui.portSpin->value());
300             emit methodChanged("udp-caching");
301             break;
302         case 5: /* UDP multicast */
303             mrl = "udp://@";
304             /* Add [] to IPv6 */
305             if ( addr.contains(':') && !addr.contains('[') ) {
306                 mrl += "[" + addr + "]";
307             } else mrl += addr;
308             mrl += QString(":%1").arg(ui.portSpin->value());
309             emit methodChanged("udp-caching");
310         }
311     }
312     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
313         mrl += " :access-filter=timeshift";
314     }
315     emit mrlUpdated(mrl);
316 }
317
318 /**************************************************************************
319  * Capture open
320  **************************************************************************/
321 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
322                                 OpenPanel( _parent, _p_intf )
323 {
324     ui.setupUi( this );
325 }
326
327 CaptureOpenPanel::~CaptureOpenPanel()
328 {}
329
330 void CaptureOpenPanel::clear()
331 {}
332
333 void CaptureOpenPanel::updateMRL()
334 {
335     QString mrl = "";
336     emit mrlUpdated(mrl);
337 }