]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
Enable verbosity setting
[vlc] / modules / gui / qt4 / dialogs_provider.cpp
1 /*****************************************************************************
2  * main_inteface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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. *****************************************************************************/
22
23 #include "qt4.hpp"
24 #include <QEvent>
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>
32 #include "menus.hpp"
33 #include <vlc_intf_strings.h>
34 #include <QFileDialog>
35
36 DialogsProvider* DialogsProvider::instance = NULL;
37
38 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
39                                       QObject( NULL ), p_intf( _p_intf )
40 {
41 //    idle_timer = new QTimer( this );
42 //    idle_timer->start( 0 );
43
44     fixed_timer = new QTimer( this );
45     fixed_timer->start( 150 /* milliseconds */ );
46
47     menusMapper = new QSignalMapper();
48     connect( menusMapper, SIGNAL( mapped(QObject *) ), this,
49             SLOT(menuAction( QObject *)) );
50
51     menusUpdateMapper = new QSignalMapper();
52     connect( menusUpdateMapper, SIGNAL( mapped(QObject *) ), this,
53             SLOT(menuUpdateAction( QObject *)) );
54 }
55
56 DialogsProvider::~DialogsProvider()
57 {
58 }
59 void DialogsProvider::customEvent( QEvent *event )
60 {
61     if( event->type() == DialogEvent_Type )
62     {
63         DialogEvent *de = static_cast<DialogEvent*>(event);
64         switch( de->i_dialog )
65         {
66             case INTF_DIALOG_FILE:
67             case INTF_DIALOG_DISC:
68             case INTF_DIALOG_NET:
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:
76                prefsDialog(); break;
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;
86             case INTF_DIALOG_VLM:
87             case INTF_DIALOG_BOOKMARKS:
88                bookmarksDialog(); break;
89             case INTF_DIALOG_WIZARD:
90             default:
91                msg_Warn( p_intf, "unimplemented dialog\n" );
92         }
93     }
94 }
95
96 void DialogsProvider::playlistDialog()
97 {
98     PlaylistDialog::getInstance( p_intf )->toggleVisible();
99 }
100
101 void DialogsProvider::openDialog()
102 {
103     openDialog( 0 );
104 }
105 void DialogsProvider::PLAppendDialog()
106 {
107 }
108 void DialogsProvider::MLAppendDialog()
109 {
110 }
111 void DialogsProvider::openDialog( int i_dialog )
112 {
113 }
114
115 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
116 {
117     InteractionDialog *qdialog;
118     interaction_dialog_t *p_dialog = p_arg->p_dialog;
119     switch( p_dialog->i_action )
120     {
121     case INTERACT_NEW:
122         qdialog = new InteractionDialog( p_intf, p_dialog );
123         p_dialog->p_private = (void*)qdialog;
124         if( !(p_dialog->i_status == ANSWERED_DIALOG) )
125             qdialog->show();
126         break;
127     case INTERACT_UPDATE:
128         qdialog = (InteractionDialog*)(p_dialog->p_private);
129         if( qdialog)
130             qdialog->Update();
131         break;
132     case INTERACT_HIDE:
133         qdialog = (InteractionDialog*)(p_dialog->p_private);
134         if( qdialog )
135             qdialog->hide();
136         p_dialog->i_status = HIDDEN_DIALOG;
137         break;
138     case INTERACT_DESTROY:
139         qdialog = (InteractionDialog*)(p_dialog->p_private);
140         delete qdialog;
141         p_dialog->i_status = DESTROYED_DIALOG;
142         break;
143     }
144 }
145
146 void DialogsProvider::quit()
147 {
148     p_intf->b_die = VLC_TRUE;
149     QApplication::quit();
150 }
151
152 void DialogsProvider::streaminfoDialog()
153 {
154     StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
155 }
156
157 void DialogsProvider::streamingDialog()
158 {
159 }
160
161 void DialogsProvider::prefsDialog()
162 {
163     PrefsDialog::getInstance( p_intf )->toggleVisible();
164 }
165
166 void DialogsProvider::messagesDialog()
167 {
168     MessagesDialog::getInstance( p_intf )->toggleVisible();
169 }
170
171 void DialogsProvider::menuAction( QObject *data )
172 {
173     QVLCMenu::DoAction( p_intf, data );
174 }
175
176 void DialogsProvider::menuUpdateAction( QObject *data )
177 {
178     MenuFunc * f = qobject_cast<MenuFunc *>(data);
179     f->doFunc( p_intf );
180 }
181
182 void DialogsProvider::simplePLAppendDialog()
183 {
184     QStringList files = showSimpleOpen();
185     QString file;
186     foreach( file, files )
187     {
188         const char * psz_utf8 = file.toUtf8().data();
189         playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
190                      PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
191     }
192 }
193
194 void DialogsProvider::simpleMLAppendDialog()
195 {
196     QStringList files = showSimpleOpen();
197     QString file;
198     foreach( file, files )
199     {
200         const char * psz_utf8 = file.toUtf8().data();
201         playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
202                         PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
203     }
204 }
205
206 void DialogsProvider::simpleOpenDialog()
207 {
208     QStringList files = showSimpleOpen();
209     QString file;
210     for( size_t i = 0 ; i< files.size(); i++ )
211     {
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 ),
217                      PLAYLIST_END );
218     }
219 }
220
221 QStringList DialogsProvider::showSimpleOpen()
222 {
223     QString FileTypes;
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 );
234 }
235
236 void DialogsProvider::bookmarksDialog()
237 {
238 }
239
240 void DialogsProvider::popupMenu( int i_dialog )
241 {
242
243 }