dialogs_provider.cpp 8.17 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * main_inteface.cpp : Main interface
 ****************************************************************************
4
5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
zorglub's avatar
zorglub committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
zorglub's avatar
zorglub committed
22

zorglub's avatar
zorglub committed
23
#include <QEvent>
zorglub's avatar
zorglub committed
24
25
26
27
28
#include <QApplication>
#include <QSignalMapper>
#include <QFileDialog>

#include "qt4.hpp"
zorglub's avatar
zorglub committed
29
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
30
31
32
33
#include "menus.hpp"
#include <vlc_intf_strings.h>

/* The dialogs */
zorglub's avatar
zorglub committed
34
#include "dialogs/playlist.hpp"
zorglub's avatar
zorglub committed
35
#include "dialogs/prefs_dialog.hpp"
zorglub's avatar
zorglub committed
36
#include "dialogs/streaminfo.hpp"
37
#include "dialogs/messages.hpp"
zorglub's avatar
zorglub committed
38
39
40

DialogsProvider* DialogsProvider::instance = NULL;

zorglub's avatar
zorglub committed
41
42
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
                                      QObject( NULL ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
43
{
zorglub's avatar
zorglub committed
44
    fixed_timer = new QTimer( this );
45
    fixed_timer->start( 150 /* milliseconds */ );
zorglub's avatar
zorglub committed
46
47

    menusMapper = new QSignalMapper();
zorglub's avatar
zorglub committed
48
    CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
zorglub's avatar
zorglub committed
49

50
    menusUpdateMapper = new QSignalMapper();
zorglub's avatar
zorglub committed
51
52
    CONNECT( menusUpdateMapper, mapped(QObject *),
             this, menuUpdateAction( QObject *) );
zorglub's avatar
zorglub committed
53
}
zorglub's avatar
zorglub committed
54

zorglub's avatar
zorglub committed
55
56
57
58
void DialogsProvider::customEvent( QEvent *event )
{
    if( event->type() == DialogEvent_Type )
    {
zorglub's avatar
zorglub committed
59
        DialogEvent *de = static_cast<DialogEvent*>(event);
zorglub's avatar
zorglub committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        switch( de->i_dialog )
        {
            case INTF_DIALOG_FILE:
            case INTF_DIALOG_DISC:
            case INTF_DIALOG_NET:
            case INTF_DIALOG_CAPTURE:
                openDialog( de->i_dialog ); break;
            case INTF_DIALOG_PLAYLIST:
                playlistDialog(); break;
            case INTF_DIALOG_MESSAGES:
                messagesDialog(); break;
            case INTF_DIALOG_PREFS:
               prefsDialog(); break;
            case INTF_DIALOG_POPUPMENU:
            case INTF_DIALOG_AUDIOPOPUPMENU:
            case INTF_DIALOG_VIDEOPOPUPMENU:
            case INTF_DIALOG_MISCPOPUPMENU:
               popupMenu( de->i_dialog ); break;
zorglub's avatar
zorglub committed
78
79
            case INTF_DIALOG_FILEINFO:
               streaminfoDialog(); break;
zorglub's avatar
zorglub committed
80
            case INTF_DIALOG_INTERACTION:
zorglub's avatar
zorglub committed
81
82
               doInteraction( de->p_arg ); break;
            case INTF_DIALOG_VLM:
zorglub's avatar
zorglub committed
83
            case INTF_DIALOG_BOOKMARKS:
zorglub's avatar
zorglub committed
84
               bookmarksDialog(); break;
zorglub's avatar
zorglub committed
85
86
            case INTF_DIALOG_WIZARD:
            default:
zorglub's avatar
zorglub committed
87
               msg_Warn( p_intf, "unimplemented dialog\n" );
zorglub's avatar
zorglub committed
88
89
90
91
92
93
94
95
96
        }
    }
}

void DialogsProvider::playlistDialog()
{
    PlaylistDialog::getInstance( p_intf )->toggleVisible();
}

zorglub's avatar
zorglub committed
97
98
99
100
void DialogsProvider::openDialog()
{
    openDialog( 0 );
}
zorglub's avatar
zorglub committed
101
102
103
104
105
106
void DialogsProvider::PLAppendDialog()
{
}
void DialogsProvider::MLAppendDialog()
{
}
zorglub's avatar
zorglub committed
107
108
109
110
void DialogsProvider::openDialog( int i_dialog )
{
}

zorglub's avatar
zorglub committed
111
112
113
114
115
116
117
118
119
void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
{
    InteractionDialog *qdialog;
    interaction_dialog_t *p_dialog = p_arg->p_dialog;
    switch( p_dialog->i_action )
    {
    case INTERACT_NEW:
        qdialog = new InteractionDialog( p_intf, p_dialog );
        p_dialog->p_private = (void*)qdialog;
zorglub's avatar
zorglub committed
120
121
        if( !(p_dialog->i_status == ANSWERED_DIALOG) )
            qdialog->show();
zorglub's avatar
zorglub committed
122
123
124
125
        break;
    case INTERACT_UPDATE:
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog)
126
            qdialog->update();
zorglub's avatar
zorglub committed
127
128
129
130
131
132
133
134
135
        break;
    case INTERACT_HIDE:
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog )
            qdialog->hide();
        p_dialog->i_status = HIDDEN_DIALOG;
        break;
    case INTERACT_DESTROY:
        qdialog = (InteractionDialog*)(p_dialog->p_private);
136
137
        if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
            delete qdialog;
zorglub's avatar
zorglub committed
138
139
140
141
142
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
    }
}

zorglub's avatar
zorglub committed
143
144
145
146
147
148
void DialogsProvider::quit()
{
    p_intf->b_die = VLC_TRUE;
    QApplication::quit();
}

zorglub's avatar
zorglub committed
149
150
void DialogsProvider::streaminfoDialog()
{
151
    StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
zorglub's avatar
zorglub committed
152
153
}

zorglub's avatar
zorglub committed
154
155
156
157
void DialogsProvider::streamingDialog()
{
}

zorglub's avatar
zorglub committed
158
159
void DialogsProvider::prefsDialog()
{
zorglub's avatar
zorglub committed
160
    PrefsDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
161
162
163
164
}

void DialogsProvider::messagesDialog()
{
zorglub's avatar
zorglub committed
165
    MessagesDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
166
167
}

zorglub's avatar
zorglub committed
168
169
170
171
172
void DialogsProvider::menuAction( QObject *data )
{
    QVLCMenu::DoAction( p_intf, data );
}

173
174
175
176
177
178
void DialogsProvider::menuUpdateAction( QObject *data )
{
    MenuFunc * f = qobject_cast<MenuFunc *>(data);
    f->doFunc( p_intf );
}

zorglub's avatar
zorglub committed
179
void DialogsProvider::simplePLAppendDialog()
180
{
zorglub's avatar
zorglub committed
181
182
183
184
    QStringList files = showSimpleOpen();
    QString file;
    foreach( file, files )
    {
zorglub's avatar
zorglub committed
185
        const char * psz_utf8 = qtu( file );
zorglub's avatar
zorglub committed
186
187
188
        playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
                     PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
    }
189
190
}

zorglub's avatar
zorglub committed
191
192
193
194
195
196
void DialogsProvider::simpleMLAppendDialog()
{
    QStringList files = showSimpleOpen();
    QString file;
    foreach( file, files )
    {
zorglub's avatar
zorglub committed
197
        const char * psz_utf8 =  qtu( file );
zorglub's avatar
zorglub committed
198
199
200
201
202
        playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
                        PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
    }
}

zorglub's avatar
zorglub committed
203
204
void DialogsProvider::simpleOpenDialog()
{
zorglub's avatar
zorglub committed
205
206
207
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
208
    {
zorglub's avatar
zorglub committed
209
        const char * psz_utf8 = qtu( files[i] );
zorglub's avatar
zorglub committed
210
211
212
213
214
        /* Play the first one, parse and enqueue the other ones */
        playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
                     PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
                     ( i ? PLAYLIST_PREPARSE : 0 ),
                     PLAYLIST_END );
215
    }
zorglub's avatar
zorglub committed
216
}
217

zorglub's avatar
zorglub committed
218
219
220
221
222
223
void DialogsProvider::openPlaylist()
{
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
    {
zorglub's avatar
zorglub committed
224
        const char * psz_utf8 = qtu( files[i] );
zorglub's avatar
zorglub committed
225
226
227
228
229
230
231
232
233
        /* Play the first one, parse and enqueue the other ones */
        playlist_Import( THEPL, psz_utf8, THEPL->p_root_category, VLC_FALSE );
    }
}

void DialogsProvider::openDirectory()
{
    QString dir = QFileDialog::getExistingDirectory ( 0,
                                                     _("Open directory") );
zorglub's avatar
zorglub committed
234
    const char *psz_utf8 = qtu( dir );
zorglub's avatar
zorglub committed
235
236
237
238
239
240
241
242
243
244
    input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
                                               0, NULL, -1 );
    playlist_PlaylistAddInput( THEPL, p_input,
                               PLAYLIST_APPEND, PLAYLIST_END );
    input_Read( THEPL, p_input, VLC_FALSE );
}
void DialogsProvider::openMLDirectory()
{
    QString dir = QFileDialog::getExistingDirectory ( 0,
                                                     _("Open directory") );
zorglub's avatar
zorglub committed
245
    const char *psz_utf8 = qtu( dir );
zorglub's avatar
zorglub committed
246
247
248
249
250
251
    input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
                                               0, NULL, -1 );
    playlist_MLAddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END );
    input_Read( THEPL, p_input, VLC_FALSE );
}

zorglub's avatar
zorglub committed
252
253
QStringList DialogsProvider::showSimpleOpen()
{
254
    QString FileTypes;
255
    FileTypes = "Video Files ( ";
256
    FileTypes += EXTENSIONS_VIDEO;
257
258
    FileTypes += ");; Sound Files ( ";
    FileTypes += EXTENSIONS_AUDIO;
259
260
    FileTypes += ");; PlayList Files ( ";
    FileTypes += EXTENSIONS_PLAYLIST;
zorglub's avatar
zorglub committed
261
    FileTypes += ");; All Files (*.*)" ;
262
    FileTypes.replace(QString(";*"), QString(" *"));
zorglub's avatar
zorglub committed
263
    return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
264
                    p_intf->p_libvlc->psz_homedir, FileTypes );
zorglub's avatar
zorglub committed
265
}
266

zorglub's avatar
zorglub committed
267
268
269
270
void DialogsProvider::bookmarksDialog()
{
}

zorglub's avatar
zorglub committed
271
272
273
274
void DialogsProvider::popupMenu( int i_dialog )
{

}