]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/open.cpp
* Only allow playlist files in open playlist (Refs:#940)
[vlc] / modules / gui / qt4 / dialogs / open.cpp
1 /*****************************************************************************
2  * open.cpp : Advanced open dialog
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
22
23 #include <QTabWidget>
24 #include <QGridLayout>
25 #include <QFileDialog>
26
27 #include "dialogs/open.hpp"
28 #include "components/open.hpp"
29
30 #include "qt4.hpp"
31 #include "util/qvlcframe.hpp"
32
33 #include "input_manager.hpp"
34 #include "dialogs_provider.hpp"
35
36 OpenDialog *OpenDialog::instance = NULL;
37
38 OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
39                                                 QVLCDialog( parent, _p_intf )
40 {
41     setModal( modal );
42     ui.setupUi( this );
43     setWindowTitle( qtr("Open" ) );
44     fileOpenPanel = new FileOpenPanel(this , p_intf );
45     diskOpenPanel = new DiskOpenPanel(this , p_intf );
46     netOpenPanel = new NetOpenPanel(this , p_intf );
47     ui.Tab->addTab(fileOpenPanel, qtr("File"));
48     ui.Tab->addTab(diskOpenPanel, qtr("Disk"));
49     ui.Tab->addTab(netOpenPanel, qtr("Network"));
50
51     ui.advancedFrame->hide();
52
53     /* Force MRL update on tab change */
54     CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
55
56     CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
57     CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
58     CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
59
60     CONNECT( fileOpenPanel, methodChanged( QString ),
61              this, newMethod(QString) );
62     CONNECT( netOpenPanel, methodChanged( QString ),
63              this, newMethod(QString) );
64     CONNECT( diskOpenPanel, methodChanged( QString ),
65              this, newMethod(QString) );
66
67     CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
68     CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
69
70     BUTTONACT( ui.closeButton, ok());
71     BUTTONACT( ui.cancelButton, cancel());
72     BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
73
74     /* Initialize caching */
75     storedMethod = "";
76     newMethod("file-caching");
77
78     mainHeight = advHeight = 0;
79 }
80
81 OpenDialog::~OpenDialog()
82 {
83 }
84
85 void OpenDialog::showTab(int i_tab=0)
86 {
87     printf ( "%i" , i_tab);
88     this->show();
89     ui.Tab->setCurrentIndex(i_tab);
90 }
91
92 void OpenDialog::signalCurrent() {
93     if (ui.Tab->currentWidget() != NULL) {
94         (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
95     }
96 }
97
98 void OpenDialog::cancel()
99 {
100     fileOpenPanel->clear();
101     this->toggleVisible();
102     if( isModal() )
103         reject();
104 }
105
106 void OpenDialog::ok()
107 {
108     this->toggleVisible();
109     mrl = ui.advancedLineInput->text();
110     QStringList tempMRL = mrl.split(" ");
111     if( !isModal() )
112     {
113         for( size_t i = 0 ; i< tempMRL.size(); i++ )
114         {
115              const char * psz_utf8 = qtu( tempMRL[i] );
116              /* Play the first one, parse and enqueue the other ones */
117              playlist_Add( THEPL, psz_utf8, NULL,
118                            PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
119                            ( i ? PLAYLIST_PREPARSE : 0 ),
120                            PLAYLIST_END, VLC_TRUE );
121          }
122
123     }
124     else
125         accept();
126 }
127
128 void OpenDialog::toggleAdvancedPanel()
129 {
130     if (ui.advancedFrame->isVisible()) {
131         ui.advancedFrame->hide();
132         setMinimumHeight(1);
133         resize( width(), mainHeight );
134
135     } else {
136         if( mainHeight == 0 )
137             mainHeight = height();
138
139         ui.advancedFrame->show();
140         if( advHeight == 0 ) {
141             advHeight = height() - mainHeight;
142         }
143         resize( width(), mainHeight + advHeight );
144     }
145
146     showTab( 2 );
147 }
148
149 void OpenDialog::updateMRL() {
150     mrl = mainMRL;
151     if( ui.slaveCheckbox->isChecked() ) {
152         mrl += " :input-slave=" + ui.slaveText->text();
153     }
154     int i_cache = config_GetInt( p_intf, qta(storedMethod) );
155     if( i_cache != ui.cacheSpinBox->value() ) {
156         mrl += QString(" :%1=%2").arg(storedMethod).
157                                   arg(ui.cacheSpinBox->value());
158     }
159     ui.advancedLineInput->setText(mrl);
160 }
161
162 void OpenDialog::updateMRL(QString tempMRL)
163 {
164     mainMRL = tempMRL;
165     updateMRL();
166 }
167
168 void OpenDialog::newMethod(QString method)
169 {
170     if( method != storedMethod ) {
171         storedMethod = method;
172         int i_value = config_GetInt( p_intf, qta(storedMethod) );
173         ui.cacheSpinBox->setValue(i_value);
174     }
175 }