int cmd_sort(int argc, char *argv[]) { const char *errmsg; if (argc != 2) { paint_error("usage: sort <sort-description>"); return 1; } /* setup global sort description */ if (mi_sort_set(argv[1], &errmsg) != 0) { paint_error("%s: bad sort description: %s", argv[0], errmsg); return 2; } /* do the actual sort */ qsort(viewing_playlist->files, viewing_playlist->nfiles, sizeof(meta_info*), mi_compare); if (!ui_is_init()) return 0; /* redraw */ paint_playlist(); /* if we sorted a playlist other than library, and user wants to save sorts */ if (viewing_playlist != mdb.library && sorts_need_saving) { viewing_playlist->needs_saving = true; paint_library(); } return 0; }
int cmd_display(int argc, char *argv[]) { const char *errmsg; if (argc != 2) { paint_error("usage: display [ reset | show | <display-description> ]"); return 1; } /* show existng display? */ if (strcasecmp(argv[1], "show") == 0) { paint_message(":display %s", mi_display_tostr()); return 0; } /* reset display to default? */ if (strcasecmp(argv[1], "reset") == 0) { mi_display_reset(); paint_playlist(); return 0; } /* if reached here, setup global display description */ if (mi_display_set(argv[1], &errmsg) != 0) { paint_error("%s: bad display description: %s", argv[0], errmsg); return 1; } if(ui_is_init()) paint_playlist(); return 0; }
int cmd_set(int argc, char *argv[]) { const char *err; char *property; char *value; bool tf; int max_w, max_h, new_width; /* lwidth */ bool player_is_setup; if (argc != 2) { paint_error("usage: %s <property>=<value>", argv[0]); return 1; } /* determine if the player has been setup (needed for redraws below) */ player_is_setup = (player.name != NULL) && (*player.name != NULL); /* extract property and value */ property = argv[1]; if ((value = strchr(property, '=')) == NULL) { paint_error("usage: %s <property>=<value>", argv[0]); return 2; } *value = '\0'; value++; /* handle property */ if (strcasecmp(property, "lwidth") == 0) { /* get max width and height */ getmaxyx(stdscr, max_h, max_w); /* validate and convert width user provided */ new_width = (int)strtonum(value, 1, max_w, &err); if (err != NULL) { paint_error("%s %s: bad width: '%s' %s", argv[0], property, value, err); return 3; } /* resize & redraw (if we're past setup & curses is running) */ ui.lwidth = new_width; ui_resize(); if(player_is_setup && ui_is_init()) { ui_clear(); paint_all(); } } else if (strcasecmp(property, "lhide") == 0) { if (str2bool(value, &tf) < 0) { paint_error("%s %s: value must be boolean", argv[0], property); return 4; } ui.lhide = tf; if (ui.lhide) { if (ui.active == ui.playlist) ui_hide_library(); if (player_is_setup && ui_is_init()) { ui_clear(); paint_all(); paint_message("library window hidden"); } } else { if (ui.library->cwin == NULL) ui_unhide_library(); if (player_is_setup && ui_is_init()) paint_all(); paint_message("library window un-hidden"); } } else if (strcasecmp(property, "match-fname") == 0) { if (str2bool(value, &tf) < 0) { paint_error("%s %s: value must be boolean", argv[0], property); return 5; } mi_query_match_filename = tf; if (mi_query_match_filename) paint_message("filenames will be matched against"); else paint_message("filenames will NOT be matched against"); } else if (strcasecmp(property, "save-sorts") == 0) { if (str2bool(value, &tf) < 0) { paint_error("%s %s: value must be boolean", argv[0], property); return 6; } sorts_need_saving = tf; if (sorts_need_saving) paint_message("changing sort will be prompted for saving"); else paint_message("changing sort will NOT be prompted for saving"); } else { paint_error("%s: unknown property '%s'", argv[0], property); return 7; } return 0; }
int cmd_color(int argc, char *argv[]) { char *item; char *fg, *bg; int i_item, i_fg, i_bg, j; if (argc != 2) { paint_error("usage: %s ITEM=FG,BG", argv[0]); return 1; } /* extract item and foreground/background colors */ item = argv[1]; if ((fg = strchr(item, '=')) == NULL) { paint_error("usage: %s ITEM=FG,BG", argv[0]); return 2; } *fg = '\0'; fg++; if ((bg = strchr(fg, ',')) == NULL) { paint_error("usage: %s ITEM=FG,BG", argv[0]); return 3; } *bg = '\0'; bg++; /* convert all */ if ((i_item = paint_str2item(item)) < 0) { paint_error("invalid item '%s'", item); return 4; } if ((i_fg = paint_str2color(fg)) == -2) { paint_error("invalid foreground color '%s'", fg); return 5; } if ((i_bg = paint_str2color(bg)) == -2) { paint_error("invalid background color '%s'", bg); return 6; } /* init color */ init_pair(i_item, i_fg, i_bg); /* if this was a cinfo item, indicate that it was set */ for (j = 0; j < MI_NUM_CINFO; j++) { if (i_item == colors.cinfos[j]) colors.cinfos_set[j] = true; } /* redraw */ if (ui_is_init()) { ui_clear(); paint_all(); } return 0; }