]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
Qt4 - Open: Capture Tab added. Still almost empty, but well, this is coming after. :D
[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         fileString += "\"" + file + "\" ";
63     }
64     ui.fileInput->setEditText( fileString );
65     ui.fileInput->addItem( fileString );
66     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
67
68     updateMRL();
69 }
70
71 void FileOpenPanel::browseFileSub()
72 {
73     ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
74     updateMRL();
75 }
76
77 void FileOpenPanel::updateMRL()
78 {
79     QString mrl = ui.fileInput->currentText();
80
81     if( ui.subGroupBox->isChecked() ) {
82         mrl.append( " :sub-file=" + ui.subInput->currentText() );
83         mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
84         mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
85     }
86     emit mrlUpdated(mrl);
87     emit methodChanged( "file-caching" );
88 }
89
90 void FileOpenPanel::clear()
91 {
92     ui.fileInput->setEditText( "");
93     ui.subInput->setEditText( "");
94 }
95
96
97 /**************************************************************************
98  * Disk open
99  **************************************************************************/
100 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
101                                 OpenPanel( _parent, _p_intf )
102 {
103     ui.setupUi( this );
104
105     CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
106     BUTTONACT( ui.dvdRadioButton, updateMRL());
107     BUTTONACT( ui.vcdRadioButton, updateMRL());
108     BUTTONACT( ui.audioCDRadioButton, updateMRL());
109
110     CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
111     CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
112 }
113
114 DiskOpenPanel::~DiskOpenPanel()
115 {}
116
117 void DiskOpenPanel::clear()
118 {
119     ui.titleSpin->setValue(0);
120     ui.chapterSpin->setValue(0);
121 }
122
123 void DiskOpenPanel::updateMRL()
124 {
125     QString mrl = "";
126     /* DVD */
127     if( ui.dvdRadioButton->isChecked() ) {
128         mrl = "dvd://" + ui.deviceCombo->currentText();
129         emit methodChanged( "dvdnav-caching" );
130
131         if ( ui.titleSpin->value() > 0 ) {
132             mrl += QString("@%1").arg(ui.titleSpin->value());
133             if ( ui.chapterSpin->value() > 0 ) {
134                 mrl+= QString(":%1").arg(ui.chapterSpin->value());
135             }
136         }
137
138     /* VCD */
139     } else if (ui.vcdRadioButton->isChecked() ) {
140         mrl = "vcd://" + ui.deviceCombo->currentText();
141         emit methodChanged( "vcd-caching" );
142
143         if( ui.titleSpin->value() > 0 ) {
144             mrl += QString("@%1").arg(ui.titleSpin->value());
145         }
146
147     /* CDDA */
148     } else {
149         mrl = "cdda://" + ui.deviceCombo->currentText();
150     }
151
152     emit mrlUpdated(mrl);
153 }
154
155
156
157 /**************************************************************************
158  * Net open
159  **************************************************************************/
160 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
161                                 OpenPanel( _parent, _p_intf )
162 {
163     ui.setupUi( this );
164
165     CONNECT( ui.protocolCombo, currentIndexChanged(int),
166              this, updateProtocol(int) );
167     CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
168     CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
169     CONNECT( ui.timeShift, clicked(), this, updateMRL());
170     CONNECT( ui.ipv6, clicked(), this, updateMRL());
171
172     ui.protocolCombo->addItem("HTTP", QVariant("http"));
173     ui.protocolCombo->addItem("FTP", QVariant("ftp"));
174     ui.protocolCombo->addItem("MMS", QVariant("mms"));
175     ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
176     ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
177     ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
178 }
179
180 NetOpenPanel::~NetOpenPanel()
181 {}
182
183 void NetOpenPanel::clear()
184 {}
185
186 void NetOpenPanel::updateProtocol(int idx) {
187     QString addr = ui.addressText->text();
188     QString proto = ui.protocolCombo->itemData(idx).toString();
189
190     ui.timeShift->setEnabled( idx >= 4);
191     ui.ipv6->setEnabled( idx == 4 );
192     ui.addressText->setEnabled( idx != 4 );
193     ui.portSpin->setEnabled( idx >= 4 );
194
195     /* If we already have a protocol in the address, replace it */
196     if( addr.contains( "://")) {
197         msg_Err( p_intf, "replace");
198         addr.replace(QRegExp("^.*://"), proto + "://");
199         ui.addressText->setText(addr);
200     }
201
202     updateMRL();
203 }
204
205 void NetOpenPanel::updateAddress() {
206     updateMRL();
207 }
208
209 void NetOpenPanel::updateMRL() {
210     QString mrl = "";
211     QString addr = ui.addressText->text();
212     int proto = ui.protocolCombo->currentIndex();
213
214     if( addr.contains( "://") && proto != 4 ) {
215         mrl = addr;
216     } else {
217         switch(proto) {
218         case 0:
219             mrl = "http://" + addr;
220             emit methodChanged("http-caching");
221             break;
222         case 2:
223             mrl = "mms://" + addr;
224             emit methodChanged("mms-caching");
225             break;
226         case 1:
227             mrl = "ftp://" + addr;
228             emit methodChanged("ftp-caching");
229             break;
230         case 3: /* RTSP */
231             mrl = "rtsp://" + addr;
232             emit methodChanged("rtsp-caching");
233             break;
234         case 4:
235             mrl = "udp://@";
236             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
237                 mrl += "[::]";
238             }
239             mrl += QString(":%1").arg(ui.portSpin->value());
240             emit methodChanged("udp-caching");
241             break;
242         case 5: /* UDP multicast */
243             mrl = "udp://@";
244             /* Add [] to IPv6 */
245             if ( addr.contains(':') && !addr.contains('[') ) {
246                 mrl += "[" + addr + "]";
247             } else mrl += addr;
248             mrl += QString(":%1").arg(ui.portSpin->value());
249             emit methodChanged("udp-caching");
250         }
251     }
252     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
253         mrl += " :access-filter=timeshift";
254     }
255     emit mrlUpdated(mrl);
256 }
257
258 /**************************************************************************
259  * Capture open
260  **************************************************************************/
261 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
262                                 OpenPanel( _parent, _p_intf )
263 {
264     ui.setupUi( this );
265 }
266
267 CaptureOpenPanel::~CaptureOpenPanel()
268 {}
269
270 void CaptureOpenPanel::clear()
271 {}
272
273 void CaptureOpenPanel::updateMRL()
274 {
275     QString mrl = "";
276     emit mrlUpdated(mrl);
277 }