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"
30 #include "main_interface.hpp"
32 #include <vlc_intf_strings.h>
35 #include "dialogs/playlist.hpp"
36 #include "dialogs/prefs_dialog.hpp"
37 #include "dialogs/mediainfo.hpp"
38 #include "dialogs/messages.hpp"
39 #include "dialogs/extended.hpp"
40 #include "dialogs/sout.hpp"
41 #include "dialogs/open.hpp"
42 #include "dialogs/help.hpp"
44 DialogsProvider* DialogsProvider::instance = NULL;
46 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
47 QObject( NULL ), p_intf( _p_intf )
49 fixed_timer = new QTimer( this );
50 fixed_timer->start( 150 /* milliseconds */ );
52 menusMapper = new QSignalMapper();
53 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
55 menusUpdateMapper = new QSignalMapper();
56 CONNECT( menusUpdateMapper, mapped(QObject *),
57 this, menuUpdateAction( QObject *) );
59 SDMapper = new QSignalMapper();
60 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
63 DialogsProvider::~DialogsProvider()
65 PlaylistDialog::killInstance();
66 MediaInfoDialog::killInstance();
69 void DialogsProvider::quit()
71 p_intf->b_die = VLC_TRUE;
75 void DialogsProvider::customEvent( QEvent *event )
77 if( event->type() == DialogEvent_Type )
79 DialogEvent *de = static_cast<DialogEvent*>(event);
80 switch( de->i_dialog )
82 case INTF_DIALOG_FILE:
84 case INTF_DIALOG_DISC:
85 openDiscDialog(); break;
87 openNetDialog(); break;
88 case INTF_DIALOG_CAPTURE:
89 openCaptureDialog(); break;
90 case INTF_DIALOG_PLAYLIST:
91 playlistDialog(); break;
92 case INTF_DIALOG_MESSAGES:
93 messagesDialog(); break;
94 case INTF_DIALOG_PREFS:
96 case INTF_DIALOG_POPUPMENU:
97 case INTF_DIALOG_AUDIOPOPUPMENU:
98 case INTF_DIALOG_VIDEOPOPUPMENU:
99 case INTF_DIALOG_MISCPOPUPMENU:
100 popupMenu( de->i_dialog ); break;
101 case INTF_DIALOG_FILEINFO:
102 mediaInfoDialog(); break;
103 case INTF_DIALOG_INTERACTION:
104 doInteraction( de->p_arg ); break;
105 case INTF_DIALOG_BOOKMARKS:
106 bookmarksDialog(); break;
107 case INTF_DIALOG_VLM:
108 case INTF_DIALOG_WIZARD:
110 msg_Warn( p_intf, "unimplemented dialog\n" );
115 /****************************************************************************
116 * Individual simple dialogs
117 ****************************************************************************/
118 void DialogsProvider::playlistDialog()
120 PlaylistDialog::getInstance( p_intf )->toggleVisible();
123 void DialogsProvider::prefsDialog()
125 PrefsDialog::getInstance( p_intf )->toggleVisible();
127 void DialogsProvider::extendedDialog()
129 ExtendedDialog::getInstance( p_intf )->toggleVisible();
132 void DialogsProvider::messagesDialog()
134 MessagesDialog::getInstance( p_intf )->toggleVisible();
137 void DialogsProvider::helpDialog()
139 HelpDialog::getInstance( p_intf )->toggleVisible();
142 void DialogsProvider::aboutDialog()
144 AboutDialog::getInstance( p_intf )->toggleVisible();
147 void DialogsProvider::mediaInfoDialog()
149 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
152 void DialogsProvider::mediaCodecDialog()
154 MediaInfoDialog::getInstance( p_intf )->showTab( 1 );
157 void DialogsProvider::bookmarksDialog()
161 /****************************************************************************
162 * All the open/add stuff
163 ****************************************************************************/
165 void DialogsProvider::openDialog()
169 void DialogsProvider::openFileDialog()
173 void DialogsProvider::openDiscDialog()
177 void DialogsProvider::openNetDialog()
181 void DialogsProvider::openCaptureDialog()
185 void DialogsProvider::openDialog( int i_tab )
187 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
190 void DialogsProvider::PLAppendDialog()
193 void DialogsProvider::MLAppendDialog()
197 /**** Simple open ****/
199 QStringList DialogsProvider::showSimpleOpen(QString help, bool all,
200 bool audio, bool video,
203 QString fileTypes = "";
205 ADD_FILTER_MEDIA( fileTypes );
208 ADD_FILTER_VIDEO( fileTypes );
211 ADD_FILTER_AUDIO( fileTypes );
214 ADD_FILTER_PLAYLIST( fileTypes );
217 ADD_FILTER_SUBTITLE( fileTypes );
219 ADD_FILTER_ALL( fileTypes );
220 fileTypes.replace(QString(";*"), QString(" *"));
221 return QFileDialog::getOpenFileNames( NULL,
223 qfu(I_OP_SEL_FILES ) : help,
224 qfu( p_intf->p_libvlc->psz_homedir ),
228 void DialogsProvider::addFromSimple( bool pl, bool go)
230 QStringList files = DialogsProvider::showSimpleOpen();
232 foreach( QString file, files )
234 const char * psz_utf8 = qtu( file );
235 playlist_Add( THEPL, psz_utf8, NULL,
236 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
237 ( i ? PLAYLIST_PREPARSE : 0 ) )
238 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
240 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
245 void DialogsProvider::simplePLAppendDialog()
247 addFromSimple( true, false );
250 void DialogsProvider::simpleMLAppendDialog()
252 addFromSimple( false, false );
255 void DialogsProvider::simpleOpenDialog()
257 addFromSimple( true, true );
260 void DialogsProvider::openPlaylist()
262 QStringList files = showSimpleOpen( qtr( "Open playlist file" ), false,
263 false, false, false );
264 foreach( QString file, files )
266 playlist_Import( THEPL, qtu(file) );
270 void DialogsProvider::savePlaylist()
272 QFileDialog *qfd = new QFileDialog( NULL,
273 qtr("Choose a filename to save playlist"),
274 qfu( p_intf->p_libvlc->psz_homedir ),
275 qtr("XSPF playlist (*.xspf);; ") +
276 qtr("M3U playlist (*.m3u);; Any (*.*) ") );
277 qfd->setFileMode( QFileDialog::AnyFile );
278 qfd->setAcceptMode( QFileDialog::AcceptSave );
279 qfd->setConfirmOverwrite( true );
281 if( qfd->exec() == QDialog::Accepted )
283 if( qfd->selectedFiles().count() > 0 )
285 char *psz_module, *psz_m3u = "export-m3u",
286 *psz_xspf = "export-xspf";
288 QString file = qfd->selectedFiles().first();
289 QString filter = qfd->selectedFilter();
291 if( file.contains(".xsp") ||
292 ( filter.contains(".xspf") && !file.contains(".m3u") ) )
294 psz_module = psz_xspf;
295 if( !file.contains( ".xsp" ) )
296 file.append( ".xspf" );
300 psz_module = psz_m3u;
301 if( !file.contains( ".m3u" ) )
302 file.append( ".m3u" );
305 playlist_Export( THEPL, qtu(file), THEPL->p_local_category,
312 static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
314 QString dir = QFileDialog::getExistingDirectory ( 0,
315 _("Open directory") );
316 input_item_t *p_input = input_ItemNewExt( THEPL, qtu(dir), NULL,
318 playlist_AddInput( THEPL, p_input,
319 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
320 PLAYLIST_END, pl, VLC_FALSE );
321 input_Read( THEPL, p_input, VLC_FALSE );
324 void DialogsProvider::PLAppendDir()
326 openDirectory( p_intf, true, false );
329 void DialogsProvider::MLAppendDir()
331 openDirectory( p_intf, false , false );
335 /****************************************************************************
337 ****************************************************************************/
339 void DialogsProvider::streamingDialog()
341 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
342 if ( o->exec() == QDialog::Accepted )
344 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
345 if( s->exec() == QDialog::Accepted )
347 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
349 int i_len = strlen( qtu(s->mrl) ) + 10;
350 char *psz_option = (char*)malloc(i_len);
351 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
353 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
354 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
355 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
362 /****************************************************************************
363 * Menus / Interaction
364 ****************************************************************************/
366 void DialogsProvider::menuAction( QObject *data )
368 QVLCMenu::DoAction( p_intf, data );
371 void DialogsProvider::menuUpdateAction( QObject *data )
373 MenuFunc * f = qobject_cast<MenuFunc *>(data);
377 void DialogsProvider::SDMenuAction( QString data )
379 char *psz_sd = strdup( qtu( data ) );
380 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
381 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
383 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
389 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
391 InteractionDialog *qdialog;
392 interaction_dialog_t *p_dialog = p_arg->p_dialog;
393 switch( p_dialog->i_action )
396 qdialog = new InteractionDialog( p_intf, p_dialog );
397 p_dialog->p_private = (void*)qdialog;
398 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
401 case INTERACT_UPDATE:
402 qdialog = (InteractionDialog*)(p_dialog->p_private);
407 qdialog = (InteractionDialog*)(p_dialog->p_private);
410 p_dialog->i_status = HIDDEN_DIALOG;
412 case INTERACT_DESTROY:
413 qdialog = (InteractionDialog*)(p_dialog->p_private);
414 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
416 p_dialog->i_status = DESTROYED_DIALOG;
421 void DialogsProvider::switchToSkins()
423 var_SetString( p_intf, "intf-switch", "skins2" );
426 void DialogsProvider::popupMenu( int i_dialog )