1 /*****************************************************************************
2 * vlc_extension.h: Extensions (meta data, web information, ...)
3 *****************************************************************************
4 * Copyright (C) 2009-2010 VideoLAN and authors
7 * Authors: Jean-Philippe André < jpeg # videolan.org >
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_EXTENSIONS_H
25 #define VLC_EXTENSIONS_H
27 #include "vlc_common.h"
28 #include "vlc_arrays.h"
31 typedef struct extensions_manager_sys_t extensions_manager_sys_t;
32 typedef struct extensions_manager_t extensions_manager_t;
33 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) */
40 char *psz_title; /**< Display title (ro) */
41 char *psz_author; /**< Author of the extension (ro) */
42 char *psz_version; /**< Version (ro) */
43 char *psz_url; /**< A URL to the official page (ro) */
44 char *psz_description; /**< Full description (ro) */
45 char *psz_shortdescription; /**< Short description (eg. 1 line) (ro) */
47 extension_sys_t *p_sys; /**< Reserved for the manager module */
50 /** Extensions manager object */
51 struct extensions_manager_t
55 module_t *p_module; /**< Extensions manager module */
56 extensions_manager_sys_t *p_sys; /**< Reserved for the module */
58 DECL_ARRAY(extension_t*) extensions; /**< Array of extension descriptors */
59 vlc_mutex_t lock; /**< A lock for the extensions array */
61 /** Control, see extension_Control */
62 int ( *pf_control ) ( extensions_manager_t*, int, va_list );
65 /* Control commands */
68 /* Control extensions */
69 EXTENSION_ACTIVATE, /**< arg1: extension_t* */
70 EXTENSION_DEACTIVATE, /**< arg1: extension_t* */
71 EXTENSION_IS_ACTIVATED, /**< arg1: extension_t*, arg2: bool* */
72 EXTENSION_HAS_MENU, /**< arg1: extension_t* */
73 EXTENSION_GET_MENU, /**< arg1: extension_t*, arg2: char***, arg3: uint16_t** */
74 EXTENSION_TRIGGER_ONLY, /**< arg1: extension_t*, arg2: bool* */
75 EXTENSION_TRIGGER, /**< arg1: extension_t* */
76 EXTENSION_TRIGGER_MENU, /**< arg1: extension_t*, int (uint16_t) */
77 EXTENSION_SET_INPUT, /**< arg1: extension_t*, arg2 (input_thread_t) */
81 * Control function for extensions.
82 * Every GUI -> extension command will go through this function.
84 static inline int extension_Control( extensions_manager_t *p_mgr,
88 va_start( args, i_control );
89 int i_ret = p_mgr->pf_control( p_mgr, i_control, args );
95 * Helper for extension_HasMenu, extension_IsActivated...
98 static inline bool __extension_GetBool( extensions_manager_t *p_mgr,
104 int i_ret = extension_Control( p_mgr, i_flag, p_ext, &b );
105 if( i_ret != VLC_SUCCESS )
111 /** Activate or trigger an extension */
112 #define extension_Activate( mgr, ext ) \
113 extension_Control( mgr, EXTENSION_ACTIVATE, ext )
115 /** Trigger the extension. Attention: NOT multithreaded! */
116 #define extension_Trigger( mgr, ext ) \
117 extension_Control( mgr, EXTENSION_TRIGGER, ext )
119 /** Deactivate an extension */
120 #define extension_Deactivate( mgr, ext ) \
121 extension_Control( mgr, EXTENSION_DEACTIVATE, ext )
123 /** Is this extension activated? */
124 #define extension_IsActivated( mgr, ext ) \
125 __extension_GetBool( mgr, ext, EXTENSION_IS_ACTIVATED, false )
127 /** Does this extension have a sub-menu? */
128 #define extension_HasMenu( mgr, ext ) \
129 __extension_GetBool( mgr, ext, EXTENSION_HAS_MENU, false )
131 /** Get this extension's sub-menu */
132 static inline int extension_GetMenu( extensions_manager_t *p_mgr,
137 return extension_Control( p_mgr, EXTENSION_GET_MENU, p_ext, pppsz, ppi );
140 /** Trigger an entry of the extension menu */
141 static inline int extension_TriggerMenu( extensions_manager_t *p_mgr,
145 return extension_Control( p_mgr, EXTENSION_TRIGGER_MENU, p_ext, i );
148 /** Trigger an entry of the extension menu */
149 static inline int extension_SetInput( extensions_manager_t *p_mgr,
151 struct input_thread_t *p_input )
153 return extension_Control( p_mgr, EXTENSION_SET_INPUT, p_ext, p_input );
156 /** Can this extension only be triggered but not activated?
157 Not compatible with HasMenu */
158 #define extension_TriggerOnly( mgr, ext ) \
159 __extension_GetBool( mgr, ext, EXTENSION_TRIGGER_ONLY, false )
162 /*****************************************************************************
164 *****************************************************************************/
166 typedef struct extension_dialog_t extension_dialog_t;
167 typedef struct extension_widget_t extension_widget_t;
169 /// User interface event types
172 EXTENSION_EVENT_CLICK, ///< Click on a widget: data = widget
173 EXTENSION_EVENT_CLOSE, ///< Close the dialog: no data
174 // EXTENSION_EVENT_SELECTION_CHANGED,
175 // EXTENSION_EVENT_TEXT_CHANGED,
176 } extension_dialog_event_e;
178 /// Command to pass to the extension dialog owner
181 extension_dialog_t *p_dlg; ///< Destination dialog
182 extension_dialog_event_e event; ///< Event, @see extension_dialog_event_e
183 void *p_data; ///< Opaque data to send
184 } extension_dialog_command_t;
187 /// Dialog descriptor for extensions
188 struct extension_dialog_t
190 vlc_object_t *p_object; ///< Owner object (callback on "dialog-event")
192 char *psz_title; ///< Title for the Dialog (in TitleBar)
193 int i_width; ///< Width hint in pixels (may be discarded)
194 int i_height; ///< Height hint in pixels (may be discarded)
196 DECL_ARRAY(extension_widget_t*) widgets; ///< Widgets owned by the dialog
198 bool b_hide; ///< Hide this dialog (!b_hide shows)
199 bool b_kill; ///< Kill this dialog
201 void *p_sys; ///< Dialog private pointer
202 void *p_sys_intf; ///< GUI private pointer
203 vlc_mutex_t lock; ///< Dialog mutex
204 vlc_cond_t cond; ///< Signaled == UI is done working on the dialog
207 /** Send a command to an Extension dialog
208 * @param p_dialog The dialog
209 * @param event @see extension_dialog_event_e for a list of possible events
210 * @param data Optional opaque data, @see extension_dialog_event_e
211 * @return VLC error code
213 static inline int extension_DialogCommand( extension_dialog_t* p_dialog,
214 extension_dialog_event_e event,
217 extension_dialog_command_t command;
218 command.p_dlg = p_dialog;
219 command.event = event;
220 command.p_data = data;
221 var_SetAddress( p_dialog->p_object, "dialog-event", &command );
226 * @param dlg The dialog
228 #define extension_DialogClosed( dlg ) \
229 extension_DialogCommand( dlg, EXTENSION_EVENT_CLOSE, NULL )
231 /** Forward a click on a widget
232 * @param dlg The dialog
233 * @param wdg The widget (button, ...)
235 #define extension_WidgetClicked( dlg, wdg ) \
236 extension_DialogCommand( dlg, EXTENSION_EVENT_CLICK, wdg )
241 EXTENSION_WIDGET_LABEL, ///< Non editable text label
242 EXTENSION_WIDGET_BUTTON, ///< Clickable button
243 EXTENSION_WIDGET_IMAGE, ///< Image label (psz_text is local URI)
244 EXTENSION_WIDGET_HTML, ///< HTML or rich text area (non editable)
245 EXTENSION_WIDGET_TEXT_FIELD, ///< Editable text line for user input
246 EXTENSION_WIDGET_PASSWORD, ///< Editable password input (******)
247 EXTENSION_WIDGET_DROPDOWN, ///< Drop-down box
248 EXTENSION_WIDGET_LIST, ///< Vertical list box (of strings)
249 EXTENSION_WIDGET_CHECK_BOX, ///< Checkable box with label
250 } extension_widget_type_e;
252 /// Widget descriptor for extensions
253 struct extension_widget_t
256 extension_widget_type_e type; ///< Type of the widget
257 char *psz_text; ///< Text. May be NULL or modified by the UI
259 /* Drop-down & List widgets */
260 struct extension_widget_value_t {
261 int i_id; ///< Identifier for the extension module
262 // (weird behavior may occur if not unique)
263 char *psz_text; ///< String value
264 bool b_selected; ///< True if this item is selected
265 struct extension_widget_value_t *p_next; ///< Next value or NULL
266 } *p_values; ///< Chained list of values (Drop-down/List)
269 bool b_checked; ///< Is this entry checked
272 int i_row; ///< Row in the grid
273 int i_column; ///< Column in the grid
274 int i_horiz_span; ///< Horizontal size of the object
275 int i_vert_span; ///< Vertical size of the object
276 int i_width; ///< Width hint
277 int i_height; ///< Height hint
278 bool b_hide; ///< Hide this widget (make it invisible)
281 bool b_kill; ///< Destroy this widget
282 bool b_update; ///< Update this widget
285 void *p_sys; ///< Reserved for the extension manager
286 void *p_sys_intf; ///< Reserved for the UI, but:
287 // NULL means the UI has destroyed the widget
288 // or has not created it yet
289 extension_dialog_t *p_dialog; ///< Parent dialog
292 VLC_EXPORT(int, dialog_ExtensionUpdate, (vlc_object_t*, extension_dialog_t *));
293 #define dialog_ExtensionUpdate(o, d) dialog_ExtensionUpdate(VLC_OBJECT(o), d)
295 #endif /* VLC_EXTENSIONS_H */