extensions.hpp 4.22 KB
Newer Older
Jean-Philippe André's avatar
Jean-Philippe André committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*****************************************************************************
 * extensions.hpp: Extensions manager for Qt: dialogs manager
 ****************************************************************************
 * Copyright (C) 2009-2010 VideoLAN and authors
 * $Id$
 *
 * Authors: Jean-Philippe André < jpeg # 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.
 *****************************************************************************/

#ifndef EXTENSIONS_HPP
#define EXTENSIONS_HPP

#include "qt4.hpp"
#include <vlc_extensions.h>

#include "assert.h"

#include <QDialog>
class QObject;
class QGridLayout;
class QSignalMapper;
class QCloseEvent;
37
class QKeyEvent;
Jean-Philippe André's avatar
Jean-Philippe André committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

class ExtensionsDialogProvider;
class ExtensionDialog;

class ExtensionsDialogProvider : public QObject
{
    /** This is the dialog provider for Extensions dialogs
     * @todo Make this class be a public Singleton<EDP>
     * @todo Add a setExtManager() function (with vlc_object_hold)
     **/

    Q_OBJECT

private:
    static ExtensionsDialogProvider *instance;
    intf_thread_t *p_intf;
    extensions_manager_t *p_extensions_manager;

private slots:
57 58 59
    ExtensionDialog* CreateExtDialog( extension_dialog_t *p_dialog );
    int DestroyExtDialog( extension_dialog_t *p_dialog );
    ExtensionDialog* UpdateExtDialog( extension_dialog_t *p_dialog );
Jean-Philippe André's avatar
Jean-Philippe André committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

public:
    ExtensionsDialogProvider( intf_thread_t *p_intf,
                              extensions_manager_t *p_mgr );
    virtual ~ExtensionsDialogProvider();

    static ExtensionsDialogProvider* getInstance( intf_thread_t *p_intf = NULL,
                                                  extensions_manager_t *p_mgr = NULL )
    {
        if( !instance )
        {
            assert( p_intf != NULL && p_mgr != NULL );
            instance = new ExtensionsDialogProvider( p_intf, p_mgr );
        }
        return instance;
    }
    static void killInstance()
    {
        delete instance;
        instance = NULL;
    }

    void ManageDialog( extension_dialog_t *p_dialog );

signals:
    void SignalDialog( extension_dialog_t *p_dialog );
};


class ExtensionDialog : public QDialog
{
    Q_OBJECT
private:
    intf_thread_t *p_intf;
    extensions_manager_t *p_extensions_manager;
    extension_t *p_extension;
    extension_dialog_t *p_dialog;
    bool has_lock; ///< Indicates whether Qt thread owns the lock
    QGridLayout *layout;
    QSignalMapper *clickMapper;
    QSignalMapper *inputMapper;
    QSignalMapper *selectMapper;

    QWidget *CreateWidget( extension_widget_t *p_widget );
    QWidget *UpdateWidget( extension_widget_t *p_widget );
105
    void DestroyWidget( extension_widget_t *p_widget, bool b_cond = true );
Jean-Philippe André's avatar
Jean-Philippe André committed
106 107

protected:
108 109
    void closeEvent( QCloseEvent* ) Q_DECL_OVERRIDE;
    void keyPressEvent( QKeyEvent* ) Q_DECL_OVERRIDE;
Jean-Philippe André's avatar
Jean-Philippe André committed
110 111 112 113 114

private slots:
    int TriggerClick( QObject *object );
    void SyncInput( QObject *object );
    void SyncSelection( QObject *object );
115
    void parentDestroyed();
Jean-Philippe André's avatar
Jean-Philippe André committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

signals:
    void destroyDialog( extension_dialog_t *p_dialog );

public:
    ExtensionDialog( intf_thread_t *p_intf,
                     extensions_manager_t *p_mgr,
                     extension_dialog_t *p_dialog );
    virtual ~ExtensionDialog();

    void UpdateWidgets();

    // FIXME: This totally sucks (access to has_lock)
    friend class ExtensionsDialogProvider;
};

class WidgetMapper : public QObject
{
    Q_OBJECT
private:
    extension_widget_t *p_widget;
public:
    WidgetMapper( extension_widget_t *_p_widget ) :
            QObject(NULL), p_widget(_p_widget) {}
    extension_widget_t* getWidget() { return p_widget; }
};

#endif // EXTENSIONS_HPP