1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5  * gmerlin-general@lists.sourceforge.net
6  * http://gmerlin.sourceforge.net
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 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 General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  * *****************************************************************/
21 
22 #ifndef __BG_TREE_H_
23 #define __BG_TREE_H_
24 
25 #include <wchar.h> /* wchar_t */
26 
27 #include <gmerlin/pluginregistry.h>
28 
29 /* Entry flags                 */
30 /* Flags should not be changed */
31 
32 #define BG_ALBUM_ENTRY_ERROR      (1<<0)
33 #define BG_ALBUM_ENTRY_SELECTED   (1<<1)
34 #define BG_ALBUM_ENTRY_REDIRECTOR (1<<3)
35 #define BG_ALBUM_ENTRY_SAVE_AUTH  (1<<4)
36 #define BG_ALBUM_ENTRY_EDL        (1<<5)
37 
38 #define BG_ALBUM_ENTRY_SYNC       (1<<6) /* Used only internally */
39 
40 /*
41  *  Shuffle mode passed to bg_media_tree_next() and
42  *  bg_media_tree_previous()
43  */
44 
45 typedef enum
46   {
47     BG_SHUFFLE_MODE_OFF     = 0,
48     BG_SHUFFLE_MODE_CURRENT = 1,
49     BG_SHUFFLE_MODE_ALL     = 2,
50     BG_NUM_SHUFFLE_MODES    = 3,
51   } bg_shuffle_mode_t;
52 
53 typedef struct bg_album_entry_s
54   {
55   char * name;
56   void * location;
57   char * plugin;
58   gavl_time_t duration;
59 
60   int num_audio_streams;
61   int num_video_streams;
62   /* Need to distinguish between
63      normal and still streams here, because they get different
64      icons in the widget */
65   int num_still_streams;
66   int num_subtitle_streams;
67 
68   /*
69    *  Track index for multi track files/plugins
70    */
71 
72   int index;
73   int total_tracks;
74 
75   /* Authentication data */
76 
77   char * username;
78   char * password;
79 
80   int flags;
81   struct bg_album_entry_s * next;
82 
83   wchar_t * name_w;
84   int len_w;
85   time_t mtime;
86   } bg_album_entry_t;
87 
88 typedef struct bg_album_s bg_album_t;
89 typedef struct bg_mediatree_s bg_media_tree_t;
90 
91 typedef enum
92   {
93     /* Regular album */
94     BG_ALBUM_TYPE_REGULAR    = 0,
95     /* Drive for removable media */
96     BG_ALBUM_TYPE_REMOVABLE  = 1,
97     /* Hardware plugin (Subalbums are devices) */
98     BG_ALBUM_TYPE_PLUGIN     = 2,
99     /* Incoming album: Stuff from the commandline and the remote will go there */
100     BG_ALBUM_TYPE_INCOMING   = 3,
101     /* Favourites */
102     BG_ALBUM_TYPE_FAVOURITES = 4,
103     /* Tuner */
104     BG_ALBUM_TYPE_TUNER      = 5,
105   } bg_album_type_t;
106 
107 bg_album_type_t bg_album_get_type(bg_album_t *);
108 
109 /* Can return 0 if CD is missing or so */
110 
111 int bg_album_open(bg_album_t *);
112 void bg_album_close(bg_album_t *);
113 
114 /* Call after open() */
115 
116 const char * bg_album_get_disc_name(bg_album_t*);
117 
118 int bg_album_can_eject(bg_album_t*);
119 void bg_album_eject(bg_album_t*);
120 
121 void bg_album_select_error_tracks(bg_album_t*);
122 
123 void bg_album_get_times(bg_album_t * a,
124                         gavl_time_t * duration_before,
125                         gavl_time_t * duration_current,
126                         gavl_time_t * duration_after);
127 
128 
129 int                bg_album_get_num_entries(bg_album_t*);
130 bg_album_entry_t * bg_album_get_entry(bg_album_t*, int);
131 int                bg_album_get_index(bg_album_t*, const bg_album_entry_t * entry);
132 
133 void bg_album_set_change_callback(bg_album_t * a,
134                                   void (*change_callback)(bg_album_t * a,
135                                                           void * data),
136                                   void * change_callback_data);
137 
138 void bg_album_set_entry_change_callback(bg_album_t * a,
139                                         void (*change_callback)(bg_album_t * a,
140                                                                 const bg_album_entry_t * e,
141                                                                 void * data),
142                                         void * change_callback_data);
143 
144 void bg_album_set_name_change_callback(bg_album_t * a,
145                                        void (*name_change_callback)(bg_album_t * a,
146                                                                     const char * name,
147                                                                     void * data),
148                                        void * name_change_callback_data);
149 
150 void bg_album_set_current_change_callback(bg_album_t * a,
151                                           void (*change_callback)(bg_album_t * a,
152                                                                   const bg_album_entry_t * e,
153                                                                   void * data),
154                                           void * change_callback_data);
155 
156 void bg_album_set_delete_callback(bg_album_t * a,
157                                   void (*delete_callback)(bg_album_t * current_album,
158                                                           int * indices, void * data),
159                                   void * delete_callback_data);
160 
161 void bg_album_set_insert_callback(bg_album_t * a,
162                                   void (*insert_callback)(bg_album_t * current_album,
163                                                           int start, int num, void * data),
164                                   void * insert_callback_data);
165 
166 
167 void bg_album_move_selected_to_favourites(bg_album_t * a);
168 void bg_album_copy_selected_to_favourites(bg_album_t * a);
169 
170 bg_edl_t * bg_album_selected_to_edl(bg_album_t * a);
171 
172 
173 /* Return the current entry (might be NULL) */
174 
175 bg_album_entry_t * bg_album_get_current_entry(bg_album_t*);
176 
177 gavl_time_t bg_album_get_duration(bg_album_t*);
178 
179 int bg_album_next(bg_album_t*, int wrap);
180 int bg_album_previous(bg_album_t*, int wrap);
181 
182 void bg_album_set_current(bg_album_t * a, const bg_album_entry_t * e);
183 
184 int bg_album_is_current(bg_album_t*);
185 int bg_album_entry_is_current(bg_album_t*, bg_album_entry_t*);
186 
187 int          bg_album_get_num_children(bg_album_t *);
188 bg_album_t * bg_album_get_child(bg_album_t *, int);
189 
190 char * bg_album_get_name(bg_album_t * a);
191 
192 /* This returns the disc name or the album name */
193 char * bg_album_get_label(bg_album_t * a);
194 
195 
196 void bg_album_set_error(bg_album_t * a, int err);
197 int  bg_album_get_error(bg_album_t * a);
198 
199 void bg_album_rename(bg_album_t * a, const char *);
200 
201 void bg_album_append_child(bg_album_t * parent, bg_album_t * child);
202 
203 void bg_album_select_entry(bg_album_t * a, int entry);
204 void bg_album_unselect_entry(bg_album_t * a, int entry);
205 void bg_album_select_entries(bg_album_t * a, int start, int num);
206 void bg_album_toggle_select_entry(bg_album_t * a, int entry);
207 void bg_album_unselect_all(bg_album_t * a);
208 int bg_album_num_selected(bg_album_t * a);
209 int bg_album_entry_is_selected(bg_album_t * a, int entry);
210 
211 /* Seek support */
212 
213 typedef struct bg_album_seek_data_s bg_album_seek_data_t;
214 
215 bg_album_seek_data_t * bg_album_seek_data_create();
216 
217 int bg_album_seek_data_changed(bg_album_seek_data_t*);
218 
219 void bg_album_seek_data_set_string(bg_album_seek_data_t *, const char * str);
220 void bg_album_seek_data_ignore_case(bg_album_seek_data_t *, int ignore);
221 void bg_album_seek_data_exact_string(bg_album_seek_data_t *, int exact);
222 
223 
224 bg_album_entry_t * bg_album_seek_entry_after(bg_album_t * a,
225                                              bg_album_entry_t * e,
226                                              bg_album_seek_data_t*);
227 
228 bg_album_entry_t * bg_album_seek_entry_before(bg_album_t * a,
229                                               bg_album_entry_t * e,
230                                               bg_album_seek_data_t*);
231 
232 void bg_album_seek_data_destroy(bg_album_seek_data_t *);
233 
234 /*
235  *  Mark an album as expanded i.e. itself and all the
236  *  children are visible
237  */
238 
239 void bg_album_set_expanded(bg_album_t * a, int expanded);
240 int bg_album_get_expanded(bg_album_t * a);
241 int bg_album_is_open(bg_album_t * a);
242 
243 /* Add items */
244 
245 void bg_album_insert_urls_before(bg_album_t * a,
246                                  char ** urls,
247                                  const char * plugin,
248                                  int prefer_edl,
249                                  bg_album_entry_t * after);
250 
251 void bg_album_insert_urls_after(bg_album_t * a,
252                                 char ** urls,
253                                 const char * plugin,
254                                 int prefer_edl,
255                                 bg_album_entry_t * before);
256 
257 /* Inserts an xml-string */
258 
259 void bg_album_insert_xml_before(bg_album_t * a, const char * xml_string,
260                                 bg_album_entry_t * after);
261 
262 void bg_album_insert_xml_after(bg_album_t * a, const char * xml_string,
263                                bg_album_entry_t * before);
264 
265 /* Load an xml string and make album entries from it */
266 
267 bg_album_entry_t *
268 bg_album_entries_new_from_xml(const char * xml_string);
269 
270 bg_album_entry_t *
271 bg_album_entry_create_from_track_info(bg_track_info_t * track_info,
272                                       const char * url);
273 
274 
275 /* Destroy the list returned from the function above */
276 
277 void bg_album_entries_destroy(bg_album_entry_t*);
278 
279 /* Check, how many they are */
280 int bg_album_entries_count(bg_album_entry_t*);
281 
282 /* Inserts a string of the type text/uri-list into the album */
283 
284 void bg_album_insert_urilist_after(bg_album_t * a, const char * xml_string,
285                                    int length, bg_album_entry_t * before);
286 
287 void bg_album_insert_urilist_before(bg_album_t * a, const char * xml_string,
288                                     int length, bg_album_entry_t * after);
289 
290 /*
291  *  Play the current track. This works only, if a tree exists and
292  *  has a play callback set
293  */
294 
295 void bg_album_play(bg_album_t * a);
296 
297 /* Get the config section */
298 
299 bg_cfg_section_t * bg_album_get_cfg_section(bg_album_t * album);
300 
301 bg_plugin_registry_t * bg_album_get_plugin_registry(bg_album_t * album);
302 
303 /* album_xml.c */
304 
305 void bg_album_insert_albums_before(bg_album_t * a,
306                                    char ** locations,
307                                    bg_album_entry_t * after);
308 
309 void bg_album_insert_albums_after(bg_album_t * a,
310                                   char ** locations,
311                                   bg_album_entry_t * after);
312 
313 void bg_album_save(bg_album_t * a, const char * filename);
314 
315 /* Export to playlist formats */
316 
317 int
318 bg_album_entries_save_extm3u(bg_album_entry_t * e, const char * name,
319                              int strip_dirs, const char * prefix);
320 
321 int
322 bg_album_entries_save_pls(bg_album_entry_t * e, const char * name,
323                           int strip_dirs, const char * prefix);
324 
325 /* Create a struing containing the xml code for the album */
326 /* Can be used for Drag & Drop for example                */
327 
328 /* Delete entries */
329 
330 void bg_album_delete_selected(bg_album_t * album);
331 
332 /* Refresh entries */
333 
334 void bg_album_refresh_selected(bg_album_t * album);
335 
336 /* Move entries */
337 
338 void bg_album_move_selected_up(bg_album_t * album);
339 void bg_album_move_selected_down(bg_album_t * album);
340 void bg_album_sort_entries(bg_album_t * album);
341 void bg_album_sort_children(bg_album_t * album);
342 
343 void bg_album_rename_track(bg_album_t * album,
344                            const bg_album_entry_t * entry,
345                            const char * name);
346 /* Return value should be free()d                         */
347 
348 char * bg_album_save_to_memory(bg_album_t * a);
349 char * bg_album_save_selected_to_memory(bg_album_t * a, int preserve_current);
350 
351 char * bg_album_selected_to_string(bg_album_t * a);
352 
353 
354 
355 /*
356  *  tree.c
357  */
358 
359 /* Media tree */
360 
361 bg_media_tree_t * bg_media_tree_create(const char * filename,
362                                        bg_plugin_registry_t * plugin_reg);
363 
364 /* Call this after the configuration is set up */
365 
366 void bg_media_tree_init(bg_media_tree_t * ret);
367 
368 
369 bg_plugin_registry_t *
370 bg_media_tree_get_plugin_registry(bg_media_tree_t *);
371 
372 bg_cfg_section_t *
373 bg_media_tree_get_cfg_section(bg_media_tree_t *);
374 
375 
376 bg_album_t * bg_media_tree_get_incoming(bg_media_tree_t *);
377 
378 bg_album_t * bg_media_tree_get_device_album(bg_media_tree_t *,
379                                             const char * gml);
380 
381 void bg_media_tree_check_sync(bg_media_tree_t * t);
382 
383 
384 void
385 bg_media_tree_set_change_callback(bg_media_tree_t *,
386                                   void (*change_callback)(bg_media_tree_t*,
387                                                           void*),
388                                   void*);
389 
390 void bg_media_tree_set_userpass_callback(bg_media_tree_t *,
391                                          int (*userpass_callback)(const char * resource,
392                                                                   char ** user, char ** pass,
393                                                                   int * save_password,
394                                                                   void * data),
395                                          void * userpass_callback_data);
396 
397 void bg_media_tree_set_play_callback(bg_media_tree_t *,
398                                      void (*play_callback)(void*),
399                                      void*);
400 
401 void bg_media_tree_destroy(bg_media_tree_t *);
402 
403 int bg_media_tree_get_num_albums(bg_media_tree_t *);
404 
405 bg_album_t * bg_media_tree_get_current_album(bg_media_tree_t *);
406 
407 void bg_media_tree_add_directory(bg_media_tree_t * t, bg_album_t * parent,
408                                  const char * directory,
409                                  int recursive,
410                                  int subdirs_to_subalbums,
411                                  int watch,
412                                  const char * plugin,
413                                  int prefer_edl);
414 
415 /* Gets a root album */
416 
417 bg_album_t * bg_media_tree_get_album(bg_media_tree_t *, int);
418 
419 void bg_album_set_devices(bg_album_t * a);
420 
421 void bg_album_find_devices(bg_album_t * a);
422 
423 
424 void bg_album_add_device(bg_album_t * a,
425                           const char * device,
426                           const char * name);
427 
428 void bg_album_remove_from_parent(bg_album_t * album);
429 
430 
431 /*
432  *  Returns an array of indices to the given album
433  *  terminated with -1 and to be freed with free()
434  */
435 
436 int * bg_media_tree_get_path(bg_media_tree_t *, bg_album_t*);
437 
438 /* Manage the tree */
439 
440 bg_album_t * bg_media_tree_append_album(bg_media_tree_t *,
441                                         bg_album_t * parent);
442 
443 void bg_media_tree_remove_album(bg_media_tree_t *,
444                                 bg_album_t * album);
445 
446 
447 /* Check if we can move an album */
448 
449 int bg_media_tree_check_move_album_before(bg_media_tree_t *,
450                                           bg_album_t * album,
451                                           bg_album_t * after);
452 
453 int bg_media_tree_check_move_album_after(bg_media_tree_t *,
454                                          bg_album_t * album,
455                                          bg_album_t * before);
456 
457 int bg_media_tree_check_move_album(bg_media_tree_t *,
458                                    bg_album_t * album,
459                                    bg_album_t * parent);
460 
461 /* Move an album inside the tree */
462 
463 void bg_media_tree_move_album_before(bg_media_tree_t *,
464                                      bg_album_t * album,
465                                      bg_album_t * after);
466 
467 void bg_media_tree_move_album_after(bg_media_tree_t *,
468                                     bg_album_t * album,
469                                     bg_album_t * before);
470 
471 void bg_media_tree_move_album(bg_media_tree_t *,
472                               bg_album_t * album,
473                               bg_album_t * parent);
474 
475 
476 /* tree_xml.c */
477 
478 void bg_media_tree_load(bg_media_tree_t *);
479 void bg_media_tree_save(bg_media_tree_t *);
480 
481 /* Set and get entries for playback */
482 
483 void bg_media_tree_set_current(void * data,
484                                bg_album_t * album,
485                                const bg_album_entry_t * entry);
486 
487 /* Get the parent directory of the last added directory */
488 
489 const char *
490 bg_media_tree_get_add_directory_path(bg_media_tree_t * t);
491 
492 void
493 bg_media_tree_set_add_directory_path(bg_media_tree_t * t, const char *);
494 
495 /* Set the next and previous track */
496 
497 int bg_media_tree_next(bg_media_tree_t *, int wrap,
498                        bg_shuffle_mode_t shuffle_mode);
499 int bg_media_tree_previous(bg_media_tree_t *, int wrap,
500                            bg_shuffle_mode_t shuffle_mode);
501 
502 bg_plugin_handle_t *
503 bg_media_tree_get_current_track(bg_media_tree_t *, int * index);
504 
505 const char * bg_media_tree_get_current_track_name(bg_media_tree_t *);
506 
507 /* Configuration stuff */
508 
509 const bg_parameter_info_t * bg_media_tree_get_parameters(bg_media_tree_t*);
510 void bg_media_tree_set_parameter(void * priv, const char * name,
511                                  const bg_parameter_value_t * val);
512 
513 int
514 bg_media_tree_get_parameter(void * priv, const char * name,
515                             bg_parameter_value_t * val);
516 
517 
518 /* Mark the current entry as error */
519 
520 void bg_media_tree_mark_error(bg_media_tree_t * , int err);
521 
522 void bg_media_tree_copy_current_to_favourites(bg_media_tree_t * t);
523 
524 #endif //  __BG_TREE_H_
525 
526