FIX: examples/supports.c: type_n: Return correct type
[libquvi.git] / src / misc / playlist.c
blob0831503c79390010ae7e27827f11f6b6a71a5f0d
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <glib.h>
25 #include "quvi.h"
26 /* -- */
27 #include "_quvi_s.h"
28 #include "_quvi_playlist_s.h"
29 /* -- */
30 #include "misc/playlist.h"
32 gpointer m_playlist_new(_quvi_t q, const gchar *url)
34 _quvi_playlist_t qp = g_new0(struct _quvi_playlist_s, 1);
35 /* URL */
36 qp->url.thumbnail = g_string_new(NULL);
37 qp->url.input = g_string_new(url);
38 /* ID */
39 qp->id.playlist = g_string_new(NULL);
40 /* Handle */
41 qp->handle.quvi = q;
42 /* Other */
43 qp->title = g_string_new(NULL);
44 return (qp);
47 void m_playlist_media_free(_quvi_playlist_media_t qpm)
49 if (qpm == NULL)
50 return;
52 g_string_free(qpm->title, TRUE);
53 qpm->title = NULL;
55 g_string_free(qpm->url, TRUE);
56 qpm->url = NULL;
58 g_free(qpm);
59 qpm = NULL;
62 static void _playlist_media_free(gpointer p, gpointer userdata)
64 m_playlist_media_free(p);
67 void m_playlist_free(_quvi_playlist_t qp)
69 if (qp == NULL)
70 return;
72 #ifdef HAVE_GLIB_2_28
73 g_slist_free_full(qp->media, _playlist_media_free);
74 #else
75 g_slist_foreach(qp->media, _playlist_media_free, NULL);
76 g_slist_free(qp->media);
77 #endif
78 qp->media = NULL;
80 /* URL */
82 g_string_free(qp->url.thumbnail, TRUE);
83 qp->url.thumbnail = NULL;
85 g_string_free(qp->url.input, TRUE);
86 qp->url.input = NULL;
88 /* ID */
90 g_string_free(qp->id.playlist, TRUE);
91 qp->id.playlist = NULL;
93 /* Other */
95 g_string_free(qp->title, TRUE);
96 qp->title = NULL;
98 g_free(qp);
99 qp = NULL;
102 /* vim: set ts=2 sw=2 tw=72 expandtab: */