1 /*****************************************************************************
2 * main_inteface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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. *****************************************************************************/
24 #include <QApplication>
25 #include <QSignalMapper>
26 #include <QFileDialog>
29 #include "dialogs_provider.hpp"
31 #include <vlc_intf_strings.h>
34 #include "dialogs/playlist.hpp"
35 #include "dialogs/prefs_dialog.hpp"
36 #include "dialogs/streaminfo.hpp"
37 #include "dialogs/messages.hpp"
38 #include "dialogs/extended.hpp"
39 #include "dialogs/sout.hpp"
41 DialogsProvider* DialogsProvider::instance = NULL;
43 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
44 QObject( NULL ), p_intf( _p_intf )
46 fixed_timer = new QTimer( this );
47 fixed_timer->start( 150 /* milliseconds */ );
49 menusMapper = new QSignalMapper();
50 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
52 menusUpdateMapper = new QSignalMapper();
53 CONNECT( menusUpdateMapper, mapped(QObject *),
54 this, menuUpdateAction( QObject *) );
56 SDMapper = new QSignalMapper();
57 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
60 DialogsProvider::~DialogsProvider()
62 PlaylistDialog::killInstance();
63 StreamInfoDialog::killInstance();
66 void DialogsProvider::customEvent( QEvent *event )
68 if( event->type() == DialogEvent_Type )
70 DialogEvent *de = static_cast<DialogEvent*>(event);
71 switch( de->i_dialog )
73 case INTF_DIALOG_FILE:
74 case INTF_DIALOG_DISC:
76 case INTF_DIALOG_CAPTURE:
77 openDialog( de->i_dialog ); break;
78 case INTF_DIALOG_PLAYLIST:
79 playlistDialog(); break;
80 case INTF_DIALOG_MESSAGES:
81 messagesDialog(); break;
82 case INTF_DIALOG_PREFS:
84 case INTF_DIALOG_POPUPMENU:
85 case INTF_DIALOG_AUDIOPOPUPMENU:
86 case INTF_DIALOG_VIDEOPOPUPMENU:
87 case INTF_DIALOG_MISCPOPUPMENU:
88 popupMenu( de->i_dialog ); break;
89 case INTF_DIALOG_FILEINFO:
90 streaminfoDialog(); break;
91 case INTF_DIALOG_INTERACTION:
92 doInteraction( de->p_arg ); break;
94 case INTF_DIALOG_BOOKMARKS:
95 bookmarksDialog(); break;
96 case INTF_DIALOG_WIZARD:
98 msg_Warn( p_intf, "unimplemented dialog\n" );
103 void DialogsProvider::playlistDialog()
105 PlaylistDialog::getInstance( p_intf )->toggleVisible();
108 void DialogsProvider::openDialog()
112 void DialogsProvider::PLAppendDialog()
115 void DialogsProvider::MLAppendDialog()
118 void DialogsProvider::openDialog( int i_dialog )
122 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
124 InteractionDialog *qdialog;
125 interaction_dialog_t *p_dialog = p_arg->p_dialog;
126 switch( p_dialog->i_action )
129 qdialog = new InteractionDialog( p_intf, p_dialog );
130 p_dialog->p_private = (void*)qdialog;
131 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
134 case INTERACT_UPDATE:
135 qdialog = (InteractionDialog*)(p_dialog->p_private);
140 qdialog = (InteractionDialog*)(p_dialog->p_private);
143 p_dialog->i_status = HIDDEN_DIALOG;
145 case INTERACT_DESTROY:
146 qdialog = (InteractionDialog*)(p_dialog->p_private);
147 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
149 p_dialog->i_status = DESTROYED_DIALOG;
154 void DialogsProvider::quit()
156 p_intf->b_die = VLC_TRUE;
157 QApplication::quit();
160 void DialogsProvider::streaminfoDialog()
162 (new SoutDialog( p_intf ))->show();
163 StreamInfoDialog::getInstance( p_intf )->toggleVisible();
166 void DialogsProvider::streamingDialog()
170 void DialogsProvider::prefsDialog()
172 PrefsDialog::getInstance( p_intf )->toggleVisible();
174 void DialogsProvider::extendedDialog()
176 ExtendedDialog::getInstance( p_intf )->toggleVisible();
179 void DialogsProvider::messagesDialog()
181 MessagesDialog::getInstance( p_intf )->toggleVisible();
184 void DialogsProvider::menuAction( QObject *data )
186 QVLCMenu::DoAction( p_intf, data );
189 void DialogsProvider::menuUpdateAction( QObject *data )
191 MenuFunc * f = qobject_cast<MenuFunc *>(data);
195 void DialogsProvider::SDMenuAction( QString data )
197 char *psz_sd = data.toUtf8().data();
198 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
199 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
201 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
205 void DialogsProvider::simplePLAppendDialog()
207 QStringList files = showSimpleOpen();
209 foreach( file, files )
211 const char * psz_utf8 = qtu( file );
212 playlist_Add( THEPL, psz_utf8, NULL,
213 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END, VLC_TRUE );
217 void DialogsProvider::simpleMLAppendDialog()
219 QStringList files = showSimpleOpen();
221 foreach( file, files )
223 const char * psz_utf8 = qtu( file );
224 playlist_Add( THEPL, psz_utf8, psz_utf8,
225 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END,
230 void DialogsProvider::simpleOpenDialog()
232 QStringList files = showSimpleOpen();
234 for( size_t i = 0 ; i< files.size(); i++ )
236 const char * psz_utf8 = qtu( files[i] );
237 /* Play the first one, parse and enqueue the other ones */
238 playlist_Add( THEPL, psz_utf8, NULL,
239 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
240 ( i ? PLAYLIST_PREPARSE : 0 ),
241 PLAYLIST_END, VLC_TRUE );
245 void DialogsProvider::openPlaylist()
247 QStringList files = showSimpleOpen();
249 for( size_t i = 0 ; i< files.size(); i++ )
251 const char * psz_utf8 = qtu( files[i] );
252 playlist_Import( THEPL, psz_utf8 );
256 void DialogsProvider::openDirectory()
258 QString dir = QFileDialog::getExistingDirectory ( 0,
259 _("Open directory") );
260 const char *psz_utf8 = qtu( dir );
261 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
263 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE);
264 input_Read( THEPL, p_input, VLC_FALSE );
266 void DialogsProvider::openMLDirectory()
268 QString dir = QFileDialog::getExistingDirectory ( 0,
269 _("Open directory") );
270 const char *psz_utf8 = qtu( dir );
271 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
273 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END,
275 input_Read( THEPL, p_input, VLC_FALSE );
278 QStringList DialogsProvider::showSimpleOpen()
281 FileTypes = _("Media Files");
283 FileTypes += EXTENSIONS_MEDIA;
285 FileTypes += _("Video Files");
287 FileTypes += EXTENSIONS_VIDEO;
289 FileTypes += _("Sound Files");
291 FileTypes += EXTENSIONS_AUDIO;
293 FileTypes += _("PlayList Files");
295 FileTypes += EXTENSIONS_PLAYLIST;
297 FileTypes += _("All Files");
298 FileTypes += " (*.*)";
299 FileTypes.replace(QString(";*"), QString(" *"));
300 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
301 p_intf->p_libvlc->psz_homedir, FileTypes );
304 void DialogsProvider::switchToSkins()
306 var_SetString( p_intf, "intf-switch", "skins2" );
309 void DialogsProvider::bookmarksDialog()
313 void DialogsProvider::popupMenu( int i_dialog )