~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/dbUtils.c

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 
 * http://www.musicpd.org
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License along
16
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
#include "dbUtils.h"
22
 
#include "locate.h"
23
 
#include "database.h"
24
 
#include "db_visitor.h"
25
 
#include "playlist.h"
26
 
#include "stored_playlist.h"
27
 
 
28
 
#include <glib.h>
29
 
 
30
 
static bool
31
 
add_to_queue_song(struct song *song, void *ctx, GError **error_r)
32
 
{
33
 
        struct player_control *pc = ctx;
34
 
 
35
 
        enum playlist_result result =
36
 
                playlist_append_song(&g_playlist, pc, song, NULL);
37
 
        if (result != PLAYLIST_RESULT_SUCCESS) {
38
 
                g_set_error(error_r, playlist_quark(), result,
39
 
                            "Playlist error");
40
 
                return false;
41
 
        }
42
 
 
43
 
        return true;
44
 
}
45
 
 
46
 
static const struct db_visitor add_to_queue_visitor = {
47
 
        .song = add_to_queue_song,
48
 
};
49
 
 
50
 
bool
51
 
addAllIn(struct player_control *pc, const char *uri, GError **error_r)
52
 
{
53
 
        return db_walk(uri, &add_to_queue_visitor, pc, error_r);
54
 
}
55
 
 
56
 
struct add_data {
57
 
        const char *path;
58
 
};
59
 
 
60
 
static bool
61
 
add_to_spl_song(struct song *song, void *ctx, GError **error_r)
62
 
{
63
 
        struct add_data *data = ctx;
64
 
 
65
 
        if (!spl_append_song(data->path, song, error_r))
66
 
                return false;
67
 
 
68
 
        return true;
69
 
}
70
 
 
71
 
static const struct db_visitor add_to_spl_visitor = {
72
 
        .song = add_to_spl_song,
73
 
};
74
 
 
75
 
bool
76
 
addAllInToStoredPlaylist(const char *uri_utf8, const char *path_utf8,
77
 
                         GError **error_r)
78
 
{
79
 
        struct add_data data = {
80
 
                .path = path_utf8,
81
 
        };
82
 
 
83
 
        return db_walk(uri_utf8, &add_to_spl_visitor, &data, error_r);
84
 
}
85
 
 
86
 
struct find_add_data {
87
 
        struct player_control *pc;
88
 
        const struct locate_item_list *criteria;
89
 
};
90
 
 
91
 
static bool
92
 
find_add_song(struct song *song, void *ctx, GError **error_r)
93
 
{
94
 
        struct find_add_data *data = ctx;
95
 
 
96
 
        if (!locate_song_match(song, data->criteria))
97
 
                return true;
98
 
 
99
 
        enum playlist_result result =
100
 
                playlist_append_song(&g_playlist, data->pc,
101
 
                                     song, NULL);
102
 
        if (result != PLAYLIST_RESULT_SUCCESS) {
103
 
                g_set_error(error_r, playlist_quark(), result,
104
 
                            "Playlist error");
105
 
                return false;
106
 
        }
107
 
 
108
 
        return true;
109
 
}
110
 
 
111
 
static const struct db_visitor find_add_visitor = {
112
 
        .song = find_add_song,
113
 
};
114
 
 
115
 
bool
116
 
findAddIn(struct player_control *pc, const char *name,
117
 
          const struct locate_item_list *criteria, GError **error_r)
118
 
{
119
 
        struct find_add_data data;
120
 
        data.pc = pc;
121
 
        data.criteria = criteria;
122
 
 
123
 
        return db_walk(name, &find_add_visitor, &data, error_r);
124
 
}
125
 
 
126
 
static bool
127
 
searchadd_visitor_song(struct song *song, void *_data, GError **error_r)
128
 
{
129
 
        struct find_add_data *data = _data;
130
 
 
131
 
        if (!locate_song_search(song, data->criteria))
132
 
                return true;
133
 
 
134
 
        enum playlist_result result =
135
 
                playlist_append_song(&g_playlist, data->pc, song, NULL);
136
 
        if (result != PLAYLIST_RESULT_SUCCESS) {
137
 
                g_set_error(error_r, playlist_quark(), result,
138
 
                            "Playlist error");
139
 
                return false;
140
 
        }
141
 
 
142
 
        return true;
143
 
}
144
 
 
145
 
static const struct db_visitor searchadd_visitor = {
146
 
        .song = searchadd_visitor_song,
147
 
};
148
 
 
149
 
bool
150
 
search_add_songs(struct player_control *pc, const char *uri,
151
 
                 const struct locate_item_list *criteria,
152
 
                 GError **error_r)
153
 
{
154
 
        struct locate_item_list *new_list =
155
 
                locate_item_list_casefold(criteria);
156
 
        struct find_add_data data = {
157
 
                .pc = pc,
158
 
                .criteria = new_list,
159
 
        };
160
 
 
161
 
        bool success = db_walk(uri, &searchadd_visitor, &data, error_r);
162
 
 
163
 
        locate_item_list_free(new_list);
164
 
 
165
 
        return success;
166
 
}
167
 
 
168
 
struct search_add_playlist_data {
169
 
        const char *playlist;
170
 
        const struct locate_item_list *criteria;
171
 
};
172
 
 
173
 
static bool
174
 
searchaddpl_visitor_song(struct song *song, void *_data,
175
 
                         G_GNUC_UNUSED GError **error_r)
176
 
{
177
 
        struct search_add_playlist_data *data = _data;
178
 
 
179
 
        if (!locate_song_search(song, data->criteria))
180
 
                return true;
181
 
 
182
 
        if (!spl_append_song(data->playlist, song, error_r))
183
 
                return false;
184
 
 
185
 
        return true;
186
 
}
187
 
 
188
 
static const struct db_visitor searchaddpl_visitor = {
189
 
        .song = searchaddpl_visitor_song,
190
 
};
191
 
 
192
 
bool
193
 
search_add_to_playlist(const char *uri, const char *path_utf8,
194
 
                       const struct locate_item_list *criteria,
195
 
                       GError **error_r)
196
 
{
197
 
        struct locate_item_list *new_list
198
 
                = locate_item_list_casefold(criteria);
199
 
        struct search_add_playlist_data data = {
200
 
                .playlist = path_utf8,
201
 
                .criteria = new_list,
202
 
        };
203
 
 
204
 
        bool success = db_walk(uri, &searchaddpl_visitor, &data, error_r);
205
 
 
206
 
        locate_item_list_free(new_list);
207
 
 
208
 
        return success;
209
 
}