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. *****************************************************************************/
25 #include "dialogs_provider.hpp"
26 #include "dialogs/playlist.hpp"
27 #include "dialogs/prefs_dialog.hpp"
28 #include "dialogs/streaminfo.hpp"
29 #include "dialogs/messages.hpp"
30 #include <QApplication>
31 #include <QSignalMapper>
33 #include <vlc_intf_strings.h>
34 #include <QFileDialog>
36 DialogsProvider* DialogsProvider::instance = NULL;
38 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
39 QObject( NULL ), p_intf( _p_intf )
41 // idle_timer = new QTimer( this );
42 // idle_timer->start( 0 );
44 fixed_timer = new QTimer( this );
45 fixed_timer->start( 150 /* milliseconds */ );
47 menusMapper = new QSignalMapper();
48 connect( menusMapper, SIGNAL( mapped(QObject *) ), this,
49 SLOT(menuAction( QObject *)) );
51 menusUpdateMapper = new QSignalMapper();
52 connect( menusUpdateMapper, SIGNAL( mapped(QObject *) ), this,
53 SLOT(menuUpdateAction( QObject *)) );
56 DialogsProvider::~DialogsProvider()
59 void DialogsProvider::customEvent( QEvent *event )
61 if( event->type() == DialogEvent_Type )
63 DialogEvent *de = static_cast<DialogEvent*>(event);
64 switch( de->i_dialog )
66 case INTF_DIALOG_FILE:
67 case INTF_DIALOG_DISC:
69 case INTF_DIALOG_CAPTURE:
70 openDialog( de->i_dialog ); break;
71 case INTF_DIALOG_PLAYLIST:
72 playlistDialog(); break;
73 case INTF_DIALOG_MESSAGES:
74 messagesDialog(); break;
75 case INTF_DIALOG_PREFS:
77 case INTF_DIALOG_POPUPMENU:
78 case INTF_DIALOG_AUDIOPOPUPMENU:
79 case INTF_DIALOG_VIDEOPOPUPMENU:
80 case INTF_DIALOG_MISCPOPUPMENU:
81 popupMenu( de->i_dialog ); break;
82 case INTF_DIALOG_FILEINFO:
83 streaminfoDialog(); break;
84 case INTF_DIALOG_INTERACTION:
85 doInteraction( de->p_arg ); break;
87 case INTF_DIALOG_BOOKMARKS:
88 bookmarksDialog(); break;
89 case INTF_DIALOG_WIZARD:
91 msg_Warn( p_intf, "unimplemented dialog\n" );
96 void DialogsProvider::playlistDialog()
98 PlaylistDialog::getInstance( p_intf )->toggleVisible();
101 void DialogsProvider::openDialog()
105 void DialogsProvider::PLAppendDialog()
108 void DialogsProvider::MLAppendDialog()
111 void DialogsProvider::openDialog( int i_dialog )
115 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
117 InteractionDialog *qdialog;
118 interaction_dialog_t *p_dialog = p_arg->p_dialog;
119 switch( p_dialog->i_action )
122 qdialog = new InteractionDialog( p_intf, p_dialog );
123 p_dialog->p_private = (void*)qdialog;
124 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
127 case INTERACT_UPDATE:
128 qdialog = (InteractionDialog*)(p_dialog->p_private);
133 qdialog = (InteractionDialog*)(p_dialog->p_private);
136 p_dialog->i_status = HIDDEN_DIALOG;
138 case INTERACT_DESTROY:
139 qdialog = (InteractionDialog*)(p_dialog->p_private);
141 p_dialog->i_status = DESTROYED_DIALOG;
146 void DialogsProvider::quit()
148 p_intf->b_die = VLC_TRUE;
149 QApplication::quit();
152 void DialogsProvider::streaminfoDialog()
154 StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
157 void DialogsProvider::streamingDialog()
161 void DialogsProvider::prefsDialog()
163 PrefsDialog::getInstance( p_intf )->toggleVisible();
166 void DialogsProvider::messagesDialog()
168 MessagesDialog::getInstance( p_intf )->toggleVisible();
171 void DialogsProvider::menuAction( QObject *data )
173 QVLCMenu::DoAction( p_intf, data );
176 void DialogsProvider::menuUpdateAction( QObject *data )
178 MenuFunc * f = qobject_cast<MenuFunc *>(data);
182 void DialogsProvider::simplePLAppendDialog()
184 QStringList files = showSimpleOpen();
186 foreach( file, files )
188 const char * psz_utf8 = file.toUtf8().data();
189 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
190 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
194 void DialogsProvider::simpleMLAppendDialog()
196 QStringList files = showSimpleOpen();
198 foreach( file, files )
200 const char * psz_utf8 = file.toUtf8().data();
201 playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
202 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
206 void DialogsProvider::simpleOpenDialog()
208 QStringList files = showSimpleOpen();
210 for( size_t i = 0 ; i< files.size(); i++ )
212 const char * psz_utf8 = files[i].toUtf8().data();
213 /* Play the first one, parse and enqueue the other ones */
214 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
215 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
216 ( i ? PLAYLIST_PREPARSE : 0 ),
221 QStringList DialogsProvider::showSimpleOpen()
224 FileTypes = "Video Files ( ";
225 FileTypes += EXTENSIONS_VIDEO;
226 FileTypes += ");; Sound Files ( ";
227 FileTypes += EXTENSIONS_AUDIO;
228 FileTypes += ");; PlayList Files ( ";
229 FileTypes += EXTENSIONS_PLAYLIST;
230 FileTypes += ");; All Files (*.*)" ;
231 FileTypes.replace(QString(";*"), QString(" *"));
232 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
233 p_intf->p_vlc->psz_homedir, FileTypes );
236 void DialogsProvider::bookmarksDialog()
240 void DialogsProvider::popupMenu( int i_dialog )