VLC 4.0.0-dev
vlc_extensions.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_extensions.h: Extensions (meta data, web information, ...)
3 *****************************************************************************
4 * Copyright (C) 2009-2010 VideoLAN and authors
5 *
6 * Authors: Jean-Philippe André < jpeg # videolan.org >
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
22
23#ifndef VLC_EXTENSIONS_H
24#define VLC_EXTENSIONS_H
25
26#include "vlc_common.h"
27#include "vlc_threads.h"
28#include "vlc_arrays.h"
29
30/* Structures */
34struct vlc_logger;
35
36/** Extension descriptor: name, title, author, ... */
37typedef struct extension_t {
38 void *p_sys; /**< Reserved for the manager module */
40 /**
41 * The LibVLC logger to use for the extension.
42 */
43 struct vlc_logger *logger;
45 /* Below, (ro) means read-only for the GUI */
46 char *psz_name; /**< Real name of the extension (ro) */
48 char *psz_title; /**< Display title (ro) */
49 char *psz_author; /**< Author of the extension (ro) */
50 char *psz_version; /**< Version (ro) */
51 char *psz_url; /**< A URL to the official page (ro) */
52 char *psz_description; /**< Full description (ro) */
53 char *psz_shortdescription; /**< Short description (eg. 1 line) (ro) */
54 char *p_icondata; /**< Embedded data for the icon (ro) */
55 int i_icondata_size; /**< Size of that data */
58/** Extensions manager object */
61 struct vlc_object_t obj;
63 module_t *p_module; /**< Extensions manager module */
64 void *p_sys; /**< Reserved for the module */
67 DECL_ARRAY(extension_t*) extensions; /**< Array of extension descriptors */
68 vlc_mutex_t lock; /**< A lock for the extensions array */
70 /** Control, see extension_Control */
71 int (*pf_control)(extensions_manager_t*, int, extension_t *, va_list);
72};
73
74/* Control commands */
75enum
76{
77 /* Control extensions */
78 EXTENSION_ACTIVATE, /**< arg1: extension_t* */
79 EXTENSION_DEACTIVATE, /**< arg1: extension_t* */
80 EXTENSION_IS_ACTIVATED, /**< arg1: extension_t*, arg2: bool* */
81 EXTENSION_HAS_MENU, /**< arg1: extension_t* */
82 EXTENSION_GET_MENU, /**< arg1: extension_t*, arg2: char***, arg3: uint16_t** */
83 EXTENSION_TRIGGER_ONLY, /**< arg1: extension_t*, arg2: bool* */
84 EXTENSION_TRIGGER, /**< arg1: extension_t* */
85 EXTENSION_TRIGGER_MENU, /**< arg1: extension_t*, int (uint16_t) */
86 EXTENSION_SET_INPUT, /**< arg1: extension_t*, arg2 (input_item_t*) */
87 EXTENSION_PLAYING_CHANGED, /**< arg1: extension_t*, arg2 int( playing status ) */
88 EXTENSION_META_CHANGED, /**< arg1: extension_t*, arg2 (input_item_t*) */
89};
90
91/**
92 * Control function for extensions.
93 * Every GUI -> extension command will go through this function.
94 **/
95static inline int extension_Control( extensions_manager_t *p_mgr,
96 int i_control,
97 extension_t *ext, ... )
98{
99 va_list args;
100 va_start(args, ext);
101 int i_ret = p_mgr->pf_control(p_mgr, i_control, ext, args);
102 va_end( args );
103 return i_ret;
104}
105
106/**
107 * Helper for extension_HasMenu, extension_IsActivated...
108 * Do not use.
109 **/
110static inline bool
112 int i_flag, bool b_default )
113{
114 bool b = b_default;
115 int i_ret = extension_Control( p_mgr, i_flag, p_ext, &b );
116 if( i_ret != VLC_SUCCESS )
117 return b_default;
118 else
119 return b;
120}
121
122/** Activate or trigger an extension */
123#define extension_Activate( mgr, ext ) \
124 extension_Control( mgr, EXTENSION_ACTIVATE, ext )
125
126/** Trigger the extension. Attention: NOT multithreaded! */
127#define extension_Trigger( mgr, ext ) \
128 extension_Control( mgr, EXTENSION_TRIGGER, ext )
129
130/** Deactivate an extension */
131#define extension_Deactivate( mgr, ext ) \
132 extension_Control( mgr, EXTENSION_DEACTIVATE, ext )
133
134/** Is this extension activated? */
135#define extension_IsActivated( mgr, ext ) \
136 vlc_extension_GetBool( mgr, ext, EXTENSION_IS_ACTIVATED, false )
137
138/** Does this extension have a sub-menu? */
139#define extension_HasMenu( mgr, ext ) \
140 vlc_extension_GetBool( mgr, ext, EXTENSION_HAS_MENU, false )
141
142/** Get this extension's sub-menu */
143static inline int extension_GetMenu( extensions_manager_t *p_mgr,
145 char ***pppsz,
146 uint16_t **ppi )
147{
148 return extension_Control( p_mgr, EXTENSION_GET_MENU, p_ext, pppsz, ppi );
149}
150
151/** Trigger an entry of the extension menu */
152static inline int extension_TriggerMenu( extensions_manager_t *p_mgr,
154 uint16_t i )
155{
156 return extension_Control( p_mgr, EXTENSION_TRIGGER_MENU, p_ext, i );
157}
158
159/** Trigger an entry of the extension menu */
160/* TODO: use player */
161static inline int extension_SetInput( extensions_manager_t *p_mgr,
162 extension_t *p_ext, input_item_t *p_item )
163{
164 return extension_Control( p_mgr, EXTENSION_SET_INPUT, p_ext, p_item );
165}
166
167static inline int extension_PlayingChanged( extensions_manager_t *p_mgr,
169 int state )
170{
171 return extension_Control( p_mgr, EXTENSION_PLAYING_CHANGED, p_ext, state );
172}
173
174static inline int extension_MetaChanged( extensions_manager_t *p_mgr,
175 extension_t *p_ext )
176{
177 return extension_Control( p_mgr, EXTENSION_META_CHANGED, p_ext );
178}
179
180/** Can this extension only be triggered but not activated?
181 Not compatible with HasMenu */
182#define extension_TriggerOnly( mgr, ext ) \
183 vlc_extension_GetBool( mgr, ext, EXTENSION_TRIGGER_ONLY, false )
184
185
186/*****************************************************************************
187 * Extension dialogs
188 *****************************************************************************/
189
193/// User interface event types
194typedef enum
196 EXTENSION_EVENT_CLICK, ///< Click on a widget: data = widget
197 EXTENSION_EVENT_CLOSE, ///< Close the dialog: no data
198 // EXTENSION_EVENT_SELECTION_CHANGED,
199 // EXTENSION_EVENT_TEXT_CHANGED,
201
202/// Command to pass to the extension dialog owner
203typedef struct
205 extension_dialog_t *p_dlg; ///< Destination dialog
206 extension_dialog_event_e event; ///< Event, @see extension_dialog_event_e
207 void *p_data; ///< Opaque data to send
209
210
211/// Dialog descriptor for extensions
214 vlc_object_t *p_object; ///< Owner object (callback on "dialog-event")
216 char *psz_title; ///< Title for the Dialog (in TitleBar)
217 int i_width; ///< Width hint in pixels (may be discarded)
218 int i_height; ///< Height hint in pixels (may be discarded)
220 DECL_ARRAY(extension_widget_t*) widgets; ///< Widgets owned by the dialog
222 bool b_hide; ///< Hide this dialog (!b_hide shows)
223 bool b_kill; ///< Kill this dialog
225 void *p_sys; ///< Dialog private pointer
226 void *p_sys_intf; ///< GUI private pointer
227 vlc_mutex_t lock; ///< Dialog mutex
228 vlc_cond_t cond; ///< Signaled == UI is done working on the dialog
230
231/** Send a command to an Extension dialog
232 * @param p_dialog The dialog
233 * @param event @see extension_dialog_event_e for a list of possible events
234 * @param data Optional opaque data, @see extension_dialog_event_e
235 * @return VLC error code
236 **/
237static inline int extension_DialogCommand( extension_dialog_t* p_dialog,
239 void *data )
240{
242 command.p_dlg = p_dialog;
243 command.event = event;
244 command.p_data = data;
245 var_SetAddress( p_dialog->p_object, "dialog-event", &command );
246 return VLC_SUCCESS;
247}
248
249/** Close the dialog
250 * @param dlg The dialog
251 **/
252#define extension_DialogClosed( dlg ) \
253 extension_DialogCommand( dlg, EXTENSION_EVENT_CLOSE, NULL )
254
255/** Forward a click on a widget
256 * @param dlg The dialog
257 * @param wdg The widget (button, ...)
258 **/
259#define extension_WidgetClicked( dlg, wdg ) \
260 extension_DialogCommand( dlg, EXTENSION_EVENT_CLICK, wdg )
261
262/// Widget types
263typedef enum
265 EXTENSION_WIDGET_LABEL, ///< Text label
266 EXTENSION_WIDGET_BUTTON, ///< Clickable button
267 EXTENSION_WIDGET_IMAGE, ///< Image label (psz_text is local URI)
268 EXTENSION_WIDGET_HTML, ///< HTML or rich text area (non editable)
269 EXTENSION_WIDGET_TEXT_FIELD, ///< Editable text line for user input
270 EXTENSION_WIDGET_PASSWORD, ///< Editable password input (******)
271 EXTENSION_WIDGET_DROPDOWN, ///< Drop-down box
272 EXTENSION_WIDGET_LIST, ///< Vertical list box (of strings)
273 EXTENSION_WIDGET_CHECK_BOX, ///< Checkable box with label
274 EXTENSION_WIDGET_SPIN_ICON, ///< A "loading..." spinning icon
276
277/// Widget descriptor for extensions
280 /* All widgets */
281 extension_widget_type_e type; ///< Type of the widget
282 char *psz_text; ///< Text. May be NULL or modified by the UI
284 /* Drop-down & List widgets */
286 int i_id; ///< Identifier for the extension module
287 ///< (weird behavior may occur if not unique)
288 char *psz_text; ///< String value
289 bool b_selected; ///< True if this item is selected
290 struct extension_widget_value_t *p_next; ///< Next value or NULL
291 } *p_values; ///< Chained list of values (Drop-down/List)
293 /* Check-box */
294 bool b_checked; ///< Is this entry checked
296 /* Layout */
297 int i_row; ///< Row in the grid
298 int i_column; ///< Column in the grid
299 int i_horiz_span; ///< Horizontal size of the object
300 int i_vert_span; ///< Vertical size of the object
301 int i_width; ///< Width hint
302 int i_height; ///< Height hint
303 bool b_hide; ///< Hide this widget (make it invisible)
305 /* Spinning icon */
306 int i_spin_loops; ///< Number of loops to play (-1 = infinite,
307 ///< 0 = stop animation)
308
309 /* Orders */
310 bool b_kill; ///< Destroy this widget
311 bool b_update; ///< Update this widget
313 /* Misc */
314 void *p_sys; ///< Reserved for the extension manager
315 void *p_sys_intf; ///< Reserved for the UI, but:
316 ///< NULL means the UI has destroyed the widget
317 ///< or has not created it yet
318 extension_dialog_t *p_dialog; ///< Parent dialog
320
321#endif /* VLC_EXTENSIONS_H */
#define VLC_SUCCESS
No error.
Definition: vlc_common.h:503
static int var_SetAddress(vlc_object_t *p_obj, const char *psz_name, void *ptr)
Set the value of a pointer variable.
Definition: vlc_variables.h:360
static thread_local struct @81 state
Command to pass to the extension dialog owner.
Definition: vlc_extensions.h:205
void * p_data
Opaque data to send.
Definition: vlc_extensions.h:208
extension_dialog_t * p_dlg
Destination dialog.
Definition: vlc_extensions.h:206
extension_dialog_event_e event
Event,.
Definition: vlc_extensions.h:207
Dialog descriptor for extensions.
Definition: vlc_extensions.h:214
vlc_cond_t cond
Signaled == UI is done working on the dialog.
Definition: vlc_extensions.h:229
struct extension_dialog_t::@223 widgets
Widgets owned by the dialog.
bool b_hide
Hide this dialog (!b_hide shows)
Definition: vlc_extensions.h:223
char * psz_title
Title for the Dialog (in TitleBar)
Definition: vlc_extensions.h:217
int i_height
Height hint in pixels (may be discarded)
Definition: vlc_extensions.h:219
vlc_object_t * p_object
Owner object (callback on "dialog-event")
Definition: vlc_extensions.h:215
void * p_sys_intf
GUI private pointer.
Definition: vlc_extensions.h:227
int i_width
Width hint in pixels (may be discarded)
Definition: vlc_extensions.h:218
void * p_sys
Dialog private pointer.
Definition: vlc_extensions.h:226
bool b_kill
Kill this dialog.
Definition: vlc_extensions.h:224
vlc_mutex_t lock
Dialog mutex.
Definition: vlc_extensions.h:228
Extension descriptor: name, title, author, ...
Definition: vlc_extensions.h:38
char * psz_version
Version (ro)
Definition: vlc_extensions.h:51
struct vlc_logger * logger
The LibVLC logger to use for the extension.
Definition: vlc_extensions.h:44
char * psz_url
A URL to the official page (ro)
Definition: vlc_extensions.h:52
char * psz_shortdescription
Short description (eg.
Definition: vlc_extensions.h:54
char * psz_name
Real name of the extension (ro)
Definition: vlc_extensions.h:47
char * p_icondata
Embedded data for the icon (ro)
Definition: vlc_extensions.h:55
char * psz_description
Full description (ro)
Definition: vlc_extensions.h:53
char * psz_title
Display title (ro)
Definition: vlc_extensions.h:49
void * p_sys
Reserved for the manager module.
Definition: vlc_extensions.h:39
char * psz_author
Author of the extension (ro)
Definition: vlc_extensions.h:50
int i_icondata_size
Size of that data.
Definition: vlc_extensions.h:56
Definition: vlc_extensions.h:286
int i_id
Identifier for the extension module (weird behavior may occur if not unique)
Definition: vlc_extensions.h:287
bool b_selected
True if this item is selected.
Definition: vlc_extensions.h:290
struct extension_widget_value_t * p_next
Next value or NULL.
Definition: vlc_extensions.h:291
char * psz_text
String value.
Definition: vlc_extensions.h:289
Widget descriptor for extensions.
Definition: vlc_extensions.h:280
int i_spin_loops
Number of loops to play (-1 = infinite, 0 = stop animation)
Definition: vlc_extensions.h:307
char * psz_text
Text. May be NULL or modified by the UI.
Definition: vlc_extensions.h:283
bool b_hide
Hide this widget (make it invisible)
Definition: vlc_extensions.h:304
extension_widget_type_e type
Type of the widget.
Definition: vlc_extensions.h:282
int i_horiz_span
Horizontal size of the object.
Definition: vlc_extensions.h:300
bool b_checked
Is this entry checked.
Definition: vlc_extensions.h:295
struct extension_widget_t::extension_widget_value_t * p_values
Chained list of values (Drop-down/List)
int i_column
Column in the grid.
Definition: vlc_extensions.h:299
int i_width
Width hint.
Definition: vlc_extensions.h:302
int i_vert_span
Vertical size of the object.
Definition: vlc_extensions.h:301
bool b_kill
Destroy this widget.
Definition: vlc_extensions.h:311
void * p_sys
Reserved for the extension manager.
Definition: vlc_extensions.h:315
int i_row
Row in the grid.
Definition: vlc_extensions.h:298
int i_height
Height hint.
Definition: vlc_extensions.h:303
extension_dialog_t * p_dialog
Parent dialog.
Definition: vlc_extensions.h:319
bool b_update
Update this widget.
Definition: vlc_extensions.h:312
void * p_sys_intf
Reserved for the UI, but: NULL means the UI has destroyed the widget or has not created it yet.
Definition: vlc_extensions.h:316
Extensions manager object.
Definition: vlc_extensions.h:61
int(* pf_control)(extensions_manager_t *, int, extension_t *, va_list)
Control, see extension_Control.
Definition: vlc_extensions.h:72
struct vlc_player_t * player
Definition: vlc_extensions.h:66
struct vlc_object_t obj
Definition: vlc_extensions.h:62
struct extensions_manager_t::@222 extensions
Array of extension descriptors.
void * p_sys
Reserved for the module.
Definition: vlc_extensions.h:65
module_t * p_module
Extensions manager module.
Definition: vlc_extensions.h:64
vlc_mutex_t lock
A lock for the extensions array.
Definition: vlc_extensions.h:69
Describes an input and is used to spawn input_thread_t objects.
Definition: vlc_input_item.h:89
Internal module descriptor.
Definition: modules.h:76
Condition variable.
Definition: vlc_threads.h:322
Definition: messages.c:85
Mutex.
Definition: vlc_threads.h:195
VLC object common members.
Definition: vlc_objects.h:45
Definition: player.h:231
This file defines functions, structures and macros for handling arrays in vlc.
#define DECL_ARRAY(type)
Definition: vlc_arrays.h:179
This file is a collection of common definitions and types.
static bool vlc_extension_GetBool(extensions_manager_t *p_mgr, extension_t *p_ext, int i_flag, bool b_default)
Helper for extension_HasMenu, extension_IsActivated... Do not use.
Definition: vlc_extensions.h:112
static int extension_Control(extensions_manager_t *p_mgr, int i_control, extension_t *ext,...)
Control function for extensions.
Definition: vlc_extensions.h:96
struct extensions_manager_sys_t extensions_manager_sys_t
Definition: vlc_extensions.h:32
static int extension_SetInput(extensions_manager_t *p_mgr, extension_t *p_ext, input_item_t *p_item)
Trigger an entry of the extension menu.
Definition: vlc_extensions.h:162
extension_dialog_event_e
User interface event types.
Definition: vlc_extensions.h:196
@ EXTENSION_EVENT_CLOSE
Close the dialog: no data.
Definition: vlc_extensions.h:198
@ EXTENSION_EVENT_CLICK
Click on a widget: data = widget.
Definition: vlc_extensions.h:197
static int extension_TriggerMenu(extensions_manager_t *p_mgr, extension_t *p_ext, uint16_t i)
Trigger an entry of the extension menu.
Definition: vlc_extensions.h:153
extension_widget_type_e
Widget types.
Definition: vlc_extensions.h:265
@ EXTENSION_WIDGET_LIST
Vertical list box (of strings)
Definition: vlc_extensions.h:273
@ EXTENSION_WIDGET_BUTTON
Clickable button.
Definition: vlc_extensions.h:267
@ EXTENSION_WIDGET_CHECK_BOX
Checkable box with label.
Definition: vlc_extensions.h:274
@ EXTENSION_WIDGET_HTML
HTML or rich text area (non editable)
Definition: vlc_extensions.h:269
@ EXTENSION_WIDGET_DROPDOWN
Drop-down box.
Definition: vlc_extensions.h:272
@ EXTENSION_WIDGET_TEXT_FIELD
Editable text line for user input.
Definition: vlc_extensions.h:270
@ EXTENSION_WIDGET_PASSWORD
Editable password input (******)
Definition: vlc_extensions.h:271
@ EXTENSION_WIDGET_SPIN_ICON
A "loading..." spinning icon.
Definition: vlc_extensions.h:275
@ EXTENSION_WIDGET_IMAGE
Image label (psz_text is local URI)
Definition: vlc_extensions.h:268
@ EXTENSION_WIDGET_LABEL
Text label.
Definition: vlc_extensions.h:266
static int extension_DialogCommand(extension_dialog_t *p_dialog, extension_dialog_event_e event, void *data)
Send a command to an Extension dialog.
Definition: vlc_extensions.h:238
static int extension_GetMenu(extensions_manager_t *p_mgr, extension_t *p_ext, char ***pppsz, uint16_t **ppi)
Get this extension's sub-menu.
Definition: vlc_extensions.h:144
static int extension_PlayingChanged(extensions_manager_t *p_mgr, extension_t *p_ext, int state)
Definition: vlc_extensions.h:168
struct extension_t extension_t
Extension descriptor: name, title, author, ...
static int extension_MetaChanged(extensions_manager_t *p_mgr, extension_t *p_ext)
Definition: vlc_extensions.h:175
@ EXTENSION_GET_MENU
arg1: extension_t*, arg2: char***, arg3: uint16_t**
Definition: vlc_extensions.h:83
@ EXTENSION_PLAYING_CHANGED
arg1: extension_t*, arg2 int( playing status )
Definition: vlc_extensions.h:88
@ EXTENSION_IS_ACTIVATED
arg1: extension_t*, arg2: bool*
Definition: vlc_extensions.h:81
@ EXTENSION_ACTIVATE
arg1: extension_t*
Definition: vlc_extensions.h:79
@ EXTENSION_HAS_MENU
arg1: extension_t*
Definition: vlc_extensions.h:82
@ EXTENSION_TRIGGER
arg1: extension_t*
Definition: vlc_extensions.h:85
@ EXTENSION_SET_INPUT
arg1: extension_t*, arg2 (input_item_t*)
Definition: vlc_extensions.h:87
@ EXTENSION_META_CHANGED
arg1: extension_t*, arg2 (input_item_t*)
Definition: vlc_extensions.h:89
@ EXTENSION_TRIGGER_MENU
arg1: extension_t*, int (uint16_t)
Definition: vlc_extensions.h:86
@ EXTENSION_TRIGGER_ONLY
arg1: extension_t*, arg2: bool*
Definition: vlc_extensions.h:84
@ EXTENSION_DEACTIVATE
arg1: extension_t*
Definition: vlc_extensions.h:80
Thread primitive declarations.