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"
40 DialogsProvider* DialogsProvider::instance = NULL;
42 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
43 QObject( NULL ), p_intf( _p_intf )
45 fixed_timer = new QTimer( this );
46 fixed_timer->start( 150 /* milliseconds */ );
48 menusMapper = new QSignalMapper();
49 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
51 menusUpdateMapper = new QSignalMapper();
52 CONNECT( menusUpdateMapper, mapped(QObject *),
53 this, menuUpdateAction( QObject *) );
55 SDMapper = new QSignalMapper();
56 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
59 DialogsProvider::~DialogsProvider()
61 PlaylistDialog::killInstance();
62 StreamInfoDialog::killInstance();
65 void DialogsProvider::customEvent( QEvent *event )
67 if( event->type() == DialogEvent_Type )
69 DialogEvent *de = static_cast<DialogEvent*>(event);
70 switch( de->i_dialog )
72 case INTF_DIALOG_FILE:
73 case INTF_DIALOG_DISC:
75 case INTF_DIALOG_CAPTURE:
76 openDialog( de->i_dialog ); break;
77 case INTF_DIALOG_PLAYLIST:
78 playlistDialog(); break;
79 case INTF_DIALOG_MESSAGES:
80 messagesDialog(); break;
81 case INTF_DIALOG_PREFS:
83 case INTF_DIALOG_POPUPMENU:
84 case INTF_DIALOG_AUDIOPOPUPMENU:
85 case INTF_DIALOG_VIDEOPOPUPMENU:
86 case INTF_DIALOG_MISCPOPUPMENU:
87 popupMenu( de->i_dialog ); break;
88 case INTF_DIALOG_FILEINFO:
89 streaminfoDialog(); break;
90 case INTF_DIALOG_INTERACTION:
91 doInteraction( de->p_arg ); break;
93 case INTF_DIALOG_BOOKMARKS:
94 bookmarksDialog(); break;
95 case INTF_DIALOG_WIZARD:
97 msg_Warn( p_intf, "unimplemented dialog\n" );
102 void DialogsProvider::playlistDialog()
104 PlaylistDialog::getInstance( p_intf )->toggleVisible();
107 void DialogsProvider::openDialog()
111 void DialogsProvider::PLAppendDialog()
114 void DialogsProvider::MLAppendDialog()
117 void DialogsProvider::openDialog( int i_dialog )
121 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
123 InteractionDialog *qdialog;
124 interaction_dialog_t *p_dialog = p_arg->p_dialog;
125 switch( p_dialog->i_action )
128 qdialog = new InteractionDialog( p_intf, p_dialog );
129 p_dialog->p_private = (void*)qdialog;
130 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
133 case INTERACT_UPDATE:
134 qdialog = (InteractionDialog*)(p_dialog->p_private);
139 qdialog = (InteractionDialog*)(p_dialog->p_private);
142 p_dialog->i_status = HIDDEN_DIALOG;
144 case INTERACT_DESTROY:
145 qdialog = (InteractionDialog*)(p_dialog->p_private);
146 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
148 p_dialog->i_status = DESTROYED_DIALOG;
153 void DialogsProvider::quit()
155 p_intf->b_die = VLC_TRUE;
156 QApplication::quit();
159 void DialogsProvider::streaminfoDialog()
161 StreamInfoDialog::getInstance( p_intf )->toggleVisible();
164 void DialogsProvider::streamingDialog()
168 void DialogsProvider::prefsDialog()
170 PrefsDialog::getInstance( p_intf )->toggleVisible();
172 void DialogsProvider::extendedDialog()
174 ExtendedDialog::getInstance( p_intf )->toggleVisible();
177 void DialogsProvider::messagesDialog()
179 MessagesDialog::getInstance( p_intf )->toggleVisible();
182 void DialogsProvider::menuAction( QObject *data )
184 QVLCMenu::DoAction( p_intf, data );
187 void DialogsProvider::menuUpdateAction( QObject *data )
189 MenuFunc * f = qobject_cast<MenuFunc *>(data);
193 void DialogsProvider::SDMenuAction( QString data )
195 char *psz_sd = data.toUtf8().data();
196 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
197 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
199 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
203 void DialogsProvider::simplePLAppendDialog()
205 QStringList files = showSimpleOpen();
207 foreach( file, files )
209 const char * psz_utf8 = qtu( file );
210 playlist_PlaylistAdd( THEPL, psz_utf8, NULL,
211 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
215 void DialogsProvider::simpleMLAppendDialog()
217 QStringList files = showSimpleOpen();
219 foreach( file, files )
221 const char * psz_utf8 = qtu( file );
222 playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
223 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
227 void DialogsProvider::simpleOpenDialog()
229 QStringList files = showSimpleOpen();
231 for( size_t i = 0 ; i< files.size(); i++ )
233 const char * psz_utf8 = qtu( files[i] );
234 /* Play the first one, parse and enqueue the other ones */
235 playlist_PlaylistAdd( THEPL, psz_utf8, NULL,
236 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
237 ( i ? PLAYLIST_PREPARSE : 0 ),
242 void DialogsProvider::openPlaylist()
244 QStringList files = showSimpleOpen();
246 for( size_t i = 0 ; i< files.size(); i++ )
248 const char * psz_utf8 = qtu( files[i] );
249 /* Play the first one, parse and enqueue the other ones */
250 playlist_Import( THEPL, psz_utf8, THEPL->p_root_category, VLC_FALSE );
254 void DialogsProvider::openDirectory()
256 QString dir = QFileDialog::getExistingDirectory ( 0,
257 _("Open directory") );
258 const char *psz_utf8 = qtu( dir );
259 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
261 playlist_PlaylistAddInput( THEPL, p_input,
262 PLAYLIST_APPEND, PLAYLIST_END );
263 input_Read( THEPL, p_input, VLC_FALSE );
265 void DialogsProvider::openMLDirectory()
267 QString dir = QFileDialog::getExistingDirectory ( 0,
268 _("Open directory") );
269 const char *psz_utf8 = qtu( dir );
270 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
272 playlist_MLAddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END );
273 input_Read( THEPL, p_input, VLC_FALSE );
276 QStringList DialogsProvider::showSimpleOpen()
279 FileTypes = _("Media Files");
281 FileTypes += EXTENSIONS_MEDIA;
283 FileTypes += _("Video Files");
285 FileTypes += EXTENSIONS_VIDEO;
287 FileTypes += _("Sound Files");
289 FileTypes += EXTENSIONS_AUDIO;
291 FileTypes += _("PlayList Files");
293 FileTypes += EXTENSIONS_PLAYLIST;
295 FileTypes += _("All Files");
296 FileTypes += " (*.*)";
297 FileTypes.replace(QString(";*"), QString(" *"));
298 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
299 p_intf->p_libvlc->psz_homedir, FileTypes );
302 void DialogsProvider::switchToSkins()
304 var_SetString( p_intf, "intf-switch", "skins2" );
307 void DialogsProvider::bookmarksDialog()
311 void DialogsProvider::popupMenu( int i_dialog )