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>
34 DialogsProvider* DialogsProvider::instance = NULL;
36 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
37 QObject( NULL ), p_intf( _p_intf )
39 // idle_timer = new QTimer( this );
40 // idle_timer->start( 0 );
42 fixed_timer = new QTimer( this );
43 fixed_timer->start( 150 /* milliseconds */ );
45 menusMapper = new QSignalMapper();
46 connect( menusMapper, SIGNAL( mapped(QObject *) ), this,
47 SLOT(menuAction( QObject *)) );
49 menusUpdateMapper = new QSignalMapper();
50 connect( menusUpdateMapper, SIGNAL( mapped(QObject *) ), this,
51 SLOT(menuUpdateAction( QObject *)) );
54 DialogsProvider::~DialogsProvider()
57 void DialogsProvider::customEvent( QEvent *event )
59 if( event->type() == DialogEvent_Type )
61 DialogEvent *de = static_cast<DialogEvent*>(event);
62 switch( de->i_dialog )
64 case INTF_DIALOG_FILE:
65 case INTF_DIALOG_DISC:
67 case INTF_DIALOG_CAPTURE:
68 openDialog( de->i_dialog ); break;
69 case INTF_DIALOG_PLAYLIST:
70 playlistDialog(); break;
71 case INTF_DIALOG_MESSAGES:
72 messagesDialog(); break;
73 case INTF_DIALOG_PREFS:
75 case INTF_DIALOG_POPUPMENU:
76 case INTF_DIALOG_AUDIOPOPUPMENU:
77 case INTF_DIALOG_VIDEOPOPUPMENU:
78 case INTF_DIALOG_MISCPOPUPMENU:
79 popupMenu( de->i_dialog ); break;
80 case INTF_DIALOG_FILEINFO:
81 streaminfoDialog(); break;
82 case INTF_DIALOG_INTERACTION:
83 doInteraction( de->p_arg ); break;
85 case INTF_DIALOG_BOOKMARKS:
86 bookmarksDialog(); break;
87 case INTF_DIALOG_WIZARD:
89 msg_Warn( p_intf, "unimplemented dialog\n" );
94 void DialogsProvider::playlistDialog()
96 PlaylistDialog::getInstance( p_intf )->toggleVisible();
99 void DialogsProvider::openDialog()
103 void DialogsProvider::openDialog( int i_dialog )
107 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
109 InteractionDialog *qdialog;
110 interaction_dialog_t *p_dialog = p_arg->p_dialog;
111 switch( p_dialog->i_action )
114 qdialog = new InteractionDialog( p_intf, p_dialog );
115 p_dialog->p_private = (void*)qdialog;
118 case INTERACT_UPDATE:
119 qdialog = (InteractionDialog*)(p_dialog->p_private);
124 qdialog = (InteractionDialog*)(p_dialog->p_private);
127 p_dialog->i_status = HIDDEN_DIALOG;
129 case INTERACT_DESTROY:
130 qdialog = (InteractionDialog*)(p_dialog->p_private);
132 p_dialog->i_status = DESTROYED_DIALOG;
137 void DialogsProvider::quit()
139 p_intf->b_die = VLC_TRUE;
140 QApplication::quit();
143 void DialogsProvider::streaminfoDialog()
145 StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
148 void DialogsProvider::streamingDialog()
152 void DialogsProvider::prefsDialog()
154 PrefsDialog::getInstance( p_intf )->toggleVisible();
157 void DialogsProvider::messagesDialog()
159 MessagesDialog::getInstance( p_intf, true )->toggleVisible();
162 void DialogsProvider::menuAction( QObject *data )
164 QVLCMenu::DoAction( p_intf, data );
167 void DialogsProvider::menuUpdateAction( QObject *data )
169 MenuFunc * f = qobject_cast<MenuFunc *>(data);
173 void DialogsProvider::simpleAppendDialog()
178 void DialogsProvider::simpleOpenDialog()
180 playlist_t *p_playlist =
181 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
183 if( p_playlist == NULL )
189 FileTypes = "Video Files ( ";
190 FileTypes += EXTENSIONS_VIDEO;
191 FileTypes += ");; Sound Files ( ";
192 FileTypes += EXTENSIONS_AUDIO;
193 FileTypes += ");; PlayList Files ( ";
194 FileTypes += EXTENSIONS_PLAYLIST;
195 FileTypes += ");; Subtitles Files ( ";
196 FileTypes += EXTENSIONS_SUBTITLE;
197 FileTypes += ");; All Files (*.*) " ;
198 FileTypes.replace(QString(";*"), QString(" *"));
200 QStringList fileList = QFileDialog::getOpenFileNames(
202 qtr("Select one or more files to open"),
203 p_intf->p_vlc->psz_homedir,
206 QStringList files = fileList;
208 for (size_t i = 0; i < files.size(); i++)
210 const char * psz_utf8 = files[i].toUtf8().data();
211 playlist_PlaylistAdd( p_playlist, psz_utf8, psz_utf8,
212 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
213 (i ? PLAYLIST_PREPARSE : 0 ),
217 vlc_object_release(p_playlist);
220 void DialogsProvider::bookmarksDialog()
224 void DialogsProvider::popupMenu( int i_dialog )