dialogs_provider.cpp 9.22 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
#include "dialogs/extended.hpp"
zorglub's avatar
zorglub committed
39
#include "dialogs/sout.hpp"
40
#include "dialogs/open.hpp"
zorglub's avatar
zorglub committed
41
42
43

DialogsProvider* DialogsProvider::instance = NULL;

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

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

53
    menusUpdateMapper = new QSignalMapper();
zorglub's avatar
zorglub committed
54
55
    CONNECT( menusUpdateMapper, mapped(QObject *),
             this, menuUpdateAction( QObject *) );
zorglub's avatar
zorglub committed
56
57
58

    SDMapper = new QSignalMapper();
    CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
zorglub's avatar
zorglub committed
59
}
zorglub's avatar
zorglub committed
60

zorglub's avatar
zorglub committed
61
62
63
DialogsProvider::~DialogsProvider()
{
    PlaylistDialog::killInstance();
64
    MediaInfoDialog::killInstance();
zorglub's avatar
zorglub committed
65
66
}

zorglub's avatar
zorglub committed
67
68
69
70
void DialogsProvider::customEvent( QEvent *event )
{
    if( event->type() == DialogEvent_Type )
    {
zorglub's avatar
zorglub committed
71
        DialogEvent *de = static_cast<DialogEvent*>(event);
zorglub's avatar
zorglub committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        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
90
            case INTF_DIALOG_FILEINFO:
91
               MediaInfoDialog(); break;
zorglub's avatar
zorglub committed
92
            case INTF_DIALOG_INTERACTION:
zorglub's avatar
zorglub committed
93
94
               doInteraction( de->p_arg ); break;
            case INTF_DIALOG_VLM:
zorglub's avatar
zorglub committed
95
            case INTF_DIALOG_BOOKMARKS:
zorglub's avatar
zorglub committed
96
               bookmarksDialog(); break;
zorglub's avatar
zorglub committed
97
98
            case INTF_DIALOG_WIZARD:
            default:
zorglub's avatar
zorglub committed
99
               msg_Warn( p_intf, "unimplemented dialog\n" );
zorglub's avatar
zorglub committed
100
101
102
103
104
105
106
107
108
        }
    }
}

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

zorglub's avatar
zorglub committed
109
110
111
112
void DialogsProvider::openDialog()
{
    openDialog( 0 );
}
zorglub's avatar
zorglub committed
113
114
115
116
117
118
void DialogsProvider::PLAppendDialog()
{
}
void DialogsProvider::MLAppendDialog()
{
}
zorglub's avatar
zorglub committed
119
120
void DialogsProvider::openDialog( int i_dialog )
{
121
    OpenDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
122
123
}

zorglub's avatar
zorglub committed
124
125
126
127
128
129
130
131
132
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
133
134
        if( !(p_dialog->i_status == ANSWERED_DIALOG) )
            qdialog->show();
zorglub's avatar
zorglub committed
135
136
137
138
        break;
    case INTERACT_UPDATE:
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog)
139
            qdialog->update();
zorglub's avatar
zorglub committed
140
141
142
143
144
145
146
147
148
        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);
149
150
        if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
            delete qdialog;
zorglub's avatar
zorglub committed
151
152
153
154
155
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
    }
}

zorglub's avatar
zorglub committed
156
157
158
159
160
161
void DialogsProvider::quit()
{
    p_intf->b_die = VLC_TRUE;
    QApplication::quit();
}

162
void DialogsProvider::MediaInfoDialog()
zorglub's avatar
zorglub committed
163
{
164
    MediaInfoDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
165
166
}

zorglub's avatar
zorglub committed
167
168
void DialogsProvider::streamingDialog()
{
169
    (new SoutDialog( p_intf ))->show();
zorglub's avatar
zorglub committed
170
171
}

zorglub's avatar
zorglub committed
172
173
void DialogsProvider::prefsDialog()
{
zorglub's avatar
zorglub committed
174
    PrefsDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
175
}
zorglub's avatar
zorglub committed
176
177
178
179
void DialogsProvider::extendedDialog()
{
    ExtendedDialog::getInstance( p_intf )->toggleVisible();
}
zorglub's avatar
zorglub committed
180
181
182

void DialogsProvider::messagesDialog()
{
zorglub's avatar
zorglub committed
183
    MessagesDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
184
185
}

zorglub's avatar
zorglub committed
186
187
188
189
190
void DialogsProvider::menuAction( QObject *data )
{
    QVLCMenu::DoAction( p_intf, data );
}

191
192
193
194
195
196
void DialogsProvider::menuUpdateAction( QObject *data )
{
    MenuFunc * f = qobject_cast<MenuFunc *>(data);
    f->doFunc( p_intf );
}

zorglub's avatar
zorglub committed
197
198
199
200
201
202
203
204
205
206
void DialogsProvider::SDMenuAction( QString data )
{
    char *psz_sd = data.toUtf8().data();
    if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
        playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
    else
        playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
}


zorglub's avatar
zorglub committed
207
void DialogsProvider::simplePLAppendDialog()
208
{
zorglub's avatar
zorglub committed
209
210
211
212
    QStringList files = showSimpleOpen();
    QString file;
    foreach( file, files )
    {
zorglub's avatar
zorglub committed
213
        const char * psz_utf8 = qtu( file );
214
215
        playlist_Add( THEPL, psz_utf8, NULL,
                PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END, VLC_TRUE );
zorglub's avatar
zorglub committed
216
    }
217
218
}

zorglub's avatar
zorglub committed
219
220
221
222
223
224
void DialogsProvider::simpleMLAppendDialog()
{
    QStringList files = showSimpleOpen();
    QString file;
    foreach( file, files )
    {
zorglub's avatar
zorglub committed
225
        const char * psz_utf8 =  qtu( file );
226
227
228
        playlist_Add( THEPL, psz_utf8, psz_utf8,
                      PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END,
                      VLC_TRUE);
zorglub's avatar
zorglub committed
229
230
231
    }
}

zorglub's avatar
zorglub committed
232
233
void DialogsProvider::simpleOpenDialog()
{
zorglub's avatar
zorglub committed
234
235
236
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
237
    {
zorglub's avatar
zorglub committed
238
        const char * psz_utf8 = qtu( files[i] );
zorglub's avatar
zorglub committed
239
        /* Play the first one, parse and enqueue the other ones */
240
241
242
243
        playlist_Add( THEPL, psz_utf8, NULL,
                      PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
                      ( i ? PLAYLIST_PREPARSE : 0 ),
                      PLAYLIST_END, VLC_TRUE );
244
    }
zorglub's avatar
zorglub committed
245
}
246

zorglub's avatar
zorglub committed
247
248
249
250
251
252
void DialogsProvider::openPlaylist()
{
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
    {
zorglub's avatar
zorglub committed
253
        const char * psz_utf8 = qtu( files[i] );
254
        playlist_Import( THEPL, psz_utf8 );
zorglub's avatar
zorglub committed
255
256
257
258
259
260
261
    }
}

void DialogsProvider::openDirectory()
{
    QString dir = QFileDialog::getExistingDirectory ( 0,
                                                     _("Open directory") );
zorglub's avatar
zorglub committed
262
    const char *psz_utf8 = qtu( dir );
263
    input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
zorglub's avatar
zorglub committed
264
                                               0, NULL, -1 );
265
    playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE);
zorglub's avatar
zorglub committed
266
267
268
269
270
271
    input_Read( THEPL, p_input, VLC_FALSE );
}
void DialogsProvider::openMLDirectory()
{
    QString dir = QFileDialog::getExistingDirectory ( 0,
                                                     _("Open directory") );
zorglub's avatar
zorglub committed
272
    const char *psz_utf8 = qtu( dir );
273
    input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
zorglub's avatar
zorglub committed
274
                                               0, NULL, -1 );
275
276
    playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END,
                        VLC_FALSE );
zorglub's avatar
zorglub committed
277
278
279
    input_Read( THEPL, p_input, VLC_FALSE );
}

zorglub's avatar
zorglub committed
280
281
QStringList DialogsProvider::showSimpleOpen()
{
282
    QString FileTypes;
283
284
285
286
287
288
    FileTypes = _("Media Files");
    FileTypes += " ( ";
    FileTypes += EXTENSIONS_MEDIA;
    FileTypes += ");;";
    FileTypes += _("Video Files");
    FileTypes += " ( ";
289
    FileTypes += EXTENSIONS_VIDEO;
290
291
292
    FileTypes += ");;";
    FileTypes += _("Sound Files");
    FileTypes += " ( ";
293
    FileTypes += EXTENSIONS_AUDIO;
294
295
296
    FileTypes += ");;";
    FileTypes += _("PlayList Files");
    FileTypes += " ( ";
297
    FileTypes += EXTENSIONS_PLAYLIST;
298
299
300
    FileTypes += ");;";
    FileTypes += _("All Files");
    FileTypes += " (*.*)";
301
    FileTypes.replace(QString(";*"), QString(" *"));
zorglub's avatar
zorglub committed
302
    return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
303
                    p_intf->p_libvlc->psz_homedir, FileTypes );
zorglub's avatar
zorglub committed
304
}
305

zorglub's avatar
zorglub committed
306
307
308
309
310
void DialogsProvider::switchToSkins()
{
    var_SetString( p_intf, "intf-switch", "skins2" );
}

zorglub's avatar
zorglub committed
311
312
313
314
void DialogsProvider::bookmarksDialog()
{
}

zorglub's avatar
zorglub committed
315
316
317
318
void DialogsProvider::popupMenu( int i_dialog )
{

}