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