]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
Qt4 - Open - Hide the OK/Cancel for everyone ( Windows too )
[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/open.hpp"
29 #include "dialogs_provider.hpp"
30 #include "util/customwidgets.hpp"
31
32 #include <QFileDialog>
33 #include <QDialogButtonBox>
34 #include <QLineEdit>
35
36 /**************************************************************************
37  * File open
38  **************************************************************************/
39 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
40                                 OpenPanel( _parent, _p_intf )
41 {
42     /* Classic UI Setup */
43     ui.setupUi( this );
44
45     /* Use a QFileDialog and customize it because we don't want to
46        rewrite it all. Be careful to your eyes cause there are a few hacks.
47        Be very careful and test correctly when you modify this. */
48
49     /* Set Filters for file selection */
50     QString fileTypes = "";
51     ADD_FILTER_MEDIA( fileTypes );
52     ADD_FILTER_VIDEO( fileTypes );
53     ADD_FILTER_AUDIO( fileTypes );
54     ADD_FILTER_PLAYLIST( fileTypes );
55     ADD_FILTER_ALL( fileTypes );
56     fileTypes.replace(QString(";*"), QString(" *"));
57
58     // Make this QFileDialog a child of tempWidget from the ui.
59     dialogBox = new FileOpenBox( ui.tempWidget, NULL,
60             qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
61     dialogBox->setFileMode( QFileDialog::ExistingFiles );
62     dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
63
64     /* We don't want to see a grip in the middle of the window, do we? */
65     dialogBox->setSizeGripEnabled( false );
66     dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
67
68     // Add it to the layout
69     ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
70
71     // But hide the two OK/Cancel buttons. Enable them for debug.
72     fileDialogAcceptBox = findChildren<QDialogButtonBox*>()[0];
73     fileDialogAcceptBox->hide();
74
75     /* Ugly hacks to get the good Widget */
76     //This lineEdit is the normal line in the fileDialog.
77     lineFileEdit = findChildren<QLineEdit*>()[3];
78     lineFileEdit->hide();
79
80     /* Make a list of QLabel inside the QFileDialog to access the good ones */
81     QList<QLabel *> listLabel = findChildren<QLabel*>();
82
83     /* Hide the FileNames one. Enable it for debug */
84     listLabel[4]->hide();
85     /* Change the text that was uncool in the usual box */
86     listLabel[5]->setText( qtr( "Filter:" ) );
87
88     // Hide the subtitles control by default.
89     ui.subFrame->hide();
90
91     /* Build the subs size combo box */
92     module_config_t *p_item =
93         config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
94     if( p_item )
95     {
96         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
97         {
98             ui.sizeSubComboBox->addItem(
99                 qfu( p_item->ppsz_list_text[i_index] ),
100                 QVariant( p_item->pi_list[i_index] ) );
101             if( p_item->value.i == p_item->pi_list[i_index] )
102             {
103                 ui.sizeSubComboBox->setCurrentIndex( i_index );
104             }
105         }
106     }
107
108     /* Build the subs align combo box */
109     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
110     if( p_item )
111     {
112         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
113         {
114             ui.alignSubComboBox->addItem(
115                 qfu( p_item->ppsz_list_text[i_index] ),
116                 QVariant( p_item->pi_list[i_index] ) );
117             if( p_item->value.i == p_item->pi_list[i_index] )
118             {
119                 ui.alignSubComboBox->setCurrentIndex( i_index );
120             }
121         }
122     }
123
124     BUTTONACT( ui.subBrowseButton, browseFileSub() );
125     BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
126
127     CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
128     CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
129     CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
130     CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
131     CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
132 }
133
134 FileOpenPanel::~FileOpenPanel()
135 {}
136
137 QStringList FileOpenPanel::browse(QString help)
138 {
139     return THEDP->showSimpleOpen( help );
140 }
141
142 void FileOpenPanel::browseFile()
143 {
144     QString fileString = "";
145     foreach( QString file, dialogBox->selectedFiles() ) {
146          fileString += "\"" + file + "\" ";
147     }
148     ui.fileInput->setEditText( fileString );
149     updateMRL();
150 }
151
152 void FileOpenPanel::browseFileSub()
153 {
154     // FIXME Handle selection of more than one subtitles file
155     QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
156                             EXT_FILTER_SUBTITLE,
157                             dialogBox->directory().absolutePath() );
158     if( files.isEmpty() ) return;
159     ui.subInput->setEditText( files.join(" ") );
160     updateMRL();
161 }
162
163 void FileOpenPanel::updateMRL()
164 {
165     QString mrl = ui.fileInput->currentText();
166
167     if( ui.subCheckBox->isChecked() ) {
168         mrl.append( " :sub-file=" + ui.subInput->currentText() );
169         int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
170         mrl.append( " :subsdec-align=" + QString().setNum( align ) );
171         int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
172         mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
173     }
174     emit mrlUpdated( mrl );
175     emit methodChanged( "file-caching" );
176 }
177
178
179 /* Function called by Open Dialog when clicke on Play/Enqueue */
180 void FileOpenPanel::accept()
181 {
182     ui.fileInput->addItem(ui.fileInput->currentText());
183     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
184 }
185
186 void FileOpenBox::accept()
187 {
188     OpenDialog::getInstance( NULL, NULL )->play();
189 }
190
191 /* Function called by Open Dialog when clicked on cancel */
192 void FileOpenPanel::clear()
193 {
194     ui.fileInput->setEditText( "" );
195     ui.subInput->setEditText( "" );
196 }
197
198 void FileOpenPanel::toggleSubtitleFrame()
199 {
200     if (ui.subFrame->isVisible())
201     {
202         ui.subFrame->hide();
203 //        setMinimumHeight(1);
204         resize( sizeHint());
205     }
206     else
207     {
208         ui.subFrame->show();
209     }
210
211     /* Update the MRL */
212     updateMRL();
213 }
214
215 /**************************************************************************
216  * Disk open
217  **************************************************************************/
218 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
219                                 OpenPanel( _parent, _p_intf )
220 {
221     ui.setupUi( this );
222
223     CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
224     BUTTONACT( ui.dvdRadioButton, updateMRL());
225     BUTTONACT( ui.vcdRadioButton, updateMRL());
226     BUTTONACT( ui.audioCDRadioButton, updateMRL());
227
228     CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
229     CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
230 }
231
232 DiscOpenPanel::~DiscOpenPanel()
233 {}
234
235 void DiscOpenPanel::clear()
236 {
237     ui.titleSpin->setValue(0);
238     ui.chapterSpin->setValue(0);
239 }
240
241 void DiscOpenPanel::updateMRL()
242 {
243     QString mrl = "";
244     /* DVD */
245     if( ui.dvdRadioButton->isChecked() ) {
246         mrl = "dvd://" + ui.deviceCombo->currentText();
247         emit methodChanged( "dvdnav-caching" );
248
249         if ( ui.titleSpin->value() > 0 ) {
250             mrl += QString("@%1").arg(ui.titleSpin->value());
251             if ( ui.chapterSpin->value() > 0 ) {
252                 mrl+= QString(":%1").arg(ui.chapterSpin->value());
253             }
254         }
255
256     /* VCD */
257     } else if (ui.vcdRadioButton->isChecked() ) {
258         mrl = "vcd://" + ui.deviceCombo->currentText();
259         emit methodChanged( "vcd-caching" );
260
261         if( ui.titleSpin->value() > 0 ) {
262             mrl += QString("@%1").arg(ui.titleSpin->value());
263         }
264
265     /* CDDA */
266     } else {
267         mrl = "cdda://" + ui.deviceCombo->currentText();
268     }
269
270     emit mrlUpdated(mrl);
271 }
272
273
274
275 /**************************************************************************
276  * Net open
277  **************************************************************************/
278 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
279                                 OpenPanel( _parent, _p_intf )
280 {
281     ui.setupUi( this );
282
283     CONNECT( ui.protocolCombo, currentIndexChanged(int),
284              this, updateProtocol(int) );
285     CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
286     CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
287     CONNECT( ui.timeShift, clicked(), this, updateMRL());
288     CONNECT( ui.ipv6, clicked(), this, updateMRL());
289
290     ui.protocolCombo->addItem("HTTP", QVariant("http"));
291     ui.protocolCombo->addItem("FTP", QVariant("ftp"));
292     ui.protocolCombo->addItem("MMS", QVariant("mms"));
293     ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
294     ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
295     ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
296 }
297
298 NetOpenPanel::~NetOpenPanel()
299 {}
300
301 void NetOpenPanel::clear()
302 {}
303
304 void NetOpenPanel::updateProtocol(int idx) {
305     QString addr = ui.addressText->text();
306     QString proto = ui.protocolCombo->itemData(idx).toString();
307
308     ui.timeShift->setEnabled( idx >= 4);
309     ui.ipv6->setEnabled( idx == 4 );
310     ui.addressText->setEnabled( idx != 4 );
311     ui.portSpin->setEnabled( idx >= 4 );
312
313     /* If we already have a protocol in the address, replace it */
314     if( addr.contains( "://")) {
315         msg_Err( p_intf, "replace");
316         addr.replace(QRegExp("^.*://"), proto + "://");
317         ui.addressText->setText(addr);
318     }
319
320     updateMRL();
321 }
322
323 void NetOpenPanel::updateAddress() {
324     updateMRL();
325 }
326
327 void NetOpenPanel::updateMRL() {
328     QString mrl = "";
329     QString addr = ui.addressText->text();
330     int proto = ui.protocolCombo->currentIndex();
331
332     if( addr.contains( "://") && proto != 4 ) {
333         mrl = addr;
334     } else {
335         switch(proto) {
336         case 0:
337             mrl = "http://" + addr;
338             emit methodChanged("http-caching");
339             break;
340         case 2:
341             mrl = "mms://" + addr;
342             emit methodChanged("mms-caching");
343             break;
344         case 1:
345             mrl = "ftp://" + addr;
346             emit methodChanged("ftp-caching");
347             break;
348         case 3: /* RTSP */
349             mrl = "rtsp://" + addr;
350             emit methodChanged("rtsp-caching");
351             break;
352         case 4:
353             mrl = "udp://@";
354             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
355                 mrl += "[::]";
356             }
357             mrl += QString(":%1").arg(ui.portSpin->value());
358             emit methodChanged("udp-caching");
359             break;
360         case 5: /* UDP multicast */
361             mrl = "udp://@";
362             /* Add [] to IPv6 */
363             if ( addr.contains(':') && !addr.contains('[') ) {
364                 mrl += "[" + addr + "]";
365             } else mrl += addr;
366             mrl += QString(":%1").arg(ui.portSpin->value());
367             emit methodChanged("udp-caching");
368         }
369     }
370     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
371         mrl += " :access-filter=timeshift";
372     }
373     emit mrlUpdated(mrl);
374 }
375
376 /**************************************************************************
377  * Capture open
378  **************************************************************************/
379 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
380                                 OpenPanel( _parent, _p_intf )
381 {
382     ui.setupUi( this );
383 }
384
385 CaptureOpenPanel::~CaptureOpenPanel()
386 {}
387
388 void CaptureOpenPanel::clear()
389 {}
390
391 void CaptureOpenPanel::updateMRL()
392 {
393     QString mrl = "";
394     emit mrlUpdated(mrl);
395 }