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"
39 DialogsProvider* DialogsProvider::instance = NULL;
41 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
42 QObject( NULL ), p_intf( _p_intf )
44 fixed_timer = new QTimer( this );
45 fixed_timer->start( 150 /* milliseconds */ );
47 menusMapper = new QSignalMapper();
48 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
50 menusUpdateMapper = new QSignalMapper();
51 CONNECT( menusUpdateMapper, mapped(QObject *),
52 this, menuUpdateAction( QObject *) );
55 void DialogsProvider::customEvent( QEvent *event )
57 if( event->type() == DialogEvent_Type )
59 DialogEvent *de = static_cast<DialogEvent*>(event);
60 switch( de->i_dialog )
62 case INTF_DIALOG_FILE:
63 case INTF_DIALOG_DISC:
65 case INTF_DIALOG_CAPTURE:
66 openDialog( de->i_dialog ); break;
67 case INTF_DIALOG_PLAYLIST:
68 playlistDialog(); break;
69 case INTF_DIALOG_MESSAGES:
70 messagesDialog(); break;
71 case INTF_DIALOG_PREFS:
73 case INTF_DIALOG_POPUPMENU:
74 case INTF_DIALOG_AUDIOPOPUPMENU:
75 case INTF_DIALOG_VIDEOPOPUPMENU:
76 case INTF_DIALOG_MISCPOPUPMENU:
77 popupMenu( de->i_dialog ); break;
78 case INTF_DIALOG_FILEINFO:
79 streaminfoDialog(); break;
80 case INTF_DIALOG_INTERACTION:
81 doInteraction( de->p_arg ); break;
83 case INTF_DIALOG_BOOKMARKS:
84 bookmarksDialog(); break;
85 case INTF_DIALOG_WIZARD:
87 msg_Warn( p_intf, "unimplemented dialog\n" );
92 void DialogsProvider::playlistDialog()
94 PlaylistDialog::getInstance( p_intf )->toggleVisible();
97 void DialogsProvider::openDialog()
101 void DialogsProvider::PLAppendDialog()
104 void DialogsProvider::MLAppendDialog()
107 void DialogsProvider::openDialog( int i_dialog )
111 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
113 InteractionDialog *qdialog;
114 interaction_dialog_t *p_dialog = p_arg->p_dialog;
115 switch( p_dialog->i_action )
118 qdialog = new InteractionDialog( p_intf, p_dialog );
119 p_dialog->p_private = (void*)qdialog;
120 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
123 case INTERACT_UPDATE:
124 qdialog = (InteractionDialog*)(p_dialog->p_private);
129 qdialog = (InteractionDialog*)(p_dialog->p_private);
132 p_dialog->i_status = HIDDEN_DIALOG;
134 case INTERACT_DESTROY:
135 qdialog = (InteractionDialog*)(p_dialog->p_private);
137 p_dialog->i_status = DESTROYED_DIALOG;
142 void DialogsProvider::quit()
144 p_intf->b_die = VLC_TRUE;
145 QApplication::quit();
148 void DialogsProvider::streaminfoDialog()
150 StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
153 void DialogsProvider::streamingDialog()
157 void DialogsProvider::prefsDialog()
159 PrefsDialog::getInstance( p_intf )->toggleVisible();
162 void DialogsProvider::messagesDialog()
164 MessagesDialog::getInstance( p_intf )->toggleVisible();
167 void DialogsProvider::menuAction( QObject *data )
169 QVLCMenu::DoAction( p_intf, data );
172 void DialogsProvider::menuUpdateAction( QObject *data )
174 MenuFunc * f = qobject_cast<MenuFunc *>(data);
178 void DialogsProvider::simplePLAppendDialog()
180 QStringList files = showSimpleOpen();
182 foreach( file, files )
184 const char * psz_utf8 = qtu( file );
185 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
186 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
190 void DialogsProvider::simpleMLAppendDialog()
192 QStringList files = showSimpleOpen();
194 foreach( file, files )
196 const char * psz_utf8 = qtu( file );
197 playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
198 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
202 void DialogsProvider::simpleOpenDialog()
204 QStringList files = showSimpleOpen();
206 for( size_t i = 0 ; i< files.size(); i++ )
208 const char * psz_utf8 = qtu( files[i] );
209 /* Play the first one, parse and enqueue the other ones */
210 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
211 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
212 ( i ? PLAYLIST_PREPARSE : 0 ),
217 void DialogsProvider::openPlaylist()
219 QStringList files = showSimpleOpen();
221 for( size_t i = 0 ; i< files.size(); i++ )
223 const char * psz_utf8 = qtu( files[i] );
224 /* Play the first one, parse and enqueue the other ones */
225 playlist_Import( THEPL, psz_utf8, THEPL->p_root_category, VLC_FALSE );
229 void DialogsProvider::openDirectory()
231 QString dir = QFileDialog::getExistingDirectory ( 0,
232 _("Open directory") );
233 const char *psz_utf8 = qtu( dir );
234 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
236 playlist_PlaylistAddInput( THEPL, p_input,
237 PLAYLIST_APPEND, PLAYLIST_END );
238 input_Read( THEPL, p_input, VLC_FALSE );
240 void DialogsProvider::openMLDirectory()
242 QString dir = QFileDialog::getExistingDirectory ( 0,
243 _("Open directory") );
244 const char *psz_utf8 = qtu( dir );
245 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
247 playlist_MLAddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END );
248 input_Read( THEPL, p_input, VLC_FALSE );
251 QStringList DialogsProvider::showSimpleOpen()
254 FileTypes = "Video Files ( ";
255 FileTypes += EXTENSIONS_VIDEO;
256 FileTypes += ");; Sound Files ( ";
257 FileTypes += EXTENSIONS_AUDIO;
258 FileTypes += ");; PlayList Files ( ";
259 FileTypes += EXTENSIONS_PLAYLIST;
260 FileTypes += ");; All Files (*.*)" ;
261 FileTypes.replace(QString(";*"), QString(" *"));
262 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
263 p_intf->p_vlc->psz_homedir, FileTypes );
266 void DialogsProvider::bookmarksDialog()
270 void DialogsProvider::popupMenu( int i_dialog )