diff --git a/src/mpdclient.c b/src/mpdclient.c
index aa420eec1280455d922894bde4e1ab8489243654..4a12515752b9037366d99f1662022ea4269289e3 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
#include "config.h"
#include "options.h"
#include "strfsong.h"
+#include "utils.h"
#include <stdlib.h>
#include <unistd.h>
#define BUFSIZE 1024
-#define MPD_ERROR(c) (c==NULL || c->connection==NULL || c->connection->error)
-
-/* from utils.c */
-extern GList *string_list_free(GList *string_list);
-
+static bool
+MPD_ERROR(const struct mpdclient *client)
+{
+ return client == NULL || client->connection==NULL ||
+ client->connection->error != MPD_ERROR_SUCCESS;
+}
/* filelist sorting functions */
static gint
/* Error callbacks */
static gint
-error_cb(mpdclient_t *c, gint error, gchar *msg)
+error_cb(mpdclient_t *c, gint error, const gchar *msg)
{
GList *list = c->error_callbacks;
c = g_malloc0(sizeof(mpdclient_t));
playlist_init(&c->playlist);
+ c->volume = MPD_STATUS_NO_VOLUME;
return c;
}
{
gint retval = 0;
+ c->volume = MPD_STATUS_NO_VOLUME;
+
if (MPD_ERROR(c))
return -1;
if ((retval=mpdclient_finish_command(c)))
return retval;
+ if (c->updatingdb && c->updatingdb != c->status->updatingDb)
+ mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
+
+ c->updatingdb = c->status->updatingDb;
+ c->volume = c->status->volume;
+
/* check if the playlist needs an update */
if (c->playlist.id != c->status->playlist) {
if (playlist_is_empty(&c->playlist))
gint
mpdclient_cmd_crop(mpdclient_t *c)
{
+ gint error;
mpd_Status *status;
- int length;
+ bool playing;
+ int length, current;
mpd_sendStatusCommand(c->connection);
status = mpd_getStatus(c->connection);
- length = status->playlistLength - 1;
+ error = mpdclient_finish_command(c);
+ if (error)
+ return error;
- if (length <= 0) {
- mpd_freeStatus(status);
- } else if (status->state == 3 || status->state == 2) {
- /* If playing or paused */
+ playing = status->state == MPD_STATUS_STATE_PLAY ||
+ status->state == MPD_STATUS_STATE_PAUSE;
+ length = status->playlistLength;
+ current = status->song;
- mpd_sendCommandListBegin( c->connection );
+ mpd_freeStatus(status);
- while (length >= 0) {
- if (length != status->song)
- mpd_sendDeleteCommand(c->connection, length);
+ if (!playing || length < 2)
+ return 0;
- length--;
- }
+ mpd_sendCommandListBegin( c->connection );
- mpd_sendCommandListEnd(c->connection);
- mpd_freeStatus(status);
- } else {
- mpd_freeStatus(status);
- }
+ while (--length >= 0)
+ if (length != current)
+ mpd_sendDeleteCommand(c->connection, length);
+
+ mpd_sendCommandListEnd(c->connection);
return mpdclient_finish_command(c);
}
return mpdclient_finish_command(c);
}
+gint
+mpdclient_cmd_consume(mpdclient_t *c, gint value)
+{
+ mpd_sendConsumeCommand(c->connection, value);
+ return mpdclient_finish_command(c);
+}
+
gint
mpdclient_cmd_crossfade(mpdclient_t *c, gint value)
{
gint
mpdclient_cmd_db_update(mpdclient_t *c, gchar *path)
{
+ gint ret;
+
mpd_sendUpdateCommand(c->connection, path ? path : "");
- return mpdclient_finish_command(c);
+ ret = mpdclient_finish_command(c);
+
+ if (ret == 0)
+ /* set updatingDb to make sure the browse callback
+ gets called even if the update has finished before
+ status is updated */
+ c->updatingdb = 1;
+
+ return ret;
}
gint
return mpdclient_finish_command(c);
}
+gint mpdclient_cmd_volume_up(struct mpdclient *c)
+{
+ if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME)
+ return 0;
+
+ if (c->volume == MPD_STATUS_NO_VOLUME)
+ c->volume = c->status->volume;
+
+ if (c->volume >= 100)
+ return 0;
+
+ return mpdclient_cmd_volume(c, ++c->volume);
+}
+
+gint mpdclient_cmd_volume_down(struct mpdclient *c)
+{
+ if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME)
+ return 0;
+
+ if (c->volume == MPD_STATUS_NO_VOLUME)
+ c->volume = c->status->volume;
+
+ if (c->volume <= 0)
+ return 0;
+
+ return mpdclient_cmd_volume(c, --c->volume);
+}
+
gint
mpdclient_cmd_add_path(mpdclient_t *c, gchar *path_utf8)
{