diff options
Diffstat (limited to '')
-rw-r--r-- | src/list_window.c | 71 | ||||
-rw-r--r-- | src/main.c | 25 | ||||
-rw-r--r-- | src/mpdclient.c | 100 | ||||
-rw-r--r-- | src/mpdclient.h | 66 | ||||
-rw-r--r-- | src/screen.c | 8 |
5 files changed, 128 insertions, 142 deletions
diff --git a/src/list_window.c b/src/list_window.c index 967f56a7b..01e15c0c5 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -310,50 +310,49 @@ list_window_init_state(void) list_window_state_t * list_window_free_state(list_window_state_t *state) { - if( state ) - { - if( state->list ) - { - GList *list = state->list; - while( list ) - { - g_free(list->data); - list->data = NULL; - list = list->next; - } - g_list_free(state->list); - state->list = NULL; + if (state) { + if (state->list) { + GList *list = state->list; + + while (list) { + g_free(list->data); + list->data = NULL; + list = list->next; + } + + g_list_free(state->list); + state->list = NULL; + } + + g_free(state); } - g_free(state); - } - return NULL; + + return NULL; } -void +void list_window_push_state(list_window_state_t *state, list_window_t *lw) { - if( state ) - { - list_window_t *tmp = g_malloc(sizeof(list_window_t)); - memcpy(tmp, lw, sizeof(list_window_t)); - state->list = g_list_prepend(state->list, (gpointer) tmp); - list_window_reset(lw); - } + if (state) { + list_window_t *tmp = g_malloc(sizeof(list_window_t)); + memcpy(tmp, lw, sizeof(list_window_t)); + state->list = g_list_prepend(state->list, (gpointer) tmp); + list_window_reset(lw); + } } bool list_window_pop_state(list_window_state_t *state, list_window_t *lw) { - if( state && state->list ) - { - list_window_t *tmp = state->list->data; - - memcpy(lw, tmp, sizeof(list_window_t)); - g_free(tmp); - state->list->data = NULL; - state->list = g_list_delete_link(state->list, state->list); - } - - // return TRUE if there are still states in the list - return (state && state->list) ? TRUE : FALSE; + if (state && state->list) { + list_window_t *tmp = state->list->data; + + memcpy(lw, tmp, sizeof(list_window_t)); + g_free(tmp); + state->list->data = NULL; + state->list = g_list_delete_link(state->list, state->list); + } + + // return TRUE if there are still states in the list + return (state && state->list) ? TRUE : FALSE; } diff --git a/src/main.c b/src/main.c index b16cab889..52cbd4758 100644 --- a/src/main.c +++ b/src/main.c @@ -301,36 +301,34 @@ main(int argc, const char *argv[]) while (connected || options.reconnect) { static gdouble t = G_MAXDOUBLE; - if( key_error ) { + if (key_error) { char buf[BUFSIZE]; key_error=check_key_bindings(NULL, buf, BUFSIZE); screen_status_printf("%s", buf); } - if( connected && (t>=MPD_UPDATE_TIME || mpd->need_update) ) { + if (connected && (t >= MPD_UPDATE_TIME || mpd->need_update)) { mpdclient_update(mpd); g_timer_start(timer); } - if( connected ) { + if (connected) { command_t cmd; screen_update(mpd); - if( (cmd=get_keyboard_command()) != CMD_NONE ) - { - screen_cmd(mpd, cmd); - if( cmd==CMD_VOLUME_UP || cmd==CMD_VOLUME_DOWN) - /* make shure we dont update the volume yet */ - g_timer_start(timer); - } - else + if ((cmd=get_keyboard_command()) != CMD_NONE) { + screen_cmd(mpd, cmd); + if (cmd == CMD_VOLUME_UP || cmd == CMD_VOLUME_DOWN) + /* make shure we dont update the volume yet */ + g_timer_start(timer); + } else screen_idle(mpd); - } else if( options.reconnect ) { + } else if (options.reconnect) { screen_status_printf(_("Connecting to %s... [Press %s to abort]"), options.host, get_key_names(CMD_QUIT,0) ); - if( get_keyboard_command_with_timeout(MPD_RECONNECT_TIME)==CMD_QUIT) + if (get_keyboard_command_with_timeout(MPD_RECONNECT_TIME) == CMD_QUIT) exit(EXIT_SUCCESS); if (mpdclient_connect(mpd, @@ -351,4 +349,3 @@ main(int argc, const char *argv[]) } exit(EXIT_FAILURE); } - diff --git a/src/mpdclient.c b/src/mpdclient.c index f26b42cfd..bf18a1c3b 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -160,44 +160,44 @@ mpdclient_finish_command(mpdclient_t *c) mpdclient_t * mpdclient_new(void) { - mpdclient_t *c; + mpdclient_t *c; - c = g_malloc0(sizeof(mpdclient_t)); - c->playlist.list = g_array_sized_new(FALSE, FALSE, sizeof(mpd_Song *), 1024); + c = g_malloc0(sizeof(mpdclient_t)); + c->playlist.list = g_array_sized_new(FALSE, FALSE, sizeof(mpd_Song *), 1024); - return c; + return c; } mpdclient_t * mpdclient_free(mpdclient_t *c) { - mpdclient_disconnect(c); - g_list_free(c->error_callbacks); - g_list_free(c->playlist_callbacks); - g_list_free(c->browse_callbacks); - g_free(c); + mpdclient_disconnect(c); + g_list_free(c->error_callbacks); + g_list_free(c->playlist_callbacks); + g_list_free(c->browse_callbacks); + g_free(c); - return NULL; + return NULL; } gint mpdclient_disconnect(mpdclient_t *c) { - if( c->connection ) - mpd_closeConnection(c->connection); - c->connection = NULL; + if (c->connection) + mpd_closeConnection(c->connection); + c->connection = NULL; - if( c->status ) - mpd_freeStatus(c->status); - c->status = NULL; + if (c->status) + mpd_freeStatus(c->status); + c->status = NULL; - if( c->playlist.list ) - mpdclient_playlist_free(&c->playlist); + if (c->playlist.list) + mpdclient_playlist_free(&c->playlist); - if( c->song ) - c->song = NULL; - - return 0; + if (c->song) + c->song = NULL; + + return 0; } gint @@ -232,43 +232,41 @@ mpdclient_connect(mpdclient_t *c, gint mpdclient_update(mpdclient_t *c) { - gint retval = 0; + gint retval = 0; + + if (MPD_ERROR(c)) + return -1; - if( MPD_ERROR(c) ) - return -1; + /* free the old status */ + if (c->status) + mpd_freeStatus(c->status); - /* free the old status */ - if( c->status ) - mpd_freeStatus(c->status); - - /* retreive new status */ - mpd_sendStatusCommand(c->connection); - c->status = mpd_getStatus(c->connection); - if( (retval=mpdclient_finish_command(c)) ) - return retval; + /* retreive new status */ + mpd_sendStatusCommand(c->connection); + c->status = mpd_getStatus(c->connection); + if ((retval=mpdclient_finish_command(c))) + return retval; #ifndef NDEBUG - if( c->status->error ) - D("status> %s\n", c->status->error); + if (c->status->error) + D("status> %s\n", c->status->error); #endif - /* check if the playlist needs an update */ - if( c->playlist.id != c->status->playlist ) - { - if( c->playlist.list ) - retval = mpdclient_playlist_update_changes(c); - else - retval = mpdclient_playlist_update(c); - } + /* check if the playlist needs an update */ + if (c->playlist.id != c->status->playlist) { + if (c->playlist.list) + retval = mpdclient_playlist_update_changes(c); + else + retval = mpdclient_playlist_update(c); + } - /* update the current song */ - if( !c->song || c->status->songid != c->song->id ) - { - c->song = playlist_get_song(c, c->status->song); - } + /* update the current song */ + if (!c->song || c->status->songid != c->song->id) { + c->song = playlist_get_song(c, c->status->song); + } - c->need_update = FALSE; + c->need_update = FALSE; - return retval; + return retval; } diff --git a/src/mpdclient.h b/src/mpdclient.h index 787839193..6da4d0f3b 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -20,53 +20,47 @@ /* Playlist */ /****************************************************************************/ -typedef struct -{ - /* playlist id */ - long long id; - /* true if the list is updated */ - gboolean updated; - /* the list */ - GArray *list; +typedef struct { + /* playlist id */ + long long id; + /* true if the list is updated */ + gboolean updated; + /* the list */ + GArray *list; } mpdclient_playlist_t; - -typedef struct -{ - guint flags; - mpd_InfoEntity *entity; +typedef struct { + guint flags; + mpd_InfoEntity *entity; } filelist_entry_t; -typedef struct -{ - /* path */ - gchar *path; - /* list length */ - guint length; - /* true if the list is updated */ - gboolean updated; - /* the list */ - GList *list; +typedef struct { + /* path */ + gchar *path; + /* list length */ + guint length; + /* true if the list is updated */ + gboolean updated; + /* the list */ + GList *list; } mpdclient_filelist_t; -typedef struct -{ - /* playlist */ - mpdclient_playlist_t playlist; - - /* Callbacks */ - GList *error_callbacks; - GList *playlist_callbacks; - GList *browse_callbacks; +typedef struct { + /* playlist */ + mpdclient_playlist_t playlist; - mpd_Connection *connection; - mpd_Status *status; - mpd_Song *song; + /* Callbacks */ + GList *error_callbacks; + GList *playlist_callbacks; + GList *browse_callbacks; - gboolean need_update; + mpd_Connection *connection; + mpd_Status *status; + mpd_Song *song; + gboolean need_update; } mpdclient_t; /** functions ***************************************************************/ diff --git a/src/screen.c b/src/screen.c index 3db9730e8..e89e4ebf8 100644 --- a/src/screen.c +++ b/src/screen.c @@ -767,12 +767,10 @@ screen_update(mpdclient_t *c) void screen_idle(mpdclient_t *c) { - if( c->song && seek_id == c->song->id && + if (c->song && seek_id == c->song->id && (screen->last_cmd == CMD_SEEK_FORWARD || - screen->last_cmd == CMD_SEEK_BACKWARD) ) - { - mpdclient_cmd_seek(c, seek_id, seek_target_time); - } + screen->last_cmd == CMD_SEEK_BACKWARD)) + mpdclient_cmd_seek(c, seek_id, seek_target_time); screen->last_cmd = CMD_NONE; seek_id = -1; |