Jean-Philippe Bernardy | 0f6b379 | 2005-02-09 10:56:54 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * |
Jean-Philippe Bernardy | 0f6b379 | 2005-02-09 10:56:54 +0000 | [diff] [blame] | 9 | * Copyright (C)2003 by Benjamin Metzler |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 10 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version 2 |
| 14 | * of the License, or (at your option) any later version. |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 15 | * |
| 16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 17 | * KIND, either express or implied. |
| 18 | * |
| 19 | ****************************************************************************/ |
| 20 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <stdbool.h> |
| 25 | |
Bertrik Sikken | ef1ce43 | 2008-04-28 16:28:21 +0000 | [diff] [blame] | 26 | #include "config.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 27 | #include "action.h" |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 28 | #include "audio.h" |
Christi Scarborough | 4c0b83f | 2005-11-17 20:14:59 +0000 | [diff] [blame] | 29 | #include "playlist.h" |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 30 | #include "settings.h" |
Jens Arnold | 3423259 | 2005-05-17 23:34:16 +0000 | [diff] [blame] | 31 | #include "tree.h" |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 32 | #include "bookmark.h" |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 33 | #include "system.h" |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 34 | #include "icons.h" |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 35 | #include "menu.h" |
| 36 | #include "lang.h" |
Jörg Hohensohn | fa97f16 | 2004-03-19 22:15:53 +0000 | [diff] [blame] | 37 | #include "talk.h" |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 38 | #include "misc.h" |
Kevin Ferrare | e991bee | 2005-11-16 15:12:15 +0000 | [diff] [blame] | 39 | #include "splash.h" |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 40 | #include "yesno.h" |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 41 | #include "list.h" |
| 42 | #include "plugin.h" |
Bertrik Sikken | ef1ce43 | 2008-04-28 16:28:21 +0000 | [diff] [blame] | 43 | #include "file.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 44 | #include "pathfuncs.h" |
Peter D'Hoye | e60cb43 | 2006-07-15 14:40:44 +0000 | [diff] [blame] | 45 | |
Linus Nielsen Feltzing | 19480d5 | 2004-03-02 13:50:35 +0000 | [diff] [blame] | 46 | #define MAX_BOOKMARKS 10 |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 47 | #define MAX_BOOKMARK_SIZE 350 |
| 48 | #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark" |
| 49 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 50 | /* Used to buffer bookmarks while displaying the bookmark list. */ |
| 51 | struct bookmark_list |
| 52 | { |
| 53 | const char* filename; |
| 54 | size_t buffer_size; |
| 55 | int start; |
| 56 | int count; |
| 57 | int total_count; |
| 58 | bool show_dont_resume; |
| 59 | bool reload; |
Magnus Holmgren | 47167e7 | 2007-11-18 12:59:08 +0000 | [diff] [blame] | 60 | bool show_playlist_name; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 61 | char* items[]; |
| 62 | }; |
| 63 | |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 64 | /* flags for optional bookmark tokens */ |
| 65 | #define BM_PITCH 0x01 |
| 66 | #define BM_SPEED 0x02 |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 67 | |
Jeffrey Goode | b2ba112 | 2010-04-06 21:49:33 +0000 | [diff] [blame] | 68 | /* bookmark values */ |
| 69 | static struct { |
| 70 | int resume_index; |
| 71 | unsigned long resume_offset; |
| 72 | int resume_seed; |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 73 | long resume_time; |
| 74 | int repeat_mode; |
| 75 | bool shuffle; |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 76 | /* optional values */ |
| 77 | int pitch; |
| 78 | int speed; |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 79 | } bm; |
| 80 | |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 81 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, |
| 82 | bool most_recent); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 83 | static char* create_bookmark(void); |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 84 | static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id); |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 85 | static void say_bookmark(const char* bookmark, |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 86 | int bookmark_id, bool show_playlist_name); |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 87 | static bool play_bookmark(const char* bookmark); |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 88 | static bool generate_bookmark_file_name(const char *in); |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 89 | static bool parse_bookmark(const char *bookmark, const bool get_filenames); |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 90 | static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line); |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 91 | static const char* get_bookmark_info(int list_index, |
| 92 | void* data, |
| 93 | char *buffer, |
| 94 | size_t buffer_len); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 95 | static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume, char** selected_bookmark); |
Steve Bavin | eb66b55 | 2008-07-16 06:10:26 +0000 | [diff] [blame] | 96 | static bool write_bookmark(bool create_bookmark_file, const char *bookmark); |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 97 | static int get_bookmark_count(const char* bookmark_file_name); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 98 | |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 99 | #define TEMP_BUF_SIZE (MAX_PATH + 1) |
| 100 | static char global_temp_buffer[TEMP_BUF_SIZE]; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 101 | /* File name created by generate_bookmark_file_name */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 102 | static char global_bookmark_file_name[MAX_PATH]; |
| 103 | static char global_read_buffer[MAX_BOOKMARK_SIZE]; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 104 | /* Bookmark created by create_bookmark*/ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 105 | static char global_bookmark[MAX_BOOKMARK_SIZE]; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 106 | /* Filename from parsed bookmark (can be made local where needed) */ |
Linus Nielsen Feltzing | 8f032ae | 2004-12-07 14:20:37 +0000 | [diff] [blame] | 107 | static char global_filename[MAX_PATH]; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 108 | |
| 109 | /* ----------------------------------------------------------------------- */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 110 | /* This is an interface function from the context menu. */ |
| 111 | /* Returns true on successful bookmark creation. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 112 | /* ----------------------------------------------------------------------- */ |
| 113 | bool bookmark_create_menu(void) |
| 114 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 115 | return write_bookmark(true, create_bookmark()); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* ----------------------------------------------------------------------- */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 119 | /* This function acts as the load interface from the context menu. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 120 | /* This function determines the bookmark file name and then loads that file*/ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 121 | /* for the user. The user can then select or delete previous bookmarks. */ |
| 122 | /* This function returns BOOKMARK_SUCCESS on the selection of a track to */ |
| 123 | /* resume, BOOKMARK_FAIL if the menu is exited without a selection and */ |
| 124 | /* BOOKMARK_USB_CONNECTED if the menu is forced to exit due to a USB */ |
| 125 | /* connection. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 126 | /* ----------------------------------------------------------------------- */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 127 | int bookmark_load_menu(void) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 128 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 129 | char* bookmark; |
| 130 | int ret = BOOKMARK_FAIL; |
Osborne Jacobs | bcfa783 | 2012-03-02 22:34:14 -0500 | [diff] [blame] | 131 | |
| 132 | push_current_activity(ACTIVITY_BOOKMARKSLIST); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 133 | |
| 134 | char* name = playlist_get_name(NULL, global_temp_buffer, |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 135 | sizeof(global_temp_buffer)); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 136 | if (generate_bookmark_file_name(name)) |
| 137 | { |
| 138 | ret = select_bookmark(global_bookmark_file_name, false, &bookmark); |
| 139 | if (bookmark != NULL) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 140 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 141 | ret = play_bookmark(bookmark) ? BOOKMARK_SUCCESS : BOOKMARK_FAIL; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 142 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Osborne Jacobs | bcfa783 | 2012-03-02 22:34:14 -0500 | [diff] [blame] | 145 | pop_current_activity(); |
| 146 | return ret; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* ----------------------------------------------------------------------- */ |
| 150 | /* Gives the user a list of the Most Recent Bookmarks. This is an */ |
| 151 | /* interface function */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 152 | /* Returns true on the successful selection of a recent bookmark. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 153 | /* ----------------------------------------------------------------------- */ |
| 154 | bool bookmark_mrb_load() |
| 155 | { |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 156 | char* bookmark; |
| 157 | bool ret = false; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 158 | |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 159 | push_current_activity(ACTIVITY_BOOKMARKSLIST); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 160 | select_bookmark(RECENT_BOOKMARK_FILE, false, &bookmark); |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 161 | if (bookmark != NULL) |
| 162 | { |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 163 | ret = play_bookmark(bookmark); |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 164 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 165 | |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 166 | pop_current_activity(); |
Jonathan Gordon | 0bba82b | 2011-08-07 09:35:50 +0000 | [diff] [blame] | 167 | return ret; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 170 | /* ----------------------------------------------------------------------- */ |
| 171 | /* This function handles an autobookmark creation. This is an interface */ |
| 172 | /* function. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 173 | /* Returns true on successful bookmark creation. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 174 | /* ----------------------------------------------------------------------- */ |
Torne Wuff | 05ace8e | 2010-03-28 23:27:49 +0000 | [diff] [blame] | 175 | bool bookmark_autobookmark(bool prompt_ok) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 176 | { |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 177 | char* bookmark; |
Alexander Levin | 2c56ac8 | 2010-07-06 17:03:45 +0000 | [diff] [blame] | 178 | bool update; |
| 179 | |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 180 | if (!bookmark_is_bookmarkable_state()) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 181 | return false; |
| 182 | |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 183 | audio_pause(); /* first pause playback */ |
Alexander Levin | 2c56ac8 | 2010-07-06 17:03:45 +0000 | [diff] [blame] | 184 | update = (global_settings.autoupdatebookmark && bookmark_exists()); |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 185 | bookmark = create_bookmark(); |
Michael Sevakis | 29b5b32 | 2011-08-21 21:21:40 +0000 | [diff] [blame] | 186 | #if CONFIG_CODEC != SWCODEC |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 187 | /* Workaround for inability to speak when paused: all callers will |
| 188 | just do audio_stop() when we return, so we can do it right |
| 189 | away. This makes it possible to speak the "Create a Bookmark?" |
| 190 | prompt and the "Bookmark Created" splash. */ |
| 191 | audio_stop(); |
Michael Sevakis | 29b5b32 | 2011-08-21 21:21:40 +0000 | [diff] [blame] | 192 | #endif |
Alexander Levin | f8e7870 | 2010-07-07 17:30:53 +0000 | [diff] [blame] | 193 | |
Torne Wuff | db1b823 | 2010-07-05 16:39:00 +0000 | [diff] [blame] | 194 | if (update) |
| 195 | return write_bookmark(true, bookmark); |
Alexander Levin | f8e7870 | 2010-07-07 17:30:53 +0000 | [diff] [blame] | 196 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 197 | switch (global_settings.autocreatebookmark) |
| 198 | { |
| 199 | case BOOKMARK_YES: |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 200 | return write_bookmark(true, bookmark); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 201 | |
| 202 | case BOOKMARK_NO: |
| 203 | return false; |
| 204 | |
| 205 | case BOOKMARK_RECENT_ONLY_YES: |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 206 | return write_bookmark(false, bookmark); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 207 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 208 | #ifdef HAVE_LCD_BITMAP |
Nils Wallménius | 33c4446 | 2008-04-26 09:30:24 +0000 | [diff] [blame] | 209 | const char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY)}; |
| 210 | const struct text_message message={lines, 1}; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 211 | #else |
Nils Wallménius | 33c4446 | 2008-04-26 09:30:24 +0000 | [diff] [blame] | 212 | const char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY), |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 213 | str(LANG_CONFIRM_WITH_BUTTON)}; |
Nils Wallménius | 33c4446 | 2008-04-26 09:30:24 +0000 | [diff] [blame] | 214 | const struct text_message message={lines, 2}; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 215 | #endif |
Thomas Martitz | 4764ee0 | 2009-08-06 00:14:40 +0000 | [diff] [blame] | 216 | |
Torne Wuff | 05ace8e | 2010-03-28 23:27:49 +0000 | [diff] [blame] | 217 | if(prompt_ok && gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 218 | { |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 219 | if (global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK) |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 220 | return write_bookmark(false, bookmark); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 221 | else |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 222 | return write_bookmark(true, bookmark); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 223 | } |
Jens Arnold | 4dab0d2 | 2004-10-24 21:45:37 +0000 | [diff] [blame] | 224 | return false; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* ----------------------------------------------------------------------- */ |
| 228 | /* This function takes the current current resume information and writes */ |
| 229 | /* that to the beginning of the bookmark file. */ |
| 230 | /* This file will contain N number of bookmarks in the following format: */ |
| 231 | /* resume_index*resume_offset*resume_seed*resume_first_index* */ |
| 232 | /* resume_file*milliseconds*MP3 Title* */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 233 | /* Returns true on successful bookmark write. */ |
| 234 | /* Returns false if any part of the bookmarking process fails. It is */ |
| 235 | /* possible that a bookmark is successfully added to the most recent */ |
| 236 | /* bookmark list but fails to be added to the bookmark file or vice versa. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 237 | /* ------------------------------------------------------------------------*/ |
Steve Bavin | eb66b55 | 2008-07-16 06:10:26 +0000 | [diff] [blame] | 238 | static bool write_bookmark(bool create_bookmark_file, const char *bookmark) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 239 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 240 | bool ret=true; |
| 241 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 242 | if (!bookmark) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 243 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 244 | ret = false; /* something didn't happen correctly, do nothing */ |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | if (global_settings.usemrb) |
| 249 | ret = add_bookmark(RECENT_BOOKMARK_FILE, bookmark, true); |
| 250 | |
| 251 | |
| 252 | /* writing the bookmark */ |
| 253 | if (create_bookmark_file) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 254 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 255 | char* name = playlist_get_name(NULL, global_temp_buffer, |
| 256 | sizeof(global_temp_buffer)); |
| 257 | if (generate_bookmark_file_name(name)) |
| 258 | { |
| 259 | ret = ret & add_bookmark(global_bookmark_file_name, bookmark, false); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | ret = false; /* generating bookmark file failed */ |
| 264 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 268 | splash(HZ, ret ? ID2P(LANG_BOOKMARK_CREATE_SUCCESS) |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 269 | : ID2P(LANG_BOOKMARK_CREATE_FAILURE)); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 270 | |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 271 | return ret; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* ----------------------------------------------------------------------- */ |
| 275 | /* This function adds a bookmark to a file. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 276 | /* Returns true on successful bookmark add. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 277 | /* ------------------------------------------------------------------------*/ |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 278 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, |
| 279 | bool most_recent) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 280 | { |
| 281 | int temp_bookmark_file = 0; |
| 282 | int bookmark_file = 0; |
| 283 | int bookmark_count = 0; |
| 284 | char* playlist = NULL; |
| 285 | char* cp; |
Henrik Backe | 0e90bc3 | 2004-03-21 13:42:18 +0000 | [diff] [blame] | 286 | char* tmp; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 287 | int len = 0; |
| 288 | bool unique = false; |
| 289 | |
| 290 | /* Opening up a temp bookmark file */ |
| 291 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), |
| 292 | "%s.tmp", bookmark_file_name); |
| 293 | temp_bookmark_file = open(global_temp_buffer, |
Thomas Martitz | 0a1d7c2 | 2010-05-06 17:35:13 +0000 | [diff] [blame] | 294 | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 295 | if (temp_bookmark_file < 0) |
| 296 | return false; /* can't open the temp file */ |
| 297 | |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 298 | if (most_recent && (global_settings.usemrb == BOOKMARK_UNIQUE_ONLY)) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 299 | { |
| 300 | playlist = strchr(bookmark,'/'); |
| 301 | cp = strrchr(bookmark,';'); |
| 302 | len = cp - playlist; |
| 303 | unique = true; |
| 304 | } |
| 305 | |
| 306 | /* Writing the new bookmark to the begining of the temp file */ |
| 307 | write(temp_bookmark_file, bookmark, strlen(bookmark)); |
| 308 | write(temp_bookmark_file, "\n", 1); |
Linus Nielsen Feltzing | 19480d5 | 2004-03-02 13:50:35 +0000 | [diff] [blame] | 309 | bookmark_count++; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 310 | |
| 311 | /* Reading in the previous bookmarks and writing them to the temp file */ |
| 312 | bookmark_file = open(bookmark_file_name, O_RDONLY); |
| 313 | if (bookmark_file >= 0) |
| 314 | { |
| 315 | while (read_line(bookmark_file, global_read_buffer, |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 316 | sizeof(global_read_buffer)) > 0) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 317 | { |
Linus Nielsen Feltzing | 19480d5 | 2004-03-02 13:50:35 +0000 | [diff] [blame] | 318 | /* The MRB has a max of MAX_BOOKMARKS in it */ |
| 319 | /* This keeps it from getting too large */ |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 320 | if (most_recent && (bookmark_count >= MAX_BOOKMARKS)) |
Linus Nielsen Feltzing | 19480d5 | 2004-03-02 13:50:35 +0000 | [diff] [blame] | 321 | break; |
Linus Nielsen Feltzing | 19480d5 | 2004-03-02 13:50:35 +0000 | [diff] [blame] | 322 | |
Henrik Backe | 0e90bc3 | 2004-03-21 13:42:18 +0000 | [diff] [blame] | 323 | cp = strchr(global_read_buffer,'/'); |
| 324 | tmp = strrchr(global_read_buffer,';'); |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 325 | if (parse_bookmark(global_read_buffer, false) && |
Henrik Backe | 0e90bc3 | 2004-03-21 13:42:18 +0000 | [diff] [blame] | 326 | (!unique || len != tmp -cp || strncmp(playlist,cp,len))) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 327 | { |
Henrik Backe | 0e90bc3 | 2004-03-21 13:42:18 +0000 | [diff] [blame] | 328 | bookmark_count++; |
| 329 | write(temp_bookmark_file, global_read_buffer, |
| 330 | strlen(global_read_buffer)); |
| 331 | write(temp_bookmark_file, "\n", 1); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | close(bookmark_file); |
| 335 | } |
| 336 | close(temp_bookmark_file); |
| 337 | |
| 338 | remove(bookmark_file_name); |
| 339 | rename(global_temp_buffer, bookmark_file_name); |
| 340 | |
| 341 | return true; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /* ----------------------------------------------------------------------- */ |
| 346 | /* This function takes the system resume data and formats it into a valid */ |
| 347 | /* bookmark. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 348 | /* Returns not NULL on successful bookmark format. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 349 | /* ----------------------------------------------------------------------- */ |
| 350 | static char* create_bookmark() |
| 351 | { |
| 352 | int resume_index = 0; |
| 353 | char *file; |
| 354 | |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 355 | if (!bookmark_is_bookmarkable_state()) |
Stéphane Doyon | 431c895 | 2008-07-15 19:50:22 +0000 | [diff] [blame] | 356 | return NULL; /* something didn't happen correctly, do nothing */ |
| 357 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 358 | /* grab the currently playing track */ |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 359 | struct mp3entry *id3 = audio_current_track(); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 360 | if(!id3) |
| 361 | return NULL; |
| 362 | |
| 363 | /* Get some basic resume information */ |
| 364 | /* queue_resume and queue_resume_index are not used and can be ignored.*/ |
| 365 | playlist_get_resume_info(&resume_index); |
| 366 | |
| 367 | /* Get the currently playing file minus the path */ |
| 368 | /* This is used when displaying the available bookmarks */ |
| 369 | file = strrchr(id3->path,'/'); |
| 370 | if(NULL == file) |
| 371 | return NULL; |
| 372 | |
| 373 | /* create the bookmark */ |
| 374 | snprintf(global_bookmark, sizeof(global_bookmark), |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 375 | /* new optional bookmark token descriptors should be inserted |
| 376 | just before the "%s;%s" in this line... */ |
Nils Wallménius | d29a11b | 2012-05-08 16:34:26 +0200 | [diff] [blame] | 377 | #if CONFIG_CODEC == SWCODEC && defined(HAVE_PITCHCONTROL) |
Thomas Martitz | 50a6ca3 | 2010-05-06 21:04:40 +0000 | [diff] [blame] | 378 | ">%d;%d;%ld;%d;%ld;%d;%d;%ld;%ld;%s;%s", |
Jeffrey Goode | bbbf529 | 2010-04-11 02:32:58 +0000 | [diff] [blame] | 379 | #else |
| 380 | ">%d;%d;%ld;%d;%ld;%d;%d;%s;%s", |
Jeffrey Goode | 4f3f7dd | 2010-04-10 21:41:01 +0000 | [diff] [blame] | 381 | #endif |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 382 | /* ... their flags should go here ... */ |
Nils Wallménius | d29a11b | 2012-05-08 16:34:26 +0200 | [diff] [blame] | 383 | #if CONFIG_CODEC == SWCODEC && defined(HAVE_PITCHCONTROL) |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 384 | BM_PITCH | BM_SPEED, |
Jeffrey Goode | 4f3f7dd | 2010-04-10 21:41:01 +0000 | [diff] [blame] | 385 | #else |
| 386 | 0, |
| 387 | #endif |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 388 | resume_index, |
| 389 | id3->offset, |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 390 | playlist_get_seed(NULL), |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 391 | id3->elapsed, |
| 392 | global_settings.repeat_mode, |
| 393 | global_settings.playlist_shuffle, |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 394 | /* ...and their values should go here */ |
Nils Wallménius | d29a11b | 2012-05-08 16:34:26 +0200 | [diff] [blame] | 395 | #if CONFIG_CODEC == SWCODEC && defined(HAVE_PITCHCONTROL) |
Thomas Martitz | 50a6ca3 | 2010-05-06 21:04:40 +0000 | [diff] [blame] | 396 | (long)sound_get_pitch(), |
| 397 | (long)dsp_get_timestretch(), |
Jeffrey Goode | 4f3f7dd | 2010-04-10 21:41:01 +0000 | [diff] [blame] | 398 | #endif |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 399 | /* more mandatory tokens */ |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 400 | playlist_get_name(NULL, global_temp_buffer, |
| 401 | sizeof(global_temp_buffer)), |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 402 | file+1); |
| 403 | |
| 404 | /* checking to see if the bookmark is valid */ |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 405 | if (parse_bookmark(global_bookmark, false)) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 406 | return global_bookmark; |
| 407 | else |
| 408 | return NULL; |
| 409 | } |
| 410 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 411 | /* ----------------------------------------------------------------------- */ |
| 412 | /* This function will determine if an autoload is necessary. This is an */ |
| 413 | /* interface function. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 414 | /* Returns true on bookmark load or bookmark selection. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 415 | /* ------------------------------------------------------------------------*/ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 416 | bool bookmark_autoload(const char* file) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 417 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 418 | char* bookmark; |
| 419 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 420 | if(global_settings.autoloadbookmark == BOOKMARK_NO) |
| 421 | return false; |
| 422 | |
| 423 | /*Checking to see if a bookmark file exists.*/ |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 424 | if(!generate_bookmark_file_name(file)) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 425 | { |
| 426 | return false; |
| 427 | } |
Nils Wallménius | a019964 | 2008-04-16 19:51:43 +0000 | [diff] [blame] | 428 | |
| 429 | if(!file_exists(global_bookmark_file_name)) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 430 | return false; |
Nils Wallménius | a019964 | 2008-04-16 19:51:43 +0000 | [diff] [blame] | 431 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 432 | if(global_settings.autoloadbookmark == BOOKMARK_YES) |
| 433 | { |
| 434 | return bookmark_load(global_bookmark_file_name, true); |
| 435 | } |
| 436 | else |
| 437 | { |
Richard Quirk | dcba741 | 2013-03-05 19:31:36 +0100 | [diff] [blame] | 438 | int ret = select_bookmark(global_bookmark_file_name, true, &bookmark); |
Martin Scarratt | 9c43c38 | 2006-07-18 19:11:56 +0000 | [diff] [blame] | 439 | |
Magnus Holmgren | 9824dac | 2007-08-11 14:44:05 +0000 | [diff] [blame] | 440 | if (bookmark != NULL) |
Martin Scarratt | 9c43c38 | 2006-07-18 19:11:56 +0000 | [diff] [blame] | 441 | { |
Magnus Holmgren | 04dc828 | 2008-02-10 12:16:27 +0000 | [diff] [blame] | 442 | if (!play_bookmark(bookmark)) |
| 443 | { |
| 444 | /* Selected bookmark not found. */ |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 445 | splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME)); |
Magnus Holmgren | 04dc828 | 2008-02-10 12:16:27 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* Act as if autoload was done even if it failed, since the |
| 449 | * user did make an active selection. |
| 450 | */ |
| 451 | return true; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 452 | } |
Martin Scarratt | 7847dde | 2006-08-20 17:25:56 +0000 | [diff] [blame] | 453 | |
Richard Quirk | dcba741 | 2013-03-05 19:31:36 +0100 | [diff] [blame] | 454 | return ret != BOOKMARK_SUCCESS; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | /* ----------------------------------------------------------------------- */ |
| 459 | /* This function loads the bookmark information into the resume memory. */ |
| 460 | /* This is an interface function. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 461 | /* Returns true on successful bookmark load. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 462 | /* ------------------------------------------------------------------------*/ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 463 | bool bookmark_load(const char* file, bool autoload) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 464 | { |
| 465 | int fd; |
Magnus Holmgren | 04dc828 | 2008-02-10 12:16:27 +0000 | [diff] [blame] | 466 | char* bookmark = NULL; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 467 | |
| 468 | if(autoload) |
| 469 | { |
| 470 | fd = open(file, O_RDONLY); |
| 471 | if(fd >= 0) |
| 472 | { |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 473 | if(read_line(fd, global_read_buffer, sizeof(global_read_buffer)) > 0) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 474 | bookmark=global_read_buffer; |
| 475 | close(fd); |
| 476 | } |
| 477 | } |
| 478 | else |
| 479 | { |
| 480 | /* This is not an auto-load, so list the bookmarks */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 481 | select_bookmark(file, false, &bookmark); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 484 | if (bookmark != NULL) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 485 | { |
Magnus Holmgren | 04dc828 | 2008-02-10 12:16:27 +0000 | [diff] [blame] | 486 | if (!play_bookmark(bookmark)) |
| 487 | { |
| 488 | /* Selected bookmark not found. */ |
Magnus Holmgren | 932ef00 | 2008-02-21 21:01:42 +0000 | [diff] [blame] | 489 | if (!autoload) |
| 490 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 491 | splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME)); |
Magnus Holmgren | 932ef00 | 2008-02-21 21:01:42 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Magnus Holmgren | 04dc828 | 2008-02-10 12:16:27 +0000 | [diff] [blame] | 494 | return false; |
| 495 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 498 | return true; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 502 | static int get_bookmark_count(const char* bookmark_file_name) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 503 | { |
| 504 | int read_count = 0; |
| 505 | int file = open(bookmark_file_name, O_RDONLY); |
| 506 | |
| 507 | if(file < 0) |
| 508 | return -1; |
| 509 | |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 510 | while(read_line(file, global_read_buffer, sizeof(global_read_buffer)) > 0) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 511 | { |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 512 | read_count++; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | close(file); |
| 516 | return read_count; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line) |
| 520 | { |
| 521 | char* dest = ((char*) bookmarks) + bookmarks->buffer_size - 1; |
| 522 | int read_count = 0; |
| 523 | int file = open(bookmarks->filename, O_RDONLY); |
| 524 | |
| 525 | if (file < 0) |
| 526 | { |
| 527 | return -1; |
| 528 | } |
| 529 | |
| 530 | if ((first_line != 0) && ((size_t) filesize(file) < bookmarks->buffer_size |
| 531 | - sizeof(*bookmarks) - (sizeof(char*) * bookmarks->total_count))) |
| 532 | { |
| 533 | /* Entire file fits in buffer */ |
| 534 | first_line = 0; |
| 535 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 536 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 537 | bookmarks->start = first_line; |
| 538 | bookmarks->count = 0; |
| 539 | bookmarks->reload = false; |
| 540 | |
| 541 | while(read_line(file, global_read_buffer, sizeof(global_read_buffer)) > 0) |
| 542 | { |
| 543 | read_count++; |
| 544 | |
| 545 | if (read_count >= first_line) |
| 546 | { |
| 547 | dest -= strlen(global_read_buffer) + 1; |
| 548 | |
| 549 | if (dest < ((char*) bookmarks) + sizeof(*bookmarks) |
| 550 | + (sizeof(char*) * (bookmarks->count + 1))) |
| 551 | { |
| 552 | break; |
| 553 | } |
| 554 | |
| 555 | strcpy(dest, global_read_buffer); |
| 556 | bookmarks->items[bookmarks->count] = dest; |
| 557 | bookmarks->count++; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | close(file); |
| 562 | return bookmarks->start + bookmarks->count; |
| 563 | } |
| 564 | |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 565 | static const char* get_bookmark_info(int list_index, |
| 566 | void* data, |
| 567 | char *buffer, |
| 568 | size_t buffer_len) |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 569 | { |
| 570 | struct bookmark_list* bookmarks = (struct bookmark_list*) data; |
| 571 | int index = list_index / 2; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 572 | |
| 573 | if (bookmarks->show_dont_resume) |
| 574 | { |
| 575 | if (index == 0) |
| 576 | { |
| 577 | return list_index % 2 == 0 |
| 578 | ? (char*) str(LANG_BOOKMARK_DONT_RESUME) : " "; |
| 579 | } |
| 580 | |
| 581 | index--; |
| 582 | } |
| 583 | |
| 584 | if (bookmarks->reload || (index >= bookmarks->start + bookmarks->count) |
| 585 | || (index < bookmarks->start)) |
| 586 | { |
| 587 | int read_index = index; |
| 588 | |
| 589 | /* Using count as a guide on how far to move could possibly fail |
| 590 | * sometimes. Use byte count if that is a problem? |
| 591 | */ |
| 592 | |
| 593 | if (read_index != 0) |
| 594 | { |
| 595 | /* Move count * 3 / 4 items in the direction the user is moving, |
| 596 | * but don't go too close to the end. |
| 597 | */ |
| 598 | int offset = bookmarks->count; |
| 599 | int max = bookmarks->total_count - (bookmarks->count / 2); |
| 600 | |
| 601 | if (read_index < bookmarks->start) |
| 602 | { |
| 603 | offset *= 3; |
| 604 | } |
| 605 | |
| 606 | read_index = index - offset / 4; |
| 607 | |
| 608 | if (read_index > max) |
| 609 | { |
| 610 | read_index = max; |
| 611 | } |
| 612 | |
| 613 | if (read_index < 0) |
| 614 | { |
| 615 | read_index = 0; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | if (buffer_bookmarks(bookmarks, read_index) <= index) |
| 620 | { |
| 621 | return ""; |
| 622 | } |
| 623 | } |
| 624 | |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 625 | if (!parse_bookmark(bookmarks->items[index - bookmarks->start], true)) |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 626 | { |
| 627 | return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " "; |
| 628 | } |
| 629 | |
| 630 | if (list_index % 2 == 0) |
| 631 | { |
Magnus Holmgren | 47167e7 | 2007-11-18 12:59:08 +0000 | [diff] [blame] | 632 | char *name; |
| 633 | char *format; |
| 634 | int len = strlen(global_temp_buffer); |
| 635 | |
| 636 | if (bookmarks->show_playlist_name && len > 0) |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 637 | { |
Magnus Holmgren | 47167e7 | 2007-11-18 12:59:08 +0000 | [diff] [blame] | 638 | name = global_temp_buffer; |
| 639 | len--; |
| 640 | |
| 641 | if (name[len] != '/') |
| 642 | { |
| 643 | strrsplt(name, '.'); |
| 644 | } |
| 645 | else if (len > 1) |
| 646 | { |
| 647 | name[len] = '\0'; |
| 648 | } |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 649 | |
Magnus Holmgren | 47167e7 | 2007-11-18 12:59:08 +0000 | [diff] [blame] | 650 | if (len > 1) |
| 651 | { |
| 652 | name = strrsplt(name, '/'); |
| 653 | } |
| 654 | |
| 655 | format = "%s : %s"; |
| 656 | } |
| 657 | else |
| 658 | { |
| 659 | name = global_filename; |
| 660 | format = "%s"; |
| 661 | } |
| 662 | |
| 663 | strrsplt(global_filename, '.'); |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 664 | snprintf(buffer, buffer_len, format, name, global_filename); |
Magnus Holmgren | 47167e7 | 2007-11-18 12:59:08 +0000 | [diff] [blame] | 665 | return buffer; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 666 | } |
| 667 | else |
| 668 | { |
| 669 | char time_buf[32]; |
| 670 | |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 671 | format_time(time_buf, sizeof(time_buf), bm.resume_time); |
| 672 | snprintf(buffer, buffer_len, "%s, %d%s", time_buf, bm.resume_index + 1, |
| 673 | bm.shuffle ? (char*) str(LANG_BOOKMARK_SHUFFLE) : ""); |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 674 | return buffer; |
| 675 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 678 | static int bookmark_list_voice_cb(int list_index, void* data) |
| 679 | { |
| 680 | struct bookmark_list* bookmarks = (struct bookmark_list*) data; |
| 681 | int index = list_index / 2; |
| 682 | |
| 683 | if (bookmarks->show_dont_resume) |
| 684 | { |
| 685 | if (index == 0) |
| 686 | return talk_id(LANG_BOOKMARK_DONT_RESUME, false); |
| 687 | index--; |
| 688 | } |
| 689 | say_bookmark(bookmarks->items[index - bookmarks->start], index, |
| 690 | bookmarks->show_playlist_name); |
| 691 | return 0; |
| 692 | } |
| 693 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 694 | /* ----------------------------------------------------------------------- */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 695 | /* This displays the bookmarks in a file and allows the user to */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 696 | /* select one to play. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 697 | /* *selected_bookmark contains a non NULL value on successful bookmark */ |
| 698 | /* selection. */ |
| 699 | /* Returns BOOKMARK_SUCCESS on successful bookmark selection, BOOKMARK_FAIL*/ |
| 700 | /* if no selection was made and BOOKMARK_USB_CONNECTED if the selection */ |
| 701 | /* menu is forced to exit due to a USB connection. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 702 | /* ------------------------------------------------------------------------*/ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 703 | static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume, char** selected_bookmark) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 704 | { |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 705 | struct bookmark_list* bookmarks; |
| 706 | struct gui_synclist list; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 707 | int item = 0; |
| 708 | int action; |
| 709 | size_t size; |
| 710 | bool exit = false; |
| 711 | bool refresh = true; |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 712 | int ret = BOOKMARK_FAIL; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 713 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 714 | bookmarks = plugin_get_buffer(&size); |
| 715 | bookmarks->buffer_size = size; |
| 716 | bookmarks->show_dont_resume = show_dont_resume; |
| 717 | bookmarks->filename = bookmark_file_name; |
| 718 | bookmarks->start = 0; |
Magnus Holmgren | 47167e7 | 2007-11-18 12:59:08 +0000 | [diff] [blame] | 719 | bookmarks->show_playlist_name |
| 720 | = strcmp(bookmark_file_name, RECENT_BOOKMARK_FILE) == 0; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 721 | gui_synclist_init(&list, &get_bookmark_info, (void*) bookmarks, false, 2, NULL); |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 722 | if(global_settings.talk_menu) |
| 723 | gui_synclist_set_voice_callback(&list, bookmark_list_voice_cb); |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 724 | gui_synclist_set_title(&list, str(LANG_BOOKMARK_SELECT_BOOKMARK), |
| 725 | Icon_Bookmark); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 726 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 727 | while (!exit) |
| 728 | { |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 729 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 730 | if (refresh) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 731 | { |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 732 | int count = get_bookmark_count(bookmark_file_name); |
| 733 | bookmarks->total_count = count; |
| 734 | |
| 735 | if (bookmarks->total_count < 1) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 736 | { |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 737 | /* No more bookmarks, delete file and exit */ |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 738 | splash(HZ, ID2P(LANG_BOOKMARK_LOAD_EMPTY)); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 739 | remove(bookmark_file_name); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 740 | *selected_bookmark = NULL; |
| 741 | return BOOKMARK_FAIL; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 742 | } |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 743 | |
| 744 | if (bookmarks->show_dont_resume) |
| 745 | { |
| 746 | count++; |
| 747 | item++; |
| 748 | } |
| 749 | |
| 750 | gui_synclist_set_nb_items(&list, count * 2); |
| 751 | |
| 752 | if (item >= count) |
| 753 | { |
| 754 | /* Selected item has been deleted */ |
| 755 | item = count - 1; |
| 756 | gui_synclist_select_item(&list, item * 2); |
| 757 | } |
| 758 | |
| 759 | buffer_bookmarks(bookmarks, bookmarks->start); |
| 760 | gui_synclist_draw(&list); |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 761 | cond_talk_ids_fq(VOICE_EXT_BMARK); |
| 762 | gui_synclist_speak_item(&list); |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 763 | refresh = false; |
| 764 | } |
| 765 | |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 766 | list_do_action(CONTEXT_BOOKMARKSCREEN, HZ / 2, |
| 767 | &list, &action, LIST_WRAP_UNLESS_HELD); |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 768 | item = gui_synclist_get_sel_pos(&list) / 2; |
| 769 | |
| 770 | if (bookmarks->show_dont_resume) |
| 771 | { |
| 772 | item--; |
| 773 | } |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 774 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 775 | if (action == ACTION_STD_CONTEXT) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 776 | { |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 777 | MENUITEM_STRINGLIST(menu_items, ID2P(LANG_BOOKMARK_CONTEXT_MENU), |
| 778 | NULL, ID2P(LANG_BOOKMARK_CONTEXT_RESUME), |
| 779 | ID2P(LANG_BOOKMARK_CONTEXT_DELETE)); |
| 780 | static const int menu_actions[] = |
| 781 | { |
| 782 | ACTION_STD_OK, ACTION_BMS_DELETE |
| 783 | }; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 784 | int selection = do_menu(&menu_items, NULL, NULL, false); |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 785 | |
| 786 | refresh = true; |
| 787 | |
| 788 | if (selection >= 0 && selection <= |
| 789 | (int) (sizeof(menu_actions) / sizeof(menu_actions[0]))) |
| 790 | { |
| 791 | action = menu_actions[selection]; |
| 792 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 795 | switch (action) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 796 | { |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 797 | case ACTION_STD_OK: |
| 798 | if (item >= 0) |
| 799 | { |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 800 | talk_shutup(); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 801 | *selected_bookmark = bookmarks->items[item - bookmarks->start]; |
| 802 | return BOOKMARK_SUCCESS; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 803 | } |
Richard Quirk | dcba741 | 2013-03-05 19:31:36 +0100 | [diff] [blame] | 804 | exit = true; |
| 805 | ret = BOOKMARK_SUCCESS; |
| 806 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 807 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 808 | case ACTION_TREE_WPS: |
| 809 | case ACTION_STD_CANCEL: |
| 810 | exit = true; |
| 811 | break; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 812 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 813 | case ACTION_BMS_DELETE: |
| 814 | if (item >= 0) |
Jonathan Gordon | b9aabcb | 2009-12-16 08:18:40 +0000 | [diff] [blame] | 815 | { |
| 816 | const char *lines[]={ |
Jonathan Gordon | 4e89025 | 2009-12-16 08:38:27 +0000 | [diff] [blame] | 817 | ID2P(LANG_REALLY_DELETE) |
Jonathan Gordon | b9aabcb | 2009-12-16 08:18:40 +0000 | [diff] [blame] | 818 | }; |
| 819 | const char *yes_lines[]={ |
Jonathan Gordon | 4e89025 | 2009-12-16 08:38:27 +0000 | [diff] [blame] | 820 | ID2P(LANG_DELETING) |
Jonathan Gordon | b9aabcb | 2009-12-16 08:18:40 +0000 | [diff] [blame] | 821 | }; |
| 822 | |
Jonathan Gordon | 4e89025 | 2009-12-16 08:38:27 +0000 | [diff] [blame] | 823 | const struct text_message message={lines, 1}; |
| 824 | const struct text_message yes_message={yes_lines, 1}; |
Jonathan Gordon | b9aabcb | 2009-12-16 08:18:40 +0000 | [diff] [blame] | 825 | |
| 826 | if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES) |
| 827 | { |
Jonathan Gordon | b9aabcb | 2009-12-16 08:18:40 +0000 | [diff] [blame] | 828 | delete_bookmark(bookmark_file_name, item); |
| 829 | bookmarks->reload = true; |
| 830 | } |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 831 | refresh = true; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 832 | } |
| 833 | break; |
Jens Arnold | 3423259 | 2005-05-17 23:34:16 +0000 | [diff] [blame] | 834 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 835 | default: |
| 836 | if (default_event_handler(action) == SYS_USB_CONNECTED) |
| 837 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 838 | ret = BOOKMARK_USB_CONNECTED; |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 839 | exit = true; |
| 840 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 841 | |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 842 | break; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 843 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 844 | } |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 845 | |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 846 | talk_shutup(); |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 847 | *selected_bookmark = NULL; |
| 848 | return ret; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 851 | /* ----------------------------------------------------------------------- */ |
| 852 | /* This function takes a location in a bookmark file and deletes that */ |
| 853 | /* bookmark. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 854 | /* Returns true on successful bookmark deletion. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 855 | /* ------------------------------------------------------------------------*/ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 856 | static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 857 | { |
| 858 | int temp_bookmark_file = 0; |
| 859 | int bookmark_file = 0; |
| 860 | int bookmark_count = 0; |
| 861 | |
| 862 | /* Opening up a temp bookmark file */ |
| 863 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), |
| 864 | "%s.tmp", bookmark_file_name); |
| 865 | temp_bookmark_file = open(global_temp_buffer, |
Thomas Martitz | 0a1d7c2 | 2010-05-06 17:35:13 +0000 | [diff] [blame] | 866 | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 867 | |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 868 | if (temp_bookmark_file < 0) |
| 869 | return false; /* can't open the temp file */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 870 | |
| 871 | /* Reading in the previous bookmarks and writing them to the temp file */ |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 872 | bookmark_file = open(bookmark_file_name, O_RDONLY); |
| 873 | if (bookmark_file >= 0) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 874 | { |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 875 | while (read_line(bookmark_file, global_read_buffer, |
| 876 | sizeof(global_read_buffer)) > 0) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 877 | { |
| 878 | if (bookmark_id != bookmark_count) |
| 879 | { |
| 880 | write(temp_bookmark_file, global_read_buffer, |
| 881 | strlen(global_read_buffer)); |
| 882 | write(temp_bookmark_file, "\n", 1); |
| 883 | } |
| 884 | bookmark_count++; |
| 885 | } |
Magnus Holmgren | 12bf625 | 2007-02-20 21:08:54 +0000 | [diff] [blame] | 886 | close(bookmark_file); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 887 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 888 | close(temp_bookmark_file); |
| 889 | |
| 890 | remove(bookmark_file_name); |
| 891 | rename(global_temp_buffer, bookmark_file_name); |
| 892 | |
| 893 | return true; |
| 894 | } |
| 895 | |
| 896 | /* ----------------------------------------------------------------------- */ |
Jörg Hohensohn | f2d8b0e | 2004-04-12 12:29:44 +0000 | [diff] [blame] | 897 | /* This function parses a bookmark, says the voice UI part of it. */ |
| 898 | /* ------------------------------------------------------------------------*/ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 899 | static void say_bookmark(const char* bookmark, |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 900 | int bookmark_id, bool show_playlist_name) |
Jörg Hohensohn | f2d8b0e | 2004-04-12 12:29:44 +0000 | [diff] [blame] | 901 | { |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 902 | if (!parse_bookmark(bookmark, true)) |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 903 | { |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 904 | talk_id(LANG_BOOKMARK_INVALID, false); |
Magnus Holmgren | e676b81 | 2007-05-26 10:44:38 +0000 | [diff] [blame] | 905 | return; |
| 906 | } |
| 907 | |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 908 | talk_number(bookmark_id + 1, false); |
| 909 | |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 910 | #if CONFIG_CODEC == SWCODEC |
Nils Wallménius | 2e3162f | 2011-05-24 10:56:01 +0000 | [diff] [blame] | 911 | bool is_dir = (global_temp_buffer[0] |
| 912 | && global_temp_buffer[strlen(global_temp_buffer)-1] == '/'); |
| 913 | |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 914 | /* HWCODEC cannot enqueue voice file entries and .talk thumbnails |
| 915 | together, because there is no guarantee that the same mp3 |
| 916 | parameters are used. */ |
| 917 | if(show_playlist_name) |
| 918 | { /* It's useful to know which playlist this is */ |
| 919 | if(is_dir) |
| 920 | talk_dir_or_spell(global_temp_buffer, |
| 921 | TALK_IDARRAY(VOICE_DIR), true); |
| 922 | else talk_file_or_spell(NULL, global_temp_buffer, |
| 923 | TALK_IDARRAY(LANG_PLAYLIST), true); |
Jörg Hohensohn | f2d8b0e | 2004-04-12 12:29:44 +0000 | [diff] [blame] | 924 | } |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 925 | #else |
| 926 | (void)show_playlist_name; |
Jörg Hohensohn | f2d8b0e | 2004-04-12 12:29:44 +0000 | [diff] [blame] | 927 | #endif |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 928 | |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 929 | if(bm.shuffle) |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 930 | talk_id(LANG_SHUFFLE, true); |
| 931 | |
Magnus Holmgren | f9f3cad | 2007-05-26 11:59:24 +0000 | [diff] [blame] | 932 | talk_id(VOICE_BOOKMARK_SELECT_INDEX_TEXT, true); |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 933 | talk_number(bm.resume_index + 1, true); |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 934 | talk_id(LANG_TIME, true); |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 935 | talk_value(bm.resume_time / 1000, UNIT_TIME, true); |
Stéphane Doyon | bd06769 | 2008-07-15 16:10:15 +0000 | [diff] [blame] | 936 | |
| 937 | #if CONFIG_CODEC == SWCODEC |
| 938 | /* Track filename */ |
| 939 | if(is_dir) |
| 940 | talk_file_or_spell(global_temp_buffer, global_filename, |
| 941 | TALK_IDARRAY(VOICE_FILE), true); |
| 942 | else |
| 943 | { /* Unfortunately if this is a playlist, we do not know in which |
| 944 | directory the file is and therefore cannot find the track's |
| 945 | .talk file. */ |
| 946 | talk_id(VOICE_FILE, true); |
| 947 | talk_spell(global_filename, true); |
| 948 | } |
| 949 | #endif |
Jörg Hohensohn | f2d8b0e | 2004-04-12 12:29:44 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 952 | /* ----------------------------------------------------------------------- */ |
| 953 | /* This function parses a bookmark and then plays it. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 954 | /* Returns true on successful bookmark play. */ |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 955 | /* ------------------------------------------------------------------------*/ |
| 956 | static bool play_bookmark(const char* bookmark) |
| 957 | { |
Nils Wallménius | d29a11b | 2012-05-08 16:34:26 +0200 | [diff] [blame] | 958 | #if CONFIG_CODEC == SWCODEC && defined(HAVE_PITCHCONTROL) |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 959 | /* preset pitch and speed to 100% in case bookmark doesn't have info */ |
| 960 | bm.pitch = sound_get_pitch(); |
| 961 | bm.speed = dsp_get_timestretch(); |
Jeffrey Goode | 4f3f7dd | 2010-04-10 21:41:01 +0000 | [diff] [blame] | 962 | #endif |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 963 | |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 964 | if (parse_bookmark(bookmark, true)) |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 965 | { |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 966 | global_settings.repeat_mode = bm.repeat_mode; |
| 967 | global_settings.playlist_shuffle = bm.shuffle; |
Nils Wallménius | d29a11b | 2012-05-08 16:34:26 +0200 | [diff] [blame] | 968 | #if CONFIG_CODEC == SWCODEC && defined(HAVE_PITCHCONTROL) |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 969 | sound_set_pitch(bm.pitch); |
| 970 | dsp_set_timestretch(bm.speed); |
Jeffrey Goode | 4f3f7dd | 2010-04-10 21:41:01 +0000 | [diff] [blame] | 971 | #endif |
Bertrik Sikken | 1ca28a4 | 2010-09-26 21:13:25 +0000 | [diff] [blame] | 972 | if (!warn_on_pl_erase()) |
| 973 | return false; |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 974 | return bookmark_play(global_temp_buffer, bm.resume_index, |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 975 | bm.resume_time, bm.resume_offset, bm.resume_seed, global_filename); |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | return false; |
| 979 | } |
Jörg Hohensohn | f2d8b0e | 2004-04-12 12:29:44 +0000 | [diff] [blame] | 980 | |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 981 | static const char* skip_token(const char* s) |
| 982 | { |
| 983 | while (*s && *s != ';') |
| 984 | { |
| 985 | s++; |
| 986 | } |
| 987 | |
| 988 | if (*s) |
| 989 | { |
| 990 | s++; |
| 991 | } |
| 992 | |
| 993 | return s; |
| 994 | } |
| 995 | |
Bertrik Sikken | ab99e94 | 2011-05-08 20:35:29 +0000 | [diff] [blame] | 996 | static const char* int_token(const char* s, int* dest) |
| 997 | { |
Jeffrey Goode | e2eff49 | 2010-04-10 21:53:55 +0000 | [diff] [blame] | 998 | *dest = atoi(s); |
Bertrik Sikken | ab99e94 | 2011-05-08 20:35:29 +0000 | [diff] [blame] | 999 | return skip_token(s); |
| 1000 | } |
Jeffrey Goode | e2eff49 | 2010-04-10 21:53:55 +0000 | [diff] [blame] | 1001 | |
Bertrik Sikken | ab99e94 | 2011-05-08 20:35:29 +0000 | [diff] [blame] | 1002 | static const char* long_token(const char* s, long* dest) |
| 1003 | { |
Jeffrey Goode | e2eff49 | 2010-04-10 21:53:55 +0000 | [diff] [blame] | 1004 | *dest = atoi(s); /* Should be atol, but we don't have it. */ |
Bertrik Sikken | ab99e94 | 2011-05-08 20:35:29 +0000 | [diff] [blame] | 1005 | return skip_token(s); |
| 1006 | } |
Jeffrey Goode | bec9232 | 2010-04-06 22:49:06 +0000 | [diff] [blame] | 1007 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1008 | /* ----------------------------------------------------------------------- */ |
| 1009 | /* This function takes a bookmark and parses it. This function also */ |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 1010 | /* validates the bookmark. The parse_filenames flag indicates whether */ |
| 1011 | /* the filename tokens are to be extracted. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1012 | /* Returns true on successful bookmark parse. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1013 | /* ----------------------------------------------------------------------- */ |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 1014 | static bool parse_bookmark(const char *bookmark, const bool parse_filenames) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1015 | { |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 1016 | const char* s = bookmark; |
| 1017 | const char* end; |
| 1018 | |
Jeffrey Goode | e2eff49 | 2010-04-10 21:53:55 +0000 | [diff] [blame] | 1019 | #define GET_INT_TOKEN(var) s = int_token(s, &var) |
| 1020 | #define GET_LONG_TOKEN(var) s = long_token(s, &var) |
Jeffrey Goode | b2ba112 | 2010-04-06 21:49:33 +0000 | [diff] [blame] | 1021 | #define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s) |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1022 | |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 1023 | /* if new format bookmark, extract the optional content flags, |
| 1024 | otherwise treat as an original format bookmark */ |
| 1025 | int opt_flags = 0; |
| 1026 | bool new_format = (strchr(s, '>') == s); |
| 1027 | if (new_format) |
| 1028 | { |
| 1029 | s++; |
| 1030 | GET_INT_TOKEN(opt_flags); |
| 1031 | } |
| 1032 | |
| 1033 | /* extract all original bookmark tokens */ |
Jeffrey Goode | b2ba112 | 2010-04-06 21:49:33 +0000 | [diff] [blame] | 1034 | GET_INT_TOKEN(bm.resume_index); |
Jeffrey Goode | e2eff49 | 2010-04-10 21:53:55 +0000 | [diff] [blame] | 1035 | GET_LONG_TOKEN(bm.resume_offset); |
Jeffrey Goode | b2ba112 | 2010-04-06 21:49:33 +0000 | [diff] [blame] | 1036 | GET_INT_TOKEN(bm.resume_seed); |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 1037 | if (!new_format) /* skip deprecated token */ |
| 1038 | s = skip_token(s); |
Jeffrey Goode | e2eff49 | 2010-04-10 21:53:55 +0000 | [diff] [blame] | 1039 | GET_LONG_TOKEN(bm.resume_time); |
Jeffrey Goode | b2ba112 | 2010-04-06 21:49:33 +0000 | [diff] [blame] | 1040 | GET_INT_TOKEN(bm.repeat_mode); |
| 1041 | GET_BOOL_TOKEN(bm.shuffle); |
| 1042 | |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 1043 | /* extract all optional bookmark tokens */ |
| 1044 | if (opt_flags & BM_PITCH) |
| 1045 | GET_INT_TOKEN(bm.pitch); |
| 1046 | if (opt_flags & BM_SPEED) |
| 1047 | GET_INT_TOKEN(bm.speed); |
| 1048 | |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 1049 | if (*s == 0) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1050 | { |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 1051 | return false; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1052 | } |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 1053 | |
| 1054 | end = strchr(s, ';'); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1055 | |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1056 | /* extract file names */ |
Jeffrey Goode | 55064f7 | 2010-04-10 21:17:09 +0000 | [diff] [blame] | 1057 | if (parse_filenames) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1058 | { |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 1059 | size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1060 | len = MIN(TEMP_BUF_SIZE - 1, len); |
| 1061 | strlcpy(global_temp_buffer, s, len + 1); |
| 1062 | |
| 1063 | if (end != NULL) |
| 1064 | { |
| 1065 | end++; |
| 1066 | strlcpy(global_filename, end, MAX_PATH); |
| 1067 | } |
| 1068 | } |
Magnus Holmgren | 375b7e0 | 2007-02-15 22:13:14 +0000 | [diff] [blame] | 1069 | |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1070 | return true; |
| 1071 | } |
| 1072 | |
| 1073 | /* ----------------------------------------------------------------------- */ |
| 1074 | /* This function is used by multiple functions and is used to generate a */ |
| 1075 | /* bookmark named based off of the input. */ |
| 1076 | /* Changing this function could result in how the bookmarks are stored. */ |
| 1077 | /* it would be here that the centralized/decentralized bookmark code */ |
| 1078 | /* could be placed. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1079 | /* Always returns true */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1080 | /* ----------------------------------------------------------------------- */ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 1081 | static bool generate_bookmark_file_name(const char *in) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1082 | { |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 1083 | int len = strlen(in); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1084 | |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 1085 | /* if this is a root dir MP3, rename the bookmark file root_dir.bmark */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1086 | /* otherwise, name it based on the in variable */ |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 1087 | if (!strcmp("/", in)) |
| 1088 | strcpy(global_bookmark_file_name, "/root_dir.bmark"); |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1089 | else |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 1090 | { |
Magnus Holmgren | 30f3855 | 2009-03-08 13:57:10 +0000 | [diff] [blame] | 1091 | #ifdef HAVE_MULTIVOLUME |
| 1092 | /* The "root" of an extra volume need special handling too. */ |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 1093 | const char *filename; |
| 1094 | path_strip_volume(in, &filename, true); |
| 1095 | bool volume_root = *filename == '\0'; |
Magnus Holmgren | 30f3855 | 2009-03-08 13:57:10 +0000 | [diff] [blame] | 1096 | #endif |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 1097 | strcpy(global_bookmark_file_name, in); |
| 1098 | if(global_bookmark_file_name[len-1] == '/') |
| 1099 | len--; |
Magnus Holmgren | 30f3855 | 2009-03-08 13:57:10 +0000 | [diff] [blame] | 1100 | #ifdef HAVE_MULTIVOLUME |
| 1101 | if (volume_root) |
| 1102 | strcpy(&global_bookmark_file_name[len], "/volume_dir.bmark"); |
| 1103 | else |
| 1104 | #endif |
| 1105 | strcpy(&global_bookmark_file_name[len], ".bmark"); |
Linus Nielsen Feltzing | 0907631 | 2004-06-22 06:23:14 +0000 | [diff] [blame] | 1106 | } |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1107 | |
| 1108 | return true; |
| 1109 | } |
| 1110 | |
| 1111 | /* ----------------------------------------------------------------------- */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1112 | /* Returns true if a bookmark file exists for the current playlist. */ |
| 1113 | /* This is an interface function. */ |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 1114 | /* ----------------------------------------------------------------------- */ |
Alexander Levin | 7d4c0c5 | 2010-07-06 16:53:52 +0000 | [diff] [blame] | 1115 | bool bookmark_exists(void) |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 1116 | { |
| 1117 | bool exist=false; |
| 1118 | |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1119 | char* name = playlist_get_name(NULL, global_temp_buffer, |
| 1120 | sizeof(global_temp_buffer)); |
| 1121 | if (generate_bookmark_file_name(name)) |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 1122 | { |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1123 | exist = file_exists(global_bookmark_file_name); |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 1124 | } |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 1125 | return exist; |
| 1126 | } |
| 1127 | |
| 1128 | /* ----------------------------------------------------------------------- */ |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1129 | /* Checks the current state of the system and returns true if it is in a */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1130 | /* bookmarkable state. */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1131 | /* This is an interface funtion. */ |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1132 | /* ----------------------------------------------------------------------- */ |
Osborne Jacobs | fb30d01 | 2012-03-11 00:47:28 -0500 | [diff] [blame] | 1133 | bool bookmark_is_bookmarkable_state(void) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1134 | { |
| 1135 | int resume_index = 0; |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1136 | |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1137 | if (!(audio_status() && audio_current_track()) || |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1138 | /* no track playing */ |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1139 | (playlist_get_resume_info(&resume_index) == -1) || |
| 1140 | /* invalid queue info */ |
| 1141 | (playlist_modified(NULL))) |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1142 | /* can't bookmark while in the queue */ |
Jeffrey Goode | 7209c5d | 2010-04-05 20:53:04 +0000 | [diff] [blame] | 1143 | { |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 1144 | return false; |
| 1145 | } |
| 1146 | |
| 1147 | return true; |
| 1148 | } |
| 1149 | |