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