]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/open.cpp
Qt4 open:
[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( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
39 {
40     setWindowTitle( qtr("Open" ) );
41     ui.setupUi( this );
42     fileOpenPanel = new FileOpenPanel(this , p_intf );
43     diskOpenPanel = new DiskOpenPanel(this , p_intf );
44     netOpenPanel = new NetOpenPanel(this , p_intf );
45     ui.Tab->addTab(fileOpenPanel, qtr("File"));
46     ui.Tab->addTab(diskOpenPanel, qtr("Disk"));
47     ui.Tab->addTab(netOpenPanel, qtr("Network"));
48
49     ui.advancedFrame->hide();
50
51     /* Force MRL update on tab change */
52     CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
53
54     CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
55     CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
56     CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
57
58     CONNECT( fileOpenPanel, methodChanged( QString ),
59              this, newMethod(QString) );
60     CONNECT( netOpenPanel, methodChanged( QString ),
61              this, newMethod(QString) );
62     CONNECT( diskOpenPanel, methodChanged( QString ),
63              this, newMethod(QString) );
64
65     CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
66     CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
67
68     BUTTONACT( ui.closeButton, ok());
69     BUTTONACT( ui.cancelButton, cancel());
70     BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
71
72     /* Initialize caching */
73     storedMethod = "";
74     newMethod("file-caching");
75
76     mainHeight = advHeight = 0;
77 }
78
79 OpenDialog::~OpenDialog()
80 {
81 }
82
83 void OpenDialog::showTab(int i_tab=0)
84 {
85     this->show();
86     ui.Tab->setCurrentIndex(i_tab);
87 }
88
89 void OpenDialog::signalCurrent() {
90     if (ui.Tab->currentWidget() != NULL) {
91         (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
92     }
93 }
94
95 void OpenDialog::cancel()
96 {
97     fileOpenPanel->clear();
98     this->toggleVisible();
99 }
100
101 void OpenDialog::ok()
102 {
103     QString mrl = ui.advancedLineInput->text();
104     QStringList tempMRL = mrl.split(" ");
105     for( size_t i = 0 ; i< tempMRL.size(); i++ )
106     {
107          const char * psz_utf8 = qtu( tempMRL[i] );
108          /* Play the first one, parse and enqueue the other ones */
109          playlist_Add( THEPL, psz_utf8, NULL,
110                        PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
111                        ( i ? PLAYLIST_PREPARSE : 0 ),
112                        PLAYLIST_END, VLC_TRUE );
113       }
114
115     this->toggleVisible();
116 }
117
118 void OpenDialog::changedTab()
119 {
120 }
121
122 void OpenDialog::toggleAdvancedPanel()
123 {
124     if (ui.advancedFrame->isVisible()) {
125         ui.advancedFrame->hide();
126         setMinimumHeight(1);
127         resize( width(), mainHeight );
128
129     } else {
130         if( mainHeight == 0 )
131             mainHeight = height();
132
133         ui.advancedFrame->show();
134         if( advHeight == 0 ) {
135             advHeight = height() - mainHeight;
136         }
137         resize( width(), mainHeight + advHeight );
138     }
139 }
140
141 void OpenDialog::updateMRL() {
142     QString mrl = mainMRL;
143     if( ui.slaveCheckbox->isChecked() ) {
144         mrl += " :input-slave=" + ui.slaveText->text();
145     }
146     int i_cache = config_GetInt( p_intf, qta(storedMethod) );
147     if( i_cache != ui.cacheSpinBox->value() ) {
148         mrl += QString(" :%1=%2").arg(storedMethod).
149                                   arg(ui.cacheSpinBox->value());
150     }
151     ui.advancedLineInput->setText(mrl);
152 }
153
154 void OpenDialog::updateMRL(QString tempMRL)
155 {
156     mainMRL = tempMRL;
157     updateMRL();
158 }
159
160 void OpenDialog::newMethod(QString method)
161 {
162     if( method != storedMethod ) {
163         storedMethod = method;
164         int i_value = config_GetInt( p_intf, qta(storedMethod) );
165         ui.cacheSpinBox->setValue(i_value);
166     }
167 }