]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/open.cpp
e9a532a14254194a6f9e8d48ff6146bb1bfb454d
[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     setWindowTitle( qtr("Open" ) );
42     setModal( modal );
43     ui.setupUi( this );
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     this->show();
88     ui.Tab->setCurrentIndex(i_tab);
89 }
90
91 void OpenDialog::signalCurrent() {
92     if (ui.Tab->currentWidget() != NULL) {
93         (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
94     }
95 }
96
97 void OpenDialog::cancel()
98 {
99     fileOpenPanel->clear();
100     this->toggleVisible();
101     if( isModal() )
102         reject();
103 }
104
105 void OpenDialog::ok()
106 {
107     this->toggleVisible();
108     mrl = ui.advancedLineInput->text();
109     QStringList tempMRL = mrl.split(" ");
110     if( !isModal() )
111     {
112         for( size_t i = 0 ; i< tempMRL.size(); i++ )
113         {
114              const char * psz_utf8 = qtu( tempMRL[i] );
115              /* Play the first one, parse and enqueue the other ones */
116              playlist_Add( THEPL, psz_utf8, NULL,
117                            PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
118                            ( i ? PLAYLIST_PREPARSE : 0 ),
119                            PLAYLIST_END, VLC_TRUE );
120          }
121
122     }
123     else
124         accept();
125 }
126
127 void OpenDialog::toggleAdvancedPanel()
128 {
129     if (ui.advancedFrame->isVisible()) {
130         ui.advancedFrame->hide();
131         setMinimumHeight(1);
132         resize( width(), mainHeight );
133
134     } else {
135         if( mainHeight == 0 )
136             mainHeight = height();
137
138         ui.advancedFrame->show();
139         if( advHeight == 0 ) {
140             advHeight = height() - mainHeight;
141         }
142         resize( width(), mainHeight + advHeight );
143     }
144 }
145
146 void OpenDialog::updateMRL() {
147     mrl = mainMRL;
148     if( ui.slaveCheckbox->isChecked() ) {
149         mrl += " :input-slave=" + ui.slaveText->text();
150     }
151     int i_cache = config_GetInt( p_intf, qta(storedMethod) );
152     if( i_cache != ui.cacheSpinBox->value() ) {
153         mrl += QString(" :%1=%2").arg(storedMethod).
154                                   arg(ui.cacheSpinBox->value());
155     }
156     ui.advancedLineInput->setText(mrl);
157 }
158
159 void OpenDialog::updateMRL(QString tempMRL)
160 {
161     mainMRL = tempMRL;
162     updateMRL();
163 }
164
165 void OpenDialog::newMethod(QString method)
166 {
167     if( method != storedMethod ) {
168         storedMethod = method;
169         int i_value = config_GetInt( p_intf, qta(storedMethod) );
170         ui.cacheSpinBox->setValue(i_value);
171     }
172 }