From a8cf6c4f3ebad251ec0f28f9c6b0e3880528c950 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 18 Sep 2008 23:35:10 +0200 Subject: [PATCH] code style, indent with tabs VI Follow the same code style als MPD itself. --- src/command.c | 413 +++++++++++++++++++++---------------------- src/screen_file.c | 126 +++++++------ src/screen_search.c | 422 +++++++++++++++++++++----------------------- src/utils.c | 104 ++++++----- 4 files changed, 515 insertions(+), 550 deletions(-) diff --git a/src/command.c b/src/command.c index 151d465..93afe42 100644 --- a/src/command.c +++ b/src/command.c @@ -208,178 +208,170 @@ static command_definition_t cmds[] = command_definition_t * get_command_definitions(void) { - return cmds; + return cmds; } const char * key2str(int key) { - static char buf[32]; - int i; + static char buf[32]; + int i; - buf[0] = 0; - switch(key) - { - case 0: - return _("Undefined"); - case ' ': - return _("Space"); - case 13: - return _("Enter"); - case BS: - return _("Backspace"); - case DEL: - return _("Delete"); - case UP: - return _("Up"); - case DWN: - return _("Down"); - case LEFT: - return _("Left"); - case RGHT: - return _("Right"); - case HOME: - return _("Home"); - case END: - return _("End"); - case PGDN: - return _("PageDown"); - case PGUP: - return _("PageUp"); - case TAB: - return _("Tab"); - case STAB: - return _("Shift+Tab"); - case ESC: - return _("Esc"); - case KEY_IC: - return _("Insert"); - default: - for(i=0; i<=63; i++) - if( key==KEY_F(i) ) - { - g_snprintf(buf, 32, "F%d", i ); - return buf; - } - if( !(key & ~037) ) - g_snprintf(buf, 32, "Ctrl-%c", 'A'+(key & 037)-1 ); - else if( (key & ~037) == 224 ) - g_snprintf(buf, 32, "Alt-%c", 'A'+(key & 037)-1 ); - else if( key>32 && key<256 ) - g_snprintf(buf, 32, "%c", key); - else - g_snprintf(buf, 32, "0x%03X", key); - } - return buf; + buf[0] = 0; + switch(key) { + case 0: + return _("Undefined"); + case ' ': + return _("Space"); + case 13: + return _("Enter"); + case BS: + return _("Backspace"); + case DEL: + return _("Delete"); + case UP: + return _("Up"); + case DWN: + return _("Down"); + case LEFT: + return _("Left"); + case RGHT: + return _("Right"); + case HOME: + return _("Home"); + case END: + return _("End"); + case PGDN: + return _("PageDown"); + case PGUP: + return _("PageUp"); + case TAB: + return _("Tab"); + case STAB: + return _("Shift+Tab"); + case ESC: + return _("Esc"); + case KEY_IC: + return _("Insert"); + default: + for (i = 0; i <= 63; i++) + if (key == KEY_F(i)) { + g_snprintf(buf, 32, "F%d", i ); + return buf; + } + if (!(key & ~037)) + g_snprintf(buf, 32, "Ctrl-%c", 'A'+(key & 037)-1 ); + else if ((key & ~037) == 224) + g_snprintf(buf, 32, "Alt-%c", 'A'+(key & 037)-1 ); + else if (key > 32 && key < 256) + g_snprintf(buf, 32, "%c", key); + else + g_snprintf(buf, 32, "0x%03X", key); + } + + return buf; } void command_dump_keys(void) { - int i; + int i; - i=0; - while( cmds[i].description ) - { - if( cmds[i].command != CMD_NONE ) - printf(" %20s : %s\n", get_key_names(cmds[i].command,1),cmds[i].name); - i++; - } + i = 0; + while (cmds[i].description) { + if (cmds[i].command != CMD_NONE) + printf(" %20s : %s\n", get_key_names(cmds[i].command,1),cmds[i].name); + i++; + } } static int set_key_flags(command_definition_t *cp, command_t command, int flags) { - int i; + int i; - i=0; - while( cp[i].name ) - { - if( cp[i].command == command ) - { - cp[i].flags |= flags; - return 0; + i = 0; + while (cp[i].name) { + if (cp[i].command == command) { + cp[i].flags |= flags; + return 0; + } + i++; } - i++; - } - return 1; + + return 1; } const char * get_key_names(command_t command, int all) { int i; - + i=0; - while( cmds[i].description ) - { - if( cmds[i].command == command ) - { - int j; - static char keystr[80]; - - g_strlcpy(keystr, key2str(cmds[i].keys[0]), sizeof(keystr)); - if( !all ) - return keystr; - j=1; - while( j0 ) - { - g_strlcat(keystr, " ", sizeof(keystr)); - g_strlcat(keystr, key2str(cmds[i].keys[j]), sizeof(keystr)); - j++; - } - return keystr; - } - i++; - } + while (cmds[i].description) { + if (cmds[i].command == command) { + int j; + static char keystr[80]; + + g_strlcpy(keystr, key2str(cmds[i].keys[0]), sizeof(keystr)); + if (!all) + return keystr; + j=1; + while (j < MAX_COMMAND_KEYS && cmds[i].keys[j] > 0) { + g_strlcat(keystr, " ", sizeof(keystr)); + g_strlcat(keystr, key2str(cmds[i].keys[j]), sizeof(keystr)); + j++; + } + return keystr; + } + i++; + } return NULL; } const char * get_key_description(command_t command) { - int i; + int i; - i=0; - while( cmds[i].description ) - { - if( cmds[i].command == command ) - return _(cmds[i].description); - i++; - } - return NULL; + i=0; + while (cmds[i].description) { + if (cmds[i].command == command) + return _(cmds[i].description); + i++; + } + + return NULL; } const char * get_key_command_name(command_t command) { - int i; + int i; - i=0; - while( cmds[i].name ) - { - if( cmds[i].command == command ) - return cmds[i].name; - i++; - } - return NULL; + i=0; + while (cmds[i].name) { + if (cmds[i].command == command) + return cmds[i].name; + i++; + } + return NULL; } -command_t +command_t get_key_command_from_name(char *name) { - int i; + int i; - i=0; - while( cmds[i].name ) - { - if( strcmp(name, cmds[i].name) == 0 ) - return cmds[i].command; - i++; - } - return CMD_NONE; -} + i=0; + while (cmds[i].name) { + if (strcmp(name, cmds[i].name) == 0) + return cmds[i].command; + i++; + } + return CMD_NONE; +} command_t find_key_command(int key, command_definition_t *c) @@ -447,111 +439,104 @@ get_keyboard_command(void) int assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]) { - int i; + int i; - i=0; - while( cmds[i].name ) - { - if( cmds[i].command == command ) - { - memcpy(cmds[i].keys, keys, sizeof(int)*MAX_COMMAND_KEYS); - cmds[i].flags |= COMMAND_KEY_MODIFIED; - return 0; + i=0; + while (cmds[i].name) { + if (cmds[i].command == command) { + memcpy(cmds[i].keys, keys, sizeof(int)*MAX_COMMAND_KEYS); + cmds[i].flags |= COMMAND_KEY_MODIFIED; + return 0; + } + i++; } - i++; - } - return -1; + return -1; } -int +int check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize) { - int i; - int retval = 0; + int i; + int retval = 0; - if( cp==NULL ) - cp = cmds; + if (cp == NULL) + cp = cmds; - i=0; - while( cp[i].name ) - { - cp[i].flags &= ~COMMAND_KEY_CONFLICT; - i++; - } - - i=0; - while( cp[i].name ) - { - int j; - command_t cmd; - - for(j=0; jpainted = 0; - lw->clear = 1; - lw->repaint = 1; - filelist = mpdclient_filelist_update(c, filelist); - list_window_check_selected(lw, filelist->length); - screen_status_printf(_("Screen updated!")); - return 1; - case CMD_DB_UPDATE: - if (c->status == NULL) - return 1; - - if( !c->status->updatingDb ) - { - if( mpdclient_cmd_db_update_utf8(c,filelist->path)==0 ) - { - if(strcmp(filelist->path,"")) { - screen_status_printf(_("Database update of %s started!"), - filelist->path); - } else { - screen_status_printf(_("Database update started!")); - } - /* set updatingDb to make shure the browse callback gets called - * even if the updated has finished before status is updated */ - c->status->updatingDb = 1; - } - } - else - screen_status_printf(_("Database update running...")); - return 1; - case CMD_LIST_FIND: - case CMD_LIST_RFIND: - case CMD_LIST_FIND_NEXT: - case CMD_LIST_RFIND_NEXT: - return screen_find(screen, - lw, filelist->length, - cmd, browse_lw_callback, (void *) filelist); - case CMD_MOUSE_EVENT: - return browse_handle_mouse_event(screen,c,lw,filelist); - default: - break; + switch(cmd) { + case CMD_PLAY: + browse_handle_enter(screen, c, lw, filelist); + return 1; + case CMD_GO_ROOT_DIRECTORY: + return change_directory(screen, c, NULL, ""); + break; + case CMD_GO_PARENT_DIRECTORY: + return change_directory(screen, c, NULL, ".."); + break; + case CMD_SELECT: + if (browse_handle_select(screen, c, lw, filelist) == 0) { + /* continue and select next item... */ + cmd = CMD_LIST_NEXT; } + break; + case CMD_DELETE: + handle_delete(screen, c); + break; + case CMD_SAVE_PLAYLIST: + handle_save(screen, c); + break; + case CMD_SCREEN_UPDATE: + screen->painted = 0; + lw->clear = 1; + lw->repaint = 1; + filelist = mpdclient_filelist_update(c, filelist); + list_window_check_selected(lw, filelist->length); + screen_status_printf(_("Screen updated!")); + return 1; + case CMD_DB_UPDATE: + if (c->status == NULL) + return 1; + + if (!c->status->updatingDb) { + if (mpdclient_cmd_db_update_utf8(c,filelist->path) == 0) { + if (strcmp(filelist->path, "")) + screen_status_printf(_("Database update of %s started!"), + filelist->path); + else + screen_status_printf(_("Database update started!")); + + /* set updatingDb to make shure the browse callback gets called + * even if the updated has finished before status is updated */ + c->status->updatingDb = 1; + } + } else + screen_status_printf(_("Database update running...")); + return 1; + case CMD_LIST_FIND: + case CMD_LIST_RFIND: + case CMD_LIST_FIND_NEXT: + case CMD_LIST_RFIND_NEXT: + return screen_find(screen, + lw, filelist->length, + cmd, browse_lw_callback, (void *) filelist); + case CMD_MOUSE_EVENT: + return browse_handle_mouse_event(screen,c,lw,filelist); + default: + break; + } + return list_window_cmd(lw, filelist->length, cmd); } diff --git a/src/screen_search.c b/src/screen_search.c index d1b2b92..7e971f5 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -42,7 +42,6 @@ /* new search stuff with qball's libmpdclient */ #define FUTURE - #ifdef FUTURE extern gint mpdclient_finish_command(mpdclient_t *c); @@ -54,39 +53,37 @@ typedef struct { } search_tag_t; static search_tag_t search_tag[] = { - { MPD_TAG_ITEM_ARTIST, "artist", N_("artist") }, - { MPD_TAG_ITEM_ALBUM, "album", N_("album") }, - { MPD_TAG_ITEM_TITLE, "title", N_("title") }, - { MPD_TAG_ITEM_TRACK, "track", N_("track") }, - { MPD_TAG_ITEM_NAME, "name", N_("name") }, - { MPD_TAG_ITEM_GENRE, "genre", N_("genre") }, - { MPD_TAG_ITEM_DATE, "date", N_("date") }, - { MPD_TAG_ITEM_COMPOSER, "composer", N_("composer") }, - { MPD_TAG_ITEM_PERFORMER,"performer", N_("performer") }, - { MPD_TAG_ITEM_COMMENT, "comment", N_("comment") }, - { MPD_TAG_ITEM_FILENAME, "filename", N_("file") }, - { -1, NULL, NULL } + { MPD_TAG_ITEM_ARTIST, "artist", N_("artist") }, + { MPD_TAG_ITEM_ALBUM, "album", N_("album") }, + { MPD_TAG_ITEM_TITLE, "title", N_("title") }, + { MPD_TAG_ITEM_TRACK, "track", N_("track") }, + { MPD_TAG_ITEM_NAME, "name", N_("name") }, + { MPD_TAG_ITEM_GENRE, "genre", N_("genre") }, + { MPD_TAG_ITEM_DATE, "date", N_("date") }, + { MPD_TAG_ITEM_COMPOSER, "composer", N_("composer") }, + { MPD_TAG_ITEM_PERFORMER, "performer", N_("performer") }, + { MPD_TAG_ITEM_COMMENT, "comment", N_("comment") }, + { MPD_TAG_ITEM_FILENAME, "filename", N_("file") }, + { -1, NULL, NULL } }; static int search_get_tag_id(char *name) { - int i; - - i=0; - while( search_tag[i].name ) - { - if( strcasecmp(search_tag[i].name, name)==0 || - strcasecmp(search_tag[i].localname, name)==0 ) - return search_tag[i].id; - i++; - } - return -1; + int i = 0; + + while (search_tag[i].name) { + if (strcasecmp(search_tag[i].name, name) == 0 || + strcasecmp(search_tag[i].localname, name) == 0) + return search_tag[i].id; + i++; + } + + return -1; } #endif - #define SEARCH_TITLE 0 #define SEARCH_ARTIST 1 #define SEARCH_ALBUM 2 @@ -100,12 +97,12 @@ typedef struct { } search_type_t; static search_type_t mode[] = { - { MPD_TABLE_TITLE, N_("Title") }, - { MPD_TABLE_ARTIST, N_("Artist") }, - { MPD_TABLE_ALBUM, N_("Album") }, - { MPD_TABLE_FILENAME, N_("Filename") }, - { SEARCH_ARTIST_TITLE, N_("Artist + Title") }, - { 0, NULL } + { MPD_TABLE_TITLE, N_("Title") }, + { MPD_TABLE_ARTIST, N_("Artist") }, + { MPD_TABLE_ALBUM, N_("Album") }, + { MPD_TABLE_FILENAME, N_("Filename") }, + { SEARCH_ARTIST_TITLE, N_("Artist + Title") }, + { 0, NULL } }; static list_window_t *lw = NULL; @@ -144,35 +141,34 @@ lw_search_help_callback(unsigned idx, mpd_unused int *highlight, } /* the playlist have been updated -> fix highlights */ -static void +static void playlist_changed_callback(mpdclient_t *c, int event, mpd_unused gpointer data) { - if( filelist==NULL ) - return; - D("screen_search.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_search.c> playlist_callback() [%d]\n", event); + switch(event) { + case PLAYLIST_EVENT_CLEAR: + clear_highlights(filelist); + break; + default: + sync_highlights(c, filelist); + break; + } } /* sanity check search mode value */ static void search_check_mode(void) { - int max = 0; - - while( mode[max].label != NULL ) - max++; - if( options.search_mode<0 ) - options.search_mode = 0; - else if( options.search_mode>=max ) - options.search_mode = max-1; + int max = 0; + + while (mode[max].label != NULL) + max++; + if (options.search_mode < 0) + options.search_mode = 0; + else if (options.search_mode >= max) + options.search_mode = max-1; } static void @@ -195,26 +191,22 @@ static mpdclient_filelist_t * filelist_search(mpdclient_t *c, mpd_unused int exact_match, int table, gchar *local_pattern) { - mpdclient_filelist_t *list, *list2; - - if( table == SEARCH_ARTIST_TITLE ) - { - list = mpdclient_filelist_search(c, FALSE, MPD_TABLE_ARTIST, - local_pattern); - list2 = mpdclient_filelist_search(c, FALSE, MPD_TABLE_TITLE, - local_pattern); - - list->length += list2->length; - list->list = g_list_concat(list->list, list2->list); - list->list = g_list_sort(list->list, compare_filelistentry_format); - list->updated = TRUE; - } - else - { - list = mpdclient_filelist_search(c, FALSE, table, local_pattern); - } - - return list; + mpdclient_filelist_t *list, *list2; + + if (table == SEARCH_ARTIST_TITLE) { + list = mpdclient_filelist_search(c, FALSE, MPD_TABLE_ARTIST, + local_pattern); + list2 = mpdclient_filelist_search(c, FALSE, MPD_TABLE_TITLE, + local_pattern); + + list->length += list2->length; + list->list = g_list_concat(list->list, list2->list); + list->list = g_list_sort(list->list, compare_filelistentry_format); + list->updated = TRUE; + } else + list = mpdclient_filelist_search(c, FALSE, table, local_pattern); + + return list; } /*----------------------------------------------------------------------- @@ -328,36 +320,35 @@ search_advanced_query(char *query, mpdclient_t *c) static void search_new(screen_t *screen, mpdclient_t *c) { - search_clear(screen, c, TRUE); - - pattern = screen_readln(screen->status_window.w, - _("Search: "), - NULL, - &search_history, - NULL); - - if( pattern && strcmp(pattern,"")==0 ) - { - g_free(pattern); - pattern=NULL; - } - - if( pattern==NULL ) - { - list_window_reset(lw); - return; - } - - if( !MPD_VERSION_LT(c, 0, 12, 0) ) - filelist = search_advanced_query(pattern, c); - if( !advanced_search_mode && filelist==NULL ) - filelist = filelist_search(c, - FALSE, - mode[options.search_mode].table, - pattern); - sync_highlights(c, filelist); - mpdclient_install_playlist_callback(c, playlist_changed_callback); - list_window_check_selected(lw, filelist->length); + search_clear(screen, c, TRUE); + + pattern = screen_readln(screen->status_window.w, + _("Search: "), + NULL, + &search_history, + NULL); + + if (pattern && strcmp(pattern,"") == 0) { + g_free(pattern); + pattern=NULL; + } + + if (pattern == NULL) { + list_window_reset(lw); + return; + } + + if (!MPD_VERSION_LT(c, 0, 12, 0)) + filelist = search_advanced_query(pattern, c); + + if (!advanced_search_mode && filelist == NULL) + filelist = filelist_search(c, FALSE, + mode[options.search_mode].table, + pattern); + + sync_highlights(c, filelist); + mpdclient_install_playlist_callback(c, playlist_changed_callback); + list_window_check_selected(lw, filelist->length); } @@ -386,145 +377,140 @@ quit(void) static void open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - // if( pattern==NULL ) - // search_new(screen, c); - // else - screen_status_printf(_("Press %s for a new search"), - get_key_names(CMD_SCREEN_SEARCH,0)); - search_check_mode(); + // if( pattern==NULL ) + // search_new(screen, c); + // else + screen_status_printf(_("Press %s for a new search"), + get_key_names(CMD_SCREEN_SEARCH,0)); + search_check_mode(); } static void resize(int cols, int rows) { - lw->cols = cols; - lw->rows = rows; + lw->cols = cols; + lw->rows = rows; } -static void +static void paint(mpd_unused screen_t *screen, mpdclient_t *c) { - lw->clear = 1; - - if( filelist ) - { - lw->flags = 0; - list_window_paint(lw, browse_lw_callback, (void *) filelist); - filelist->updated = FALSE; - } - else - { - lw->flags = LW_HIDE_CURSOR; - list_window_paint(lw, lw_search_help_callback, NULL); - if( !MPD_VERSION_LT(c, 0, 12, 0) ) - g_strdup_printf("Advanced search disabled (MPD version < 0.12.0"); - // wmove(lw->w, 0, 0); - //wclrtobot(lw->w); - } - wnoutrefresh(lw->w); + lw->clear = 1; + + if (filelist) { + lw->flags = 0; + list_window_paint(lw, browse_lw_callback, (void *) filelist); + filelist->updated = FALSE; + } else { + lw->flags = LW_HIDE_CURSOR; + list_window_paint(lw, lw_search_help_callback, NULL); + if( !MPD_VERSION_LT(c, 0, 12, 0) ) + g_strdup_printf("Advanced search disabled (MPD version < 0.12.0"); + // wmove(lw->w, 0, 0); + //wclrtobot(lw->w); + } + + wnoutrefresh(lw->w); } -static void +static void update(screen_t *screen, mpdclient_t *c) { - if( filelist==NULL || filelist->updated ) - { - paint(screen, c); - return; - } - list_window_paint(lw, browse_lw_callback, (void *) filelist); - wnoutrefresh(lw->w); + if (filelist==NULL || filelist->updated) { + paint(screen, c); + return; + } + + list_window_paint(lw, browse_lw_callback, (void *) filelist); + wnoutrefresh(lw->w); } static const char * get_title(char *str, size_t size) { - if( advanced_search_mode && pattern ) - g_snprintf(str, size, _("Search: %s"), pattern); - else if( pattern ) - g_snprintf(str, size, - _("Search: Results for %s [%s]"), - pattern, - _(mode[options.search_mode].label)); - else - g_snprintf(str, size, _("Search: Press %s for a new search [%s]"), - get_key_names(CMD_SCREEN_SEARCH,0), - _(mode[options.search_mode].label)); - - return str; + if (advanced_search_mode && pattern) + g_snprintf(str, size, _("Search: %s"), pattern); + else if (pattern) + g_snprintf(str, size, + _("Search: Results for %s [%s]"), + pattern, + _(mode[options.search_mode].label)); + else + g_snprintf(str, size, _("Search: Press %s for a new search [%s]"), + get_key_names(CMD_SCREEN_SEARCH,0), + _(mode[options.search_mode].label)); + + return str; } -static int +static int search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { - switch(cmd) - { - case CMD_PLAY: - browse_handle_enter(screen, c, lw, filelist); - return 1; - - case CMD_SELECT: - if( browse_handle_select(screen, c, lw, filelist) == 0 ) - { - /* continue and select next item... */ - cmd = CMD_LIST_NEXT; - } - /* call list_window_cmd to go to the next item */ - return list_window_cmd(lw, filelist->length, cmd); - - case CMD_SELECT_ALL: - browse_handle_select_all (screen, c, lw, filelist); - paint (screen, c); - return 0; - - case CMD_SEARCH_MODE: - options.search_mode++; - if( mode[options.search_mode].label == NULL ) - options.search_mode = 0; - screen_status_printf(_("Search mode: %s"), - _(mode[options.search_mode].label)); - /* continue and update... */ - case CMD_SCREEN_UPDATE: - if( pattern ) - { - search_clear(screen, c, FALSE); - filelist = filelist_search(c, - FALSE, - mode[options.search_mode].table, - pattern); - sync_highlights(c, filelist); + switch (cmd) { + case CMD_PLAY: + browse_handle_enter(screen, c, lw, filelist); + return 1; + + case CMD_SELECT: + if (browse_handle_select(screen, c, lw, filelist) == 0) { + /* continue and select next item... */ + cmd = CMD_LIST_NEXT; + } + /* call list_window_cmd to go to the next item */ + return list_window_cmd(lw, filelist->length, cmd); + + case CMD_SELECT_ALL: + browse_handle_select_all (screen, c, lw, filelist); + paint (screen, c); + return 0; + + case CMD_SEARCH_MODE: + options.search_mode++; + if (mode[options.search_mode].label == NULL) + options.search_mode = 0; + screen_status_printf(_("Search mode: %s"), + _(mode[options.search_mode].label)); + /* continue and update... */ + case CMD_SCREEN_UPDATE: + if (pattern) { + search_clear(screen, c, FALSE); + filelist = filelist_search(c, + FALSE, + mode[options.search_mode].table, + pattern); + sync_highlights(c, filelist); + } + return 1; + + case CMD_SCREEN_SEARCH: + search_new(screen, c); + return 1; + + case CMD_CLEAR: + search_clear(screen, c, TRUE); + list_window_reset(lw); + return 1; + + 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 + return 1; + + case CMD_MOUSE_EVENT: + return browse_handle_mouse_event(screen,c,lw,filelist); + + default: + if (filelist) + return list_window_cmd(lw, filelist->length, cmd); } - return 1; - - case CMD_SCREEN_SEARCH: - search_new(screen, c); - return 1; - - case CMD_CLEAR: - search_clear(screen, c, TRUE); - list_window_reset(lw); - return 1; - - 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 - return 1; - - case CMD_MOUSE_EVENT: - return browse_handle_mouse_event(screen,c,lw,filelist); - - default: - if( filelist ) - return list_window_cmd(lw, filelist->length, cmd); - } - - return 0; + + return 0; } const struct screen_functions screen_search = { diff --git a/src/utils.c b/src/utils.c index ac836a2..9241296 100644 --- a/src/utils.c +++ b/src/utils.c @@ -30,16 +30,16 @@ GList * string_list_free(GList *string_list) { - GList *list = g_list_first(string_list); - - while(list) - { - g_free(list->data); - list->data=NULL; - list=list->next; - } - g_list_free(string_list); - return NULL; + GList *list = g_list_first(string_list); + + while (list) { + g_free(list->data); + list->data = NULL; + list = list->next; + } + + g_list_free(string_list); + return NULL; } GList * @@ -75,49 +75,47 @@ string_list_remove(GList *string_list, const gchar *str) GList * gcmp_list_from_path(mpdclient_t *c, const gchar *path, GList *list, gint types) { - GList *flist = NULL; - mpdclient_filelist_t *filelist; - - if( (filelist=mpdclient_filelist_get(c, path)) == NULL ) - return list; - D("retrieved filelist!\n"); - flist = filelist->list; - while( flist ) - { - filelist_entry_t *entry = flist->data; - mpd_InfoEntity *entity = entry ? entry->entity : NULL; - char *name = NULL; - - if( entity && entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY && - types & GCMP_TYPE_DIR) - { - mpd_Directory *dir = entity->info.directory; - gchar *tmp = utf8_to_locale(dir->path); - gsize size = strlen(tmp)+2; - - name = g_malloc(size); - g_strlcpy(name, tmp, size); - g_strlcat(name, "/", size); - g_free(tmp); - } - else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG && - types & GCMP_TYPE_FILE ) - { - mpd_Song *song = entity->info.song; - name = utf8_to_locale(song->file); - } - else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE && - types & GCMP_TYPE_PLAYLIST ) - { - mpd_PlaylistFile *plf = entity->info.playlistFile; - name = utf8_to_locale(plf->path); - } + GList *flist = NULL; + mpdclient_filelist_t *filelist; - if( name ) - list = g_list_append(list, name); + if ((filelist = mpdclient_filelist_get(c, path)) == NULL) + return list; - flist = flist->next; - } - mpdclient_filelist_free(filelist); - return list; + D("retrieved filelist!\n"); + flist = filelist->list; + while (flist) { + filelist_entry_t *entry = flist->data; + mpd_InfoEntity *entity = entry ? entry->entity : NULL; + char *name = NULL; + + if (entity && entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY && + types & GCMP_TYPE_DIR) { + mpd_Directory *dir = entity->info.directory; + gchar *tmp = utf8_to_locale(dir->path); + gsize size = strlen(tmp)+2; + + name = g_malloc(size); + g_strlcpy(name, tmp, size); + g_strlcat(name, "/", size); + g_free(tmp); + } else if (entity && + entity->type == MPD_INFO_ENTITY_TYPE_SONG && + types & GCMP_TYPE_FILE) { + mpd_Song *song = entity->info.song; + name = utf8_to_locale(song->file); + } else if (entity && + entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE && + types & GCMP_TYPE_PLAYLIST) { + mpd_PlaylistFile *plf = entity->info.playlistFile; + name = utf8_to_locale(plf->path); + } + + if (name) + list = g_list_append(list, name); + + flist = flist->next; + } + + mpdclient_filelist_free(filelist); + return list; } -- 2.30.2