Add/Update translations
[gmpc-dynamic-playlist.git] / src / prune.c
blob037c04b897f276e0b39ac69d415e8dc3bf6e2079
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.
20 #include "prune.h"
21 #include "plugin.h"
22 #include <gmpc/playlist3-messages.h>
23 #include <libmpd/libmpd.h>
24 #include <glib/gi18n-lib.h>
25 #include "defaults.h"
27 static gint m_keep = -1;
29 void init_prune()
31 m_keep = cfg_get_single_value_as_int_with_default(config, "dynamic-playlist", "keep", -1);
34 void set_prune_value(gint l_value)
36 m_keep = l_value;
37 cfg_set_single_value_as_int(config, "dynamic-playlist", "keep", m_keep);
40 gint get_prune_value()
42 return m_keep;
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)
53 return;
55 gint del;
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);
69 return;
72 mpd_Song* curSong = mpd_playlist_get_current_song(connection);
73 if(curSong == NULL)
75 playlist3_show_error_message(_("Cannot prune playlist! You need to play a song for pruning."), ERROR_INFO);
76 return;
79 if(l_param[0] == '\0')
80 prune_playlist(curSong->pos);
81 else
82 prune_playlist_value(curSong->pos, atoi(l_param));
85 /* vim:set ts=4 sw=4: */