dialogs_provider.cpp 8.32 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
22
23
 *
 * 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. *****************************************************************************/
#include "qt4.hpp"
#include <QEvent>
zorglub's avatar
zorglub committed
24
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
25
#include "dialogs/playlist.hpp"
zorglub's avatar
zorglub committed
26
#include "dialogs/prefs_dialog.hpp"
zorglub's avatar
zorglub committed
27
#include "dialogs/streaminfo.hpp"
28
#include "dialogs/messages.hpp"
zorglub's avatar
zorglub committed
29
#include <QApplication>
zorglub's avatar
zorglub committed
30
31
#include <QSignalMapper>
#include "menus.hpp"
32
#include <vlc_intf_strings.h>
zorglub's avatar
zorglub committed
33
#include <QFileDialog>
zorglub's avatar
zorglub committed
34
35
36

DialogsProvider* DialogsProvider::instance = NULL;

zorglub's avatar
zorglub committed
37
38
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
                                      QObject( NULL ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
39
{
zorglub's avatar
zorglub committed
40
41
//    idle_timer = new QTimer( this );
//    idle_timer->start( 0 );
zorglub's avatar
zorglub committed
42
43

    fixed_timer = new QTimer( this );
44
    fixed_timer->start( 150 /* milliseconds */ );
zorglub's avatar
zorglub committed
45
46
47
48
49

    menusMapper = new QSignalMapper();
    connect( menusMapper, SIGNAL( mapped(QObject *) ), this,
            SLOT(menuAction( QObject *)) );

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

zorglub's avatar
zorglub committed
55
56
57
58
59
60
61
DialogsProvider::~DialogsProvider()
{
}
void DialogsProvider::customEvent( QEvent *event )
{
    if( event->type() == DialogEvent_Type )
    {
zorglub's avatar
zorglub committed
62
        DialogEvent *de = static_cast<DialogEvent*>(event);
zorglub's avatar
zorglub committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        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
81
82
            case INTF_DIALOG_FILEINFO:
               streaminfoDialog(); break;
zorglub's avatar
zorglub committed
83
            case INTF_DIALOG_INTERACTION:
zorglub's avatar
zorglub committed
84
85
               doInteraction( de->p_arg ); break;
            case INTF_DIALOG_VLM:
zorglub's avatar
zorglub committed
86
            case INTF_DIALOG_BOOKMARKS:
zorglub's avatar
zorglub committed
87
               bookmarksDialog(); break;
zorglub's avatar
zorglub committed
88
89
            case INTF_DIALOG_WIZARD:
            default:
zorglub's avatar
zorglub committed
90
               msg_Warn( p_intf, "unimplemented dialog\n" );
zorglub's avatar
zorglub committed
91
92
93
94
95
96
97
98
99
        }
    }
}

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

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

zorglub's avatar
zorglub committed
114
115
116
117
118
119
120
121
122
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
123
124
        if( !(p_dialog->i_status == ANSWERED_DIALOG) )
            qdialog->show();
zorglub's avatar
zorglub committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
        break;
    case INTERACT_UPDATE:
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog)
            qdialog->Update();
        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);
zorglub's avatar
zorglub committed
139
        delete qdialog;
zorglub's avatar
zorglub committed
140
141
142
143
144
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
    }
}

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

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

zorglub's avatar
zorglub committed
156
157
158
159
void DialogsProvider::streamingDialog()
{
}

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

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

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

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

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

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

zorglub's avatar
zorglub committed
205
206
void DialogsProvider::simpleOpenDialog()
{
zorglub's avatar
zorglub committed
207
208
209
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
210
    {
zorglub's avatar
zorglub committed
211
212
213
214
215
216
        const char * psz_utf8 = files[i].toUtf8().data();
        /* 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 );
217
    }
zorglub's avatar
zorglub committed
218
}
219

zorglub's avatar
zorglub committed
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
void DialogsProvider::openPlaylist()
{
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
    {
        const char * psz_utf8 = files[i].toUtf8().data();
        /* 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") );
    const char *psz_utf8 = dir.toUtf8().data();
    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") );
    const char *psz_utf8 = dir.toUtf8().data();
    fprintf( stderr, "%s\n", psz_utf8 );
    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
255
256
QStringList DialogsProvider::showSimpleOpen()
{
257
    QString FileTypes;
258
    FileTypes = "Video Files ( ";
259
    FileTypes += EXTENSIONS_VIDEO;
260
261
    FileTypes += ");; Sound Files ( ";
    FileTypes += EXTENSIONS_AUDIO;
262
263
    FileTypes += ");; PlayList Files ( ";
    FileTypes += EXTENSIONS_PLAYLIST;
zorglub's avatar
zorglub committed
264
    FileTypes += ");; All Files (*.*)" ;
265
    FileTypes.replace(QString(";*"), QString(" *"));
zorglub's avatar
zorglub committed
266
267
    return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
                    p_intf->p_vlc->psz_homedir, FileTypes );
zorglub's avatar
zorglub committed
268
}
269

zorglub's avatar
zorglub committed
270
271
272
273
void DialogsProvider::bookmarksDialog()
{
}

zorglub's avatar
zorglub committed
274
275
276
277
void DialogsProvider::popupMenu( int i_dialog )
{

}