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