summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a0fdb07)
raw | patch | inline | side by side (parent: a0fdb07)
author | Max Kellermann <max@duempel.org> | |
Sat, 3 Oct 2009 23:18:06 +0000 (01:18 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sat, 3 Oct 2009 23:18:06 +0000 (01:18 +0200) |
Added mpdclient_put_connection() to release the connection before
control is returned to the GLib main loop.
control is returned to the GLib main loop.
13 files changed:
diff --git a/src/main.c b/src/main.c
index fa68e8c218ec5bda585b17bb5402f8aec64c7caa..e5afa359728fafaf8d3a3667ab7d56b8ff6c8b2f 100644 (file)
--- a/src/main.c
+++ b/src/main.c
screen_update(mpd);
mpd->events = 0;
+ mpdclient_put_connection(mpd);
check_reconnect();
}
timer_reconnect(G_GNUC_UNUSED gpointer data)
{
bool success;
+ struct mpd_connection *connection;
assert(!mpdclient_is_connected(mpd));
return FALSE;
}
+ connection = mpdclient_get_connection(mpd);
+
#ifndef NCMPC_MINI
/* quit if mpd is pre 0.11.0 - song id not supported by mpd */
- if (mpd_connection_cmp_server_version(mpd->connection, 0, 12, 0) < 0) {
+ if (mpd_connection_cmp_server_version(connection, 0, 12, 0) < 0) {
const unsigned *version =
- mpd_connection_get_server_version(mpd->connection);
+ mpd_connection_get_server_version(connection);
screen_status_printf(_("Error: MPD version %d.%d.%d is to old (%s needed)"),
version[0], version[1], version[2],
"0.12.0");
screen_update(mpd);
mpd->events = 0;
+ mpdclient_put_connection(mpd);
check_reconnect();
auto_update_timer();
}
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 1abc529a018e1024d62be5381d821322ffaae8e4..54ce2c7145b7dc4b95a7a277a54874337108f8eb 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
#define BUFSIZE 1024
-static bool
-MPD_ERROR(const struct mpdclient *client)
-{
- return !mpdclient_is_connected(client) ||
- mpd_connection_get_error(client->connection) != MPD_ERROR_SUCCESS;
-}
-
/* sort by list-format */
gint
compare_filelistentry_format(gconstpointer filelist_entry1,
bool
mpdclient_update(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
bool retval;
c->volume = -1;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
/* always announce these options as long as we don't have real
mpd_status_free(c->status);
/* retrieve new status */
- c->status = mpd_run_status(c->connection);
+ c->status = mpd_run_status(connection);
if (c->status == NULL)
return mpdclient_handle_error(c);
return retval;
}
+struct mpd_connection *
+mpdclient_get_connection(struct mpdclient *c)
+{
+ return c->connection;
+}
+
+void
+mpdclient_put_connection(G_GNUC_UNUSED struct mpdclient *c)
+{
+}
+
/****************************************************************************/
/*** MPD Commands **********************************************************/
bool
mpdclient_cmd_play(struct mpdclient *c, gint idx)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
const struct mpd_song *song = playlist_get_song(&c->playlist, idx);
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
if (song)
- mpd_send_play_id(c->connection, mpd_song_get_id(song));
+ mpd_send_play_id(connection, mpd_song_get_id(song));
else
- mpd_send_play(c->connection);
+ mpd_send_play(connection);
return mpdclient_finish_command(c);
}
bool
mpdclient_cmd_crop(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
struct mpd_status *status;
bool playing;
int length, current;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
- status = mpd_run_status(c->connection);
+ status = mpd_run_status(connection);
if (status == NULL)
return mpdclient_handle_error(c);
if (!playing || length < 2)
return true;
- mpd_command_list_begin(c->connection, false);
+ mpd_command_list_begin(connection, false);
while (--length >= 0)
if (length != current)
- mpd_send_delete(c->connection, length);
+ mpd_send_delete(connection, length);
- mpd_command_list_end(c->connection);
+ mpd_command_list_end(connection);
return mpdclient_finish_command(c);
}
bool
mpdclient_cmd_clear(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
bool retval;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
- mpd_send_clear(c->connection);
+ mpd_send_clear(connection);
retval = mpdclient_finish_command(c);
if (retval)
bool
mpdclient_cmd_volume(struct mpdclient *c, gint value)
{
- if (MPD_ERROR(c))
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return false;
- mpd_send_set_volume(c->connection, value);
+ mpd_send_set_volume(connection, value);
return mpdclient_finish_command(c);
}
bool
mpdclient_cmd_volume_up(struct mpdclient *c)
{
- if (MPD_ERROR(c))
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return false;
if (c->status == NULL ||
bool
mpdclient_cmd_volume_down(struct mpdclient *c)
{
- if (MPD_ERROR(c))
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return false;
if (c->status == NULL || mpd_status_get_volume(c->status) < 0)
bool
mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path_utf8)
{
- if (MPD_ERROR(c))
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return false;
- mpd_send_add(c->connection, path_utf8);
+ mpd_send_add(connection, path_utf8);
return mpdclient_finish_command(c);
}
bool
mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
struct mpd_status *status;
struct mpd_song *new_song;
assert(c != NULL);
assert(song != NULL);
- if (MPD_ERROR(c) || c->status == NULL)
+ if (connection == NULL || c->status == NULL)
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
(we hope that's the song we just added) */
- if (!mpd_command_list_begin(c->connection, true) ||
- !mpd_send_add(c->connection, mpd_song_get_uri(song)) ||
- !mpd_send_status(c->connection) ||
- !mpd_send_get_queue_song_pos(c->connection,
+ if (!mpd_command_list_begin(connection, true) ||
+ !mpd_send_add(connection, mpd_song_get_uri(song)) ||
+ !mpd_send_status(connection) ||
+ !mpd_send_get_queue_song_pos(connection,
playlist_length(&c->playlist)) ||
- !mpd_command_list_end(c->connection) ||
- !mpd_response_next(c->connection))
+ !mpd_command_list_end(connection) ||
+ !mpd_response_next(connection))
return mpdclient_handle_error(c);
c->events |= MPD_IDLE_PLAYLIST;
- status = mpd_recv_status(c->connection);
+ status = mpd_recv_status(connection);
if (status != NULL) {
if (c->status != NULL)
mpd_status_free(c->status);
c->status = status;
}
- if (!mpd_response_next(c->connection))
+ if (!mpd_response_next(connection))
return mpdclient_handle_error(c);
- new_song = mpd_recv_song(c->connection);
- if (!mpd_response_finish(c->connection) || new_song == NULL) {
+ new_song = mpd_recv_song(connection);
+ if (!mpd_response_finish(connection) || new_song == NULL) {
if (new_song != NULL)
mpd_song_free(new_song);
- return mpd_connection_clear_error(c->connection) ||
+ return mpd_connection_clear_error(connection) ||
mpdclient_handle_error(c);
}
bool
mpdclient_cmd_delete(struct mpdclient *c, gint idx)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
const struct mpd_song *song;
struct mpd_status *status;
- if (MPD_ERROR(c) || c->status == NULL)
+ if (connection == NULL || c->status == NULL)
return false;
if (idx < 0 || (guint)idx >= playlist_length(&c->playlist))
/* send the delete command to mpd; at the same time, get the
new status (to verify the playlist id) */
- if (!mpd_command_list_begin(c->connection, false) ||
- !mpd_send_delete_id(c->connection, mpd_song_get_id(song)) ||
- !mpd_send_status(c->connection) ||
- !mpd_command_list_end(c->connection))
+ if (!mpd_command_list_begin(connection, false) ||
+ !mpd_send_delete_id(connection, mpd_song_get_id(song)) ||
+ !mpd_send_status(connection) ||
+ !mpd_command_list_end(connection))
return mpdclient_handle_error(c);
c->events |= MPD_IDLE_PLAYLIST;
- status = mpd_recv_status(c->connection);
+ status = mpd_recv_status(connection);
if (status != NULL) {
if (c->status != NULL)
mpd_status_free(c->status);
c->status = status;
}
- if (!mpd_response_finish(c->connection))
+ if (!mpd_response_finish(connection))
return mpdclient_handle_error(c);
if (mpd_status_get_queue_length(status) == playlist_length(&c->playlist) - 1 &&
mpdclient_cmd_delete_range_fallback(struct mpdclient *c,
unsigned start, unsigned end)
{
- if (!mpd_command_list_begin(c->connection, false))
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
+ if (!mpd_command_list_begin(connection, false))
return mpdclient_handle_error(c);
for (; start < end; --end)
- mpd_send_delete(c->connection, start);
+ mpd_send_delete(connection, start);
- if (!mpd_command_list_end(c->connection) ||
- !mpd_response_finish(c->connection))
+ if (!mpd_command_list_end(connection) ||
+ !mpd_response_finish(connection))
return mpdclient_handle_error(c);
return true;
bool
mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end)
{
+ struct mpd_connection *connection;
struct mpd_status *status;
- if (MPD_ERROR(c))
+ connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return false;
- if (mpd_connection_cmp_server_version(c->connection, 0, 16, 0) < 0)
+ if (mpd_connection_cmp_server_version(connection, 0, 16, 0) < 0)
return mpdclient_cmd_delete_range_fallback(c, start, end);
/* MPD 0.16 supports "delete" with a range argument */
/* send the delete command to mpd; at the same time, get the
new status (to verify the playlist id) */
- if (!mpd_command_list_begin(c->connection, false) ||
- !mpd_send_delete_range(c->connection, start, end) ||
- !mpd_send_status(c->connection) ||
- !mpd_command_list_end(c->connection))
+ if (!mpd_command_list_begin(connection, false) ||
+ !mpd_send_delete_range(connection, start, end) ||
+ !mpd_send_status(connection) ||
+ !mpd_command_list_end(connection))
return mpdclient_handle_error(c);
c->events |= MPD_IDLE_PLAYLIST;
- status = mpd_recv_status(c->connection);
+ status = mpd_recv_status(connection);
if (status != NULL) {
if (c->status != NULL)
mpd_status_free(c->status);
c->status = status;
}
- if (!mpd_response_finish(c->connection))
+ if (!mpd_response_finish(connection))
return mpdclient_handle_error(c);
if (mpd_status_get_queue_length(status) == playlist_length(&c->playlist) - (end - start) &&
bool
mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
const struct mpd_song *song1, *song2;
struct mpd_status *status;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
if (old_index == new_index || new_index < 0 ||
/* send the delete command to mpd; at the same time, get the
new status (to verify the playlist id) */
- if (!mpd_command_list_begin(c->connection, false) ||
- !mpd_send_swap_id(c->connection, mpd_song_get_id(song1),
+ if (!mpd_command_list_begin(connection, false) ||
+ !mpd_send_swap_id(connection, mpd_song_get_id(song1),
mpd_song_get_id(song2)) ||
- !mpd_send_status(c->connection) ||
- !mpd_command_list_end(c->connection))
+ !mpd_send_status(connection) ||
+ !mpd_command_list_end(connection))
return mpdclient_handle_error(c);
c->events |= MPD_IDLE_PLAYLIST;
- status = mpd_recv_status(c->connection);
+ status = mpd_recv_status(connection);
if (status != NULL) {
if (c->status != NULL)
mpd_status_free(c->status);
c->status = status;
}
- if (!mpd_response_finish(c->connection))
+ if (!mpd_response_finish(connection))
return mpdclient_handle_error(c);
if (mpd_status_get_queue_length(status) == playlist_length(&c->playlist) &&
bool
mpdclient_playlist_update(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
struct mpd_entity *entity;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
playlist_clear(&c->playlist);
- mpd_send_list_queue_meta(c->connection);
- while ((entity = mpd_recv_entity(c->connection))) {
+ mpd_send_list_queue_meta(connection);
+ while ((entity = mpd_recv_entity(connection))) {
if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG)
playlist_append(&c->playlist, mpd_entity_get_song(entity));
bool
mpdclient_playlist_update_changes(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
struct mpd_song *song;
guint length;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
- mpd_send_queue_changes_meta(c->connection, c->playlist.version);
+ mpd_send_queue_changes_meta(connection, c->playlist.version);
- while ((song = mpd_recv_song(c->connection)) != NULL) {
+ while ((song = mpd_recv_song(connection)) != NULL) {
int pos = mpd_song_get_pos(song);
if (pos >= 0 && (guint)pos < c->playlist.list->len) {
bool
mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
guint i;
- if (MPD_ERROR(c))
+ if (connection == NULL)
return false;
if (filelist_is_empty(fl))
return true;
- mpd_command_list_begin(c->connection, false);
+ mpd_command_list_begin(connection, false);
for (i = 0; i < filelist_length(fl); ++i) {
struct filelist_entry *entry = filelist_get(fl, i);
const struct mpd_song *song =
mpd_entity_get_song(entity);
- mpd_send_add(c->connection, mpd_song_get_uri(song));
+ mpd_send_add(connection, mpd_song_get_uri(song));
}
}
- mpd_command_list_end(c->connection);
+ mpd_command_list_end(connection);
return mpdclient_finish_command(c);
}
GList *
mpdclient_get_artists(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
GList *list = NULL;
struct mpd_pair *pair;
- if (MPD_ERROR(c))
- return NULL;
+ if (connection == NULL)
+ return NULL;
- mpd_search_db_tags(c->connection, MPD_TAG_ARTIST);
- mpd_search_commit(c->connection);
+ mpd_search_db_tags(connection, MPD_TAG_ARTIST);
+ mpd_search_commit(connection);
- while ((pair = mpd_recv_pair_tag(c->connection,
+ while ((pair = mpd_recv_pair_tag(connection,
MPD_TAG_ARTIST)) != NULL) {
list = g_list_append(list, g_strdup(pair->value));
- mpd_return_pair(c->connection, pair);
+ mpd_return_pair(connection, pair);
}
if (!mpdclient_finish_command(c))
GList *
mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
GList *list = NULL;
struct mpd_pair *pair;
- if (MPD_ERROR(c))
- return NULL;
+ if (connection == NULL)
+ return NULL;
- mpd_search_db_tags(c->connection, MPD_TAG_ALBUM);
+ mpd_search_db_tags(connection, MPD_TAG_ALBUM);
if (artist_utf8 != NULL)
- mpd_search_add_tag_constraint(c->connection,
+ mpd_search_add_tag_constraint(connection,
MPD_OPERATOR_DEFAULT,
MPD_TAG_ARTIST, artist_utf8);
- mpd_search_commit(c->connection);
+ mpd_search_commit(connection);
- while ((pair = mpd_recv_pair_tag(c->connection,
+ while ((pair = mpd_recv_pair_tag(connection,
MPD_TAG_ALBUM)) != NULL) {
list = g_list_append(list, g_strdup(pair->value));
- mpd_return_pair(c->connection, pair);
+ mpd_return_pair(connection, pair);
}
if (!mpdclient_finish_command(c))
diff --git a/src/mpdclient.h b/src/mpdclient.h
index 789ccb42ca3d2e6613967356f01b4612ac0eb8d9..b6027da7be83c43a1db3704e5cce02b8610e7213 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
bool
mpdclient_update(struct mpdclient *c);
+struct mpd_connection *
+mpdclient_get_connection(struct mpdclient *c);
+
+void
+mpdclient_put_connection(struct mpdclient *c);
+
/**
* To be implemented by the application: mpdclient.c calls this to
* display an error message.
diff --git a/src/player_command.c b/src/player_command.c
index 337d7677d6d7334fc4453be4bf05b691614f9457..3b8476daf3924b08aec875c17ac8c74f5a7c876e 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
static void
commit_seek(struct mpdclient *c)
{
+ struct mpd_connection *connection;
+
if (seek_id < 0)
return;
return;
}
+ connection = mpdclient_get_connection(c);
+
if (c->song != NULL && (unsigned)seek_id == mpd_song_get_id(c->song))
- if (!mpd_run_seek_id(c->connection, seek_id, seek_target_time))
+ if (!mpd_run_seek_id(connection, seek_id, seek_target_time))
mpdclient_handle_error(c);
seek_id = -1;
seek_source_id = 0;
commit_seek(c);
+ mpdclient_put_connection(c);
return false;
}
bool
handle_player_command(struct mpdclient *c, command_t cmd)
{
+ struct mpd_connection *connection;
const struct mpd_song *song;
if (!mpdclient_is_connected(c) || c->status == NULL)
break;
*/
case CMD_PAUSE:
- if (!mpd_run_pause(c->connection,
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_pause(connection,
mpd_status_get_state(c->status) != MPD_STATE_PAUSE))
mpdclient_handle_error(c);
break;
case CMD_STOP:
- if (!mpd_run_stop(c->connection))
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_stop(connection))
mpdclient_handle_error(c);
break;
case CMD_CROP:
schedule_seek_timer(c);
}
break;
- /* fall through... */
case CMD_TRACK_NEXT:
- if (!mpd_run_next(c->connection))
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_next(connection))
mpdclient_handle_error(c);
break;
case CMD_SEEK_BACKWARD:
}
break;
case CMD_TRACK_PREVIOUS:
- if (!mpd_run_previous(c->connection))
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_previous(connection))
mpdclient_handle_error(c);
break;
case CMD_SHUFFLE:
- if (mpd_run_shuffle(c->connection))
+ connection = mpdclient_get_connection(c);
+ if (mpd_run_shuffle(connection))
screen_status_message(_("Shuffled playlist"));
else
mpdclient_handle_error(c);
break;
case CMD_CLEAR:
+ connection = mpdclient_get_connection(c);
if (mpdclient_cmd_clear(c))
screen_status_message(_("Cleared playlist"));
break;
case CMD_REPEAT:
- if (!mpd_run_repeat(c->connection,
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_repeat(connection,
!mpd_status_get_repeat(c->status)))
mpdclient_handle_error(c);
break;
case CMD_RANDOM:
- if (!mpd_run_random(c->connection,
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_random(connection,
!mpd_status_get_random(c->status)))
mpdclient_handle_error(c);
break;
case CMD_SINGLE:
- if (!mpd_run_single(c->connection,
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_single(connection,
!mpd_status_get_single(c->status)))
mpdclient_handle_error(c);
break;
case CMD_CONSUME:
- if (!mpd_run_consume(c->connection,
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_consume(connection,
!mpd_status_get_consume(c->status)))
mpdclient_handle_error(c);
break;
case CMD_CROSSFADE:
- if (!mpd_run_crossfade(c->connection,
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_crossfade(connection,
mpd_status_get_crossfade(c->status) > 0
? 0 : options.crossfade_time))
mpdclient_handle_error(c);
diff --git a/src/screen_artist.c b/src/screen_artist.c
index e88a04dbd0571b9bd689be52830f8d37c72da893..996a0b7914d6ebea2889abbcc2e3f005b79d7669 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
static void
load_song_list(struct mpdclient *c)
{
- struct mpd_connection *connection = c->connection;
+ struct mpd_connection *connection = mpdclient_get_connection(c);
assert(mode == LIST_SONGS);
assert(artist != NULL);
static void
add_query(struct mpdclient *c, enum mpd_tag_type table, char *_filter)
{
- struct mpd_connection *connection = c->connection;
+ struct mpd_connection *connection = mpdclient_get_connection(c);
char *str;
struct filelist *addlist;
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 604d424e30746120e75f5c866b2aa2fa93d37de7..6375ee955325c13b7206b0003b568834b62c2b53 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
@@ -125,9 +125,10 @@ browser_lw_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char **second_c
static bool
load_playlist(struct mpdclient *c, const struct mpd_playlist *playlist)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
char *filename = utf8_to_locale(mpd_playlist_get_path(playlist));
- if (mpd_run_load(c->connection, mpd_playlist_get_path(playlist))) {
+ if (mpd_run_load(connection, mpd_playlist_get_path(playlist))) {
screen_status_printf(_("Loading playlist %s..."),
g_basename(filename));
c->events |= MPD_IDLE_QUEUE;
static bool
enqueue_and_play(struct mpdclient *c, struct filelist_entry *entry)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
const struct mpd_song *song = mpd_entity_get_song(entry->entity);
int id;
if (id < 0) {
char buf[BUFSIZE];
- id = mpd_run_add_id(c->connection, mpd_song_get_uri(song));
+ id = mpd_run_add_id(connection, mpd_song_get_uri(song));
if (id < 0) {
mpdclient_handle_error(c);
return false;
screen_status_printf(_("Adding \'%s\' to playlist"), buf);
}
- if (!mpd_run_play_id(c->connection, id)) {
+ if (!mpd_run_play_id(connection, id)) {
mpdclient_handle_error(c);
return false;
}
diff --git a/src/screen_client.c b/src/screen_client.c
index 9e13ba00e3ebf9a092f8062aa7d2695c9390d2c9..90364c0af0df2506daba2839a171beb385de7482 100644 (file)
--- a/src/screen_client.c
+++ b/src/screen_client.c
static bool
_screen_auth(struct mpdclient *c, gint recursion)
{
+ struct mpd_connection *connection;
char *password;
- mpd_connection_clear_error(c->connection);
+ connection = mpdclient_get_connection(c);
+
+ mpd_connection_clear_error(connection);
if (recursion > 2)
return false;
if (password == NULL)
return false;
- mpd_send_password(c->connection, password);
+ mpd_send_password(connection, password);
g_free(password);
- mpd_response_finish(c->connection);
+ mpd_response_finish(connection);
mpdclient_update(c);
- if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
- mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD)
+ if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+ mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
return _screen_auth(c, ++recursion);
return true;
void
screen_database_update(struct mpdclient *c, const char *path)
{
+ struct mpd_connection *connection;
unsigned id;
assert(c != NULL);
assert(mpdclient_is_connected(c));
- id = mpd_run_update(c->connection, path);
+ connection = mpdclient_get_connection(c);
+
+ id = mpd_run_update(connection, path);
if (id == 0) {
- if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
- mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_UPDATE_ALREADY &&
- mpd_connection_clear_error(c->connection))
+ if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+ mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_UPDATE_ALREADY &&
+ mpd_connection_clear_error(connection))
screen_status_printf(_("Database update running..."));
else
mpdclient_handle_error(c);
diff --git a/src/screen_file.c b/src/screen_file.c
index 43c28c264de50909c8587bf909852793d04b06d1..b087068ea79f717b04093ded2555b3f4e2672f8f 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
if (!mpdclient_is_connected(c))
return;
- connection = c->connection;
+ connection = mpdclient_get_connection(c);
mpd_send_list_meta(connection, current_path);
filelist_recv(browser.filelist, connection);
static int
handle_delete(struct mpdclient *c)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
struct filelist_entry *entry;
struct mpd_entity *entity;
const struct mpd_playlist *playlist;
return 0;
}
- if (!mpd_run_rm(c->connection, mpd_playlist_get_path(playlist))) {
+ if (!mpd_run_rm(connection, mpd_playlist_get_path(playlist))) {
mpdclient_handle_error(c);
break;
}
diff --git a/src/screen_outputs.c b/src/screen_outputs.c
index 1d60bae6feedf2cc66213315d1879018f5b0a884..c1660b3d8d909b18727207d5096b6aa614462932 100644 (file)
--- a/src/screen_outputs.c
+++ b/src/screen_outputs.c
static bool
toggle_output(struct mpdclient *c, unsigned int output_index)
{
+ struct mpd_connection *connection;
struct mpd_output *output;
assert(mpd_outputs != NULL);
- if (output_index >= mpd_outputs->len)
+ if (!mpdclient_is_connected(c) ||
+ output_index >= mpd_outputs->len)
return false;
+ connection = mpdclient_get_connection(c);
output = g_ptr_array_index(mpd_outputs, output_index);
if (!mpd_output_get_enabled(output)) {
- if (!mpd_run_enable_output(c->connection,
+ if (!mpd_run_enable_output(connection,
mpd_output_get_id(output))) {
mpdclient_handle_error(c);
return false;
screen_status_printf(_("Output '%s' enabled"),
mpd_output_get_name(output));
} else {
- if (!mpd_run_disable_output(c->connection,
+ if (!mpd_run_disable_output(connection,
mpd_output_get_id(output))) {
mpdclient_handle_error(c);
return false;
static void
fill_outputs_list(struct mpdclient *c)
{
+ struct mpd_connection *connection;
struct mpd_output *output;
assert(mpd_outputs != NULL);
if (!mpdclient_is_connected(c))
return;
- mpd_send_outputs(c->connection);
- while ((output = mpd_recv_output(c->connection)) != NULL) {
+ connection = mpdclient_get_connection(c);
+ mpd_send_outputs(connection);
+ while ((output = mpd_recv_output(connection)) != NULL) {
g_ptr_array_add(mpd_outputs, output);
}
- if (!mpd_response_finish(c->connection))
+ if (!mpd_response_finish(connection))
mpdclient_handle_error(c);
}
diff --git a/src/screen_play.c b/src/screen_play.c
index 9560b2b9df4f48b68339d1cced3c22a63670bf4b..632944fdd39efab06c5db9ce27a195d02b645906 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
int
playlist_save(struct mpdclient *c, char *name, char *defaultname)
{
+ struct mpd_connection *connection;
gchar *filename, *filename_utf8;
#ifndef NCMPC_MINI
GCompletion *gcmp;
filename_utf8 = locale_to_utf8(filename);
- if (!mpd_run_save(c->connection, filename_utf8)) {
- if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
- mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_EXIST &&
- mpd_connection_clear_error(c->connection)) {
+ connection = mpdclient_get_connection(c);
+ if (!mpd_run_save(connection, filename_utf8)) {
+ if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+ mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST &&
+ mpd_connection_clear_error(connection)) {
char *buf;
int key;
return -1;
}
- if (!mpd_run_rm(c->connection, filename_utf8) ||
- !mpd_run_save(c->connection, filename_utf8)) {
+ if (!mpd_run_rm(connection, filename_utf8) ||
+ !mpd_run_save(connection, filename_utf8)) {
mpdclient_handle_error(c);
g_free(filename_utf8);
g_free(filename);
static bool
screen_playlist_cmd(struct mpdclient *c, command_t cmd)
{
+ struct mpd_connection *connection;
static command_t cached_cmd = CMD_NONE;
command_t prev_cmd = cached_cmd;
cached_cmd = cmd;
return true;
case CMD_SHUFFLE:
- {
if(!lw->range_selection)
/* No range selection, shuffle all list. */
break;
- if (mpd_run_shuffle_range(c->connection, lw->selected_start,
+ connection = mpdclient_get_connection(c);
+ if (mpd_run_shuffle_range(connection, lw->selected_start,
lw->selected_end + 1))
screen_status_message(_("Shuffled playlist"));
else
mpdclient_handle_error(c);
return true;
- }
case CMD_LIST_MOVE_UP:
if(lw->selected_start == 0)
diff --git a/src/screen_search.c b/src/screen_search.c
index 85f817964008ebe0b7f93050c4d3c6c31d42bee3..b4102192e1e9cc18691ead21ba3c3262a67b7a7f 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
static struct filelist *
do_search(struct mpdclient *c, char *query)
{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
struct filelist *fl;
- fl = search_advanced_query(c->connection, query);
+ fl = search_advanced_query(connection, query);
if (fl != NULL)
return fl;
- if (mpd_connection_get_error(c->connection) != MPD_ERROR_SUCCESS) {
+ if (mpd_connection_get_error(connection) != MPD_ERROR_SUCCESS) {
mpdclient_handle_error(c);
return NULL;
}
- fl = search_simple_query(c->connection, FALSE,
+ fl = search_simple_query(connection, FALSE,
mode[options.search_mode].table,
query);
if (fl == NULL)
diff --git a/src/screen_song.c b/src/screen_song.c
index 1de01f48ecad5f728593e249225ee0072f3c0d75..9d42eb47e1d9cb6e02734b3f76d1ce724e9769ff 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
}
/* Add some statistics about mpd */
- if (mpdclient_is_connected(c)) {
- if (!screen_song_add_stats(c->connection))
- mpdclient_handle_error(c);
- }
+ if (mpdclient_is_connected(c) &&
+ !screen_song_add_stats(mpdclient_get_connection(c)))
+ mpdclient_handle_error(c);
screen_song_repaint();
}
diff --git a/src/utils.c b/src/utils.c
index 5a43f09a5a4176004080dc7cd255e837cf10d67e..6042848bced918cab0378fdd4764a7014f7c826b 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
if (!mpdclient_is_connected(c))
return list;
- connection = c->connection;
+ connection = mpdclient_get_connection(c);
mpd_send_list_meta(connection, path);
while ((entity = mpd_recv_entity(connection)) != NULL) {