diff options
author | Max Kellermann <max@duempel.org> | 2008-09-17 21:08:06 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-17 21:08:06 +0200 |
commit | 85ef40fa57fd6b4b931394e82edbd2878966e3fd (patch) | |
tree | 8703c61097ab913072fca467f912983a4d4cbaca | |
parent | 30c7bc007f594bbf84d872b5fb1f9475610f9683 (diff) | |
download | mpd-85ef40fa57fd6b4b931394e82edbd2878966e3fd.tar.gz mpd-85ef40fa57fd6b4b931394e82edbd2878966e3fd.tar.xz mpd-85ef40fa57fd6b4b931394e82edbd2878966e3fd.zip |
code style, indent with tabs IV
Follow the same code style als MPD itself.
-rw-r--r-- | src/command.c | 52 | ||||
-rw-r--r-- | src/libmpdclient.c | 74 | ||||
-rw-r--r-- | src/main.c | 112 | ||||
-rw-r--r-- | src/screen.c | 31 | ||||
-rw-r--r-- | src/screen_artist.c | 651 |
5 files changed, 449 insertions, 471 deletions
diff --git a/src/command.c b/src/command.c index 23c15b366..881df278a 100644 --- a/src/command.c +++ b/src/command.c @@ -397,61 +397,61 @@ find_key_command(int key, command_definition_t *c) return CMD_NONE; } -command_t +command_t get_key_command(int key) { - return find_key_command(key, cmds); + return find_key_command(key, cmds); } int my_wgetch(WINDOW *w) { - int c; + int c; - c = wgetch(w); + c = wgetch(w); - /* handle resize event */ - if( c==KEY_RESIZE ) - screen_resize(); + /* handle resize event */ + if (c == KEY_RESIZE) + screen_resize(); #ifdef ENABLE_RAW_MODE - /* handle SIGSTOP (Ctrl-Z) */ - if( c==26 || c==407 ) - sigstop(); - /* handle SIGINT (Ctrl-C) */ - if( c==3 ) - exit(EXIT_SUCCESS); + /* handle SIGSTOP (Ctrl-Z) */ + if (c == 26 || c == 407) + sigstop(); + /* handle SIGINT (Ctrl-C) */ + if (c == 3) + exit(EXIT_SUCCESS); #endif - return c; + return c; } command_t get_keyboard_command_with_timeout(int ms) { - int key; + int key; - if( ms != SCREEN_TIMEOUT) - timeout(ms); - key = my_wgetch(stdscr); - if( ms != SCREEN_TIMEOUT) - timeout(SCREEN_TIMEOUT); + if (ms != SCREEN_TIMEOUT) + timeout(ms); + key = my_wgetch(stdscr); + if (ms != SCREEN_TIMEOUT) + timeout(SCREEN_TIMEOUT); - if( key==ERR ) - return CMD_NONE; + if (key == ERR) + return CMD_NONE; #ifdef HAVE_GETMOUSE - if( key==KEY_MOUSE ) - return CMD_MOUSE_EVENT; + if (key == KEY_MOUSE) + return CMD_MOUSE_EVENT; #endif - return get_key_command(key); + return get_key_command(key); } command_t get_keyboard_command(void) { - return get_keyboard_command_with_timeout(SCREEN_TIMEOUT); + return get_keyboard_command_with_timeout(SCREEN_TIMEOUT); } int diff --git a/src/libmpdclient.c b/src/libmpdclient.c index ae4bd9c24..0733ccad1 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -88,7 +88,7 @@ static int winsock_dll_error(mpd_Connection *connection) LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2 ) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "Could not find usable WinSock DLL."); + "Could not find usable WinSock DLL."); connection->error = MPD_ERROR_SYSTEM; return 1; } @@ -142,7 +142,7 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, if (error) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "host \"%s\" not found: %s",host, gai_strerror(error)); + "host \"%s\" not found: %s",host, gai_strerror(error)); connection->error = MPD_ERROR_UNKHOST; return -1; } @@ -173,8 +173,8 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, if (connection->sock < 0) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "problems connecting to \"%s\" on port" - " %i: %s",host,port, strerror(errno)); + "problems connecting to \"%s\" on port" + " %i: %s",host,port, strerror(errno)); connection->error = MPD_ERROR_CONNPORT; return -1; @@ -193,7 +193,7 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, if(!(he=gethostbyname(host))) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "host \"%s\" not found",host); + "host \"%s\" not found",host); connection->error = MPD_ERROR_UNKHOST; return -1; } @@ -228,8 +228,8 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, /* connect stuff */ if (do_connect_fail(connection, dest, destlen)) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "problems connecting to \"%s\" on port" - " %i",host,port); + "problems connecting to \"%s\" on port" + " %i",host,port); connection->error = MPD_ERROR_CONNPORT; return -1; } @@ -307,8 +307,8 @@ static int mpd_parseWelcome(mpd_Connection * connection, const char * host, int if(strncmp(output,MPD_WELCOME_MESSAGE,strlen(MPD_WELCOME_MESSAGE))) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "mpd not running on port %i on host \"%s\"", - port,host); + "mpd not running on port %i on host \"%s\"", + port,host); connection->error = MPD_ERROR_NOTMPD; return 1; } @@ -419,13 +419,13 @@ mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) { if((err = select(connection->sock+1,&fds,NULL,NULL,&tv)) == 1) { int readed; readed = recv(connection->sock, - &(connection->buffer[connection->buflen]), - MPD_BUFFER_MAX_LENGTH-connection->buflen,0); + &(connection->buffer[connection->buflen]), + MPD_BUFFER_MAX_LENGTH-connection->buflen,0); if(readed<=0) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "problems getting a response from" - " \"%s\" on port %i : %s",host, - port, strerror(errno)); + "problems getting a response from" + " \"%s\" on port %i : %s",host, + port, strerror(errno)); connection->error = MPD_ERROR_NORESPONSE; return connection; } @@ -433,19 +433,19 @@ mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) { connection->buffer[connection->buflen] = '\0'; } else if(err<0) { - if (SELECT_ERRNO_IGNORE) + if (SELECT_ERRNO_IGNORE) continue; snprintf(connection->errorStr, - MPD_BUFFER_MAX_LENGTH, - "problems connecting to \"%s\" on port" - " %i",host,port); + MPD_BUFFER_MAX_LENGTH, + "problems connecting to \"%s\" on port" + " %i",host,port); connection->error = MPD_ERROR_CONNPORT; return connection; } else { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "timeout in attempting to get a response from" - " \"%s\" on port %i",host,port); + "timeout in attempting to get a response from" + " \"%s\" on port %i",host,port); connection->error = MPD_ERROR_NORESPONSE; return connection; } @@ -485,8 +485,9 @@ static void mpd_executeCommand(mpd_Connection *connection, const char *commandPtr = command; int commandLen = strlen(command); - if(!connection->doneProcessing && !connection->commandList) { - strcpy(connection->errorStr,"not done processing current command"); + if (!connection->doneProcessing && !connection->commandList) { + strcpy(connection->errorStr, + "not done processing current command"); connection->error = 1; return; } @@ -547,27 +548,24 @@ static void mpd_getNextReturnElement(mpd_Connection * connection) { if(connection->returnElement) mpd_freeReturnElement(connection->returnElement); connection->returnElement = NULL; - if(connection->doneProcessing || (connection->listOks && - connection->doneListOk)) - { + if (connection->doneProcessing || + (connection->listOks && connection->doneListOk)) { strcpy(connection->errorStr,"already done processing current command"); connection->error = 1; return; } bufferCheck = connection->buffer+connection->bufstart; - while(connection->bufstart>=connection->buflen || - !(rt = strchr(bufferCheck,'\n'))) { - if(connection->buflen>=MPD_BUFFER_MAX_LENGTH) { + while (connection->bufstart >= connection->buflen || + !(rt = strchr(bufferCheck, '\n'))) { + if (connection->buflen >= MPD_BUFFER_MAX_LENGTH) { memmove(connection->buffer, - connection->buffer+ - connection->bufstart, - connection->buflen- - connection->bufstart+1); - connection->buflen-=connection->bufstart; + connection->buffer + connection->bufstart, + connection->buflen - connection->bufstart + 1); + connection->buflen -= connection->bufstart; connection->bufstart = 0; } - if(connection->buflen>=MPD_BUFFER_MAX_LENGTH) { + if (connection->buflen >= MPD_BUFFER_MAX_LENGTH) { strcpy(connection->errorStr,"buffer overrun"); connection->error = MPD_ERROR_BUFFEROVERRUN; connection->doneProcessing = 1; @@ -581,9 +579,9 @@ static void mpd_getNextReturnElement(mpd_Connection * connection) { FD_SET(connection->sock,&fds); if((err = select(connection->sock+1,&fds,NULL,NULL,&tv) == 1)) { readed = recv(connection->sock, - connection->buffer+connection->buflen, - MPD_BUFFER_MAX_LENGTH-connection->buflen, - MSG_DONTWAIT); + connection->buffer+connection->buflen, + MPD_BUFFER_MAX_LENGTH-connection->buflen, + MSG_DONTWAIT); if(readed<0 && SENDRECV_ERRNO_IGNORE) { continue; } @@ -671,7 +669,7 @@ static void mpd_getNextReturnElement(mpd_Connection * connection) { } else { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, - "error parsing: %s:%s",name,value); + "error parsing: %s:%s",name,value); connection->errorStr[MPD_BUFFER_MAX_LENGTH] = '\0'; connection->error = 1; } diff --git a/src/main.c b/src/main.c index c2d752ffb..a0ff34461 100644 --- a/src/main.c +++ b/src/main.c @@ -38,21 +38,22 @@ #define BUFSIZE 1024 -static mpdclient_t *mpd = NULL; +static mpdclient_t *mpd = NULL; static gboolean connected = FALSE; -static GTimer *timer = NULL; +static GTimer *timer = NULL; static const gchar * error_msg(const gchar *msg) { - gchar *p; + gchar *p; - if( (p=strchr(msg, '}' )) == NULL ) - return msg; - while( p && *p && (*p=='}' || *p==' ') ) - p++; + if ((p = strchr(msg, '}')) == NULL) + return msg; - return p; + while (p && *p && (*p=='}' || *p==' ')) + p++; + + return p; } static void @@ -79,49 +80,48 @@ error_callback(mpd_unused mpdclient_t *c, gint error, const gchar *msg) static void update_xterm_title(void) { - static char title[BUFSIZE]; - char tmp[BUFSIZE]; - mpd_Status *status = NULL; - mpd_Song *song = NULL; - - if( mpd ) - { - status = mpd->status; - song = mpd->song; - } + static char title[BUFSIZE]; + char tmp[BUFSIZE]; + mpd_Status *status = NULL; + mpd_Song *song = NULL; + + if (mpd) { + status = mpd->status; + song = mpd->song; + } - if(options.xterm_title_format && status && song && IS_PLAYING(status->state)) - { - strfsong(tmp, BUFSIZE, options.xterm_title_format, song); - } - else - g_strlcpy(tmp, PACKAGE " version " VERSION, BUFSIZE); + if (options.xterm_title_format && status && song && + IS_PLAYING(status->state)) + strfsong(tmp, BUFSIZE, options.xterm_title_format, song); + else + g_strlcpy(tmp, PACKAGE " version " VERSION, BUFSIZE); - if( strncmp(title,tmp,BUFSIZE) ) - { - g_strlcpy(title, tmp, BUFSIZE); - set_xterm_title("%s", title); - } + if (strncmp(title, tmp, BUFSIZE)) { + g_strlcpy(title, tmp, BUFSIZE); + set_xterm_title("%s", title); + } } static void exit_and_cleanup(void) { - screen_exit(); - set_xterm_title(""); - printf("\n"); - if( mpd ) - { - mpdclient_disconnect(mpd); - mpdclient_free(mpd); - } - g_free(options.host); - g_free(options.password); - g_free(options.list_format); - g_free(options.status_format); - g_free(options.scroll_sep); - if( timer ) - g_timer_destroy(timer); + screen_exit(); + set_xterm_title(""); + printf("\n"); + + if (mpd) { + mpdclient_disconnect(mpd); + mpdclient_free(mpd); + } + + g_free(options.host); + g_free(options.password); + g_free(options.list_format); + g_free(options.status_format); + g_free(options.scroll_sep); + + if (timer) + g_timer_destroy(timer); } static void @@ -212,37 +212,37 @@ main(int argc, const char *argv[]) options_parse(argc, argv); /* setup signal behavior - SIGINT */ - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; act.sa_handler = catch_sigint; - if( sigaction(SIGINT, &act, NULL)<0 ) { + if (sigaction(SIGINT, &act, NULL) < 0) { perror("signal"); exit(EXIT_FAILURE); } /* setup signal behavior - SIGTERM */ - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; act.sa_handler = catch_sigint; - if( sigaction(SIGTERM, &act, NULL)<0 ) { + if (sigaction(SIGTERM, &act, NULL) < 0) { perror("sigaction()"); exit(EXIT_FAILURE); } /* setup signal behavior - SIGCONT */ - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; act.sa_handler = catch_sigcont; - if( sigaction(SIGCONT, &act, NULL)<0 ) { + if (sigaction(SIGCONT, &act, NULL) < 0) { perror("sigaction(SIGCONT)"); exit(EXIT_FAILURE); } /* setup signal behaviour - SIGHUP*/ - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; act.sa_handler = catch_sigint; - if( sigaction(SIGHUP, &act, NULL)<0 ) { + if (sigaction(SIGHUP, &act, NULL) < 0) { perror("sigaction(SIGHUP)"); exit(EXIT_FAILURE); } diff --git a/src/screen.c b/src/screen.c index 276500bd4..b6e2b7b79 100644 --- a/src/screen.c +++ b/src/screen.c @@ -543,15 +543,15 @@ ncurses_init(void) timeout(SCREEN_TIMEOUT); /* initialize mouse support */ #ifdef HAVE_GETMOUSE - if( options.enable_mouse ) + if (options.enable_mouse) mousemask(ALL_MOUSE_EVENTS, NULL); #endif - if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS ) - { - fprintf(stderr, _("Error: Screen to small!\n")); - exit(EXIT_FAILURE); - } + if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) { + fprintf(stderr, _("Error: Screen to small!\n")); + exit(EXIT_FAILURE); + } + screen.mode = 0; screen.cols = COLS; screen.rows = LINES; @@ -604,16 +604,15 @@ ncurses_init(void) leaveok(screen.status_window.w, FALSE); keypad(screen.status_window.w, TRUE); - if( options.enable_colors ) - { - /* set background attributes */ - wbkgd(stdscr, COLOR_PAIR(COLOR_LIST)); - wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST)); - wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE)); - wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR)); - wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS)); - colors_use(screen.progress_window.w, COLOR_PROGRESSBAR); - } + if (options.enable_colors) { + /* set background attributes */ + wbkgd(stdscr, COLOR_PAIR(COLOR_LIST)); + wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST)); + wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE)); + wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR)); + wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS)); + colors_use(screen.progress_window.w, COLOR_PROGRESSBAR); + } refresh(); } diff --git a/src/screen_artist.c b/src/screen_artist.c index eb7b2e5d4..71f48514b 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -54,176 +54,174 @@ static list_window_state_t *lw_state = NULL; static gint compare_utf8(gconstpointer s1, gconstpointer s2) { - char *key1, *key2; - int n; - - key1 = g_utf8_collate_key(s1,-1); - key2 = g_utf8_collate_key(s2,-1); - n = strcmp(key1,key2); - g_free(key1); - g_free(key2); - return n; + char *key1, *key2; + int n; + + key1 = g_utf8_collate_key(s1,-1); + key2 = g_utf8_collate_key(s2,-1); + n = strcmp(key1,key2); + g_free(key1); + g_free(key2); + return n; } /* list_window callback */ static char * artist_lw_callback(int index, int *highlight, void *data) { - static char buf[BUFSIZE]; - char *str, *str_utf8; - - if( (str_utf8=(char *) g_list_nth_data(metalist,index))==NULL ) - return NULL; + static char buf[BUFSIZE]; + char *str, *str_utf8; - str = utf8_to_locale(str_utf8); - g_snprintf(buf, BUFSIZE, "[%s]", str); - g_free(str); + if ((str_utf8=(char *) g_list_nth_data(metalist,index)) == NULL) + return NULL; - return buf; + str = utf8_to_locale(str_utf8); + g_snprintf(buf, BUFSIZE, "[%s]", str); + g_free(str); + + return buf; } /* the playlist have been updated -> fix highlights */ -static void +static void playlist_changed_callback(mpdclient_t *c, int event, gpointer data) { - if( filelist==NULL ) - return; - D("screen_artist.c> playlist_callback() [%d]\n", event); - switch(event) - { - case PLAYLIST_EVENT_CLEAR: - clear_highlights(filelist); - break; - default: - sync_highlights(c, filelist); - break; - } + if (filelist == NULL) + return; + + D("screen_artist.c> playlist_callback() [%d]\n", event); + switch(event) { + case PLAYLIST_EVENT_CLEAR: + clear_highlights(filelist); + break; + default: + sync_highlights(c, filelist); + break; + } } /* fetch artists/albums/songs from mpd */ static void update_metalist(mpdclient_t *c, char *m_artist, char *m_album) { - g_free(artist); - g_free(album); - artist = NULL; - album = NULL; - if( metalist ) - metalist = string_list_free(metalist); - if (filelist ) { - mpdclient_remove_playlist_callback(c, playlist_changed_callback); - filelist = mpdclient_filelist_free(filelist); - } - if( m_album ) /* retreive songs... */ - { - artist = m_artist; - album = m_album; - if( album[0] == 0 ) - { - album = g_strdup(_("All tracks")); - filelist = mpdclient_filelist_search_utf8(c, - TRUE, - MPD_TABLE_ARTIST, - artist); + g_free(artist); + g_free(album); + artist = NULL; + album = NULL; + + if (metalist) + metalist = string_list_free(metalist); + if (filelist) { + mpdclient_remove_playlist_callback(c, playlist_changed_callback); + filelist = mpdclient_filelist_free(filelist); } - else - filelist = mpdclient_filelist_search_utf8(c, - TRUE, - MPD_TABLE_ALBUM, - album); - /* add a dummy entry for ".." */ - filelist_entry_t *entry = g_malloc0(sizeof(filelist_entry_t)); - entry->entity = NULL; - filelist->list = g_list_insert(filelist->list, entry, 0); - filelist->length++; - /* install playlist callback and fix highlights */ - sync_highlights(c, filelist); - mpdclient_install_playlist_callback(c, playlist_changed_callback); - mode = LIST_SONGS; - } - else if( m_artist ) /* retreive albums... */ - { - artist = m_artist; - metalist = mpdclient_get_albums_utf8(c, m_artist); - /* sort list */ - metalist = g_list_sort(metalist, compare_utf8); - /* add a dummy entry for ".." */ - metalist = g_list_insert(metalist, g_strdup(".."), 0); - /* add a dummy entry for all songs */ - metalist = g_list_insert(metalist, g_strdup(_("All tracks")), -1); - mode = LIST_ALBUMS; - } - else /* retreive artists... */ - { - metalist = mpdclient_get_artists_utf8(c); - /* sort list */ - metalist = g_list_sort(metalist, compare_utf8); - mode = LIST_ARTISTS; - } - metalist_length = g_list_length(metalist); - lw->clear = TRUE; + if (m_album) { + /* retreive songs... */ + + artist = m_artist; + album = m_album; + if (album[0] == 0) { + album = g_strdup(_("All tracks")); + filelist = mpdclient_filelist_search_utf8(c, + TRUE, + MPD_TABLE_ARTIST, + artist); + } else + filelist = mpdclient_filelist_search_utf8(c, + TRUE, + MPD_TABLE_ALBUM, + album); + /* add a dummy entry for ".." */ + filelist_entry_t *entry = g_malloc0(sizeof(filelist_entry_t)); + entry->entity = NULL; + filelist->list = g_list_insert(filelist->list, entry, 0); + filelist->length++; + /* install playlist callback and fix highlights */ + sync_highlights(c, filelist); + mpdclient_install_playlist_callback(c, playlist_changed_callback); + mode = LIST_SONGS; + } else if (m_artist) { + /* retreive albums... */ + + artist = m_artist; + metalist = mpdclient_get_albums_utf8(c, m_artist); + /* sort list */ + metalist = g_list_sort(metalist, compare_utf8); + /* add a dummy entry for ".." */ + metalist = g_list_insert(metalist, g_strdup(".."), 0); + /* add a dummy entry for all songs */ + metalist = g_list_insert(metalist, g_strdup(_("All tracks")), -1); + mode = LIST_ALBUMS; + } else { + /* retreive artists... */ + + metalist = mpdclient_get_artists_utf8(c); + /* sort list */ + metalist = g_list_sort(metalist, compare_utf8); + mode = LIST_ARTISTS; + } + metalist_length = g_list_length(metalist); + lw->clear = TRUE; } /* db updated */ -static void +static void browse_callback(mpdclient_t *c, int event, gpointer data) { - switch(event) - { - case BROWSE_DB_UPDATED: - D("screen_artist.c> browse_callback() [BROWSE_DB_UPDATED]\n"); - lw->clear = 1; - lw->repaint = 1; - update_metalist(c, g_strdup(artist), g_strdup(album)); - break; - default: - break; - } + switch(event) { + case BROWSE_DB_UPDATED: + D("screen_artist.c> browse_callback() [BROWSE_DB_UPDATED]\n"); + lw->clear = 1; + lw->repaint = 1; + update_metalist(c, g_strdup(artist), g_strdup(album)); + break; + default: + break; + } } static void init(WINDOW *w, int cols, int rows) { - lw = list_window_init(w, cols, rows); - lw_state = list_window_init_state(); - artist = NULL; - album = NULL; + lw = list_window_init(w, cols, rows); + lw_state = list_window_init_state(); + artist = NULL; + album = NULL; } static void quit(void) { - if( filelist ) - filelist = mpdclient_filelist_free(filelist); - if( metalist ) - metalist = string_list_free(metalist); - g_free(artist); - g_free(album); - artist = NULL; - album = NULL; - lw = list_window_free(lw); - lw_state = list_window_free_state(lw_state); + if (filelist) + filelist = mpdclient_filelist_free(filelist); + if (metalist) + metalist = string_list_free(metalist); + g_free(artist); + g_free(album); + artist = NULL; + album = NULL; + lw = list_window_free(lw); + lw_state = list_window_free_state(lw_state); } static void open(screen_t *screen, mpdclient_t *c) { - static gboolean callback_installed = FALSE; - - if( metalist==NULL && filelist ==NULL) - update_metalist(c, NULL, NULL); - if( !callback_installed ) - { - mpdclient_install_browse_callback(c, browse_callback); - callback_installed = TRUE; - } + static gboolean callback_installed = FALSE; + + if (metalist == NULL && filelist == NULL) + update_metalist(c, NULL, NULL); + if (!callback_installed) { + mpdclient_install_browse_callback(c, browse_callback); + callback_installed = TRUE; + } } static void resize(int cols, int rows) { - lw->cols = cols; - lw->rows = rows; + lw->cols = cols; + lw->rows = rows; } static void @@ -231,67 +229,56 @@ close(void) { } -static void +static void paint(screen_t *screen, mpdclient_t *c) { - lw->clear = 1; - - if( filelist ) - { - list_window_paint(lw, browse_lw_callback, (void *) filelist); - filelist->updated = FALSE; - } - else if( metalist ) - { - list_window_paint(lw, artist_lw_callback, (void *) metalist); - } - else - { - wmove(lw->w, 0, 0); - wclrtobot(lw->w); - } - wnoutrefresh(lw->w); + lw->clear = 1; + + if (filelist) { + list_window_paint(lw, browse_lw_callback, (void *) filelist); + filelist->updated = FALSE; + } else if (metalist) { + list_window_paint(lw, artist_lw_callback, (void *) metalist); + } else { + wmove(lw->w, 0, 0); + wclrtobot(lw->w); + } + + wnoutrefresh(lw->w); } -static void +static void update(screen_t *screen, mpdclient_t *c) { - if( filelist && !filelist->updated ) - { - list_window_paint(lw, browse_lw_callback, (void *) filelist); - } - else if( metalist ) - { - list_window_paint(lw, artist_lw_callback, (void *) metalist); - } - else - { - paint(screen, c); - } - wnoutrefresh(lw->w); + if (filelist && !filelist->updated) + list_window_paint(lw, browse_lw_callback, (void *) filelist); + else if (metalist) + list_window_paint(lw, artist_lw_callback, (void *) metalist); + else + paint(screen, c); + wnoutrefresh(lw->w); } static char * get_title(char *str, size_t size) { - char *s1 = artist ? utf8_to_locale(artist) : NULL; - char *s2 = album ? utf8_to_locale(album) : NULL; - - switch(mode) - { - case LIST_ARTISTS: - g_snprintf(str, size, _("Artist: [db browser - EXPERIMENTAL]")); - break; - case LIST_ALBUMS: - g_snprintf(str, size, _("Artist: %s"), s1); - break; - case LIST_SONGS: - g_snprintf(str, size, _("Artist: %s - %s"), s1, s2); - break; - } - g_free(s1); - g_free(s2); - return str; + char *s1 = artist ? utf8_to_locale(artist) : NULL; + char *s2 = album ? utf8_to_locale(album) : NULL; + + switch(mode) { + case LIST_ARTISTS: + g_snprintf(str, size, _("Artist: [db browser - EXPERIMENTAL]")); + break; + case LIST_ALBUMS: + g_snprintf(str, size, _("Artist: %s"), s1); + break; + case LIST_SONGS: + g_snprintf(str, size, _("Artist: %s - %s"), s1, s2); + break; + } + g_free(s1); + g_free(s2); + return str; } static list_window_t * @@ -303,173 +290,167 @@ get_filelist_window() static void add_query(mpdclient_t *c, int table, char *filter) { - char *str; - mpdclient_filelist_t *addlist; - - str = utf8_to_locale(filter); - if( table== MPD_TABLE_ALBUM ) - screen_status_printf("Adding album %s...", str); - else - screen_status_printf("Adding %s...", str); - g_free(str); - addlist = mpdclient_filelist_search_utf8(c, TRUE, table, filter); - if( addlist ) - { - mpdclient_filelist_add_all(c, addlist); - addlist = mpdclient_filelist_free(addlist); - } + char *str; + mpdclient_filelist_t *addlist; + + str = utf8_to_locale(filter); + if (table== MPD_TABLE_ALBUM) + screen_status_printf("Adding album %s...", str); + else + screen_status_printf("Adding %s...", str); + g_free(str); + + addlist = mpdclient_filelist_search_utf8(c, TRUE, table, filter); + if (addlist) { + mpdclient_filelist_add_all(c, addlist); + addlist = mpdclient_filelist_free(addlist); + } } -static int +static int artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { - char *selected; - - switch(cmd) - { - case CMD_PLAY: - switch(mode) - { - case LIST_ARTISTS: - selected = (char *) g_list_nth_data(metalist, lw->selected); - update_metalist(c, g_strdup(selected), NULL); - list_window_push_state(lw_state,lw); - break; - case LIST_ALBUMS: - if( lw->selected == 0 ) /* handle ".." */ - { - update_metalist(c, NULL, NULL); - list_window_reset(lw); - /* restore previous list window state */ - list_window_pop_state(lw_state,lw); - } - else if( lw->selected == metalist_length-1) /* handle "show all" */ - { - update_metalist(c, g_strdup(artist), g_strdup("\0")); - list_window_push_state(lw_state,lw); - } - else /* select album */ - { - selected = (char *) g_list_nth_data(metalist, lw->selected); - update_metalist(c, g_strdup(artist), g_strdup(selected)); - list_window_push_state(lw_state,lw); - } - break; - case LIST_SONGS: - if( lw->selected==0 ) /* handle ".." */ - { - update_metalist(c, g_strdup(artist), NULL); - list_window_reset(lw); - /* restore previous list window state */ - list_window_pop_state(lw_state,lw); - } - else - browse_handle_enter(screen, c, lw, filelist); - break; + char *selected; + + switch(cmd) { + case CMD_PLAY: + switch (mode) { + case LIST_ARTISTS: + selected = (char *) g_list_nth_data(metalist, lw->selected); + update_metalist(c, g_strdup(selected), NULL); + list_window_push_state(lw_state,lw); + break; + + case LIST_ALBUMS: + if (lw->selected == 0) { + /* handle ".." */ + + update_metalist(c, NULL, NULL); + list_window_reset(lw); + /* restore previous list window state */ + list_window_pop_state(lw_state,lw); + } else if (lw->selected == metalist_length - 1) { + /* handle "show all" */ + update_metalist(c, g_strdup(artist), g_strdup("\0")); + list_window_push_state(lw_state,lw); + } else { + /* select album */ + selected = (char *) g_list_nth_data(metalist, lw->selected); + update_metalist(c, g_strdup(artist), g_strdup(selected)); + list_window_push_state(lw_state,lw); + } + break; + + case LIST_SONGS: + if (lw->selected == 0) { + /* handle ".." */ + + update_metalist(c, g_strdup(artist), NULL); + list_window_reset(lw); + /* restore previous list window state */ + list_window_pop_state(lw_state,lw); + } else + browse_handle_enter(screen, c, lw, filelist); + break; + } + return 1; + + + /* FIXME? CMD_GO_* handling duplicates code from CMD_PLAY */ + + case CMD_GO_PARENT_DIRECTORY: + switch (mode) { + case LIST_ALBUMS: + update_metalist(c, NULL, NULL); + list_window_reset(lw); + /* restore previous list window state */ + list_window_pop_state(lw_state,lw); + break; + + case LIST_SONGS: + update_metalist(c, g_strdup(artist), NULL); + list_window_reset(lw); + /* restore previous list window state */ + list_window_pop_state(lw_state,lw); + break; + } + break; + + case CMD_GO_ROOT_DIRECTORY: + switch (mode) { + case LIST_ALBUMS: + case LIST_SONGS: + update_metalist(c, NULL, NULL); + list_window_reset(lw); + /* restore first list window state (pop while returning true) */ + while(list_window_pop_state(lw_state,lw)); + break; + } + break; + + case CMD_SELECT: + switch(mode) { + case LIST_ARTISTS: + selected = (char *) g_list_nth_data(metalist, lw->selected); + add_query(c, MPD_TABLE_ARTIST, selected); + cmd = CMD_LIST_NEXT; /* continue and select next item... */ + break; + + case LIST_ALBUMS: + if (lw->selected && lw->selected == metalist_length - 1) + add_query(c, MPD_TABLE_ARTIST, artist); + else if (lw->selected > 0) { + selected = (char *) g_list_nth_data(metalist, lw->selected); + add_query(c, MPD_TABLE_ALBUM, selected); + cmd = CMD_LIST_NEXT; /* continue and select next item... */ + } + break; + + case LIST_SONGS: + if (browse_handle_select(screen, c, lw, filelist) == 0) + /* continue and select next item... */ + cmd = CMD_LIST_NEXT; + break; + } + break; + + /* continue and update... */ + case CMD_SCREEN_UPDATE: + screen->painted = 0; + lw->clear = 1; + lw->repaint = 1; + update_metalist(c, g_strdup(artist), g_strdup(album)); + screen_status_printf(_("Screen updated!")); + return 0; + + case CMD_LIST_FIND: + case CMD_LIST_RFIND: + case CMD_LIST_FIND_NEXT: + case CMD_LIST_RFIND_NEXT: + if (filelist) + return screen_find(screen, + lw, filelist->length, + cmd, browse_lw_callback, (void *) filelist); + else if (metalist) + return screen_find(screen, + lw, metalist_length, + cmd, artist_lw_callback, (void *) metalist); + else + return 1; + + case CMD_MOUSE_EVENT: + return browse_handle_mouse_event(screen,c,lw,filelist); + + default: + break; } - return 1; - - /* FIXME? CMD_GO_* handling duplicates code from CMD_PLAY */ - - case CMD_GO_PARENT_DIRECTORY: - switch(mode) - { - case LIST_ALBUMS: - update_metalist(c, NULL, NULL); - list_window_reset(lw); - /* restore previous list window state */ - list_window_pop_state(lw_state,lw); - break; - case LIST_SONGS: - update_metalist(c, g_strdup(artist), NULL); - list_window_reset(lw); - /* restore previous list window state */ - list_window_pop_state(lw_state,lw); - break; - } - break; + if (filelist) + return list_window_cmd(lw, filelist->length, cmd); + else if (metalist) + return list_window_cmd(lw, metalist_length, cmd); - case CMD_GO_ROOT_DIRECTORY: - switch(mode) - { - case LIST_ALBUMS: - case LIST_SONGS: - update_metalist(c, NULL, NULL); - list_window_reset(lw); - /* restore first list window state (pop while returning true) */ - while(list_window_pop_state(lw_state,lw)); - break; - } - break; - - case CMD_SELECT: - switch(mode) - { - case LIST_ARTISTS: - selected = (char *) g_list_nth_data(metalist, lw->selected); - add_query(c, MPD_TABLE_ARTIST, selected); - cmd = CMD_LIST_NEXT; /* continue and select next item... */ - break; - case LIST_ALBUMS: - if( lw->selected && lw->selected == metalist_length-1) - { - add_query(c, MPD_TABLE_ARTIST, artist); - } - else if( lw->selected > 0 ) - { - selected = (char *) g_list_nth_data(metalist, lw->selected); - add_query(c, MPD_TABLE_ALBUM, selected); - cmd = CMD_LIST_NEXT; /* continue and select next item... */ - } - break; - case LIST_SONGS: - if( browse_handle_select(screen, c, lw, filelist) == 0 ) - { - cmd = CMD_LIST_NEXT; /* continue and select next item... */ - } - break; - } - break; - - /* continue and update... */ - case CMD_SCREEN_UPDATE: - screen->painted = 0; - lw->clear = 1; - lw->repaint = 1; - update_metalist(c, g_strdup(artist), g_strdup(album)); - screen_status_printf(_("Screen updated!")); - return 0; - - case CMD_LIST_FIND: - case CMD_LIST_RFIND: - case CMD_LIST_FIND_NEXT: - case CMD_LIST_RFIND_NEXT: - if( filelist ) - return screen_find(screen, - lw, filelist->length, - cmd, browse_lw_callback, (void *) filelist); - else if ( metalist ) - return screen_find(screen, - lw, metalist_length, - cmd, artist_lw_callback, (void *) metalist); - else - return 1; - - case CMD_MOUSE_EVENT: - return browse_handle_mouse_event(screen,c,lw,filelist); - - default: - break; - } - - if( filelist ) - return list_window_cmd(lw, filelist->length, cmd); - else if( metalist ) - return list_window_cmd(lw, metalist_length, cmd); - - - return 0; + return 0; } const struct screen_functions screen_artist = { |