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