Code

po: updated Russian translation
[ncmpc.git] / src / song.c
1 /* libmpdclient
2    (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
3    This project's homepage is: http://www.musicpd.org
5    Redistribution and use in source and binary forms, with or without
6    modification, are permitted provided that the following conditions
7    are met:
9    - Redistributions of source code must retain the above copyright
10    notice, this list of conditions and the following disclaimer.
12    - Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
16    - Neither the name of the Music Player Daemon nor the names of its
17    contributors may be used to endorse or promote products derived from
18    this software without specific prior written permission.
20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 #include "song.h"
34 #include "str_pool.h"
36 #define LIBMPDCLIENT_GLIB_SLICE
38 #ifndef LIBMPDCLIENT_GLIB_SLICE
39 #include <stdlib.h>
40 #else
41 #include <glib.h>
42 #endif
44 static void mpd_initSong(struct mpd_song *song) {
45         song->file = NULL;
46         song->artist = NULL;
47         song->album = NULL;
48         song->track = NULL;
49         song->title = NULL;
50         song->name = NULL;
51         song->date = NULL;
52         /* added by Qball */
53         song->genre = NULL;
54         song->composer = NULL;
55         song->disc = NULL;
56         song->comment = NULL;
58         song->time = MPD_SONG_NO_TIME;
59         song->pos = MPD_SONG_NO_NUM;
60         song->id = MPD_SONG_NO_ID;
61 }
63 static void mpd_finishSong(struct mpd_song *song) {
64         if (song->file)
65                 str_pool_put(song->file);
66         if (song->artist)
67                 str_pool_put(song->artist);
68         if (song->album)
69                 str_pool_put(song->album);
70         if (song->title)
71                 str_pool_put(song->title);
72         if (song->track)
73                 str_pool_put(song->track);
74         if (song->name)
75                 str_pool_put(song->name);
76         if (song->date)
77                 str_pool_put(song->date);
78         if (song->genre)
79                 str_pool_put(song->genre);
80         if (song->composer)
81                 str_pool_put(song->composer);
82         if (song->disc)
83                 str_pool_put(song->disc);
84         if (song->comment)
85                 str_pool_put(song->comment);
86 }
88 struct mpd_song *mpd_newSong(void) {
89 #ifndef LIBMPDCLIENT_GLIB_SLICE
90         struct mpd_song *ret = malloc(sizeof(*ret));
91 #else
92         struct mpd_song *ret = g_slice_new(struct mpd_song);
93 #endif
95         mpd_initSong(ret);
97         return ret;
98 }
100 void mpd_freeSong(struct mpd_song *song) {
101         mpd_finishSong(song);
103 #ifndef LIBMPDCLIENT_GLIB_SLICE
104         free(song);
105 #else
106         g_slice_free(struct mpd_song, song);
107 #endif
110 struct mpd_song *mpd_songDup(const struct mpd_song *song) {
111         struct mpd_song *ret = mpd_newSong();
113         if (song->file)
114                 ret->file = str_pool_dup(song->file);
115         if (song->artist)
116                 ret->artist = str_pool_dup(song->artist);
117         if (song->album)
118                 ret->album = str_pool_dup(song->album);
119         if (song->title)
120                 ret->title = str_pool_dup(song->title);
121         if (song->track)
122                 ret->track = str_pool_dup(song->track);
123         if (song->name)
124                 ret->name = str_pool_dup(song->name);
125         if (song->date)
126                 ret->date = str_pool_dup(song->date);
127         if (song->genre)
128                 ret->genre= str_pool_dup(song->genre);
129         if (song->composer)
130                 ret->composer= str_pool_dup(song->composer);
131         if (song->disc)
132                 ret->disc = str_pool_dup(song->disc);
133         if (song->comment)
134                 ret->comment = str_pool_dup(song->comment);
136         ret->time = song->time;
137         ret->pos = song->pos;
138         ret->id = song->id;
140         return ret;