vlc_extensions.h

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

Generated on Mon Nov 22 07:55:19 2010 for VLC by  doxygen 1.5.6