]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
* Allow service discoveries to state whether they prefer being displayed as tree
[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
35 DialogsProvider* DialogsProvider::instance = NULL;
36
37 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
38                                       QObject( NULL ), p_intf( _p_intf )
39 {
40 //    idle_timer = new QTimer( this );
41 //    idle_timer->start( 0 );
42
43     fixed_timer = new QTimer( this );
44     fixed_timer->start( 150 /* milliseconds */ );
45
46     menusMapper = new QSignalMapper();
47     connect( menusMapper, SIGNAL( mapped(QObject *) ), this,
48             SLOT(menuAction( QObject *)) );
49
50     menusUpdateMapper = new QSignalMapper();
51     connect( menusUpdateMapper, SIGNAL( mapped(QObject *) ), this,
52             SLOT(menuUpdateAction( QObject *)) );
53 }
54
55 DialogsProvider::~DialogsProvider()
56 {
57 }
58 void DialogsProvider::customEvent( QEvent *event )
59 {
60     if( event->type() == DialogEvent_Type )
61     {
62         DialogEvent *de = static_cast<DialogEvent*>(event);
63         switch( de->i_dialog )
64         {
65             case INTF_DIALOG_FILE:
66             case INTF_DIALOG_DISC:
67             case INTF_DIALOG_NET:
68             case INTF_DIALOG_CAPTURE:
69                 openDialog( de->i_dialog ); break;
70             case INTF_DIALOG_PLAYLIST:
71                 playlistDialog(); break;
72             case INTF_DIALOG_MESSAGES:
73                 messagesDialog(); break;
74             case INTF_DIALOG_PREFS:
75                prefsDialog(); break;
76             case INTF_DIALOG_POPUPMENU:
77             case INTF_DIALOG_AUDIOPOPUPMENU:
78             case INTF_DIALOG_VIDEOPOPUPMENU:
79             case INTF_DIALOG_MISCPOPUPMENU:
80                popupMenu( de->i_dialog ); break;
81             case INTF_DIALOG_FILEINFO:
82                streaminfoDialog(); break;
83             case INTF_DIALOG_INTERACTION:
84                doInteraction( de->p_arg ); break;
85             case INTF_DIALOG_VLM:
86             case INTF_DIALOG_BOOKMARKS:
87                bookmarksDialog(); break;
88             case INTF_DIALOG_WIZARD:
89             default:
90                msg_Warn( p_intf, "unimplemented dialog\n" );
91         }
92     }
93 }
94
95 void DialogsProvider::playlistDialog()
96 {
97     PlaylistDialog::getInstance( p_intf )->toggleVisible();
98 }
99
100 void DialogsProvider::openDialog()
101 {
102     openDialog( 0 );
103 }
104 void DialogsProvider::openDialog( int i_dialog )
105 {
106 }
107
108 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
109 {
110     InteractionDialog *qdialog;
111     interaction_dialog_t *p_dialog = p_arg->p_dialog;
112     switch( p_dialog->i_action )
113     {
114     case INTERACT_NEW:
115         qdialog = new InteractionDialog( p_intf, p_dialog );
116         p_dialog->p_private = (void*)qdialog;
117         qdialog->show();
118         break;
119     case INTERACT_UPDATE:
120         qdialog = (InteractionDialog*)(p_dialog->p_private);
121         if( qdialog)
122             qdialog->Update();
123         break;
124     case INTERACT_HIDE:
125         qdialog = (InteractionDialog*)(p_dialog->p_private);
126         if( qdialog )
127             qdialog->hide();
128         p_dialog->i_status = HIDDEN_DIALOG;
129         break;
130     case INTERACT_DESTROY:
131         qdialog = (InteractionDialog*)(p_dialog->p_private);
132         delete qdialog; 
133         p_dialog->i_status = DESTROYED_DIALOG;
134         break;
135     }
136 }
137
138 void DialogsProvider::quit()
139 {
140     p_intf->b_die = VLC_TRUE;
141     QApplication::quit();
142 }
143
144 void DialogsProvider::streaminfoDialog()
145 {
146     StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
147 }
148
149 void DialogsProvider::streamingDialog()
150 {
151 }
152
153 void DialogsProvider::prefsDialog()
154 {
155     PrefsDialog::getInstance( p_intf )->toggleVisible();
156 }
157
158 void DialogsProvider::messagesDialog()
159 {
160     MessagesDialog::getInstance( p_intf, true )->toggleVisible();
161 }
162
163 void DialogsProvider::menuAction( QObject *data )
164 {
165     QVLCMenu::DoAction( p_intf, data );
166 }
167
168 void DialogsProvider::menuUpdateAction( QObject *data )
169 {
170     MenuFunc * f = qobject_cast<MenuFunc *>(data);
171     f->doFunc( p_intf );
172 }
173
174 void DialogsProvider::simpleAppendDialog()
175 {
176
177 }
178
179 void DialogsProvider::simpleOpenDialog()
180 {
181     playlist_t *p_playlist =
182         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
183                 FIND_ANYWHERE );
184     if( p_playlist == NULL )
185     {
186         return;
187     }
188
189     QString FileTypes;
190     FileTypes = "Video Files ( ";
191     FileTypes += EXTENSIONS_VIDEO;
192     FileTypes += ");; Sound Files ( ";
193     FileTypes += EXTENSIONS_AUDIO;
194     FileTypes += ");; PlayList Files ( ";
195     FileTypes += EXTENSIONS_PLAYLIST;
196     FileTypes += ");; Subtitles Files ( ";
197     FileTypes += EXTENSIONS_SUBTITLE;
198     FileTypes += ");; All Files (*.*) " ;
199     FileTypes.replace(QString(";*"), QString(" *"));
200
201     QStringList fileList = QFileDialog::getOpenFileNames(
202                  NULL, qfu(I_POP_SEL_FILES ), p_intf->p_vlc->psz_homedir,
203                  FileTypes);
204
205     QStringList files = fileList;
206
207     for (size_t i = 0; i < files.size(); i++)
208     {
209         const char * psz_utf8 = files[i].toUtf8().data();
210              playlist_PlaylistAdd( p_playlist, psz_utf8, psz_utf8,
211                      PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
212                      (i ? PLAYLIST_PREPARSE : 0 ),
213                      PLAYLIST_END );
214     }
215
216     vlc_object_release(p_playlist);
217 }
218
219 void DialogsProvider::bookmarksDialog()
220 {
221 }
222
223 void DialogsProvider::popupMenu( int i_dialog )
224 {
225
226 }