]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
916b858b6eef81b256d112a1c1c2a812cfb711c2
[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
34 DialogsProvider* DialogsProvider::instance = NULL;
35
36 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
37                                       QObject( NULL ), p_intf( _p_intf )
38 {
39 //    idle_timer = new QTimer( this );
40 //    idle_timer->start( 0 );
41
42     fixed_timer = new QTimer( this );
43     fixed_timer->start( 150 /* milliseconds */ );
44
45     menusMapper = new QSignalMapper();
46     connect( menusMapper, SIGNAL( mapped(QObject *) ), this,
47             SLOT(menuAction( QObject *)) );
48
49     menusUpdateMapper = new QSignalMapper();
50     connect( menusUpdateMapper, SIGNAL( mapped(QObject *) ), this,
51             SLOT(menuUpdateAction( QObject *)) );
52 }
53
54 DialogsProvider::~DialogsProvider()
55 {
56 }
57 void DialogsProvider::customEvent( QEvent *event )
58 {
59     if( event->type() == DialogEvent_Type )
60     {
61         DialogEvent *de = static_cast<DialogEvent*>(event);
62         switch( de->i_dialog )
63         {
64             case INTF_DIALOG_FILE:
65             case INTF_DIALOG_DISC:
66             case INTF_DIALOG_NET:
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:
74                prefsDialog(); break;
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;
84             case INTF_DIALOG_VLM:
85             case INTF_DIALOG_BOOKMARKS:
86                bookmarksDialog(); break;
87             case INTF_DIALOG_WIZARD:
88             default:
89                msg_Warn( p_intf, "unimplemented dialog\n" );
90         }
91     }
92 }
93
94 void DialogsProvider::playlistDialog()
95 {
96     PlaylistDialog::getInstance( p_intf )->toggleVisible();
97 }
98
99 void DialogsProvider::openDialog()
100 {
101     openDialog( 0 );
102 }
103 void DialogsProvider::openDialog( int i_dialog )
104 {
105 }
106
107 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
108 {
109     InteractionDialog *qdialog;
110     interaction_dialog_t *p_dialog = p_arg->p_dialog;
111     switch( p_dialog->i_action )
112     {
113     case INTERACT_NEW:
114         qdialog = new InteractionDialog( p_intf, p_dialog );
115         p_dialog->p_private = (void*)qdialog;
116         qdialog->show();
117         break;
118     case INTERACT_UPDATE:
119         qdialog = (InteractionDialog*)(p_dialog->p_private);
120         if( qdialog)
121             qdialog->Update();
122         break;
123     case INTERACT_HIDE:
124         qdialog = (InteractionDialog*)(p_dialog->p_private);
125         if( qdialog )
126             qdialog->hide();
127         p_dialog->i_status = HIDDEN_DIALOG;
128         break;
129     case INTERACT_DESTROY:
130         qdialog = (InteractionDialog*)(p_dialog->p_private);
131         delete qdialog; 
132         p_dialog->i_status = DESTROYED_DIALOG;
133         break;
134     }
135 }
136
137 void DialogsProvider::quit()
138 {
139     p_intf->b_die = VLC_TRUE;
140     QApplication::quit();
141 }
142
143 void DialogsProvider::streaminfoDialog()
144 {
145     StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
146 }
147
148 void DialogsProvider::streamingDialog()
149 {
150 }
151
152 void DialogsProvider::prefsDialog()
153 {
154     PrefsDialog::getInstance( p_intf )->toggleVisible();
155 }
156
157 void DialogsProvider::messagesDialog()
158 {
159     MessagesDialog::getInstance( p_intf, true )->toggleVisible();
160 }
161
162 void DialogsProvider::menuAction( QObject *data )
163 {
164     QVLCMenu::DoAction( p_intf, data );
165 }
166
167 void DialogsProvider::menuUpdateAction( QObject *data )
168 {
169     MenuFunc * f = qobject_cast<MenuFunc *>(data);
170     f->doFunc( p_intf );
171 }
172
173 void DialogsProvider::simpleAppendDialog()
174 {
175
176 }
177
178 void DialogsProvider::simpleOpenDialog()
179 {
180     playlist_t *p_playlist =
181         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
182                 FIND_ANYWHERE );
183     if( p_playlist == NULL )
184     {
185         return;
186     }
187
188     QString FileTypes;
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(" *"));
199
200     QStringList fileList = QFileDialog::getOpenFileNames(
201                  NULL,
202                  qtr("Select one or more files to open"),
203                  p_intf->p_vlc->psz_homedir,
204                  FileTypes);
205
206     QStringList files = fileList;
207
208     for (size_t i = 0; i < files.size(); i++)
209     {
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 ),
214                      PLAYLIST_END );
215     }
216
217     vlc_object_release(p_playlist);
218 }
219
220 void DialogsProvider::bookmarksDialog()
221 {
222 }
223
224 void DialogsProvider::popupMenu( int i_dialog )
225 {
226
227 }