dialogs_provider.cpp 6.88 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
24
 *
 * 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
25
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
26
#include "dialogs/playlist.hpp"
zorglub's avatar
zorglub committed
27
#include "dialogs/prefs_dialog.hpp"
zorglub's avatar
zorglub committed
28
#include "dialogs/streaminfo.hpp"
29
#include "dialogs/messages.hpp"
zorglub's avatar
zorglub committed
30
#include <QApplication>
zorglub's avatar
zorglub committed
31
32
#include <QSignalMapper>
#include "menus.hpp"
33
#include <vlc_intf_strings.h>
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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;
        qdialog->show();
        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
138
        delete qdialog;
zorglub's avatar
zorglub committed
139
140
141
142
143
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
    }
}

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

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

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

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

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

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

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

zorglub's avatar
zorglub committed
180
void DialogsProvider::simplePLAppendDialog()
181
{
zorglub's avatar
zorglub committed
182
183
184
185
186
187
188
189
    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 );
    }
190
191
}

zorglub's avatar
zorglub committed
192
193
194
195
196
197
198
199
200
201
202
203
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
204
205
void DialogsProvider::simpleOpenDialog()
{
zorglub's avatar
zorglub committed
206
207
208
    QStringList files = showSimpleOpen();
    QString file;
    for( size_t i = 0 ; i< files.size(); i++ )
209
    {
zorglub's avatar
zorglub committed
210
211
212
213
214
215
        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 );
216
    }
zorglub's avatar
zorglub committed
217
}
218

zorglub's avatar
zorglub committed
219
220
QStringList DialogsProvider::showSimpleOpen()
{
221
    QString FileTypes;
222
    FileTypes = "Video Files ( ";
223
    FileTypes += EXTENSIONS_VIDEO;
224
225
    FileTypes += ");; Sound Files ( ";
    FileTypes += EXTENSIONS_AUDIO;
226
227
    FileTypes += ");; PlayList Files ( ";
    FileTypes += EXTENSIONS_PLAYLIST;
zorglub's avatar
zorglub committed
228
    FileTypes += ");; All Files (*.*)" ;
229
    FileTypes.replace(QString(";*"), QString(" *"));
zorglub's avatar
zorglub committed
230
231
    return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
                    p_intf->p_vlc->psz_homedir, FileTypes );
zorglub's avatar
zorglub committed
232
}
233

zorglub's avatar
zorglub committed
234
235
236
237
void DialogsProvider::bookmarksDialog()
{
}

zorglub's avatar
zorglub committed
238
239
240
241
void DialogsProvider::popupMenu( int i_dialog )
{

}