dialogs_provider.cpp 6.42 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1 2 3
/*****************************************************************************
 * main_inteface.cpp : Main interface
 ****************************************************************************
4 5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
Clément Stenac's avatar
Clément Stenac 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>
25
#include "dialogs_provider.hpp"
Clément Stenac's avatar
Clément Stenac committed
26
#include "dialogs/playlist.hpp"
Clément Stenac's avatar
Clément Stenac committed
27
#include "dialogs/prefs_dialog.hpp"
28
#include "dialogs/streaminfo.hpp"
29
#include "dialogs/messages.hpp"
30
#include <QApplication>
31 32
#include <QSignalMapper>
#include "menus.hpp"
Clément Stenac's avatar
Clément Stenac committed
33 34 35

DialogsProvider* DialogsProvider::instance = NULL;

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

    fixed_timer = new QTimer( this );
43
    fixed_timer->start( 150 /* milliseconds */ );
44 45 46 47 48

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

49
    menusUpdateMapper = new QSignalMapper();
Clément Stenac's avatar
Clément Stenac committed
50
    connect( menusUpdateMapper, SIGNAL( mapped(QObject *) ), this,
51
            SLOT(menuUpdateAction( QObject *)) );
Clément Stenac's avatar
Clément Stenac committed
52
}
53

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

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

99 100 101 102
void DialogsProvider::openDialog()
{
    openDialog( 0 );
}
Clément Stenac's avatar
Clément Stenac committed
103 104 105 106
void DialogsProvider::openDialog( int i_dialog )
{
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
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);
        delete qdialog; 
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
    }
}

Clément Stenac's avatar
Clément Stenac committed
137 138 139 140 141 142
void DialogsProvider::quit()
{
    p_intf->b_die = VLC_TRUE;
    QApplication::quit();
}

143 144
void DialogsProvider::streaminfoDialog()
{
145
    StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
146 147
}

148 149 150 151
void DialogsProvider::streamingDialog()
{
}

Clément Stenac's avatar
Clément Stenac committed
152 153
void DialogsProvider::prefsDialog()
{
Clément Stenac's avatar
Clément Stenac committed
154
    PrefsDialog::getInstance( p_intf )->toggleVisible();
Clément Stenac's avatar
Clément Stenac committed
155 156 157 158
}

void DialogsProvider::messagesDialog()
{
159
    MessagesDialog::getInstance( p_intf, true )->toggleVisible();
Clément Stenac's avatar
Clément Stenac committed
160 161
}

162 163 164 165 166
void DialogsProvider::menuAction( QObject *data )
{
    QVLCMenu::DoAction( p_intf, data );
}

167 168 169 170 171 172
void DialogsProvider::menuUpdateAction( QObject *data )
{
    MenuFunc * f = qobject_cast<MenuFunc *>(data);
    f->doFunc( p_intf );
}

173 174 175 176 177
void DialogsProvider::simpleAppendDialog()
{

}

178 179
void DialogsProvider::simpleOpenDialog()
{
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    QString FileTypes;
    FileTypes = "Sound Files ( ";
    FileTypes += EXTENSIONS_AUDIO;
    FileTypes += ");; Video Files ( ";
    FileTypes += EXTENSIONS_VIDEO;
    FileTypes += ");; PlayList Files ( ";
    FileTypes += EXTENSIONS_PLAYLIST;
    FileTypes += ");; Subtitles Files ( ";
    FileTypes += EXTENSIONS_SUBTITLE;
    FileTypes += ");; All Files (*.*) " ;
    FileTypes.replace(QString(";*"), QString(", *"));

    QStringList fileList = QFileDialog::getOpenFileNames(
                 NULL,
                 qtr("Select one or more files to open"),
                 p_intf->p_vlc->psz_homedir,
                 FileTypes);

    QStringList files = fileList;

    for (size_t i = 0; i < files.size(); i++)
    {
        const char * psz_utf8 = files[i].toUtf8().data();
             playlist_PlaylistAdd( p_playlist, psz_utf8, psz_utf8,
                     PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
                     (i ? PLAYLIST_PREPARSE : 0 ),
                     PLAYLIST_END );
    }

    vlc_object_release(p_playlist);
218
}
219

Clément Stenac's avatar
Clément Stenac committed
220 221 222 223
void DialogsProvider::bookmarksDialog()
{
}

Clément Stenac's avatar
Clément Stenac committed
224 225 226 227
void DialogsProvider::popupMenu( int i_dialog )
{

}