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/mediainfo.hpp"
37 #include "dialogs/messages.hpp"
38 #include "dialogs/extended.hpp"
39 #include "dialogs/sout.hpp"
40 #include "dialogs/open.hpp"
42 DialogsProvider* DialogsProvider::instance = NULL;
44 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
45 QObject( NULL ), p_intf( _p_intf )
47 fixed_timer = new QTimer( this );
48 fixed_timer->start( 150 /* milliseconds */ );
50 menusMapper = new QSignalMapper();
51 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
53 menusUpdateMapper = new QSignalMapper();
54 CONNECT( menusUpdateMapper, mapped(QObject *),
55 this, menuUpdateAction( QObject *) );
57 SDMapper = new QSignalMapper();
58 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
61 DialogsProvider::~DialogsProvider()
63 PlaylistDialog::killInstance();
64 MediaInfoDialog::killInstance();
67 void DialogsProvider::customEvent( QEvent *event )
69 if( event->type() == DialogEvent_Type )
71 DialogEvent *de = static_cast<DialogEvent*>(event);
72 switch( de->i_dialog )
74 case INTF_DIALOG_FILE:
75 case INTF_DIALOG_DISC:
77 case INTF_DIALOG_CAPTURE:
78 openDialog( de->i_dialog ); break;
79 case INTF_DIALOG_PLAYLIST:
80 playlistDialog(); break;
81 case INTF_DIALOG_MESSAGES:
82 messagesDialog(); break;
83 case INTF_DIALOG_PREFS:
85 case INTF_DIALOG_POPUPMENU:
86 case INTF_DIALOG_AUDIOPOPUPMENU:
87 case INTF_DIALOG_VIDEOPOPUPMENU:
88 case INTF_DIALOG_MISCPOPUPMENU:
89 popupMenu( de->i_dialog ); break;
90 case INTF_DIALOG_FILEINFO:
91 MediaInfoDialog(); break;
92 case INTF_DIALOG_INTERACTION:
93 doInteraction( de->p_arg ); break;
95 case INTF_DIALOG_BOOKMARKS:
96 bookmarksDialog(); break;
97 case INTF_DIALOG_WIZARD:
99 msg_Warn( p_intf, "unimplemented dialog\n" );
104 void DialogsProvider::playlistDialog()
106 PlaylistDialog::getInstance( p_intf )->toggleVisible();
109 void DialogsProvider::openDialog()
113 void DialogsProvider::PLAppendDialog()
116 void DialogsProvider::MLAppendDialog()
119 void DialogsProvider::openDialog( int i_dialog )
121 OpenDialog::getInstance( p_intf )->toggleVisible();
124 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
126 InteractionDialog *qdialog;
127 interaction_dialog_t *p_dialog = p_arg->p_dialog;
128 switch( p_dialog->i_action )
131 qdialog = new InteractionDialog( p_intf, p_dialog );
132 p_dialog->p_private = (void*)qdialog;
133 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
136 case INTERACT_UPDATE:
137 qdialog = (InteractionDialog*)(p_dialog->p_private);
142 qdialog = (InteractionDialog*)(p_dialog->p_private);
145 p_dialog->i_status = HIDDEN_DIALOG;
147 case INTERACT_DESTROY:
148 qdialog = (InteractionDialog*)(p_dialog->p_private);
149 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
151 p_dialog->i_status = DESTROYED_DIALOG;
156 void DialogsProvider::quit()
158 p_intf->b_die = VLC_TRUE;
159 QApplication::quit();
162 void DialogsProvider::MediaInfoDialog()
164 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
167 void DialogsProvider::streamingDialog()
169 (new SoutDialog( p_intf ))->show();
172 void DialogsProvider::prefsDialog()
174 PrefsDialog::getInstance( p_intf )->toggleVisible();
176 void DialogsProvider::extendedDialog()
178 ExtendedDialog::getInstance( p_intf )->toggleVisible();
181 void DialogsProvider::messagesDialog()
183 MessagesDialog::getInstance( p_intf )->toggleVisible();
186 void DialogsProvider::menuAction( QObject *data )
188 QVLCMenu::DoAction( p_intf, data );
191 void DialogsProvider::menuUpdateAction( QObject *data )
193 MenuFunc * f = qobject_cast<MenuFunc *>(data);
197 void DialogsProvider::SDMenuAction( QString data )
199 char *psz_sd = data.toUtf8().data();
200 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
201 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
203 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
207 void DialogsProvider::simplePLAppendDialog()
209 QStringList files = showSimpleOpen();
211 foreach( file, files )
213 const char * psz_utf8 = qtu( file );
214 playlist_Add( THEPL, psz_utf8, NULL,
215 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END, VLC_TRUE );
219 void DialogsProvider::simpleMLAppendDialog()
221 QStringList files = showSimpleOpen();
223 foreach( file, files )
225 const char * psz_utf8 = qtu( file );
226 playlist_Add( THEPL, psz_utf8, psz_utf8,
227 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END,
232 void DialogsProvider::simpleOpenDialog()
234 QStringList files = showSimpleOpen();
236 for( size_t i = 0 ; i< files.size(); i++ )
238 const char * psz_utf8 = qtu( files[i] );
239 /* Play the first one, parse and enqueue the other ones */
240 playlist_Add( THEPL, psz_utf8, NULL,
241 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
242 ( i ? PLAYLIST_PREPARSE : 0 ),
243 PLAYLIST_END, VLC_TRUE );
247 void DialogsProvider::openPlaylist()
249 QStringList files = showSimpleOpen();
251 for( size_t i = 0 ; i< files.size(); i++ )
253 const char * psz_utf8 = qtu( files[i] );
254 playlist_Import( THEPL, psz_utf8 );
258 void DialogsProvider::openDirectory()
260 QString dir = QFileDialog::getExistingDirectory ( 0,
261 _("Open directory") );
262 const char *psz_utf8 = qtu( dir );
263 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
265 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE);
266 input_Read( THEPL, p_input, VLC_FALSE );
268 void DialogsProvider::openMLDirectory()
270 QString dir = QFileDialog::getExistingDirectory ( 0,
271 _("Open directory") );
272 const char *psz_utf8 = qtu( dir );
273 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
275 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END,
277 input_Read( THEPL, p_input, VLC_FALSE );
280 QStringList DialogsProvider::showSimpleOpen()
283 FileTypes = _("Media Files");
285 FileTypes += EXTENSIONS_MEDIA;
287 FileTypes += _("Video Files");
289 FileTypes += EXTENSIONS_VIDEO;
291 FileTypes += _("Sound Files");
293 FileTypes += EXTENSIONS_AUDIO;
295 FileTypes += _("PlayList Files");
297 FileTypes += EXTENSIONS_PLAYLIST;
299 FileTypes += _("All Files");
300 FileTypes += " (*.*)";
301 FileTypes.replace(QString(";*"), QString(" *"));
302 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
303 p_intf->p_libvlc->psz_homedir, FileTypes );
306 void DialogsProvider::switchToSkins()
308 var_SetString( p_intf, "intf-switch", "skins2" );
311 void DialogsProvider::bookmarksDialog()
315 void DialogsProvider::popupMenu( int i_dialog )