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::customEvent( QEvent *event )
71 if( event->type() == DialogEvent_Type )
73 DialogEvent *de = static_cast<DialogEvent*>(event);
74 switch( de->i_dialog )
76 case INTF_DIALOG_FILE:
77 case INTF_DIALOG_DISC:
79 case INTF_DIALOG_CAPTURE:
80 openDialog( de->i_dialog ); break;
81 case INTF_DIALOG_PLAYLIST:
82 playlistDialog(); break;
83 case INTF_DIALOG_MESSAGES:
84 messagesDialog(); break;
85 case INTF_DIALOG_PREFS:
87 case INTF_DIALOG_POPUPMENU:
88 case INTF_DIALOG_AUDIOPOPUPMENU:
89 case INTF_DIALOG_VIDEOPOPUPMENU:
90 case INTF_DIALOG_MISCPOPUPMENU:
91 popupMenu( de->i_dialog ); break;
92 case INTF_DIALOG_FILEINFO:
93 MediaInfoDialog(); break;
94 case INTF_DIALOG_INTERACTION:
95 doInteraction( de->p_arg ); break;
97 case INTF_DIALOG_BOOKMARKS:
98 bookmarksDialog(); break;
99 case INTF_DIALOG_WIZARD:
101 msg_Warn( p_intf, "unimplemented dialog\n" );
106 void DialogsProvider::playlistDialog()
108 PlaylistDialog::getInstance( p_intf )->toggleVisible();
111 void DialogsProvider::openDialog()
115 void DialogsProvider::PLAppendDialog()
118 void DialogsProvider::MLAppendDialog()
121 void DialogsProvider::openDialog( int i_tab )
123 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
126 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
128 InteractionDialog *qdialog;
129 interaction_dialog_t *p_dialog = p_arg->p_dialog;
130 switch( p_dialog->i_action )
133 qdialog = new InteractionDialog( p_intf, p_dialog );
134 p_dialog->p_private = (void*)qdialog;
135 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
138 case INTERACT_UPDATE:
139 qdialog = (InteractionDialog*)(p_dialog->p_private);
144 qdialog = (InteractionDialog*)(p_dialog->p_private);
147 p_dialog->i_status = HIDDEN_DIALOG;
149 case INTERACT_DESTROY:
150 qdialog = (InteractionDialog*)(p_dialog->p_private);
151 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
153 p_dialog->i_status = DESTROYED_DIALOG;
158 void DialogsProvider::quit()
160 p_intf->b_die = VLC_TRUE;
161 QApplication::quit();
164 void DialogsProvider::MediaInfoDialog()
166 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
169 void DialogsProvider::streamingDialog()
171 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
172 if ( o->exec() == QDialog::Accepted )
174 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
175 if( s->exec() == QDialog::Accepted )
177 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
179 int i_len = strlen( qtu(s->mrl) ) + 10;
180 char *psz_option = (char*)malloc(i_len);
181 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
183 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
184 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
185 -1, &psz_option, 1, VLC_TRUE );
192 void DialogsProvider::prefsDialog()
194 PrefsDialog::getInstance( p_intf )->toggleVisible();
196 void DialogsProvider::extendedDialog()
198 ExtendedDialog::getInstance( p_intf )->toggleVisible();
201 void DialogsProvider::messagesDialog()
203 MessagesDialog::getInstance( p_intf )->toggleVisible();
206 void DialogsProvider::helpDialog()
208 HelpDialog::getInstance( p_intf )->toggleVisible();
211 void DialogsProvider::aboutDialog()
213 AboutDialog::getInstance( p_intf )->toggleVisible();
216 void DialogsProvider::menuAction( QObject *data )
218 QVLCMenu::DoAction( p_intf, data );
221 void DialogsProvider::menuUpdateAction( QObject *data )
223 MenuFunc * f = qobject_cast<MenuFunc *>(data);
227 void DialogsProvider::SDMenuAction( QString data )
229 char *psz_sd = data.toUtf8().data();
230 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
231 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
233 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
237 void DialogsProvider::simplePLAppendDialog()
239 QStringList files = showSimpleOpen();
241 foreach( file, files )
243 const char * psz_utf8 = qtu( file );
244 playlist_Add( THEPL, psz_utf8, NULL,
245 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END, VLC_TRUE );
249 void DialogsProvider::simpleMLAppendDialog()
251 QStringList files = showSimpleOpen();
253 foreach( file, files )
255 const char * psz_utf8 = qtu( file );
256 playlist_Add( THEPL, psz_utf8, psz_utf8,
257 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END,
262 void DialogsProvider::simpleOpenDialog()
264 QStringList files = showSimpleOpen();
266 for( size_t i = 0 ; i< files.size(); i++ )
268 const char * psz_utf8 = qtu( files[i] );
269 /* Play the first one, parse and enqueue the other ones */
270 playlist_Add( THEPL, psz_utf8, NULL,
271 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
272 ( i ? PLAYLIST_PREPARSE : 0 ),
273 PLAYLIST_END, VLC_TRUE );
277 void DialogsProvider::openPlaylist()
279 QStringList files = showSimpleOpen();
281 for( size_t i = 0 ; i< files.size(); i++ )
283 const char * psz_utf8 = qtu( files[i] );
284 playlist_Import( THEPL, psz_utf8 );
288 void DialogsProvider::openDirectory()
290 QString dir = QFileDialog::getExistingDirectory ( 0,
291 _("Open directory") );
292 const char *psz_utf8 = qtu( dir );
293 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
295 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE);
296 input_Read( THEPL, p_input, VLC_FALSE );
298 void DialogsProvider::openMLDirectory()
300 QString dir = QFileDialog::getExistingDirectory ( 0,
301 _("Open directory") );
302 const char *psz_utf8 = qtu( dir );
303 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
305 playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END,
307 input_Read( THEPL, p_input, VLC_FALSE );
310 QStringList DialogsProvider::showSimpleOpen()
313 FileTypes = _("Media Files");
315 FileTypes += EXTENSIONS_MEDIA;
317 FileTypes += _("Video Files");
319 FileTypes += EXTENSIONS_VIDEO;
321 FileTypes += _("Sound Files");
323 FileTypes += EXTENSIONS_AUDIO;
325 FileTypes += _("PlayList Files");
327 FileTypes += EXTENSIONS_PLAYLIST;
329 FileTypes += _("All Files");
330 FileTypes += " (*.*)";
331 FileTypes.replace(QString(";*"), QString(" *"));
332 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
333 p_intf->p_libvlc->psz_homedir, FileTypes );
336 void DialogsProvider::switchToSkins()
338 var_SetString( p_intf, "intf-switch", "skins2" );
341 void DialogsProvider::bookmarksDialog()
345 void DialogsProvider::popupMenu( int i_dialog )