summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e5be3d5)
raw | patch | inline | side by side (parent: e5be3d5)
author | Max Kellermann <max@duempel.org> | |
Thu, 1 Oct 2009 21:10:53 +0000 (23:10 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 1 Oct 2009 21:10:53 +0000 (23:10 +0200) |
No libmpdclient error codes.
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/player_command.c | patch | blob | history | |
src/screen_browser.c | patch | blob | history |
diff --git a/src/mpdclient.c b/src/mpdclient.c
index de9f648e12ca3c48025f97009ef65d4610862146..fd223d6f80ea5b9a5834bfd58277cf0f368f9111 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
/*** mpdclient functions ****************************************************/
/****************************************************************************/
-gint
+bool
mpdclient_handle_error(struct mpdclient *c)
{
enum mpd_error error = mpd_connection_get_error(c->connection);
if (error == MPD_ERROR_SERVER &&
mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PERMISSION &&
screen_auth(c))
- return 0;
-
- if (error == MPD_ERROR_SERVER)
- error = error | (mpd_connection_get_server_error(c->connection) << 8);
+ return true;
mpdclient_ui_error(mpd_connection_get_error_message(c->connection));
if (!mpd_connection_clear_error(c->connection))
mpdclient_disconnect(c);
- return error;
+ return false;
}
-static gint
+static bool
mpdclient_finish_command(struct mpdclient *c)
{
return mpd_response_finish(c->connection)
- ? 0 : mpdclient_handle_error(c);
+ ? true : mpdclient_handle_error(c);
}
struct mpdclient *
/* retrieve new status */
c->status = mpd_run_status(c->connection);
if (c->status == NULL)
- return mpdclient_handle_error(c) == 0;
+ return mpdclient_handle_error(c);
if (c->update_id != mpd_status_get_update_id(c->status)) {
c->events |= MPD_IDLE_UPDATE;
/*** MPD Commands **********************************************************/
/****************************************************************************/
-gint
+bool
mpdclient_cmd_play(struct mpdclient *c, gint idx)
{
const struct mpd_song *song = playlist_get_song(&c->playlist, idx);
if (MPD_ERROR(c))
- return -1;
+ return false;
if (song)
mpd_send_play_id(c->connection, mpd_song_get_id(song));
return mpdclient_finish_command(c);
}
-gint
+bool
mpdclient_cmd_crop(struct mpdclient *c)
{
struct mpd_status *status;
int length, current;
if (MPD_ERROR(c))
- return -1;
+ return false;
status = mpd_run_status(c->connection);
if (status == NULL)
mpd_status_free(status);
if (!playing || length < 2)
- return 0;
+ return true;
mpd_command_list_begin(c->connection, false);
return mpdclient_finish_command(c);
}
-gint
+bool
mpdclient_cmd_clear(struct mpdclient *c)
{
- gint retval = 0;
+ bool retval;
if (MPD_ERROR(c))
- return -1;
+ return false;
mpd_send_clear(c->connection);
retval = mpdclient_finish_command(c);
return retval;
}
-gint
+bool
mpdclient_cmd_volume(struct mpdclient *c, gint value)
{
if (MPD_ERROR(c))
- return -1;
+ return false;
mpd_send_set_volume(c->connection, value);
return mpdclient_finish_command(c);
}
-gint mpdclient_cmd_volume_up(struct mpdclient *c)
+bool
+mpdclient_cmd_volume_up(struct mpdclient *c)
{
if (MPD_ERROR(c))
- return -1;
+ return false;
if (c->status == NULL ||
mpd_status_get_volume(c->status) == -1)
- return 0;
+ return true;
if (c->volume < 0)
c->volume = mpd_status_get_volume(c->status);
if (c->volume >= 100)
- return 0;
+ return true;
return mpdclient_cmd_volume(c, ++c->volume);
}
-gint mpdclient_cmd_volume_down(struct mpdclient *c)
+bool
+mpdclient_cmd_volume_down(struct mpdclient *c)
{
if (MPD_ERROR(c))
- return -1;
+ return false;
if (c->status == NULL || mpd_status_get_volume(c->status) < 0)
- return 0;
+ return true;
if (c->volume < 0)
c->volume = mpd_status_get_volume(c->status);
if (c->volume <= 0)
- return 0;
+ return true;
return mpdclient_cmd_volume(c, --c->volume);
}
-gint
+bool
mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path_utf8)
{
if (MPD_ERROR(c))
- return -1;
+ return false;
mpd_send_add(c->connection, path_utf8);
return mpdclient_finish_command(c);
}
-gint
+bool
mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song)
{
struct mpd_status *status;
assert(song != NULL);
if (MPD_ERROR(c) || c->status == NULL)
- return -1;
+ return false;
/* send the add command to mpd; at the same time, get the new
status (to verify the new playlist id) and the last song
if (new_song != NULL)
mpd_song_free(new_song);
- return mpd_connection_clear_error(c->connection)
- ? 0 : mpdclient_handle_error(c);
+ return mpd_connection_clear_error(c->connection) ||
+ mpdclient_handle_error(c);
}
if (mpd_status_get_queue_length(status) == playlist_length(&c->playlist) + 1 &&
mpd_song_free(new_song);
- return -0;
+ return true;
}
-gint
+bool
mpdclient_cmd_delete(struct mpdclient *c, gint idx)
{
const struct mpd_song *song;
struct mpd_status *status;
if (MPD_ERROR(c) || c->status == NULL)
- return -1;
+ return false;
if (idx < 0 || (guint)idx >= playlist_length(&c->playlist))
- return -1;
+ return false;
song = playlist_get(&c->playlist, idx);
c->song = NULL;
}
- return 0;
+ return true;
}
/**
* It emulates the "delete range" command with a list of simple
* "delete" commands.
*/
-static gint
+static bool
mpdclient_cmd_delete_range_fallback(struct mpdclient *c,
unsigned start, unsigned end)
{
!mpd_response_finish(c->connection))
return mpdclient_handle_error(c);
- return 0;
+ return true;
}
-gint
+bool
mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end)
{
struct mpd_status *status;
if (MPD_ERROR(c))
- return -1;
+ return false;
if (mpd_connection_cmp_server_version(c->connection, 0, 16, 0) < 0)
return mpdclient_cmd_delete_range_fallback(c, start, end);
}
}
- return 0;
+ return true;
}
-gint
+bool
mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index)
{
const struct mpd_song *song1, *song2;
struct mpd_status *status;
if (MPD_ERROR(c))
- return -1;
+ return false;
if (old_index == new_index || new_index < 0 ||
(guint)new_index >= c->playlist.list->len)
- return -1;
+ return false;
song1 = playlist_get(&c->playlist, old_index);
song2 = playlist_get(&c->playlist, new_index);
playlist_swap(&c->playlist, old_index, new_index);
}
- return 0;
+ return true;
}
c->playlist.version = mpd_status_get_queue_version(c->status);
c->song = NULL;
- return mpdclient_finish_command(c) == 0;
+ return mpdclient_finish_command(c);
}
/* update playlist (plchanges) */
c->song = NULL;
c->playlist.version = mpd_status_get_queue_version(c->status);
- return mpdclient_finish_command(c) == 0;
+ return mpdclient_finish_command(c);
}
while ((entity = mpd_recv_entity(c->connection)) != NULL)
filelist_append(filelist, entity);
- if (mpdclient_finish_command(c)) {
+ if (!mpdclient_finish_command(c)) {
filelist_free(filelist);
return NULL;
}
while ((entity = mpd_recv_entity(c->connection)) != NULL)
filelist_append(filelist, entity);
- if (mpdclient_finish_command(c)) {
+ if (!mpdclient_finish_command(c)) {
filelist_free(filelist);
return NULL;
}
return mpdclient_recv_filelist_response(c);
}
-int
+bool
mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl)
{
guint i;
if (MPD_ERROR(c))
- return -1;
+ return false;
if (filelist_is_empty(fl))
- return 0;
+ return true;
mpd_command_list_begin(c->connection, false);
mpd_return_pair(c->connection, pair);
}
- if (mpdclient_finish_command(c))
+ if (!mpdclient_finish_command(c))
return string_list_free(list);
return list;
mpd_return_pair(c->connection, pair);
}
- if (mpdclient_finish_command(c))
+ if (!mpdclient_finish_command(c))
return string_list_free(list);
return list;
diff --git a/src/mpdclient.h b/src/mpdclient.h
index 8a1db5944dbc83ca16ceded0622bbde58558d8d8..d66bf5b1ae5ba56f701f1bce6ec7bbc6d5d76f18 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
/** functions ***************************************************************/
-gint
+bool
mpdclient_handle_error(struct mpdclient *c);
struct mpdclient *
mpdclient_ui_error(const char *message);
/*** MPD Commands **********************************************************/
-gint mpdclient_cmd_play(struct mpdclient *c, gint index);
-gint
+
+bool
+mpdclient_cmd_play(struct mpdclient *c, gint index);
+
+bool
mpdclient_cmd_crop(struct mpdclient *c);
-gint mpdclient_cmd_clear(struct mpdclient *c);
-gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
-gint mpdclient_cmd_volume_up(struct mpdclient *c);
-gint mpdclient_cmd_volume_down(struct mpdclient *c);
-gint mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
-gint mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
-gint mpdclient_cmd_delete(struct mpdclient *c, gint index);
+bool
+mpdclient_cmd_clear(struct mpdclient *c);
-gint
+bool
+mpdclient_cmd_volume(struct mpdclient *c, gint value);
+
+bool
+mpdclient_cmd_volume_up(struct mpdclient *c);
+
+bool
+mpdclient_cmd_volume_down(struct mpdclient *c);
+
+bool
+mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
+
+bool
+mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
+
+bool
+mpdclient_cmd_delete(struct mpdclient *c, gint index);
+
+bool
mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
-gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
+bool
+mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
/* list functions */
GList *mpdclient_get_artists(struct mpdclient *c);
gchar *filter_utf8);
/* add all songs in filelist to the playlist */
-int
+bool
mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
/* sort by list-format */
diff --git a/src/player_command.c b/src/player_command.c
index fbd77c4d22cbc6e39e5696fc972edb2a5bf87a54..507e697b82ffab61e1884639bb7b505696d57a76 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
mpdclient_handle_error(c);
break;
case CMD_CLEAR:
- if (mpdclient_cmd_clear(c) == 0)
+ if (mpdclient_cmd_clear(c))
screen_status_message(_("Cleared playlist"));
break;
case CMD_REPEAT:
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 59769268170aa7907f544fffb02726349643fae8..5b41c33631be260dc4a05c6dac8292c2e2ca1623 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
const struct mpd_directory *dir =
mpd_entity_get_directory(entry->entity);
- if (mpdclient_cmd_add_path(c, mpd_directory_get_path(dir)) == 0) {
+ if (mpdclient_cmd_add_path(c, mpd_directory_get_path(dir))) {
char *tmp = utf8_to_locale(mpd_directory_get_path(dir));
screen_status_printf(_("Adding \'%s\' to playlist"), tmp);
entry->flags |= HIGHLIGHT;
#endif
- if (mpdclient_cmd_add(c, song) == 0) {
+ if (mpdclient_cmd_add(c, song)) {
char buf[BUFSIZE];
strfsong(buf, BUFSIZE, options.list_format, song);