vlc_extensions.h 12 KB
Newer Older
1
/*****************************************************************************
Pere Orga's avatar
Pere Orga committed
2
 * vlc_extensions.h: Extensions (meta data, web information, ...)
3 4 5 6 7 8
 *****************************************************************************
 * Copyright (C) 2009-2010 VideoLAN and authors
 * $Id$
 *
 * Authors: Jean-Philippe André < jpeg # videolan.org >
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (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
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser 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.
22 23 24 25 26 27 28 29 30 31 32 33 34
 *****************************************************************************/

#ifndef VLC_EXTENSIONS_H
#define VLC_EXTENSIONS_H

#include "vlc_common.h"
#include "vlc_arrays.h"

/* Structures */
typedef struct extensions_manager_sys_t extensions_manager_sys_t;
typedef struct extensions_manager_t extensions_manager_t;
typedef struct extension_sys_t extension_sys_t;

35
/** Extension descriptor: name, title, author, ... */
36
typedef struct extension_t {
37
    /* Below, (ro) means read-only for the GUI */
38
    char *psz_name;           /**< Real name of the extension (ro) */
39 40 41 42 43 44

    char *psz_title;          /**< Display title (ro) */
    char *psz_author;         /**< Author of the extension (ro) */
    char *psz_version;        /**< Version (ro) */
    char *psz_url;            /**< A URL to the official page (ro) */
    char *psz_description;    /**< Full description (ro) */
45
    char *psz_shortdescription; /**< Short description (eg. 1 line)  (ro) */
46 47
    char *p_icondata;         /**< Embedded data for the icon (ro) */
    int   i_icondata_size;    /**< Size of that data */
48

49 50 51 52 53 54
    extension_sys_t *p_sys;   /**< Reserved for the manager module */
} extension_t;

/** Extensions manager object */
struct extensions_manager_t
{
55
    struct vlc_common_members obj;
56 57 58 59 60

    module_t *p_module;                /**< Extensions manager module */
    extensions_manager_sys_t *p_sys;   /**< Reserved for the module */

    DECL_ARRAY(extension_t*) extensions; /**< Array of extension descriptors */
61
    vlc_mutex_t lock;                  /**< A lock for the extensions array */
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

    /** Control, see extension_Control */
    int ( *pf_control ) ( extensions_manager_t*, int, va_list );
};

/* Control commands */
enum
{
    /* Control extensions */
    EXTENSION_ACTIVATE,       /**< arg1: extension_t* */
    EXTENSION_DEACTIVATE,     /**< arg1: extension_t* */
    EXTENSION_IS_ACTIVATED,   /**< arg1: extension_t*, arg2: bool* */
    EXTENSION_HAS_MENU,       /**< arg1: extension_t* */
    EXTENSION_GET_MENU,       /**< arg1: extension_t*, arg2: char***, arg3: uint16_t** */
    EXTENSION_TRIGGER_ONLY,   /**< arg1: extension_t*, arg2: bool* */
    EXTENSION_TRIGGER,        /**< arg1: extension_t* */
    EXTENSION_TRIGGER_MENU,   /**< arg1: extension_t*, int (uint16_t) */
79
    EXTENSION_SET_INPUT,      /**< arg1: extension_t*, arg2 (input_thread_t*) */
80
    EXTENSION_PLAYING_CHANGED, /**< arg1: extension_t*, arg2 int( playing status ) */
81
    EXTENSION_META_CHANGED,   /**< arg1: extension_t*, arg2 (input_item_t*) */
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
};

/**
 * Control function for extensions.
 * Every GUI -> extension command will go through this function.
 **/
static inline int extension_Control( extensions_manager_t *p_mgr,
                                     int i_control, ... )
{
    va_list args;
    va_start( args, i_control );
    int i_ret = p_mgr->pf_control( p_mgr, i_control, args );
    va_end( args );
    return i_ret;
}

/**
 * Helper for extension_HasMenu, extension_IsActivated...
 * Do not use.
 **/
static inline bool __extension_GetBool( extensions_manager_t *p_mgr,
                                        extension_t *p_ext,
                                        int i_flag,
                                        bool b_default )
{
    bool b = b_default;
    int i_ret = extension_Control( p_mgr, i_flag, p_ext, &b );
    if( i_ret != VLC_SUCCESS )
        return b_default;
    else
        return b;
}

/** Activate or trigger an extension */
#define extension_Activate( mgr, ext ) \
        extension_Control( mgr, EXTENSION_ACTIVATE, ext )

/** Trigger the extension. Attention: NOT multithreaded! */
#define extension_Trigger( mgr, ext ) \
        extension_Control( mgr, EXTENSION_TRIGGER, ext )

/** Deactivate an extension */
#define extension_Deactivate( mgr, ext ) \
        extension_Control( mgr, EXTENSION_DEACTIVATE, ext )

/** Is this extension activated? */
#define extension_IsActivated( mgr, ext ) \
        __extension_GetBool( mgr, ext, EXTENSION_IS_ACTIVATED, false )

/** Does this extension have a sub-menu? */
#define extension_HasMenu( mgr, ext ) \
        __extension_GetBool( mgr, ext, EXTENSION_HAS_MENU, false )

/** Get this extension's sub-menu */
static inline int extension_GetMenu( extensions_manager_t *p_mgr,
                                     extension_t *p_ext,
                                     char ***pppsz,
                                     uint16_t **ppi )
{
    return extension_Control( p_mgr, EXTENSION_GET_MENU, p_ext, pppsz, ppi );
}

/** Trigger an entry of the extension menu */
static inline int extension_TriggerMenu( extensions_manager_t *p_mgr,
                                         extension_t *p_ext,
                                         uint16_t i )
{
    return extension_Control( p_mgr, EXTENSION_TRIGGER_MENU, p_ext, i );
}

152 153 154 155 156 157 158 159
/** Trigger an entry of the extension menu */
static inline int extension_SetInput( extensions_manager_t *p_mgr,
                                        extension_t *p_ext,
                                        struct input_thread_t *p_input )
{
    return extension_Control( p_mgr, EXTENSION_SET_INPUT, p_ext, p_input );
}

160 161 162 163 164 165 166
static inline int extension_PlayingChanged( extensions_manager_t *p_mgr,
                                            extension_t *p_ext,
                                            int state )
{
    return extension_Control( p_mgr, EXTENSION_PLAYING_CHANGED, p_ext, state );
}

167 168 169 170 171 172
static inline int extension_MetaChanged( extensions_manager_t *p_mgr,
                                         extension_t *p_ext )
{
    return extension_Control( p_mgr, EXTENSION_META_CHANGED, p_ext );
}

173 174 175 176 177 178 179 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
/** Can this extension only be triggered but not activated?
    Not compatible with HasMenu */
#define extension_TriggerOnly( mgr, ext ) \
        __extension_GetBool( mgr, ext, EXTENSION_TRIGGER_ONLY, false )


/*****************************************************************************
 * Extension dialogs
 *****************************************************************************/

typedef struct extension_dialog_t extension_dialog_t;
typedef struct extension_widget_t extension_widget_t;

/// User interface event types
typedef enum
{
    EXTENSION_EVENT_CLICK,       ///< Click on a widget: data = widget
    EXTENSION_EVENT_CLOSE,       ///< Close the dialog: no data
    // EXTENSION_EVENT_SELECTION_CHANGED,
    // EXTENSION_EVENT_TEXT_CHANGED,
} extension_dialog_event_e;

/// Command to pass to the extension dialog owner
typedef struct
{
    extension_dialog_t *p_dlg;      ///< Destination dialog
    extension_dialog_event_e event; ///< Event, @see extension_dialog_event_e
    void *p_data;                   ///< Opaque data to send
} extension_dialog_command_t;


/// Dialog descriptor for extensions
struct extension_dialog_t
{
    vlc_object_t *p_object;      ///< Owner object (callback on "dialog-event")

    char *psz_title;             ///< Title for the Dialog (in TitleBar)
    int i_width;                 ///< Width hint in pixels (may be discarded)
    int i_height;                ///< Height hint in pixels (may be discarded)

    DECL_ARRAY(extension_widget_t*) widgets; ///< Widgets owned by the dialog

215
    bool b_hide;                 ///< Hide this dialog (!b_hide shows)
216 217 218 219 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 255 256 257
    bool b_kill;                 ///< Kill this dialog

    void *p_sys;                 ///< Dialog private pointer
    void *p_sys_intf;            ///< GUI private pointer
    vlc_mutex_t lock;            ///< Dialog mutex
    vlc_cond_t cond;             ///< Signaled == UI is done working on the dialog
};

/** Send a command to an Extension dialog
 * @param p_dialog The dialog
 * @param event @see extension_dialog_event_e for a list of possible events
 * @param data Optional opaque data,  @see extension_dialog_event_e
 * @return VLC error code
 **/
static inline int extension_DialogCommand( extension_dialog_t* p_dialog,
                                           extension_dialog_event_e event,
                                           void *data )
{
    extension_dialog_command_t command;
    command.p_dlg = p_dialog;
    command.event = event;
    command.p_data = data;
    var_SetAddress( p_dialog->p_object, "dialog-event", &command );
    return VLC_SUCCESS;
}

/** Close the dialog
 * @param dlg The dialog
 **/
#define extension_DialogClosed( dlg ) \
        extension_DialogCommand( dlg, EXTENSION_EVENT_CLOSE, NULL )

/** Forward a click on a widget
 * @param dlg The dialog
 * @param wdg The widget (button, ...)
 **/
#define extension_WidgetClicked( dlg, wdg ) \
        extension_DialogCommand( dlg, EXTENSION_EVENT_CLICK, wdg )

/// Widget types
typedef enum
{
258
    EXTENSION_WIDGET_LABEL,      ///< Text label
259 260 261 262 263 264 265 266
    EXTENSION_WIDGET_BUTTON,     ///< Clickable button
    EXTENSION_WIDGET_IMAGE,      ///< Image label (psz_text is local URI)
    EXTENSION_WIDGET_HTML,       ///< HTML or rich text area (non editable)
    EXTENSION_WIDGET_TEXT_FIELD, ///< Editable text line for user input
    EXTENSION_WIDGET_PASSWORD,   ///< Editable password input (******)
    EXTENSION_WIDGET_DROPDOWN,   ///< Drop-down box
    EXTENSION_WIDGET_LIST,       ///< Vertical list box (of strings)
    EXTENSION_WIDGET_CHECK_BOX,  ///< Checkable box with label
267
    EXTENSION_WIDGET_SPIN_ICON,  ///< A "loading..." spinning icon
268 269 270 271 272 273 274 275 276 277 278 279
} extension_widget_type_e;

/// Widget descriptor for extensions
struct extension_widget_t
{
    /* All widgets */
    extension_widget_type_e type; ///< Type of the widget
    char *psz_text;               ///< Text. May be NULL or modified by the UI

    /* Drop-down & List widgets */
    struct extension_widget_value_t {
        int i_id;          ///< Identifier for the extension module
280
                           ///< (weird behavior may occur if not unique)
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
        char *psz_text;    ///< String value
        bool b_selected;   ///< True if this item is selected
        struct extension_widget_value_t *p_next; ///< Next value or NULL
    } *p_values;                  ///< Chained list of values (Drop-down/List)

    /* Check-box */
    bool b_checked;               ///< Is this entry checked

    /* Layout */
    int i_row;                    ///< Row in the grid
    int i_column;                 ///< Column in the grid
    int i_horiz_span;             ///< Horizontal size of the object
    int i_vert_span;              ///< Vertical size of the object
    int i_width;                  ///< Width hint
    int i_height;                 ///< Height hint
    bool b_hide;                  ///< Hide this widget (make it invisible)

298 299
    /* Spinning icon */
    int i_spin_loops;             ///< Number of loops to play (-1 = infinite,
300
                                  ///< 0 = stop animation)
301

302 303 304 305 306 307 308
    /* Orders */
    bool b_kill;                  ///< Destroy this widget
    bool b_update;                ///< Update this widget

    /* Misc */
    void *p_sys;                  ///< Reserved for the extension manager
    void *p_sys_intf;             ///< Reserved for the UI, but:
309 310
                                  ///< NULL means the UI has destroyed the widget
                                  ///< or has not created it yet
311 312 313 314
    extension_dialog_t *p_dialog; ///< Parent dialog
};

#endif /* VLC_EXTENSIONS_H */