vlc_extensions.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_extensions.h: Extensions (meta data, web information, ...)
00003  *****************************************************************************
00004  * Copyright (C) 2009-2010 VideoLAN and authors
00005  * $Id: 1b3b90a8b30afe0d11fb3b2c5e27f97619b13e81 $
00006  *
00007  * Authors: Jean-Philippe André < jpeg # videolan.org >
00008  *
00009  * This program is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation; either version 2.1 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  * GNU Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_EXTENSIONS_H
00025 #define VLC_EXTENSIONS_H
00026 
00027 #include "vlc_common.h"
00028 #include "vlc_arrays.h"
00029 
00030 /* Structures */
00031 typedef struct extensions_manager_sys_t extensions_manager_sys_t;
00032 typedef struct extensions_manager_t extensions_manager_t;
00033 typedef struct extension_sys_t extension_sys_t;
00034 
00035 /** Extension descriptor: name, title, author, ... */
00036 typedef struct extension_t {
00037     /* Below, (ro) means read-only for the GUI */
00038     char *psz_name;           /**< Real name of the extension (ro) */
00039 
00040     char *psz_title;          /**< Display title (ro) */
00041     char *psz_author;         /**< Author of the extension (ro) */
00042     char *psz_version;        /**< Version (ro) */
00043     char *psz_url;            /**< A URL to the official page (ro) */
00044     char *psz_description;    /**< Full description (ro) */
00045     char *psz_shortdescription; /**< Short description (eg. 1 line)  (ro) */
00046     char *p_icondata;         /**< Embedded data for the icon (ro) */
00047     int   i_icondata_size;    /**< Size of that data */
00048 
00049     extension_sys_t *p_sys;   /**< Reserved for the manager module */
00050 } extension_t;
00051 
00052 /** Extensions manager object */
00053 struct extensions_manager_t
00054 {
00055     VLC_COMMON_MEMBERS
00056 
00057     module_t *p_module;                /**< Extensions manager module */
00058     extensions_manager_sys_t *p_sys;   /**< Reserved for the module */
00059 
00060     DECL_ARRAY(extension_t*) extensions; /**< Array of extension descriptors */
00061     vlc_mutex_t lock;                  /**< A lock for the extensions array */
00062 
00063     /** Control, see extension_Control */
00064     int ( *pf_control ) ( extensions_manager_t*, int, va_list );
00065 };
00066 
00067 /* Control commands */
00068 enum
00069 {
00070     /* Control extensions */
00071     EXTENSION_ACTIVATE,       /**< arg1: extension_t* */
00072     EXTENSION_DEACTIVATE,     /**< arg1: extension_t* */
00073     EXTENSION_IS_ACTIVATED,   /**< arg1: extension_t*, arg2: bool* */
00074     EXTENSION_HAS_MENU,       /**< arg1: extension_t* */
00075     EXTENSION_GET_MENU,       /**< arg1: extension_t*, arg2: char***, arg3: uint16_t** */
00076     EXTENSION_TRIGGER_ONLY,   /**< arg1: extension_t*, arg2: bool* */
00077     EXTENSION_TRIGGER,        /**< arg1: extension_t* */
00078     EXTENSION_TRIGGER_MENU,   /**< arg1: extension_t*, int (uint16_t) */
00079     EXTENSION_SET_INPUT,      /**< arg1: extension_t*, arg2 (input_thread_t*) */
00080     EXTENSION_PLAYING_CHANGED, /**< arg1: extension_t*, arg2 int( playing status ) */
00081     EXTENSION_META_CHANGED,   /**< arg1: extension_t*, arg2 (input_item_t*) */
00082 };
00083 
00084 /**
00085  * Control function for extensions.
00086  * Every GUI -> extension command will go through this function.
00087  **/
00088 static inline int extension_Control( extensions_manager_t *p_mgr,
00089                                      int i_control, ... )
00090 {
00091     va_list args;
00092     va_start( args, i_control );
00093     int i_ret = p_mgr->pf_control( p_mgr, i_control, args );
00094     va_end( args );
00095     return i_ret;
00096 }
00097 
00098 /**
00099  * Helper for extension_HasMenu, extension_IsActivated...
00100  * Do not use.
00101  **/
00102 static inline bool __extension_GetBool( extensions_manager_t *p_mgr,
00103                                         extension_t *p_ext,
00104                                         int i_flag,
00105                                         bool b_default )
00106 {
00107     bool b = b_default;
00108     int i_ret = extension_Control( p_mgr, i_flag, p_ext, &b );
00109     if( i_ret != VLC_SUCCESS )
00110         return b_default;
00111     else
00112         return b;
00113 }
00114 
00115 /** Activate or trigger an extension */
00116 #define extension_Activate( mgr, ext ) \
00117         extension_Control( mgr, EXTENSION_ACTIVATE, ext )
00118 
00119 /** Trigger the extension. Attention: NOT multithreaded! */
00120 #define extension_Trigger( mgr, ext ) \
00121         extension_Control( mgr, EXTENSION_TRIGGER, ext )
00122 
00123 /** Deactivate an extension */
00124 #define extension_Deactivate( mgr, ext ) \
00125         extension_Control( mgr, EXTENSION_DEACTIVATE, ext )
00126 
00127 /** Is this extension activated? */
00128 #define extension_IsActivated( mgr, ext ) \
00129         __extension_GetBool( mgr, ext, EXTENSION_IS_ACTIVATED, false )
00130 
00131 /** Does this extension have a sub-menu? */
00132 #define extension_HasMenu( mgr, ext ) \
00133         __extension_GetBool( mgr, ext, EXTENSION_HAS_MENU, false )
00134 
00135 /** Get this extension's sub-menu */
00136 static inline int extension_GetMenu( extensions_manager_t *p_mgr,
00137                                      extension_t *p_ext,
00138                                      char ***pppsz,
00139                                      uint16_t **ppi )
00140 {
00141     return extension_Control( p_mgr, EXTENSION_GET_MENU, p_ext, pppsz, ppi );
00142 }
00143 
00144 /** Trigger an entry of the extension menu */
00145 static inline int extension_TriggerMenu( extensions_manager_t *p_mgr,
00146                                          extension_t *p_ext,
00147                                          uint16_t i )
00148 {
00149     return extension_Control( p_mgr, EXTENSION_TRIGGER_MENU, p_ext, i );
00150 }
00151 
00152 /** Trigger an entry of the extension menu */
00153 static inline int extension_SetInput( extensions_manager_t *p_mgr,
00154                                         extension_t *p_ext,
00155                                         struct input_thread_t *p_input )
00156 {
00157     return extension_Control( p_mgr, EXTENSION_SET_INPUT, p_ext, p_input );
00158 }
00159 
00160 static inline int extension_PlayingChanged( extensions_manager_t *p_mgr,
00161                                             extension_t *p_ext,
00162                                             int state )
00163 {
00164     return extension_Control( p_mgr, EXTENSION_PLAYING_CHANGED, p_ext, state );
00165 }
00166 
00167 static inline int extension_MetaChanged( extensions_manager_t *p_mgr,
00168                                          extension_t *p_ext )
00169 {
00170     return extension_Control( p_mgr, EXTENSION_META_CHANGED, p_ext );
00171 }
00172 
00173 /** Can this extension only be triggered but not activated?
00174     Not compatible with HasMenu */
00175 #define extension_TriggerOnly( mgr, ext ) \
00176         __extension_GetBool( mgr, ext, EXTENSION_TRIGGER_ONLY, false )
00177 
00178 
00179 /*****************************************************************************
00180  * Extension dialogs
00181  *****************************************************************************/
00182 
00183 typedef struct extension_dialog_t extension_dialog_t;
00184 typedef struct extension_widget_t extension_widget_t;
00185 
00186 /// User interface event types
00187 typedef enum
00188 {
00189     EXTENSION_EVENT_CLICK,       ///< Click on a widget: data = widget
00190     EXTENSION_EVENT_CLOSE,       ///< Close the dialog: no data
00191     // EXTENSION_EVENT_SELECTION_CHANGED,
00192     // EXTENSION_EVENT_TEXT_CHANGED,
00193 } extension_dialog_event_e;
00194 
00195 /// Command to pass to the extension dialog owner
00196 typedef struct
00197 {
00198     extension_dialog_t *p_dlg;      ///< Destination dialog
00199     extension_dialog_event_e event; ///< Event, @see extension_dialog_event_e
00200     void *p_data;                   ///< Opaque data to send
00201 } extension_dialog_command_t;
00202 
00203 
00204 /// Dialog descriptor for extensions
00205 struct extension_dialog_t
00206 {
00207     vlc_object_t *p_object;      ///< Owner object (callback on "dialog-event")
00208 
00209     char *psz_title;             ///< Title for the Dialog (in TitleBar)
00210     int i_width;                 ///< Width hint in pixels (may be discarded)
00211     int i_height;                ///< Height hint in pixels (may be discarded)
00212 
00213     DECL_ARRAY(extension_widget_t*) widgets; ///< Widgets owned by the dialog
00214 
00215     bool b_hide;                 ///< Hide this dialog (!b_hide shows)
00216     bool b_kill;                 ///< Kill this dialog
00217 
00218     void *p_sys;                 ///< Dialog private pointer
00219     void *p_sys_intf;            ///< GUI private pointer
00220     vlc_mutex_t lock;            ///< Dialog mutex
00221     vlc_cond_t cond;             ///< Signaled == UI is done working on the dialog
00222 };
00223 
00224 /** Send a command to an Extension dialog
00225  * @param p_dialog The dialog
00226  * @param event @see extension_dialog_event_e for a list of possible events
00227  * @param data Optional opaque data,  @see extension_dialog_event_e
00228  * @return VLC error code
00229  **/
00230 static inline int extension_DialogCommand( extension_dialog_t* p_dialog,
00231                                            extension_dialog_event_e event,
00232                                            void *data )
00233 {
00234     extension_dialog_command_t command;
00235     command.p_dlg = p_dialog;
00236     command.event = event;
00237     command.p_data = data;
00238     var_SetAddress( p_dialog->p_object, "dialog-event", &command );
00239     return VLC_SUCCESS;
00240 }
00241 
00242 /** Close the dialog
00243  * @param dlg The dialog
00244  **/
00245 #define extension_DialogClosed( dlg ) \
00246         extension_DialogCommand( dlg, EXTENSION_EVENT_CLOSE, NULL )
00247 
00248 /** Forward a click on a widget
00249  * @param dlg The dialog
00250  * @param wdg The widget (button, ...)
00251  **/
00252 #define extension_WidgetClicked( dlg, wdg ) \
00253         extension_DialogCommand( dlg, EXTENSION_EVENT_CLICK, wdg )
00254 
00255 /// Widget types
00256 typedef enum
00257 {
00258     EXTENSION_WIDGET_LABEL,      ///< Text label
00259     EXTENSION_WIDGET_BUTTON,     ///< Clickable button
00260     EXTENSION_WIDGET_IMAGE,      ///< Image label (psz_text is local URI)
00261     EXTENSION_WIDGET_HTML,       ///< HTML or rich text area (non editable)
00262     EXTENSION_WIDGET_TEXT_FIELD, ///< Editable text line for user input
00263     EXTENSION_WIDGET_PASSWORD,   ///< Editable password input (******)
00264     EXTENSION_WIDGET_DROPDOWN,   ///< Drop-down box
00265     EXTENSION_WIDGET_LIST,       ///< Vertical list box (of strings)
00266     EXTENSION_WIDGET_CHECK_BOX,  ///< Checkable box with label
00267     EXTENSION_WIDGET_SPIN_ICON,  ///< A "loading..." spinning icon
00268 } extension_widget_type_e;
00269 
00270 /// Widget descriptor for extensions
00271 struct extension_widget_t
00272 {
00273     /* All widgets */
00274     extension_widget_type_e type; ///< Type of the widget
00275     char *psz_text;               ///< Text. May be NULL or modified by the UI
00276 
00277     /* Drop-down & List widgets */
00278     struct extension_widget_value_t {
00279         int i_id;          ///< Identifier for the extension module
00280                            // (weird behavior may occur if not unique)
00281         char *psz_text;    ///< String value
00282         bool b_selected;   ///< True if this item is selected
00283         struct extension_widget_value_t *p_next; ///< Next value or NULL
00284     } *p_values;                  ///< Chained list of values (Drop-down/List)
00285 
00286     /* Check-box */
00287     bool b_checked;               ///< Is this entry checked
00288 
00289     /* Layout */
00290     int i_row;                    ///< Row in the grid
00291     int i_column;                 ///< Column in the grid
00292     int i_horiz_span;             ///< Horizontal size of the object
00293     int i_vert_span;              ///< Vertical size of the object
00294     int i_width;                  ///< Width hint
00295     int i_height;                 ///< Height hint
00296     bool b_hide;                  ///< Hide this widget (make it invisible)
00297 
00298     /* Spinning icon */
00299     int i_spin_loops;             ///< Number of loops to play (-1 = infinite,
00300                                   // 0 = stop animation)
00301 
00302     /* Orders */
00303     bool b_kill;                  ///< Destroy this widget
00304     bool b_update;                ///< Update this widget
00305 
00306     /* Misc */
00307     void *p_sys;                  ///< Reserved for the extension manager
00308     void *p_sys_intf;             ///< Reserved for the UI, but:
00309                                   // NULL means the UI has destroyed the widget
00310                                   // or has not created it yet
00311     extension_dialog_t *p_dialog; ///< Parent dialog
00312 };
00313 
00314 VLC_API int dialog_ExtensionUpdate(vlc_object_t*, extension_dialog_t *);
00315 #define dialog_ExtensionUpdate(o, d) dialog_ExtensionUpdate(VLC_OBJECT(o), d)
00316 
00317 #endif /* VLC_EXTENSIONS_H */
00318 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines