]> git.sesse.net Git - vlc/blob - include/vlc_extensions.h
Extensions: export author, version, url and description
[vlc] / include / vlc_extensions.h
1 /*****************************************************************************
2  * vlc_extension.h: Extensions (meta data, web information, ...)
3  *****************************************************************************
4  * Copyright (C) 2009-2010 VideoLAN and authors
5  * $Id$
6  *
7  * Authors: Jean-Philippe AndrĂ© < jpeg # videolan.org >
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef VLC_EXTENSIONS_H
25 #define VLC_EXTENSIONS_H
26
27 #include "vlc_common.h"
28 #include "vlc_arrays.h"
29
30 /* Structures */
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;
34
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     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
46     extension_sys_t *p_sys;   /**< Reserved for the manager module */
47 } extension_t;
48
49 /** Extensions manager object */
50 struct extensions_manager_t
51 {
52     VLC_COMMON_MEMBERS
53
54     module_t *p_module;                /**< Extensions manager module */
55     extensions_manager_sys_t *p_sys;   /**< Reserved for the module */
56
57     DECL_ARRAY(extension_t*) extensions; /**< Array of extension descriptors */
58     vlc_mutex_t lock;                  /**< A lock for the extensions array */
59
60     /** Control, see extension_Control */
61     int ( *pf_control ) ( extensions_manager_t*, int, va_list );
62 };
63
64 /* Control commands */
65 enum
66 {
67     /* Control extensions */
68     EXTENSION_ACTIVATE,       /**< arg1: extension_t* */
69     EXTENSION_DEACTIVATE,     /**< arg1: extension_t* */
70     EXTENSION_IS_ACTIVATED,   /**< arg1: extension_t*, arg2: bool* */
71     EXTENSION_HAS_MENU,       /**< arg1: extension_t* */
72     EXTENSION_GET_MENU,       /**< arg1: extension_t*, arg2: char***, arg3: uint16_t** */
73     EXTENSION_TRIGGER_ONLY,   /**< arg1: extension_t*, arg2: bool* */
74     EXTENSION_TRIGGER,        /**< arg1: extension_t* */
75     EXTENSION_TRIGGER_MENU,   /**< arg1: extension_t*, int (uint16_t) */
76 };
77
78 /**
79  * Control function for extensions.
80  * Every GUI -> extension command will go through this function.
81  **/
82 static inline int extension_Control( extensions_manager_t *p_mgr,
83                                      int i_control, ... )
84 {
85     va_list args;
86     va_start( args, i_control );
87     int i_ret = p_mgr->pf_control( p_mgr, i_control, args );
88     va_end( args );
89     return i_ret;
90 }
91
92 /**
93  * Helper for extension_HasMenu, extension_IsActivated...
94  * Do not use.
95  **/
96 static inline bool __extension_GetBool( extensions_manager_t *p_mgr,
97                                         extension_t *p_ext,
98                                         int i_flag,
99                                         bool b_default )
100 {
101     bool b = b_default;
102     int i_ret = extension_Control( p_mgr, i_flag, p_ext, &b );
103     if( i_ret != VLC_SUCCESS )
104         return b_default;
105     else
106         return b;
107 }
108
109 /** Activate or trigger an extension */
110 #define extension_Activate( mgr, ext ) \
111         extension_Control( mgr, EXTENSION_ACTIVATE, ext )
112
113 /** Trigger the extension. Attention: NOT multithreaded! */
114 #define extension_Trigger( mgr, ext ) \
115         extension_Control( mgr, EXTENSION_TRIGGER, ext )
116
117 /** Deactivate an extension */
118 #define extension_Deactivate( mgr, ext ) \
119         extension_Control( mgr, EXTENSION_DEACTIVATE, ext )
120
121 /** Is this extension activated? */
122 #define extension_IsActivated( mgr, ext ) \
123         __extension_GetBool( mgr, ext, EXTENSION_IS_ACTIVATED, false )
124
125 /** Does this extension have a sub-menu? */
126 #define extension_HasMenu( mgr, ext ) \
127         __extension_GetBool( mgr, ext, EXTENSION_HAS_MENU, false )
128
129 /** Get this extension's sub-menu */
130 static inline int extension_GetMenu( extensions_manager_t *p_mgr,
131                                      extension_t *p_ext,
132                                      char ***pppsz,
133                                      uint16_t **ppi )
134 {
135     return extension_Control( p_mgr, EXTENSION_GET_MENU, p_ext, pppsz, ppi );
136 }
137
138 /** Trigger an entry of the extension menu */
139 static inline int extension_TriggerMenu( extensions_manager_t *p_mgr,
140                                          extension_t *p_ext,
141                                          uint16_t i )
142 {
143     return extension_Control( p_mgr, EXTENSION_TRIGGER_MENU, p_ext, i );
144 }
145
146 /** Can this extension only be triggered but not activated?
147     Not compatible with HasMenu */
148 #define extension_TriggerOnly( mgr, ext ) \
149         __extension_GetBool( mgr, ext, EXTENSION_TRIGGER_ONLY, false )
150
151
152 /*****************************************************************************
153  * Extension dialogs
154  *****************************************************************************/
155
156 typedef struct extension_dialog_t extension_dialog_t;
157 typedef struct extension_widget_t extension_widget_t;
158
159 /// User interface event types
160 typedef enum
161 {
162     EXTENSION_EVENT_CLICK,       ///< Click on a widget: data = widget
163     EXTENSION_EVENT_CLOSE,       ///< Close the dialog: no data
164     // EXTENSION_EVENT_SELECTION_CHANGED,
165     // EXTENSION_EVENT_TEXT_CHANGED,
166 } extension_dialog_event_e;
167
168 /// Command to pass to the extension dialog owner
169 typedef struct
170 {
171     extension_dialog_t *p_dlg;      ///< Destination dialog
172     extension_dialog_event_e event; ///< Event, @see extension_dialog_event_e
173     void *p_data;                   ///< Opaque data to send
174 } extension_dialog_command_t;
175
176
177 /// Dialog descriptor for extensions
178 struct extension_dialog_t
179 {
180     vlc_object_t *p_object;      ///< Owner object (callback on "dialog-event")
181
182     char *psz_title;             ///< Title for the Dialog (in TitleBar)
183     int i_width;                 ///< Width hint in pixels (may be discarded)
184     int i_height;                ///< Height hint in pixels (may be discarded)
185
186     DECL_ARRAY(extension_widget_t*) widgets; ///< Widgets owned by the dialog
187
188     bool b_hide;                 ///< Hide this dialog (!b_hide shows)
189     bool b_kill;                 ///< Kill this dialog
190
191     void *p_sys;                 ///< Dialog private pointer
192     void *p_sys_intf;            ///< GUI private pointer
193     vlc_mutex_t lock;            ///< Dialog mutex
194     vlc_cond_t cond;             ///< Signaled == UI is done working on the dialog
195 };
196
197 /** Send a command to an Extension dialog
198  * @param p_dialog The dialog
199  * @param event @see extension_dialog_event_e for a list of possible events
200  * @param data Optional opaque data,  @see extension_dialog_event_e
201  * @return VLC error code
202  **/
203 static inline int extension_DialogCommand( extension_dialog_t* p_dialog,
204                                            extension_dialog_event_e event,
205                                            void *data )
206 {
207     extension_dialog_command_t command;
208     command.p_dlg = p_dialog;
209     command.event = event;
210     command.p_data = data;
211     var_SetAddress( p_dialog->p_object, "dialog-event", &command );
212     return VLC_SUCCESS;
213 }
214
215 /** Close the dialog
216  * @param dlg The dialog
217  **/
218 #define extension_DialogClosed( dlg ) \
219         extension_DialogCommand( dlg, EXTENSION_EVENT_CLOSE, NULL )
220
221 /** Forward a click on a widget
222  * @param dlg The dialog
223  * @param wdg The widget (button, ...)
224  **/
225 #define extension_WidgetClicked( dlg, wdg ) \
226         extension_DialogCommand( dlg, EXTENSION_EVENT_CLICK, wdg )
227
228 /// Widget types
229 typedef enum
230 {
231     EXTENSION_WIDGET_LABEL,      ///< Non editable text label
232     EXTENSION_WIDGET_BUTTON,     ///< Clickable button
233     EXTENSION_WIDGET_IMAGE,      ///< Image label (psz_text is local URI)
234     EXTENSION_WIDGET_HTML,       ///< HTML or rich text area (non editable)
235     EXTENSION_WIDGET_TEXT_FIELD, ///< Editable text line for user input
236     EXTENSION_WIDGET_PASSWORD,   ///< Editable password input (******)
237     EXTENSION_WIDGET_DROPDOWN,   ///< Drop-down box
238     EXTENSION_WIDGET_LIST,       ///< Vertical list box (of strings)
239     EXTENSION_WIDGET_CHECK_BOX,  ///< Checkable box with label
240 } extension_widget_type_e;
241
242 /// Widget descriptor for extensions
243 struct extension_widget_t
244 {
245     /* All widgets */
246     extension_widget_type_e type; ///< Type of the widget
247     char *psz_text;               ///< Text. May be NULL or modified by the UI
248
249     /* Drop-down & List widgets */
250     struct extension_widget_value_t {
251         int i_id;          ///< Identifier for the extension module
252                            // (weird behavior may occur if not unique)
253         char *psz_text;    ///< String value
254         bool b_selected;   ///< True if this item is selected
255         struct extension_widget_value_t *p_next; ///< Next value or NULL
256     } *p_values;                  ///< Chained list of values (Drop-down/List)
257
258     /* Check-box */
259     bool b_checked;               ///< Is this entry checked
260
261     /* Layout */
262     int i_row;                    ///< Row in the grid
263     int i_column;                 ///< Column in the grid
264     int i_horiz_span;             ///< Horizontal size of the object
265     int i_vert_span;              ///< Vertical size of the object
266     int i_width;                  ///< Width hint
267     int i_height;                 ///< Height hint
268     bool b_hide;                  ///< Hide this widget (make it invisible)
269
270     /* Orders */
271     bool b_kill;                  ///< Destroy this widget
272     bool b_update;                ///< Update this widget
273
274     /* Misc */
275     void *p_sys;                  ///< Reserved for the extension manager
276     void *p_sys_intf;             ///< Reserved for the UI, but:
277                                   // NULL means the UI has destroyed the widget
278                                   // or has not created it yet
279     extension_dialog_t *p_dialog; ///< Parent dialog
280 };
281
282 VLC_EXPORT(int, dialog_ExtensionUpdate, (vlc_object_t*, extension_dialog_t *));
283 #define dialog_ExtensionUpdate(o, d) dialog_ExtensionUpdate(VLC_OBJECT(o), d)
284
285 #endif /* VLC_EXTENSIONS_H */
286