1 /* gmpc-dynamic-playlist (GMPC plugin)
2 * Copyright (C) 2009 Andre Klitzing <andre@incubo.de>
3 * Homepage: http://www.incubo.de
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gmpc/playlist3-messages.h>
23 #include <libmpd/libmpd.h>
24 #include <glib/gi18n-lib.h>
27 static gint m_keep
= -1;
31 m_keep
= cfg_get_single_value_as_int_with_default(config
, "dynamic-playlist", "keep", -1);
34 void set_prune_value(gint l_value
)
37 cfg_set_single_value_as_int(config
, "dynamic-playlist", "keep", m_keep
);
40 gint
get_prune_value()
45 void prune_playlist(gint l_curPos
)
47 prune_playlist_value(l_curPos
, m_keep
);
50 void prune_playlist_value(gint l_curPos
, gint l_keep
)
52 if(l_keep
< 0 || l_curPos
< 1)
56 for(del
= 0; del
< l_curPos
- l_keep
; ++del
)
57 mpd_playlist_queue_delete_pos(connection
, 0);
59 mpd_playlist_queue_commit(connection
);
62 void prune_playlist_easy(G_GNUC_UNUSED gpointer l_data
, const gchar
* l_param
)
64 g_assert(l_param
!= NULL
);
66 if(!dyn_get_enabled())
68 playlist3_show_error_message(_("Dynamic playlist is disabled"), ERROR_INFO
);
72 mpd_Song
* curSong
= mpd_playlist_get_current_song(connection
);
75 playlist3_show_error_message(_("Cannot prune playlist! You need to play a song for pruning."), ERROR_INFO
);
79 if(l_param
[0] == '\0')
80 prune_playlist(curSong
->pos
);
82 prune_playlist_value(curSong
->pos
, atoi(l_param
));
85 /* vim:set ts=4 sw=4: */