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"
41 #include "dialogs/help.hpp"
43 DialogsProvider* DialogsProvider::instance = NULL;
45 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
46 QObject( NULL ), p_intf( _p_intf )
48 fixed_timer = new QTimer( this );
49 fixed_timer->start( 150 /* milliseconds */ );
51 menusMapper = new QSignalMapper();
52 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
54 menusUpdateMapper = new QSignalMapper();
55 CONNECT( menusUpdateMapper, mapped(QObject *),
56 this, menuUpdateAction( QObject *) );
58 SDMapper = new QSignalMapper();
59 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
62 DialogsProvider::~DialogsProvider()
64 PlaylistDialog::killInstance();
65 MediaInfoDialog::killInstance();
68 void DialogsProvider::customEvent( QEvent *event )
70 if( event->type() == DialogEvent_Type )
72 DialogEvent *de = static_cast<DialogEvent*>(event);
73 switch( de->i_dialog )
75 case INTF_DIALOG_FILE:
76 case INTF_DIALOG_DISC:
78 case INTF_DIALOG_CAPTURE:
79 openDialog( de->i_dialog ); break;
80 case INTF_DIALOG_PLAYLIST:
81 playlistDialog(); break;
82 case INTF_DIALOG_MESSAGES:
83 messagesDialog(); break;
84 case INTF_DIALOG_PREFS:
86 case INTF_DIALOG_POPUPMENU:
87 case INTF_DIALOG_AUDIOPOPUPMENU:
88 case INTF_DIALOG_VIDEOPOPUPMENU:
89 case INTF_DIALOG_MISCPOPUPMENU:
90 popupMenu( de->i_dialog ); break;
91 case INTF_DIALOG_FILEINFO:
92 MediaInfoDialog(); break;
93 case INTF_DIALOG_INTERACTION:
94 doInteraction( de->p_arg ); break;
96 case INTF_DIALOG_BOOKMARKS:
97 bookmarksDialog(); break;
98 case INTF_DIALOG_WIZARD:
100 msg_Warn( p_intf, "unimplemented dialog\n" );
105 void DialogsProvider::playlistDialog()
107 PlaylistDialog::getInstance( p_intf )->toggleVisible();
110 void DialogsProvider::openDialog()
114 void DialogsProvider::PLAppendDialog()
117 void DialogsProvider::MLAppendDialog()
120 void DialogsProvider::openDialog( int i_tab )
122 OpenDialog::getInstance( p_intf )->showTab( i_tab );
125 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
127 InteractionDialog *qdialog;
128 interaction_dialog_t *p_dialog = p_arg->p_dialog;
129 switch( p_dialog->i_action )
132 qdialog = new InteractionDialog( p_intf, p_dialog );
133 p_dialog->p_private = (void*)qdialog;
134 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
137 case INTERACT_UPDATE:
138 qdialog = (InteractionDialog*)(p_dialog->p_private);
143 qdialog = (InteractionDialog*)(p_dialog->p_private);
146 p_dialog->i_status = HIDDEN_DIALOG;
148 case INTERACT_DESTROY:
149 qdialog = (InteractionDialog*)(p_dialog->p_private);
150 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
152 p_dialog->i_status = DESTROYED_DIALOG;
157 void DialogsProvider::quit()
159 p_intf->b_die = VLC_TRUE;
160 QApplication::quit();
163 void DialogsProvider::MediaInfoDialog()
165 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
168 void DialogsProvider::streamingDialog()
170 (new SoutDialog( p_intf ))->show();
173 void DialogsProvider::prefsDialog()
175 PrefsDialog::getInstance( p_intf )->toggleVisible();
177 void DialogsProvider::extendedDialog()
179 ExtendedDialog::getInstance( p_intf )->toggleVisible();
182 void DialogsProvider::messagesDialog()
184 MessagesDialog::getInstance( p_intf )->toggleVisible();
187 void DialogsProvider::helpDialog()
189 HelpDialog::getInstance( p_intf )->toggleVisible();
192 void DialogsProvider::aboutDialog()
194 AboutDialog::getInstance( p_intf )->toggleVisible();
197 void DialogsProvider::menuAction( QObject *data )
199 QVLCMenu::DoAction( p_intf, data );
202 void DialogsProvider::menuUpdateAction( QObject *data )
204 MenuFunc * f = qobject_cast<MenuFunc *>(data);
208 void DialogsProvider::SDMenuAction( QString data )
210 char *psz_sd = data.toUtf8().data();
211 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
212 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
214 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
218 void DialogsProvider::simplePLAppendDialog()
220 QStringList files = showSimpleOpen();
222 foreach( file, files )
224 const char * psz_utf8 = qtu( file );
225 playlist_Add( THEPL, psz_utf8, NULL,
226 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END, VLC_TRUE );
230 void DialogsProvider::simpleMLAppendDialog()
232 QStringList files = showSimpleOpen();
234 foreach( file, files )
236 const char * psz_utf8 = qtu( file );
237 playlist_Add( THEPL, psz_utf8, psz_utf8,
238 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END,
243 void DialogsProvider::simpleOpenDialog()
245 QStringList files = showSimpleOpen();
247 for( size_t i = 0 ; i< files.size(); i++ )
249 const char * psz_utf8 = qtu( files[i] );
250 /* Play the first one, parse and enqueue the other ones */
251 playlist_Add( THEPL, psz_utf8, NULL,
252 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
253 ( i ? PLAYLIST_PREPARSE : 0 ),
254 PLAYLIST_END, VLC_TRUE );
258 void DialogsProvider::openPlaylist()
260 QStringList files = showSimpleOpen();
262 for( size_t i = 0 ; i< files.size(); i++ )
264 const char * psz_utf8 = qtu( files[i] );
265 playlist_Import( THEPL, psz_utf8 );
269 void DialogsProvider::openDirectory()
271 QString dir = QFileDialog::getExistingDirectory ( 0,
272 _("Open directory") );
273 const char *psz_utf8 = qtu( dir );
274 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
276 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE);
277 input_Read( THEPL, p_input, VLC_FALSE );
279 void DialogsProvider::openMLDirectory()
281 QString dir = QFileDialog::getExistingDirectory ( 0,
282 _("Open directory") );
283 const char *psz_utf8 = qtu( dir );
284 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
286 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END,
288 input_Read( THEPL, p_input, VLC_FALSE );
291 QStringList DialogsProvider::showSimpleOpen()
294 FileTypes = _("Media Files");
296 FileTypes += EXTENSIONS_MEDIA;
298 FileTypes += _("Video Files");
300 FileTypes += EXTENSIONS_VIDEO;
302 FileTypes += _("Sound Files");
304 FileTypes += EXTENSIONS_AUDIO;
306 FileTypes += _("PlayList Files");
308 FileTypes += EXTENSIONS_PLAYLIST;
310 FileTypes += _("All Files");
311 FileTypes += " (*.*)";
312 FileTypes.replace(QString(";*"), QString(" *"));
313 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
314 p_intf->p_libvlc->psz_homedir, FileTypes );
317 void DialogsProvider::switchToSkins()
319 var_SetString( p_intf, "intf-switch", "skins2" );
322 void DialogsProvider::bookmarksDialog()
326 void DialogsProvider::popupMenu( int i_dialog )