]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/open.cpp
Qt4 - Open and menus links, cleaning, etc..
[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     captureOpenPanel = new CaptureOpenPanel( this, p_intf );
49
50     ui.Tab->addTab( fileOpenPanel, qtr( "&File" ) );
51     ui.Tab->addTab( diskOpenPanel, qtr( "&Disc" ) );
52     ui.Tab->addTab( netOpenPanel, qtr( "&Network" ) );
53     ui.Tab->addTab( captureOpenPanel, qtr( "Capture &Device" ) );
54
55     ui.advancedFrame->hide();
56
57     /* Force MRL update on tab change */
58     CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
59
60     CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
61     CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
62     CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
63     CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
64             updateMRL(QString) );
65
66
67     CONNECT( fileOpenPanel, methodChanged( QString ),
68              this, newMethod(QString) );
69     CONNECT( netOpenPanel, methodChanged( QString ),
70              this, newMethod(QString) );
71     CONNECT( diskOpenPanel, methodChanged( QString ),
72              this, newMethod(QString) );
73
74     CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
75     CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
76
77     BUTTONACT( ui.closeButton, play());
78     BUTTONACT( ui.cancelButton, cancel());
79     BUTTONACT( ui.enqueueButton, enqueue());
80     BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
81
82     /* Initialize caching */
83     storedMethod = "";
84     newMethod("file-caching");
85
86     mainHeight = advHeight = 0;
87 }
88
89 OpenDialog::~OpenDialog()
90 {
91 }
92
93 void OpenDialog::showTab(int i_tab=0)
94 {
95     printf ( "%i" , i_tab);
96     this->show();
97     ui.Tab->setCurrentIndex(i_tab);
98 }
99
100 void OpenDialog::signalCurrent() {
101     if (ui.Tab->currentWidget() != NULL) {
102         (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
103     }
104 }
105
106 void OpenDialog::cancel()
107 {
108     fileOpenPanel->clear();
109     this->toggleVisible();
110     if( isModal() )
111         reject();
112 }
113
114 void OpenDialog::play()
115 {
116     playOrEnqueue( false );
117 }
118
119 void OpenDialog::enqueue()
120 {
121     playOrEnqueue( true );
122 }
123
124 void OpenDialog::playOrEnqueue( bool b_enqueue = false )
125 {
126     this->toggleVisible();
127     mrl = ui.advancedLineInput->text();
128     QStringList tempMRL = mrl.split( QRegExp("\"\\s+\""),
129                                      QString::SkipEmptyParts );
130     if( !isModal() )
131     {
132         for( size_t i = 0 ; i< tempMRL.size(); i++ )
133         {
134              QString mrli = tempMRL[i].remove( QRegExp( "^\"" ) ).
135                                        remove( QRegExp( "\"\\s+$" ) );
136              const char * psz_utf8 = qtu( tempMRL[i] );
137              if ( b_enqueue )
138              {
139                  /* Enqueue and Preparse all items*/
140                  playlist_Add( THEPL, psz_utf8, NULL,
141                                 PLAYLIST_APPEND | PLAYLIST_PREPARSE,
142                                 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
143
144              }
145              else
146              {
147                  /* Play the first one, parse and enqueue the other ones */
148                  playlist_Add( THEPL, psz_utf8, NULL,
149                                 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
150                                 ( i ? PLAYLIST_PREPARSE : 0 ),
151                                 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
152              }
153         }
154
155     }
156     else
157         accept();
158 }
159
160 void OpenDialog::toggleAdvancedPanel()
161 {
162     if (ui.advancedFrame->isVisible()) {
163         ui.advancedFrame->hide();
164         setMinimumHeight(1);
165         resize( width(), mainHeight );
166
167     } else {
168         if( mainHeight == 0 )
169             mainHeight = height();
170
171         ui.advancedFrame->show();
172         if( advHeight == 0 ) {
173             advHeight = height() - mainHeight;
174         }
175         resize( width(), mainHeight + advHeight );
176     }
177 }
178
179 void OpenDialog::updateMRL() {
180     mrl = mainMRL;
181     if( ui.slaveCheckbox->isChecked() ) {
182         mrl += " :input-slave=" + ui.slaveText->text();
183     }
184     int i_cache = config_GetInt( p_intf, qta(storedMethod) );
185     if( i_cache != ui.cacheSpinBox->value() ) {
186         mrl += QString(" :%1=%2").arg(storedMethod).
187                                   arg(ui.cacheSpinBox->value());
188     }
189     ui.advancedLineInput->setText(mrl);
190 }
191
192 void OpenDialog::updateMRL(QString tempMRL)
193 {
194     mainMRL = tempMRL;
195     updateMRL();
196 }
197
198 void OpenDialog::newMethod(QString method)
199 {
200     if( method != storedMethod ) {
201         storedMethod = method;
202         int i_value = config_GetInt( p_intf, qta(storedMethod) );
203         ui.cacheSpinBox->setValue(i_value);
204     }
205 }