bool display_cuesheet_content(char* filename) { size_t bufsize = 0; struct cuesheet *cue = (struct cuesheet *)plugin_get_buffer(&bufsize); if (!cue || bufsize < sizeof(struct cuesheet)) return false; if (!parse_cuesheet(filename, cue)) return false; browse_cuesheet(cue); return true; }
bool display_cuesheet_content(char* filename) { size_t bufsize = 0; struct cuesheet_file cue_file; struct cuesheet *cue = (struct cuesheet *)plugin_get_buffer(&bufsize); if (!cue || bufsize < sizeof(struct cuesheet)) return false; strlcpy(cue_file.path, filename, MAX_PATH); cue_file.pos = 0; cue_file.size = 0; if (!parse_cuesheet(&cue_file, cue)) return false; browse_cuesheet(cue); return true; }
bool folder_select(char* setting, int setting_len) { struct folder *root; struct simplelist_info info; size_t buf_size; /* 32 separate folders should be Enough For Everybody(TM) */ char *vect[32]; char copy[setting_len]; int nb_items; /* copy onto stack as split_string() modifies it */ strlcpy(copy, setting, setting_len); nb_items = split_string(copy, ':', vect, ARRAYLEN(vect)); buffer_front = plugin_get_buffer(&buf_size); buffer_end = buffer_front + buf_size; root = load_root(); if (nb_items > 0) { for(int i = 0; i < nb_items; i++) select_paths(root, vect[i]); } simplelist_info_init(&info, str(LANG_SELECT_FOLDER), count_items(root), root); info.get_name = folder_get_name; info.action_callback = folder_action_callback; info.get_icon = folder_get_icon; simplelist_show_list(&info); /* done editing. check for changes */ save_folders(root, copy, setting_len); if (strcmp(copy, setting)) { /* prompt for saving changes and commit if yes */ if (yesno_pop(ID2P(LANG_SAVE_CHANGES))) { strcpy(setting, copy); settings_save(); return true; } } return false; }
/* ------------------------------------------------------------------------*/ static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume, char** selected_bookmark) { struct bookmark_list* bookmarks; struct gui_synclist list; int item = 0; int action; size_t size; bool exit = false; bool refresh = true; int ret = BOOKMARK_FAIL; bookmarks = plugin_get_buffer(&size); bookmarks->buffer_size = size; bookmarks->show_dont_resume = show_dont_resume; bookmarks->filename = bookmark_file_name; bookmarks->start = 0; bookmarks->show_playlist_name = strcmp(bookmark_file_name, RECENT_BOOKMARK_FILE) == 0; gui_synclist_init(&list, &get_bookmark_info, (void*) bookmarks, false, 2, NULL); if(global_settings.talk_menu) gui_synclist_set_voice_callback(&list, bookmark_list_voice_cb); gui_synclist_set_title(&list, str(LANG_BOOKMARK_SELECT_BOOKMARK), Icon_Bookmark); while (!exit) { if (refresh) { int count = get_bookmark_count(bookmark_file_name); bookmarks->total_count = count; if (bookmarks->total_count < 1) { /* No more bookmarks, delete file and exit */ splash(HZ, ID2P(LANG_BOOKMARK_LOAD_EMPTY)); remove(bookmark_file_name); *selected_bookmark = NULL; return BOOKMARK_FAIL; } if (bookmarks->show_dont_resume) { count++; item++; } gui_synclist_set_nb_items(&list, count * 2); if (item >= count) { /* Selected item has been deleted */ item = count - 1; gui_synclist_select_item(&list, item * 2); } buffer_bookmarks(bookmarks, bookmarks->start); gui_synclist_draw(&list); cond_talk_ids_fq(VOICE_EXT_BMARK); gui_synclist_speak_item(&list); refresh = false; } list_do_action(CONTEXT_BOOKMARKSCREEN, HZ / 2, &list, &action, LIST_WRAP_UNLESS_HELD); item = gui_synclist_get_sel_pos(&list) / 2; if (bookmarks->show_dont_resume) { item--; } if (action == ACTION_STD_CONTEXT) { MENUITEM_STRINGLIST(menu_items, ID2P(LANG_BOOKMARK_CONTEXT_MENU), NULL, ID2P(LANG_BOOKMARK_CONTEXT_RESUME), ID2P(LANG_BOOKMARK_CONTEXT_DELETE)); static const int menu_actions[] = { ACTION_STD_OK, ACTION_BMS_DELETE }; int selection = do_menu(&menu_items, NULL, NULL, false); refresh = true; if (selection >= 0 && selection <= (int) (sizeof(menu_actions) / sizeof(menu_actions[0]))) { action = menu_actions[selection]; } } switch (action) { case ACTION_STD_OK: if (item >= 0) { talk_shutup(); *selected_bookmark = bookmarks->items[item - bookmarks->start]; return BOOKMARK_SUCCESS; } exit = true; ret = BOOKMARK_SUCCESS; break; case ACTION_TREE_WPS: case ACTION_STD_CANCEL: exit = true; break; case ACTION_BMS_DELETE: if (item >= 0) { const char *lines[]={ ID2P(LANG_REALLY_DELETE) }; const char *yes_lines[]={ ID2P(LANG_DELETING) }; const struct text_message message={lines, 1}; const struct text_message yes_message={yes_lines, 1}; if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES) { delete_bookmark(bookmark_file_name, item); bookmarks->reload = true; } refresh = true; } break; default: if (default_event_handler(action) == SYS_USB_CONNECTED) { ret = BOOKMARK_USB_CONNECTED; exit = true; } break; } } talk_shutup(); *selected_bookmark = NULL; return ret; }
/* Paste a file to a new directory. Will overwrite always. */ static bool clipboard_pastefile(const char *src, const char *target, bool copy) { int src_fd, target_fd; size_t buffersize; ssize_t size, bytesread, byteswritten; char *buffer; bool result = false; if (copy) { /* See if we can get the plugin buffer for the file copy buffer */ buffer = (char *) plugin_get_buffer(&buffersize); if (buffer == NULL || buffersize < 512) { /* Not large enough, try for a disk sector worth of stack instead */ buffersize = 512; buffer = (char *) __builtin_alloca(buffersize); } if (buffer == NULL) { return false; } buffersize &= ~0x1ff; /* Round buffer size to multiple of sector size */ src_fd = open(src, O_RDONLY); if (src_fd >= 0) { target_fd = creat(target, 0666); if (target_fd >= 0) { result = true; size = filesize(src_fd); if (size == -1) { result = false; } while(size > 0) { bytesread = read(src_fd, buffer, buffersize); if (bytesread == -1) { result = false; break; } size -= bytesread; while(bytesread > 0) { byteswritten = write(target_fd, buffer, bytesread); if (byteswritten < 0) { result = false; size = 0; break; } bytesread -= byteswritten; draw_slider(); } } close(target_fd); /* Copy failed. Cleanup. */ if (!result) { remove(target); } } close(src_fd); } } else { result = rename(src, target) == 0; #ifdef HAVE_MULTIVOLUME if (!result) { if (errno == EXDEV) { /* Failed because cross volume rename doesn't work. Copy instead */ result = clipboard_pastefile(src, target, true); if (result) { result = remove(src) == 0; } } } #endif } return result; }
/* Initialize the playlist viewer. */ static bool playlist_viewer_init(struct playlist_viewer * viewer, const char* filename, bool reload) { char* buffer; size_t buffer_size; bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE); bool have_list = filename || is_playing; if (!have_list && (global_status.resume_index != -1)) { /* Try to restore the list from control file */ have_list = (playlist_resume() != -1); } if (!have_list && (playlist_amount() > 0)) { /*If dynamic playlist still exists, view it anyway even if playback has reached the end of the playlist */ have_list = true; } if (!have_list) { /* Nothing to view, exit */ splash(HZ, str(LANG_CATALOG_NO_PLAYLISTS)); return false; } buffer = plugin_get_buffer(&buffer_size); if (!buffer) return false; if (!filename) viewer->playlist = NULL; else { /* Viewing playlist on disk */ const char *dir, *file; char *temp_ptr; char *index_buffer = NULL; ssize_t index_buffer_size = 0; viewer->playlist = &temp_playlist; /* Separate directory from filename */ temp_ptr = strrchr(filename+1,'/'); if (temp_ptr) { *temp_ptr = 0; dir = filename; file = temp_ptr + 1; } else { dir = "/"; file = filename+1; } if (is_playing) { /* Something is playing, use half the plugin buffer for playlist indices */ index_buffer_size = buffer_size / 2; index_buffer = buffer; } playlist_create_ex(viewer->playlist, dir, file, index_buffer, index_buffer_size, buffer+index_buffer_size, buffer_size-index_buffer_size); if (temp_ptr) *temp_ptr = '/'; buffer += index_buffer_size; buffer_size -= index_buffer_size; } playlist_buffer_init(&viewer->buffer, buffer, buffer_size); viewer->moving_track = -1; viewer->moving_playlist_index = -1; if (!reload) { if (viewer->playlist) viewer->selected_track = 0; else viewer->selected_track = playlist_get_display_index() - 1; } if (!update_playlist(true)) return false; return true; }
/* to setup up the wps-data from a format-buffer (isfile = false) from a (wps-)file (isfile = true)*/ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data, const char *buf, bool isfile) { char *wps_buffer = NULL; if (!wps_data || !buf) return false; #ifdef HAVE_ALBUMART int status; struct mp3entry *curtrack; long offset; struct skin_albumart old_aa = {.state = WPS_ALBUMART_NONE}; if (wps_data->albumart) { old_aa.state = wps_data->albumart->state; old_aa.height = wps_data->albumart->height; old_aa.width = wps_data->albumart->width; } #endif #ifdef HAVE_LCD_BITMAP int i; for (i=0;i<MAXUSERFONTS;i++) { skinfonts[i].id = -1; skinfonts[i].name = NULL; } #endif #ifdef DEBUG_SKIN_ENGINE if (isfile && debug_wps) { DEBUGF("\n=====================\nLoading '%s'\n=====================\n", buf); } #endif skin_data_reset(wps_data); wps_data->wps_loaded = false; curr_screen = screen; curr_line = NULL; curr_vp = NULL; curr_viewport_element = NULL; if (isfile) { int fd = open_utf8(buf, O_RDONLY); if (fd < 0) return false; /* get buffer space from the plugin buffer */ size_t buffersize = 0; wps_buffer = (char *)plugin_get_buffer(&buffersize); if (!wps_buffer) return false; /* copy the file's content to the buffer for parsing, ensuring that every line ends with a newline char. */ unsigned int start = 0; while(read_line(fd, wps_buffer + start, buffersize - start) > 0) { start += strlen(wps_buffer + start); if (start < buffersize - 1) { wps_buffer[start++] = '\n'; wps_buffer[start] = 0; } } close(fd); if (start <= 0) return false; } else { wps_buffer = (char*)buf; } #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 wps_data->backdrop = "-"; wps_data->backdrop_id = -1; #endif /* parse the skin source */ #ifndef APPLICATION skin_buffer_save_position(); #endif wps_data->tree = skin_parse(wps_buffer, skin_element_callback, wps_data); if (!wps_data->tree) { skin_data_reset(wps_data); #ifndef APPLICATION skin_buffer_restore_position(); #endif return false; } #ifdef HAVE_LCD_BITMAP char bmpdir[MAX_PATH]; if (isfile) { /* get the bitmap dir */ char *dot = strrchr(buf, '.'); strlcpy(bmpdir, buf, dot - buf + 1); } else { /* fall back to backdrop dir for built-in themes */ /* no get_user_file_path(), assuming we ship bmps for built-in themes */ snprintf(bmpdir, MAX_PATH, "%s", BACKDROP_DIR); } /* load the bitmaps that were found by the parsing */ if (!load_skin_bitmaps(wps_data, bmpdir) || !skin_load_fonts(wps_data)) { skin_data_reset(wps_data); #ifndef APPLICATION skin_buffer_restore_position(); #endif return false; } #endif #if defined(HAVE_ALBUMART) && !defined(__PCTOOL__) status = audio_status(); if (status & AUDIO_STATUS_PLAY) { struct skin_albumart *aa = wps_data->albumart; if (aa && ((aa->state && !old_aa.state) || (aa->state && (((old_aa.height != aa->height) || (old_aa.width != aa->width)))))) { curtrack = audio_current_track(); offset = curtrack->offset; audio_stop(); if (!(status & AUDIO_STATUS_PAUSE)) audio_play(offset); } } #endif wps_data->wps_loaded = true; #ifdef DEBUG_SKIN_ENGINE // if (isfile && debug_wps) // debug_skin_usage(); #endif return true; }