summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ff86aac)
raw | patch | inline | side by side (parent: ff86aac)
author | Max Kellermann <max@duempel.org> | |
Tue, 16 Sep 2008 17:11:36 +0000 (19:11 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 16 Sep 2008 17:11:36 +0000 (19:11 +0200) |
Follow the same code style als MPD itself.
src/list_window.c | patch | blob | history | |
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/screen.c | patch | blob | history |
diff --git a/src/list_window.c b/src/list_window.c
index 967f56a7b53f8d31448d190b1b27f3762977a5ce..01e15c0c5fb780e835374bc5248b753e7871752f 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
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 b16cab889bc3e1dd424a33a291bf178aa7c85371..52cbd4758317789ef712015b01a981100a7b7015 100644 (file)
--- a/src/main.c
+++ b/src/main.c
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,
}
exit(EXIT_FAILURE);
}
-
diff --git a/src/mpdclient.c b/src/mpdclient.c
index f26b42cfd303189f13da32a94293641b33cf91c2..bf18a1c3b3bec7159b0eb9f82e954f50c8754218 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.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
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 787839193cbbcab1ce68a17100e766aaba51d52c..6da4d0f3b1e28e662b9853e869ab4294b0c1d201 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
/* 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 3db9730e8e54a47b0f7e2f24672fe1da534a9554..e89e4ebf815eb6e433d8c6653539cca3955484b6 100644 (file)
--- a/src/screen.c
+++ b/src/screen.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;