Bug Summary

File:build-analysis/../src/clients/nycli/commands_playlist.c
Warning:line 345, column 6
Function call argument is an uninitialized value

Annotated Source Code

1/* XMMS2 - X Music Multiplexer System
2 * Copyright (C) 2003-2017 XMMS2 Team
3 *
4 * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program 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 GNU
14 * General Public License for more details.
15 */
16
17#include <stdlib.h>
18#include <string.h>
19#include <sys/stat.h>
20
21#include <glib.h>
22#include <glib/gi18n.h>
23#include <glib/gprintf.h>
24
25#include <xmmsclient/xmmsclient.h>
26
27#include "cli_context.h"
28#include "column_display.h"
29#include "command.h"
30#include "commands.h"
31#include "configuration.h"
32#include "matching_browse.h"
33#include "playlist_positions.h"
34#include "xmmscall.h"
35#include "utils.h"
36
37typedef struct cli_move_positions_St {
38 xmmsc_connection_t *sync;
39 const gchar *playlist;
40 gint inc;
41 gint pos;
42} cli_move_positions_t;
43
44typedef struct cli_list_positions_St {
45 xmmsc_connection_t *sync;
46 column_display_t *coldisp;
47 xmmsv_t *entries;
48} cli_list_positions_t;
49
50typedef struct cli_remove_positions_St {
51 xmmsc_connection_t *sync;
52 const gchar *playlist;
53} cli_remove_positions_t;
54
55typedef void (*cli_list_print_func_t)(cli_context_t *ctx, column_display_t *coldisp, xmmsv_t *list, gpointer udata);
56
57static gint
58g_direct_compare (gconstpointer x, gconstpointer y)
59{
60 if (x > y)
61 return 1;
62 if (x < y)
63 return -1;
64 return 0;
65}
66
67static GTree *
68g_tree_new_from_xmmsv (xmmsv_t *list)
69{
70 xmmsv_list_iter_t *it;
71 GTree *tree;
72 gint id;
73
74 tree = g_tree_new (g_direct_compare);
75
76 xmmsv_get_list_iter (list, &it);
77 while (xmmsv_list_iter_entry_intxmmsv_list_iter_entry_int32 (it, &id)) {
78 g_tree_insert (tree, GINT_TO_POINTER (id)((gpointer) (glong) (id)), GINT_TO_POINTER (id)((gpointer) (glong) (id)));
79 xmmsv_list_iter_next (it);
80 }
81
82 return tree;
83}
84
85static void
86playlist_coll_attribute_get_position (xmmsv_t *coll, gint *pos)
87{
88 const gchar *str = NULL((void*)0);
89 if (xmmsv_coll_attribute_get_string (coll, "position", &str)) {
90 *pos = strtol (str, NULL((void*)0), 10);
91 } else {
92 *pos = -1;
93 }
94}
95
96/* Get current position in @playlist or in active playlist if
97 @playlist == NULL. */
98static gboolean
99playlist_currpos_get (cli_context_t *ctx, const gchar *playlist, gint *pos)
100{
101 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
102
103 if (playlist) {
5
Assuming 'playlist' is non-null
6
Taking true branch
104 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { playlist_coll_attribute_get_position (XMMS_PREV_VALUE
, pos); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
7
Within the expansion of the macro 'XMMS_CALL_CHAIN':
a
Assuming the condition is true
105 FUNC_CALL_P (playlist_coll_attribute_get_position, XMMS_PREV_VALUE, pos))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { playlist_coll_attribute_get_position (XMMS_PREV_VALUE
, pos); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
;
106 } else {
107 *pos = cli_context_current_position (ctx);
108 }
109
110 return TRUE(!(0));
111}
112
113static void
114playlist_coll_idlist_get_size (xmmsv_t *coll, gint *length)
115{
116 *length = xmmsv_coll_idlist_get_size (coll);
117}
118
119/* Get length of @playlist or of active playlist if @playlist == NULL. */
120static gboolean
121playlist_length_get (cli_context_t *ctx, const gchar *playlist, gint *length)
122{
123 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
124
125 *length = -1;
126
127 if (playlist) {
128 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { playlist_coll_idlist_get_size (XMMS_PREV_VALUE
, length); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
129 FUNC_CALL_P (playlist_coll_idlist_get_size, XMMS_PREV_VALUE, length))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { playlist_coll_idlist_get_size (XMMS_PREV_VALUE
, length); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
;
130 } else {
131 xmmsv_t *entries = cli_context_active_playlist (ctx);
132 *length = xmmsv_list_get_size (entries);
133 }
134
135 return *length >= 0;
136}
137
138static gboolean
139cmd_flag_pos_get_playlist (cli_context_t *ctx, command_t *cmd,
140 gint *pos, const gchar *playlist)
141{
142 gboolean next, at_isset;
143 gint at;
144 gint tmp = -1;
145
146 at_isset = command_flag_int_get (cmd, "at", &at);
147 command_flag_boolean_get (cmd, "next", &next);
148
149 if (next && at_isset) {
150 g_printf (_("Error: --next and --at are mutually exclusive!\n")gettext ("Error: --next and --at are mutually exclusive!\n"));
151 return FALSE(0);
152 } else if (next) {
153 playlist_currpos_get (ctx, playlist, &tmp);
154 if (tmp == -1) {
155 /* no current position, next == append */
156 if (!playlist_length_get (ctx, playlist, pos)) {
157 return FALSE(0);
158 }
159 } else {
160 *pos = tmp + 1;
161 }
162 } else if (at_isset) {
163 if (!playlist_length_get (ctx, playlist, &tmp)) {
164 return FALSE(0);
165 }
166
167 if (at == 0 || (at > 0 && at > tmp + 1)) {
168 g_printf (_("Error: specified position is outside the playlist!\n")gettext ("Error: specified position is outside the playlist!\n"
)
);
169 return FALSE(0);
170 } else {
171 *pos = at - 1; /* playlist ids start at 0 */
172 }
173 } else {
174 /* default to append */
175 playlist_length_get (ctx, playlist, pos);
176 }
177
178 return TRUE(!(0));
179}
180
181static column_display_t *
182cli_list_classic_column_display (cli_context_t *ctx)
183{
184 configuration_t *config = cli_context_config (ctx);
185 column_display_t *coldisp;
186 const gchar *format, *marker;
187
188 marker = configuration_get_string (config, "PLAYLIST_MARKER");
189 format = configuration_get_string (config, "CLASSIC_LIST_FORMAT");
190
191 /* FIXME: compute field size dynamically instead of hardcoding maxlen? */
192
193 coldisp = column_display_init ();
194
195 column_display_set_list_marker (coldisp, marker);
196
197 column_display_add_special (coldisp, "",
198 GINT_TO_POINTER(cli_context_current_position (ctx))((gpointer) (glong) (cli_context_current_position (ctx))), 2,
199 COLUMN_DEF_SIZE_FIXED,
200 COLUMN_DEF_ALIGN_LEFT,
201 column_display_render_highlight);
202 column_display_add_separator (coldisp, "[");
203 column_display_add_special (coldisp, "pos", NULL((void*)0), 0,
204 COLUMN_DEF_SIZE_AUTO,
205 COLUMN_DEF_ALIGN_RIGHT,
206 column_display_render_position);
207 column_display_add_separator (coldisp, "/");
208 column_display_add_property (coldisp, "id", "id", 0,
209 COLUMN_DEF_SIZE_AUTO,
210 COLUMN_DEF_ALIGN_LEFT);
211 column_display_add_separator (coldisp, "] ");
212
213 column_display_add_format (coldisp, "tracks", format, 0,
214 COLUMN_DEF_SIZE_AUTO,
215 COLUMN_DEF_ALIGN_LEFT);
216
217 /* FIXME: making duration part of the format would require proper
218 * rendering of duration in xmmsv_dict_format and conditional
219 * expressions to the parentheses if no duration is present. */
220
221 /* FIXME: if time takes 6 chars, the display will exceed termwidth.. */
222 column_display_add_separator (coldisp, " (");
223 column_display_add_special (coldisp, "duration", (gpointer) "duration", 5,
224 COLUMN_DEF_SIZE_FIXED,
225 COLUMN_DEF_ALIGN_LEFT,
226 column_display_render_time);
227 column_display_add_separator (coldisp, ")");
228
229 return coldisp;
230}
231
232
233static void
234cli_list_print_row (column_display_t *coldisp, xmmsv_t *propdict)
235{
236 xmmsv_t *info = xmmsv_propdict_to_dict (propdict, NULL((void*)0));
237 enrich_mediainfo (info);
238 column_display_print (coldisp, info);
239}
240
241static void
242cli_list_print_positions_row (gint pos, void *udata)
243{
244 cli_list_positions_t *pack = (cli_list_positions_t *) udata;
245 gint id;
246
247 if (pos >= xmmsv_list_get_size (pack->entries)) {
248 return;
249 }
250
251 if (xmmsv_list_get_intxmmsv_list_get_int32 (pack->entries, pos, &id)) {
252 column_display_set_position (pack->coldisp, pos);
253 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, pack->sync, id),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_medialib_get_info
(pack->sync, id); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print_row (pack->coldisp, XMMS_PREV_VALUE); } } while
(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
254 FUNC_CALL_P (cli_list_print_row, pack->coldisp, XMMS_PREV_VALUE))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_medialib_get_info
(pack->sync, id); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print_row (pack->coldisp, XMMS_PREV_VALUE); } } while
(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
;
255 }
256}
257
258static void
259cli_list_print_positions (cli_context_t *ctx, column_display_t *coldisp,
260 xmmsv_t *list, gpointer udata)
261{
262 cli_list_positions_t pudata = {
263 .sync = cli_context_xmms_sync (ctx),
264 .coldisp = coldisp,
265 .entries = list
266 };
267 playlist_positions_t *positions = (playlist_positions_t *) udata;
268 playlist_positions_foreach (positions, cli_list_print_positions_row, TRUE(!(0)), &pudata);
269}
270
271static void
272cli_list_print_ids (cli_context_t *ctx, column_display_t *coldisp,
273 xmmsv_t *list, gpointer udata)
274{
275 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
276 xmmsv_list_iter_t *it;
277 GTree *lookup = NULL((void*)0);
278 gint id;
279
280 xmmsv_t *filter = (xmmsv_t *) udata;
281
282 if (filter != NULL((void*)0))
283 lookup = g_tree_new_from_xmmsv (filter);
284
285 xmmsv_get_list_iter (list, &it);
286 while (xmmsv_list_iter_entry_intxmmsv_list_iter_entry_int32 (it, &id)) {
287 column_display_set_position (coldisp, xmmsv_list_iter_tell (it));
288 if (lookup == NULL((void*)0) || g_tree_lookup (lookup, GINT_TO_POINTER (id)((gpointer) (glong) (id))) != NULL((void*)0)) {
289 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, conn, id),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_medialib_get_info
(conn, id); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print_row (coldisp, XMMS_PREV_VALUE); } } while (0)
; } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
290 FUNC_CALL_P (cli_list_print_row, coldisp, XMMS_PREV_VALUE))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_medialib_get_info
(conn, id); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print_row (coldisp, XMMS_PREV_VALUE); } } while (0)
; } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
;
291 }
292 xmmsv_list_iter_next (it);
293 }
294
295 if (lookup)
296 g_tree_destroy (lookup);
297}
298
299static void
300cli_list_print (cli_context_t *ctx, xmmsv_t *list,
301 column_display_t *coldisp, gboolean column_style,
302 cli_list_print_func_t func, gpointer udata)
303{
304 column_display_prepare (coldisp);
305 if (column_style) {
306 column_display_print_header (coldisp);
307 }
308
309 func (ctx, coldisp, list, udata);
310
311 if (column_style) {
312 column_display_print_footer (coldisp);
313 } else {
314 g_printf ("\n");
315 column_display_print_footer_totaltime (coldisp);
316 }
317
318 column_display_free (coldisp);
319}
320
321gboolean
322cli_list (cli_context_t *ctx, command_t *cmd)
323{
324 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
325 configuration_t *config = cli_context_config (ctx);
326 playlist_positions_t *positions;
327 column_display_t *coldisp;
328 xmmsv_t *query = NULL((void*)0);
329 gboolean column_style, filter_by_pos = FALSE(0);
330 const gchar *default_columns[] = { "curr", "pos", "id", "artist", "album", "title", NULL((void*)0) };
331 const gchar *playlist;
332 gchar *pattern = NULL((void*)0);
333 gint pos;
1
'pos' declared without an initial value
334
335 /* Default to active playlist (from cache) */
336 if (!command_flag_string_get (cmd, "playlist", &playlist)) {
2
Assuming the condition is false
3
Taking false branch
337 playlist = XMMS_ACTIVE_PLAYLIST"_active";
338 }
339
340 if (!playlist_currpos_get (ctx, playlist, &pos)) {
4
Calling 'playlist_currpos_get'
8
Returning from 'playlist_currpos_get'
9
Taking false branch
341 g_printf (_("Error: failed to get current position in playlist.\n")gettext ("Error: failed to get current position in playlist.\n"
)
);
342 return FALSE(0);
343 }
344
345 if (command_arg_positions_get (cmd, 0, &positions, pos)) {
10
Function call argument is an uninitialized value
346 filter_by_pos = TRUE(!(0));
347 } else if (command_arg_longstring_get_escaped (cmd, 0, &pattern)) {
348 if (!xmmsv_coll_parse (pattern, &query)) {
349 g_printf (_("Error: failed to parse the pattern!\n")gettext ("Error: failed to parse the pattern!\n"));
350 g_free (pattern);
351 return FALSE(0);
352 }
353 }
354
355 /* Has filter, retrieve ids from intersection */
356 if (query != NULL((void*)0)) {
357 query = xmmsv_coll_intersect_with_playlist (query, playlist);
358 }
359
360 column_style = !configuration_get_boolean (config, "CLASSIC_LIST");
361 if (column_style) {
362 const gchar *playlist_marker;
363 playlist_marker = configuration_get_string (config, "PLAYLIST_MARKER");
364 coldisp = column_display_build (default_columns, playlist_marker, cli_context_current_position (ctx));
365 } else {
366 coldisp = cli_list_classic_column_display (ctx);
367 }
368
369 if (filter_by_pos) {
370 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_list_entries, conn, playlist),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print (ctx, XMMS_PREV_VALUE, coldisp, column_style,
cli_list_print_positions, positions); } } while (0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
371 FUNC_CALL_P (cli_list_print, ctx, XMMS_PREV_VALUE, coldisp, column_style, cli_list_print_positions, positions))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print (ctx, XMMS_PREV_VALUE, coldisp, column_style,
cli_list_print_positions, positions); } } while (0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
;
372 } else if (query != NULL((void*)0)) {
373 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_list_entries, conn, playlist),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_playlist_list_entries (conn
, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, query, ((void*)0), 0, 0); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } if (XMMS_PREV_VALUE != ((void*)0))
{ XMMS_SECOND_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (
XMMS_PREV_VALUE != ((void*)0)) { cli_list_print (ctx, XMMS_FIRST_VALUE
, coldisp, column_style, cli_list_print_ids, XMMS_SECOND_VALUE
); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, ((void*)0) }; gint __i
= 0; for (__i = 0; __i < (sizeof (__values) / sizeof ((__values
)[0])); __i++) { if (__values[__i] != ((void*)0)) xmmsv_unref
(__values[__i]); } } while (0); } while (0)
374 XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_playlist_list_entries (conn
, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, query, ((void*)0), 0, 0); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } if (XMMS_PREV_VALUE != ((void*)0))
{ XMMS_SECOND_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (
XMMS_PREV_VALUE != ((void*)0)) { cli_list_print (ctx, XMMS_FIRST_VALUE
, coldisp, column_style, cli_list_print_ids, XMMS_SECOND_VALUE
); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, ((void*)0) }; gint __i
= 0; for (__i = 0; __i < (sizeof (__values) / sizeof ((__values
)[0])); __i++) { if (__values[__i] != ((void*)0)) xmmsv_unref
(__values[__i]); } } while (0); } while (0)
375 FUNC_CALL_P (cli_list_print, ctx, XMMS_FIRST_VALUE, coldisp, column_style, cli_list_print_ids, XMMS_SECOND_VALUE))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_playlist_list_entries (conn
, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, query, ((void*)0), 0, 0); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } if (XMMS_PREV_VALUE != ((void*)0))
{ XMMS_SECOND_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (
XMMS_PREV_VALUE != ((void*)0)) { cli_list_print (ctx, XMMS_FIRST_VALUE
, coldisp, column_style, cli_list_print_ids, XMMS_SECOND_VALUE
); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, ((void*)0) }; gint __i
= 0; for (__i = 0; __i < (sizeof (__values) / sizeof ((__values
)[0])); __i++) { if (__values[__i] != ((void*)0)) xmmsv_unref
(__values[__i]); } } while (0); } while (0)
;
376 xmmsv_unref (query);
377 } else {
378 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_list_entries, conn, playlist),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print (ctx, XMMS_PREV_VALUE, coldisp, column_style,
cli_list_print_ids, ((void*)0)); } } while (0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
379 FUNC_CALL_P (cli_list_print, ctx, XMMS_PREV_VALUE, coldisp, column_style, cli_list_print_ids, NULL))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_list_print (ctx, XMMS_PREV_VALUE, coldisp, column_style,
cli_list_print_ids, ((void*)0)); } } while (0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
;
380 }
381
382 if (filter_by_pos) {
383 playlist_positions_free (positions);
384 }
385
386 g_free (pattern);
387
388 return FALSE(0);
389}
390
391static gboolean
392cli_add_guesspls (cli_context_t *ctx, const gchar *url)
393{
394 configuration_t *config = cli_context_config (ctx);
395
396 if (!configuration_get_boolean (config, "GUESS_PLS")) {
397 return FALSE(0);
398 }
399
400 if (g_str_has_suffix (url, ".m3u") || g_str_has_suffix (url, ".pls")) {
401 return TRUE(!(0));
402 }
403
404 return FALSE(0);
405}
406
407static gboolean
408cli_add_guessfile (const gchar *pattern)
409{
410 char *p;
411 struct stat filestat;
412
413 /* if matches a local path, it's probably a file */
414 if (stat (pattern, &filestat) == 0 &&
415 (S_ISREG(filestat.st_mode)((((filestat.st_mode)) & 0170000) == (0100000)) || S_ISDIR(filestat.st_mode)((((filestat.st_mode)) & 0170000) == (0040000)))) {
416 return TRUE(!(0));
417 }
418
419 p = strpbrk (pattern, ":/~");
420
421 if (!p) {
422 /* Doesn't contain any of the chars above, not a file? */
423 return FALSE(0);
424 } else if (p[0] == ':' && p[1] == '/' && p[2] == '/') {
425 /* Contains '://', likely a URL */
426 return TRUE(!(0));
427 } else if (p == pattern && p[0] == '/') {
428 /* Starts with '/', should be an absolute path */
429 return TRUE(!(0));
430 } else if (p == pattern && p[0] == '~' && strchr (p, '/')) {
431 /* Starts with '~' and contains '/', should be a home path */
432 return TRUE(!(0));
433 }
434
435 return FALSE(0);
436}
437
438/**
439 * Build a dict out of a number of key=value strings.
440 *
441 * @return a dict with 0..n attributes.
442 */
443static xmmsv_t *
444cli_add_parse_attributes (command_t *cmd)
445{
446 const gchar **attributes;
447 xmmsv_t *result;
448 gint i;
449
450 result = xmmsv_new_dict ();
451
452 if (command_flag_stringarray_get (cmd, "attribute", &attributes)) {
453 for (i = 0; attributes[i] != NULL((void*)0); i++) {
454 gchar **parts = g_strsplit (attributes[i], "=", 2);
455 if (parts[0] != NULL((void*)0) && parts[1] != NULL((void*)0)) {
456 xmmsv_dict_set_string (result, parts[0], parts[1]);
457 }
458 g_strfreev (parts);
459 }
460 }
461
462 return result;
463}
464
465/**
466 * Helper function for cli_add.
467 *
468 * Add the contents of a playlist file (specified by a url)
469 * to a playlist at a given position.
470 */
471static void
472cli_add_playlist_file (cli_context_t *ctx, const gchar *url,
473 const gchar *playlist, gint pos)
474{
475 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
476 gchar *decoded = decode_url (url);
477 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_idlist_from_playlist_file, conn, decoded),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_idlist_from_playlist_file
(conn, decoded); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_add_idlist
(conn, playlist, XMMS_PREV_VALUE); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
478 XMMS_CALL_P (xmmsc_playlist_add_idlist, conn, playlist, XMMS_PREV_VALUE))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_idlist_from_playlist_file
(conn, decoded); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_add_idlist
(conn, playlist, XMMS_PREV_VALUE); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
;
479 g_free (decoded);
480}
481
482/**
483 * Helper function for cli_add.
484 *
485 * Add a file specified by a url to a playlist at a given id.
486 */
487static void
488cli_add_file (cli_context_t *ctx, const gchar *url,
489 const gchar *playlist, gint pos, xmmsv_t *attrs)
490{
491 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
492 gchar *decoded = decode_url (url);
493 XMMS_CALL (xmmsc_playlist_insert_full, conn, playlist, pos, decoded, attrs)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_insert_full (conn, playlist
, pos, decoded, attrs); xmmsc_result_wait (__result); __value
= xmmsc_result_get_value (__result); if (xmmsv_get_error (__value
, &__message)) { g_printf (gettext ("Server error: %s\n")
, __message); } xmmsc_result_unref (__result); } while (0)
;
494 g_free (decoded);
495}
496
497/**
498 * Helper function for cli_add.
499 *
500 * Add a directory to a playlist recursively at a given position.
501 */
502static void
503cli_add_dir (cli_context_t *ctx, const gchar *url,
504 const gchar *playlist, gint pos)
505{
506 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
507 XMMS_CALL (xmmsc_playlist_rinsert_encoded, conn, playlist, pos, url)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_rinsert_encoded (conn, playlist
, pos, url); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
508}
509
510/**
511 * Helper function for cli_add.
512 *
513 * Process and add file arguments to a playlist at a given position.
514 * The files may be regular or playlist files.
515 *
516 * @return whether media has been added to the playlist.
517 */
518static gboolean
519cli_add_fileargs (cli_context_t *ctx, command_t *cmd,
520 const gchar *playlist, gint pos)
521{
522 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
523 gint i;
524 gboolean plsfile, norecurs, ret = FALSE(0);
525 xmmsv_t *attributes;
526
527 command_flag_boolean_get (cmd, "pls", &plsfile);
528 command_flag_boolean_get (cmd, "non-recursive", &norecurs);
529 attributes = cli_add_parse_attributes (cmd);
530
531 for (i = 0; i < command_arg_count (cmd); i++) {
532 GList *files, *it;
533 const gchar *path;
534 gchar *formatted, *encoded;
535
536 command_arg_string_get (cmd, i, &path);
537 formatted = format_url (path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR);
538 if (formatted == NULL((void*)0)) {
539 g_printf (_("Warning: Skipping invalid url '%s'.\n")gettext ("Warning: Skipping invalid url '%s'.\n"), path);
540 continue;
541 }
542
543 encoded = encode_url (formatted);
544 files = matching_browse (conn, encoded);
545
546 for (it = g_list_first (files); it != NULL((void*)0); it = g_list_next (it)((it) ? (((GList *)(it))->next) : ((void*)0))) {
547 const gchar *url;
548 gboolean is_directory;
549 browse_entry_t *entry = it->data;
550
551 browse_entry_get (entry, &url, &is_directory);
552
553 if (plsfile || cli_add_guesspls (ctx, url)) {
554 if (xmmsv_dict_get_size (attributes) > 0) {
555 g_printf (_("Warning: Skipping attributes together with playlist.\n")gettext ("Warning: Skipping attributes together with playlist.\n"
)
);
556 }
557
558 cli_add_playlist_file (ctx, url, playlist, pos);
559 } else if (norecurs || !is_directory) {
560 cli_add_file (ctx, url, playlist, pos, attributes);
561 } else {
562 if (xmmsv_dict_get_size (attributes) > 0) {
563 g_printf (_("Warning: Skipping attributes together with directory.\n")gettext ("Warning: Skipping attributes together with directory.\n"
)
);
564 }
565
566 cli_add_dir (ctx, url, playlist, pos);
567 }
568
569 pos++; /* next insert at next pos, to keep order */
570 browse_entry_free (entry);
571
572 ret = TRUE(!(0));
573 }
574
575 g_free (encoded);
576 g_free (formatted);
577 g_list_free (files);
578 }
579
580 xmmsv_unref (attributes);
581 return ret;
582}
583
584/**
585 * Add a list of ids to a playlist, starting at a given position.
586 *
587 * TODO: xmmsc_playlist_insert_collection should return the number of entries
588 * it inserted, and then this function will become meaningless.
589 */
590static void
591cli_add_collection (cli_context_t *ctx, xmmsv_t *ids, xmmsv_t *query,
592 const gchar *playlist, gint pos, gboolean *success)
593
594{
595 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
596 if (xmmsv_list_get_size (ids) > 0) {
597 XMMS_CALL (xmmsc_playlist_insert_collection, conn, playlist, pos, query, NULL)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_insert_collection (conn,
playlist, pos, query, ((void*)0)); xmmsc_result_wait (__result
); __value = xmmsc_result_get_value (__result); if (xmmsv_get_error
(__value, &__message)) { g_printf (gettext ("Server error: %s\n"
), __message); } xmmsc_result_unref (__result); } while (0)
;
598 *success = TRUE(!(0));
599 }
600}
601
602/**
603 * Helper function for cli_add.
604 *
605 * Process and add pattern arguments to a playlist at a given position.
606 *
607 * @return Whether any media has been added to the playlist.
608 */
609static gboolean
610cli_add_pattern (cli_context_t *ctx, command_t *cmd,
611 const gchar *playlist, gint pos, gboolean _stdin)
612{
613 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
614 xmmsv_t *query = NULL((void*)0), *ordered_query;
615 const gchar **order = NULL((void*)0);
616 gchar *pattern = NULL((void*)0);
617 gboolean success = FALSE(0);
618
619 if (_stdin) {
620 query = xmmsv_coll_from_stdin();
621 } else {
622 command_arg_pattern_get (cmd, 0, &query, TRUE(!(0)));
623 }
624
625 command_arg_longstring_get_escaped (cmd, 0, &pattern);
626
627 if (query) {
628 if (command_flag_stringlist_get (cmd, "order", &order)) {
629 xmmsv_t *orderval = xmmsv_make_stringlist ((gchar **) order, -1);
630 ordered_query = xmmsv_coll_add_order_operators (query, orderval);
631
632 xmmsv_unref (orderval);
633 } else {
634 ordered_query = xmmsv_coll_apply_default_order (query);
635 }
636
637 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, ordered_query, NULL, 0, 0),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, ordered_query, ((void*)0), 0, 0); xmmsc_result_wait (
__result); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_add_collection (ctx, XMMS_PREV_VALUE, ordered_query
, playlist, pos, &success); } } while (0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
638 FUNC_CALL_P (cli_add_collection, ctx, XMMS_PREV_VALUE, ordered_query, playlist, pos, &success))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, ordered_query, ((void*)0), 0, 0); xmmsc_result_wait (
__result); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_add_collection (ctx, XMMS_PREV_VALUE, ordered_query
, playlist, pos, &success); } } while (0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
;
639
640 xmmsv_unref (ordered_query);
641 xmmsv_unref (query);
642 }
643
644 g_free (pattern);
645 g_free (order);
646
647 return success;
648}
649
650gboolean
651cli_add (cli_context_t *ctx, command_t *cmd)
652{
653 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
654 gint pos, i;
655 const gchar *playlist;
656 gboolean forceptrn, plsfile, fileargs, jump, added, pattern_from_stdin;
657
658 /*
659 --file Add a path from the local filesystem
660 --non-recursive Do not add directories recursively.
661 --playlist Add to the given playlist.
662 --next Add after the current track.
663 --at Add media at a given position in the playlist, or at a given offset from the current track.
664 --order Order media matched by pattern.
665 --stdin Get pattern from stdin (inline mode only)
666 */
667
668 /* FIXME: offsets not supported (need to identify positive offsets) :-( */
669 if (!command_flag_string_get (cmd, "playlist", &playlist)) {
670 playlist = XMMS_ACTIVE_PLAYLIST"_active";
671 }
672
673 if (!cmd_flag_pos_get_playlist (ctx, cmd, &pos, playlist)) {
674 return FALSE(0);
675 }
676
677 command_flag_boolean_get (cmd, "stdin", &pattern_from_stdin);
678 command_flag_boolean_get (cmd, "pattern", &forceptrn);
679 command_flag_boolean_get (cmd, "pls", &plsfile);
680 command_flag_boolean_get (cmd, "file", &fileargs);
681 command_flag_boolean_get (cmd, "jump", &jump);
682
683 fileargs = fileargs || plsfile;
684 forceptrn = forceptrn || pattern_from_stdin;
685 if (forceptrn && fileargs) {
686 g_printf (_("Error: --pattern is mutually exclusive with "gettext ("Error: --pattern is mutually exclusive with " "--file and --pls!\n"
)
687 "--file and --pls!\n")gettext ("Error: --pattern is mutually exclusive with " "--file and --pls!\n"
)
);
688 return FALSE(0);
689 } else if (cli_context_in_mode(ctx, CLI_EXECUTION_MODE_SHELL) && pattern_from_stdin) {
690 g_printf (_("Error: --stdin can be used in inline mode only.\n")gettext ("Error: --stdin can be used in inline mode only.\n"));
691 return FALSE(0);
692 }
693
694 if (!forceptrn) {
695 /* if any of the arguments is a valid path, we treat them all as files */
696 for (i = 0; !fileargs && i < command_arg_count (cmd); i++) {
697 const gchar *path;
698
699 command_arg_string_get (cmd, i, &path);
700 fileargs = fileargs || cli_add_guessfile (path);
701 }
702 }
703
704 if (fileargs) {
705 added = cli_add_fileargs (ctx, cmd, playlist, pos);
706 } else {
707 gboolean norecurs;
708 xmmsv_t *attributes;
709
710 command_flag_boolean_get (cmd, "non-recursive", &norecurs);
711 if (norecurs) {
712 g_printf (_("Error:"gettext ("Error:" "--non-recursive only applies when passing --file!\n"
)
713 "--non-recursive only applies when passing --file!\n")gettext ("Error:" "--non-recursive only applies when passing --file!\n"
)
);
714 return FALSE(0);
715 }
716
717 attributes = cli_add_parse_attributes (cmd);
718 if (xmmsv_dict_get_size (attributes) > 0) {
719 g_printf (_("Warning: Skipping attributes together with pattern.\n")gettext ("Warning: Skipping attributes together with pattern.\n"
)
);
720 }
721
722 xmmsv_unref (attributes);
723
724 added = cli_add_pattern (ctx, cmd, playlist, pos, pattern_from_stdin);
725 }
726
727 if (added && jump) {
728 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next, conn, pos),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_set_next
(conn, pos); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playback_tickle
(conn); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE !=
((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE =
((void*)0); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
729 XMMS_CALL_P (xmmsc_playback_tickle, conn))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_set_next
(conn, pos); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playback_tickle
(conn); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE !=
((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE =
((void*)0); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
;
730 }
731
732 return FALSE(0);
733}
734
735static void
736cli_move_positions (gint curr, void *userdata)
737{
738 cli_move_positions_t *pack = (cli_move_positions_t *) userdata;
739
740 /* Entries are moved in descending order, pack->inc is used as
741 * offset both for forward and backward moves, and reset
742 * inbetween. */
743
744 if (curr < pack->pos) {
745 /* moving forward */
746 if (pack->inc >= 0) {
747 pack->inc = -1; /* start inc at -1, decrement */
748 }
749 XMMS_CALL (xmmsc_playlist_move_entry, pack->sync,do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (pack->sync
, pack->playlist, curr, pack->pos + pack->inc); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
750 pack->playlist, curr, pack->pos + pack->inc)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (pack->sync
, pack->playlist, curr, pack->pos + pack->inc); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
;
751 pack->inc--;
752 } else {
753 /* moving backward */
754 XMMS_CALL (xmmsc_playlist_move_entry, pack->sync,do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (pack->sync
, pack->playlist, curr + pack->inc, pack->pos); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
755 pack->playlist, curr + pack->inc, pack->pos)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (pack->sync
, pack->playlist, curr + pack->inc, pack->pos); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
;
756 pack->inc++;
757 }
758}
759
760static void
761cli_move_entries (xmmsv_t *matching, xmmsv_t *lisval, cli_context_t *ctx,
762 const gchar *playlist, gint pos)
763{
764 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
765 xmmsv_list_iter_t *it;
766 gint curr, id, inc;
767 gboolean up;
768
769 /* store matching mediaids in a tree (faster lookup) */
770 GTree *list = g_tree_new_from_xmmsv (matching);
771
772 /* move matched playlist items */
773 curr = 0;
774 inc = 0;
775 up = TRUE(!(0));
776
777 xmmsv_get_list_iter (lisval, &it);
778 while (xmmsv_list_iter_entry_intxmmsv_list_iter_entry_int32 (it, &id)) {
779 if (curr == pos) {
780 up = FALSE(0);
781 }
782 if (g_tree_lookup (list, GINT_TO_POINTER (id)((gpointer) (glong) (id))) != NULL((void*)0)) {
783 if (up) {
784 /* moving forward */
785 XMMS_CALL (xmmsc_playlist_move_entry,do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (conn, playlist
, curr - inc, pos - 1); xmmsc_result_wait (__result); __value
= xmmsc_result_get_value (__result); if (xmmsv_get_error (__value
, &__message)) { g_printf (gettext ("Server error: %s\n")
, __message); } xmmsc_result_unref (__result); } while (0)
786 conn, playlist, curr - inc, pos - 1)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (conn, playlist
, curr - inc, pos - 1); xmmsc_result_wait (__result); __value
= xmmsc_result_get_value (__result); if (xmmsv_get_error (__value
, &__message)) { g_printf (gettext ("Server error: %s\n")
, __message); } xmmsc_result_unref (__result); } while (0)
;
787 } else {
788 /* moving backward */
789 XMMS_CALL (xmmsc_playlist_move_entry,do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (conn, playlist
, curr, pos + inc); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
790 conn, playlist, curr, pos + inc)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_move_entry (conn, playlist
, curr, pos + inc); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
791 }
792 inc++;
793 }
794 curr++;
795
796 xmmsv_list_iter_next (it);
797 }
798
799 g_tree_destroy (list);
800}
801
802gboolean
803cli_move (cli_context_t *ctx, command_t *cmd)
804{
805 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
806 playlist_positions_t *positions;
807 const gchar *playlist;
808 xmmsv_t *query;
809 gint pos;
810
811 if (!command_flag_string_get (cmd, "playlist", &playlist)) {
812 playlist = NULL((void*)0);
813 }
814
815 if (!cmd_flag_pos_get_playlist (ctx, cmd, &pos, playlist)) {
816 g_printf (_("Error: you must provide a position to move entries to!\n")gettext ("Error: you must provide a position to move entries to!\n"
)
);
817 return FALSE(0);
818 }
819
820 if (command_arg_positions_get (cmd, 0, &positions, cli_context_current_position (ctx))) {
821 cli_move_positions_t udata = {
822 .sync = conn,
823 .playlist = playlist,
824 .inc = 0,
825 .pos = pos
826 };
827 playlist_positions_foreach (positions, cli_move_positions, FALSE(0), &udata);
828 playlist_positions_free (positions);
829 } else if (command_arg_pattern_get (cmd, 0, &query, TRUE(!(0)))) {
830 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_coll_query_ids (conn, query
, ((void*)0), 0, 0); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_SECOND_VALUE
= xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != (
(void*)0)) { cli_move_entries (XMMS_FIRST_VALUE, XMMS_SECOND_VALUE
, ctx, playlist, pos); } } while (0); } do { xmmsv_t *__values
[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, (
(void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values
) / sizeof ((__values)[0])); __i++) { if (__values[__i] != ((
void*)0)) xmmsv_unref (__values[__i]); } } while (0); } while
(0)
831 XMMS_CALL_P (xmmsc_playlist_list_entries, conn, playlist),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_coll_query_ids (conn, query
, ((void*)0), 0, 0); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_SECOND_VALUE
= xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != (
(void*)0)) { cli_move_entries (XMMS_FIRST_VALUE, XMMS_SECOND_VALUE
, ctx, playlist, pos); } } while (0); } do { xmmsv_t *__values
[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, (
(void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values
) / sizeof ((__values)[0])); __i++) { if (__values[__i] != ((
void*)0)) xmmsv_unref (__values[__i]); } } while (0); } while
(0)
832 FUNC_CALL_P (cli_move_entries, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, ctx, playlist, pos))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_coll_query_ids (conn, query
, ((void*)0), 0, 0); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_SECOND_VALUE
= xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != (
(void*)0)) { cli_move_entries (XMMS_FIRST_VALUE, XMMS_SECOND_VALUE
, ctx, playlist, pos); } } while (0); } do { xmmsv_t *__values
[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, (
(void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values
) / sizeof ((__values)[0])); __i++) { if (__values[__i] != ((
void*)0)) xmmsv_unref (__values[__i]); } } while (0); } while
(0)
;
833 xmmsv_unref (query);
834 }
835
836 return FALSE(0);
837}
838
839static void
840cli_remove_ids (cli_context_t *ctx, const gchar *playlist,
841 xmmsv_t *matchval, xmmsv_t *plistval)
842{
843 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
844 xmmsv_list_iter_t *matchit, *plistit;
845 gint plid, id, offset;
846
847 offset = 0;
848
849 xmmsv_get_list_iter (matchval, &matchit);
850 xmmsv_get_list_iter (plistval, &plistit);
851
852 /* Loop on the playlist */
853 while (xmmsv_list_iter_entry_intxmmsv_list_iter_entry_int32 (plistit, &plid)) {
854 xmmsv_list_iter_first (matchit);
855
856 /* Loop on the matched media */
857 while (xmmsv_list_iter_entry_intxmmsv_list_iter_entry_int32 (matchit, &id)) {
858 /* If both match, remove */
859 if (plid == id) {
860 XMMS_CALL (xmmsc_playlist_remove_entry, conn, playlist,do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_remove_entry (conn, playlist
, xmmsv_list_iter_tell (plistit) - offset); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
861 xmmsv_list_iter_tell (plistit) - offset)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_remove_entry (conn, playlist
, xmmsv_list_iter_tell (plistit) - offset); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
;
862 offset++;
863 break;
864 }
865 xmmsv_list_iter_next (matchit);
866 }
867 xmmsv_list_iter_next (plistit);
868 }
869}
870
871static void
872cli_remove_positions_each (gint pos, void *udata)
873{
874 cli_remove_positions_t *pack = (cli_remove_positions_t *) udata;
875 XMMS_CALL (xmmsc_playlist_remove_entry, pack->sync, pack->playlist, pos)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_remove_entry (pack->sync
, pack->playlist, pos); xmmsc_result_wait (__result); __value
= xmmsc_result_get_value (__result); if (xmmsv_get_error (__value
, &__message)) { g_printf (gettext ("Server error: %s\n")
, __message); } xmmsc_result_unref (__result); } while (0)
;
876}
877
878gboolean
879cli_remove (cli_context_t *ctx, command_t *cmd)
880{
881 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
882 const gchar *playlist;
883 xmmsv_t *query;
884 playlist_positions_t *positions;
885
886 if (!command_flag_string_get (cmd, "playlist", &playlist)) {
887 playlist = cli_context_active_playlist_name (ctx);
888 }
889
890 if (command_arg_positions_get (cmd, 0, &positions, cli_context_current_position (ctx))) {
891 cli_remove_positions_t udata = {
892 .sync = conn,
893 .playlist = playlist
894 };
895 playlist_positions_foreach (positions, cli_remove_positions_each, FALSE(0), &udata);
896 playlist_positions_free (positions);
897 } else if (command_arg_pattern_get (cmd, 0, &query, TRUE(!(0)))) {
898 if (!playlist) {
899 xmmsv_t *entries = cli_context_active_playlist (ctx);
900 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, query, ((void*)0), 0, 0); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_remove_ids (ctx, playlist, XMMS_PREV_VALUE
, entries); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
901 FUNC_CALL_P (cli_remove_ids, ctx, playlist, XMMS_PREV_VALUE, entries))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_query_ids
(conn, query, ((void*)0), 0, 0); xmmsc_result_wait (__result
); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_remove_ids (ctx, playlist, XMMS_PREV_VALUE
, entries); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
;
902 } else {
903 query = xmmsv_coll_intersect_with_playlist (query, playlist);
904 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_coll_query_ids (conn, query
, ((void*)0), 0, 0); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_SECOND_VALUE
= xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != (
(void*)0)) { cli_remove_ids (ctx, playlist, XMMS_FIRST_VALUE,
XMMS_SECOND_VALUE); } } while (0); } do { xmmsv_t *__values[
] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, (
(void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values
) / sizeof ((__values)[0])); __i++) { if (__values[__i] != ((
void*)0)) xmmsv_unref (__values[__i]); } } while (0); } while
(0)
905 XMMS_CALL_P (xmmsc_playlist_list_entries, conn, playlist),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_coll_query_ids (conn, query
, ((void*)0), 0, 0); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_SECOND_VALUE
= xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != (
(void*)0)) { cli_remove_ids (ctx, playlist, XMMS_FIRST_VALUE,
XMMS_SECOND_VALUE); } } while (0); } do { xmmsv_t *__values[
] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, (
(void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values
) / sizeof ((__values)[0])); __i++) { if (__values[__i] != ((
void*)0)) xmmsv_unref (__values[__i]); } } while (0); } while
(0)
906 FUNC_CALL_P (cli_remove_ids, ctx, playlist, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE, *XMMS_SECOND_VALUE
; XMMS_PREV_VALUE = XMMS_FIRST_VALUE = XMMS_SECOND_VALUE = ((
void*)0); do { xmmsc_result_t *__result; const gchar *__message
; xmmsv_t *__value; __result = xmmsc_coll_query_ids (conn, query
, ((void*)0), 0, 0); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { xmmsc_result_t *__result; const gchar
*__message; xmmsv_t *__value; __result = xmmsc_playlist_list_entries
(conn, playlist); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE
!= ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE
= ((void*)0); __value = xmmsc_result_get_value (__result); if
(xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); } if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_SECOND_VALUE
= xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != (
(void*)0)) { cli_remove_ids (ctx, playlist, XMMS_FIRST_VALUE,
XMMS_SECOND_VALUE); } } while (0); } do { xmmsv_t *__values[
] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, XMMS_SECOND_VALUE, (
(void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values
) / sizeof ((__values)[0])); __i++) { if (__values[__i] != ((
void*)0)) xmmsv_unref (__values[__i]); } } while (0); } while
(0)
;
907 }
908 xmmsv_unref (query);
909 }
910
911 return FALSE(0);
912}
913
914static void
915cli_pl_list_print (xmmsv_t *list, cli_context_t *ctx, gboolean show_hidden)
916{
917 const gchar *playlist, *s;
918 xmmsv_list_iter_t *it;
919
920 playlist = cli_context_active_playlist_name (ctx);
921
922 xmmsv_get_list_iter (list, &it);
923 while (xmmsv_list_iter_entry_string (it, &s)) {
924 /* Skip hidden playlists if all is FALSE*/
925 if ((*s != '_') || show_hidden) {
926 /* Highlight active playlist */
927 if (g_strcmp0 (s, playlist) == 0) {
928 g_printf ("* %s\n", s);
929 } else {
930 g_printf (" %s\n", s);
931 }
932 }
933 xmmsv_list_iter_next (it);
934 }
935}
936
937gboolean
938cli_pl_list (cli_context_t *ctx, command_t *cmd)
939{
940 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
941 gboolean all;
942
943 /* FIXME: support pattern argument (only display playlist containing matching media) */
944
945 command_flag_boolean_get (cmd, "all", &all);
946
947 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_list, conn),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_list
(conn); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE !=
((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE =
((void*)0); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_pl_list_print (XMMS_PREV_VALUE, ctx, all); } } while (0)
; } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
948 FUNC_CALL_P (cli_pl_list_print, XMMS_PREV_VALUE, ctx, all))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_playlist_list
(conn); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE !=
((void*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE =
((void*)0); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } else { XMMS_PREV_VALUE
= xmmsv_ref (__value); } xmmsc_result_unref (__result); } while
(0); if (XMMS_PREV_VALUE != ((void*)0)) { XMMS_FIRST_VALUE = xmmsv_ref
(XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE != ((void*)0)) {
cli_pl_list_print (XMMS_PREV_VALUE, ctx, all); } } while (0)
; } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
;
949
950 return FALSE(0);
951}
952
953gboolean
954cli_pl_switch (cli_context_t *ctx, command_t *cmd)
955{
956 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
957 gchar *playlist;
958
959 if (!command_arg_longstring_get (cmd, 0, &playlist)) {
960 g_printf (_("Error: failed to read new playlist name!\n")gettext ("Error: failed to read new playlist name!\n"));
961 return FALSE(0);
962 }
963
964 XMMS_CALL (xmmsc_playlist_load, conn, playlist)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_load (conn, playlist); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
;
965
966 g_free (playlist);
967
968 return FALSE(0);
969}
970
971static gboolean
972cli_pl_create_check_exists (cli_context_t *ctx, const gchar *playlist)
973{
974 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
975 xmmsc_result_t *res;
976 xmmsv_t *val;
977 gboolean retval = FALSE(0);
978
979 res = xmmsc_coll_get (conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS"Playlists");
980 xmmsc_result_wait (res);
981
982 val = xmmsc_result_get_value (res);
983 if (!xmmsv_is_error (val)) {
984 retval = TRUE(!(0));
985 }
986
987 xmmsc_result_unref (res);
988
989 return retval;
990}
991
992gboolean
993cli_pl_create (cli_context_t *ctx, command_t *cmd)
994{
995 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
996 gboolean switch_to;
997 gchar *newplaylist;
998 const gchar *copy;
999
1000 if (!command_arg_longstring_get (cmd, 0, &newplaylist)) {
1001 g_printf (_("Error: failed to read new playlist name!\n")gettext ("Error: failed to read new playlist name!\n"));
1002 return FALSE(0);
1003 }
1004
1005 if (!command_flag_boolean_get (cmd, "switch", &switch_to)) {
1006 switch_to = FALSE(0);
1007 }
1008
1009 /* FIXME: Prevent overwriting existing playlists! */
1010 if (cli_pl_create_check_exists (ctx, newplaylist)) {
1011 g_printf (_("Error: playlist %s already exists!\n")gettext ("Error: playlist %s already exists!\n"), newplaylist);
1012 return FALSE(0);
1013 }
1014
1015 if (command_flag_string_get (cmd, "playlist", &copy)) {
1016 /* Copy the given playlist. */
1017 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, copy, XMMS_COLLECTION_NS_PLAYLISTS),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, copy, "Playlists"); xmmsc_result_wait (__result); if (
XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE);
XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { xmmsc_result_t
*__result; const gchar *__message; xmmsv_t *__value; __result
= xmmsc_coll_save (conn, XMMS_PREV_VALUE, newplaylist, "Playlists"
); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE != ((void
*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE = ((void
*)0); __value = xmmsc_result_get_value (__result); if (xmmsv_get_error
(__value, &__message)) { g_printf (gettext ("Server error: %s\n"
), __message); } else { XMMS_PREV_VALUE = xmmsv_ref (__value)
; } xmmsc_result_unref (__result); } while(0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
1018 XMMS_CALL_P (xmmsc_coll_save, conn, XMMS_PREV_VALUE, newplaylist, XMMS_COLLECTION_NS_PLAYLISTS))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, copy, "Playlists"); xmmsc_result_wait (__result); if (
XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE);
XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { xmmsc_result_t
*__result; const gchar *__message; xmmsv_t *__value; __result
= xmmsc_coll_save (conn, XMMS_PREV_VALUE, newplaylist, "Playlists"
); xmmsc_result_wait (__result); if (XMMS_PREV_VALUE != ((void
*)0)) xmmsv_unref (XMMS_PREV_VALUE); XMMS_PREV_VALUE = ((void
*)0); __value = xmmsc_result_get_value (__result); if (xmmsv_get_error
(__value, &__message)) { g_printf (gettext ("Server error: %s\n"
), __message); } else { XMMS_PREV_VALUE = xmmsv_ref (__value)
; } xmmsc_result_unref (__result); } while(0); } do { xmmsv_t
*__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE, ((void*)0
) }; gint __i = 0; for (__i = 0; __i < (sizeof (__values) /
sizeof ((__values)[0])); __i++) { if (__values[__i] != ((void
*)0)) xmmsv_unref (__values[__i]); } } while (0); } while (0)
;
1019 } else {
1020 /* Simply create a new empty playlist */
1021 XMMS_CALL (xmmsc_playlist_create, conn, newplaylist)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_create (conn, newplaylist
); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1022 }
1023
1024 if (switch_to) {
1025 XMMS_CALL (xmmsc_playlist_load, conn, newplaylist)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_load (conn, newplaylist)
; xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1026 }
1027
1028 g_free (newplaylist);
1029
1030 return FALSE(0);
1031}
1032
1033gboolean
1034cli_pl_rename (cli_context_t *ctx, command_t *cmd)
1035{
1036 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1037 gboolean force;
1038 const gchar *oldname;
1039 gchar *newname;
1040
1041 if (!command_flag_boolean_get (cmd, "force", &force)) {
1042 force = FALSE(0);
1043 }
1044
1045 if (!command_arg_longstring_get (cmd, 0, &newname)) {
1046 g_printf (_("Error: failed to read new playlist name!\n")gettext ("Error: failed to read new playlist name!\n"));
1047 return FALSE(0);
1048 }
1049
1050 if (!command_flag_string_get (cmd, "playlist", &oldname)) {
1051 oldname = cli_context_active_playlist_name (ctx);
1052 }
1053
1054 if (force) {
1055 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, newname, XMMS_COLLECTION_NS_PLAYLISTS),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, newname, "Playlists"); xmmsc_result_wait (__result); if
(XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { xmmsc_result_t
*__result; const gchar *__message; xmmsv_t *__value; __result
= xmmsc_coll_remove (conn, newname, "Playlists"); xmmsc_result_wait
(__result); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (
XMMS_PREV_VALUE); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
1056 XMMS_CALL_P (xmmsc_coll_remove, conn, newname, XMMS_COLLECTION_NS_PLAYLISTS))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, newname, "Playlists"); xmmsc_result_wait (__result); if
(XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { xmmsc_result_t
*__result; const gchar *__message; xmmsv_t *__value; __result
= xmmsc_coll_remove (conn, newname, "Playlists"); xmmsc_result_wait
(__result); if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (
XMMS_PREV_VALUE); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
;
1057 }
1058
1059 XMMS_CALL (xmmsc_coll_rename, conn, oldname, newname, XMMS_COLLECTION_NS_PLAYLISTS)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_coll_rename (conn, oldname, newname
, "Playlists"); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1060
1061 g_free (newname);
1062
1063 return FALSE(0);
1064}
1065
1066gboolean
1067cli_pl_remove (cli_context_t *ctx, command_t *cmd)
1068{
1069 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1070 gchar *playlist;
1071
1072 if (!command_arg_longstring_get (cmd, 0, &playlist)) {
1073 g_printf (_("Error: failed to read the playlist name!\n")gettext ("Error: failed to read the playlist name!\n"));
1074 return FALSE(0);
1075 }
1076
1077 /* Do not remove active playlist! */
1078 if (strcmp (playlist, cli_context_active_playlist_name (ctx)) == 0) {
1079 g_printf (_("Error: you cannot remove the active playlist!\n")gettext ("Error: you cannot remove the active playlist!\n"));
1080 g_free (playlist);
1081 return FALSE(0);
1082 }
1083
1084 XMMS_CALL (xmmsc_playlist_remove, conn, playlist)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_remove (conn, playlist);
xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1085
1086 g_free (playlist);
1087
1088 return FALSE(0);
1089}
1090
1091gboolean
1092cli_pl_clear (cli_context_t *ctx, command_t *cmd)
1093{
1094 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1095 gchar *playlist;
1096
1097 if (!command_arg_longstring_get (cmd, 0, &playlist)) {
1098 playlist = g_strdup (cli_context_active_playlist_name (ctx));
1099 }
1100
1101 XMMS_CALL (xmmsc_playlist_clear, conn, playlist)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_clear (conn, playlist); xmmsc_result_wait
(__result); __value = xmmsc_result_get_value (__result); if (
xmmsv_get_error (__value, &__message)) { g_printf (gettext
("Server error: %s\n"), __message); } xmmsc_result_unref (__result
); } while (0)
;
1102
1103 g_free (playlist);
1104
1105 return FALSE(0);
1106}
1107
1108gboolean
1109cli_pl_shuffle (cli_context_t *ctx, command_t *cmd)
1110{
1111 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1112 gchar *playlist;
1113
1114 if (!command_arg_longstring_get (cmd, 0, &playlist)) {
1115 playlist = g_strdup (cli_context_active_playlist_name (ctx));
1116 }
1117
1118 XMMS_CALL (xmmsc_playlist_shuffle, conn, playlist)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_shuffle (conn, playlist)
; xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1119 g_free (playlist);
1120
1121 return FALSE(0);
1122}
1123
1124gboolean
1125cli_pl_sort (cli_context_t *ctx, command_t *cmd)
1126{
1127 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1128 xmmsv_t *orderval;
1129 const gchar *playlist;
1130
1131 if (!command_flag_string_get (cmd, "playlist", &playlist)) {
1132 playlist = XMMS_ACTIVE_PLAYLIST"_active";
1133 }
1134
1135 if (command_arg_count (cmd) == 0) {
1136 orderval = xmmsv_new_list ();
1137 xmmsv_list_append_string (orderval, "artist");
1138 xmmsv_list_append_string (orderval, "album");
1139 xmmsv_list_append_string (orderval, "tracknr");
1140 } else {
1141 gchar **order = command_argv_get (cmd);
1142 orderval = xmmsv_make_stringlist (order, -1);
1143 }
1144
1145 XMMS_CALL (xmmsc_playlist_sort, conn, playlist, orderval)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_playlist_sort (conn, playlist, orderval
); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1146
1147 xmmsv_unref (orderval);
1148
1149 return FALSE(0);
1150}
1151
1152static void
1153cli_pl_config_print (xmmsv_t *coll, const gchar *name)
1154{
1155 const gchar *type, *upcoming, *history, *jumplist;
1156 xmmsv_t *operands, *operand;
1157
1158 g_printf (_("name: %s\n")gettext ("name: %s\n"), name);
1159
1160 if (xmmsv_coll_attribute_get_string (coll, "type", &type))
1161 g_printf (_("type: %s\n")gettext ("type: %s\n"), type);
1162
1163 if (xmmsv_coll_attribute_get_string (coll, "history", &history))
1164 g_printf (_("history: %s\n")gettext ("history: %s\n"), history);
1165
1166 if (xmmsv_coll_attribute_get_string (coll, "upcoming", &upcoming))
1167 g_printf (_("upcoming: %s\n")gettext ("upcoming: %s\n"), upcoming);
1168
1169 operands = xmmsv_coll_operands_get (coll);
1170 if (xmmsv_list_get (operands, 0, &operand)) {
1171 if (xmmsv_coll_is_type (operand, XMMS_COLLECTION_TYPE_REFERENCE)) {
1172 const gchar *input_ns = NULL((void*)0);
1173 const gchar *input = NULL((void*)0);
1174
1175 xmmsv_coll_attribute_get_string (operand, "namespace", &input_ns);
1176 xmmsv_coll_attribute_get_string (operand, "reference", &input);
1177
1178 g_printf (_("input: %s/%s\n")gettext ("input: %s/%s\n"), input_ns, input);
1179 }
1180 }
1181
1182 if (xmmsv_coll_attribute_get_string (coll, "jumplist", &jumplist))
1183 g_printf (_("jumplist: %s\n")gettext ("jumplist: %s\n"), jumplist);
1184}
1185
1186static void
1187cli_pl_config_apply (xmmsv_t *val, cli_context_t *ctx, const gchar *playlist,
1188 gint history, gint upcoming, const gchar *typestr,
1189 const gchar *input, const gchar *jumplist)
1190{
1191 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1192 xmmsv_t *newcoll = NULL((void*)0);
1193
1194 /* If no type string passed, and collection didn't have any, there's no point
1195 * in configuring the other attributes.
1196 */
1197 if (typestr == NULL((void*)0) && !xmmsv_coll_attribute_get_string (val, "type", &typestr))
1198 return;
1199
1200 if (typestr) {
1201 xmmsv_coll_attribute_set_string (val, "type", typestr);
1202 }
1203 if (history >= 0) {
1204 xmmsv_coll_attribute_set_int (val, "history", history);
1205 }
1206 if (upcoming >= 0) {
1207 xmmsv_coll_attribute_set_int (val, "upcoming", upcoming);
1208 }
1209 if (input) {
1210 /* Replace previous operand. */
1211 newcoll = xmmsv_new_coll (XMMS_COLLECTION_TYPE_REFERENCE);
1212 xmmsv_coll_attribute_set_string (newcoll, "reference", input);
1213 xmmsv_coll_attribute_set_string (newcoll, "namespace", XMMS_COLLECTION_NS_COLLECTIONS"Collections");
1214 } else if (typestr && strcmp (typestr, "pshuffle") == 0 &&
1215 xmmsv_list_get_size (xmmsv_coll_operands_get (val)) == 0) {
1216 newcoll = xmmsv_new_coll (XMMS_COLLECTION_TYPE_UNIVERSE);
1217 }
1218
1219 if (newcoll) {
1220 xmmsv_list_clear (xmmsv_coll_operands_get (val));
1221 xmmsv_coll_add_operand (val, newcoll);
1222 xmmsv_unref (newcoll);
1223 }
1224 if (jumplist) {
1225 /* FIXME: Check for the existence of the target ? */
1226 xmmsv_coll_attribute_set_string (val, "jumplist", jumplist);
1227 }
1228
1229 XMMS_CALL (xmmsc_coll_save, conn, val, playlist, XMMS_COLLECTION_NS_PLAYLISTS)do { xmmsc_result_t *__result; const gchar *__message; xmmsv_t
*__value; __result = xmmsc_coll_save (conn, val, playlist, "Playlists"
); xmmsc_result_wait (__result); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } xmmsc_result_unref
(__result); } while (0)
;
1230}
1231
1232gboolean
1233cli_pl_config (cli_context_t *ctx, command_t *cmd)
1234{
1235 xmmsc_connection_t *conn = cli_context_xmms_sync (ctx);
1236 const gchar *playlist;
1237 gchar *ptr = NULL((void*)0);
1238 gint history, upcoming;
1239 gboolean modif = FALSE(0);
1240 const gchar *input, *jumplist, *typestr;
1241
1242 history = -1;
1243 upcoming = -1;
1244 input = NULL((void*)0);
1245 jumplist = NULL((void*)0);
1246
1247 /* Convert type string to type id */
1248 if (command_flag_string_get (cmd, "type", &typestr)) {
1249 modif = TRUE(!(0));
1250 } else {
1251 typestr = NULL((void*)0);
1252 }
1253
1254 if (command_flag_int_get (cmd, "history", &history)) {
1255 modif = TRUE(!(0));
1256 }
1257 if (command_flag_int_get (cmd, "upcoming", &upcoming)) {
1258 modif = TRUE(!(0));
1259 }
1260
1261 /* FIXME: extract namespace too */
1262 if (command_flag_string_get (cmd, "input", &input)) {
1263 modif = TRUE(!(0));
1264 }
1265
1266 if (command_flag_string_get (cmd, "jumplist", &jumplist)) {
1267 modif = TRUE(!(0));
1268 }
1269
1270 if (command_arg_longstring_get (cmd, 0, &ptr)) {
1271 playlist = ptr;
1272 } else {
1273 playlist = cli_context_active_playlist_name (ctx);
1274 }
1275
1276 if (modif) {
1277 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_pl_config_apply (XMMS_PREV_VALUE, ctx, playlist
, history, upcoming, typestr, input, jumplist); } } while (0)
; } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
1278 FUNC_CALL_P (cli_pl_config_apply, XMMS_PREV_VALUE, ctx, playlist, history, upcoming, typestr, input, jumplist))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_pl_config_apply (XMMS_PREV_VALUE, ctx, playlist
, history, upcoming, typestr, input, jumplist); } } while (0)
; } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE, XMMS_FIRST_VALUE
, ((void*)0) }; gint __i = 0; for (__i = 0; __i < (sizeof (
__values) / sizeof ((__values)[0])); __i++) { if (__values[__i
] != ((void*)0)) xmmsv_unref (__values[__i]); } } while (0); }
while (0)
;
1279 } else {
1280 /* Display current config of the playlist. */
1281 XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS),do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_pl_config_print (XMMS_PREV_VALUE, playlist
); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
1282 FUNC_CALL_P (cli_pl_config_print, XMMS_PREV_VALUE, playlist))do { xmmsv_t *XMMS_PREV_VALUE, *XMMS_FIRST_VALUE; XMMS_PREV_VALUE
= XMMS_FIRST_VALUE = ((void*)0); do { xmmsc_result_t *__result
; const gchar *__message; xmmsv_t *__value; __result = xmmsc_coll_get
(conn, playlist, "Playlists"); xmmsc_result_wait (__result);
if (XMMS_PREV_VALUE != ((void*)0)) xmmsv_unref (XMMS_PREV_VALUE
); XMMS_PREV_VALUE = ((void*)0); __value = xmmsc_result_get_value
(__result); if (xmmsv_get_error (__value, &__message)) {
g_printf (gettext ("Server error: %s\n"), __message); } else
{ XMMS_PREV_VALUE = xmmsv_ref (__value); } xmmsc_result_unref
(__result); } while(0); if (XMMS_PREV_VALUE != ((void*)0)) {
XMMS_FIRST_VALUE = xmmsv_ref (XMMS_PREV_VALUE); do { if (XMMS_PREV_VALUE
!= ((void*)0)) { cli_pl_config_print (XMMS_PREV_VALUE, playlist
); } } while (0); } do { xmmsv_t *__values[] = { XMMS_PREV_VALUE
, XMMS_FIRST_VALUE, ((void*)0) }; gint __i = 0; for (__i = 0;
__i < (sizeof (__values) / sizeof ((__values)[0])); __i++
) { if (__values[__i] != ((void*)0)) xmmsv_unref (__values[__i
]); } } while (0); } while (0)
;
1283 }
1284
1285 if (ptr != NULL((void*)0)) {
1286 g_free (ptr);
1287 }
1288
1289 return FALSE(0);
1290}