2005-02-09 10:56:54 +00:00
|
|
|
/***************************************************************************
|
2004-01-14 00:13:04 +00:00
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
2005-02-09 10:56:54 +00:00
|
|
|
* Copyright (C)2003 by Benjamin Metzler
|
2004-01-14 00:13:04 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "applimits.h"
|
|
|
|
#include "lcd.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2004-01-14 00:13:04 +00:00
|
|
|
#include "usb.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
#include "audio.h"
|
2005-11-17 20:14:59 +00:00
|
|
|
#include "playlist.h"
|
2004-01-14 00:13:04 +00:00
|
|
|
#include "settings.h"
|
2005-05-17 23:34:16 +00:00
|
|
|
#include "tree.h"
|
2004-01-14 00:13:04 +00:00
|
|
|
#include "bookmark.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "errno.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "atoi.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "kernel.h"
|
2004-01-14 00:38:45 +00:00
|
|
|
#include "sprintf.h"
|
2004-03-19 22:15:53 +00:00
|
|
|
#include "talk.h"
|
2004-07-26 16:06:59 +00:00
|
|
|
#include "misc.h"
|
2005-08-21 23:01:12 +00:00
|
|
|
#include "abrepeat.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2005-11-20 01:02:14 +00:00
|
|
|
#include "yesno.h"
|
|
|
|
|
2006-07-15 14:40:44 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
#include "backdrop.h"
|
|
|
|
#endif
|
|
|
|
|
2004-03-02 13:50:35 +00:00
|
|
|
#define MAX_BOOKMARKS 10
|
2004-01-14 00:13:04 +00:00
|
|
|
#define MAX_BOOKMARK_SIZE 350
|
|
|
|
#define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"
|
|
|
|
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool add_bookmark(const char* bookmark_file_name, const char* bookmark);
|
|
|
|
static bool check_bookmark(const char* bookmark);
|
2004-01-14 00:13:04 +00:00
|
|
|
static char* create_bookmark(void);
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id);
|
|
|
|
static void display_bookmark(const char* bookmark,
|
2004-01-14 00:13:04 +00:00
|
|
|
int bookmark_id,
|
|
|
|
int bookmark_count);
|
2004-08-18 01:09:31 +00:00
|
|
|
static void say_bookmark(const char* bookmark,
|
2004-04-12 12:29:44 +00:00
|
|
|
int bookmark_id);
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool generate_bookmark_file_name(const char *in);
|
|
|
|
static char* get_bookmark(const char* bookmark_file, int bookmark_count);
|
|
|
|
static bool parse_bookmark(const char *bookmark,
|
2004-01-14 00:13:04 +00:00
|
|
|
int *resume_index,
|
|
|
|
int *resume_offset,
|
|
|
|
int *resume_seed,
|
|
|
|
int *resume_first_index,
|
|
|
|
char* resume_file,
|
|
|
|
unsigned int resume_file_size,
|
2005-02-09 10:56:54 +00:00
|
|
|
long* ms,
|
2004-01-14 00:13:04 +00:00
|
|
|
int * repeat_mode,
|
|
|
|
bool *shuffle,
|
2004-12-07 14:20:37 +00:00
|
|
|
char* file_name);
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* select_bookmark(const char* bookmark_file_name);
|
2004-01-14 00:13:04 +00:00
|
|
|
static bool system_check(void);
|
|
|
|
static bool write_bookmark(bool create_bookmark_file);
|
2004-08-18 01:09:31 +00:00
|
|
|
static int get_bookmark_count(const char* bookmark_file_name);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
static char global_temp_buffer[MAX_PATH+1];
|
|
|
|
static char global_bookmark_file_name[MAX_PATH];
|
|
|
|
static char global_read_buffer[MAX_BOOKMARK_SIZE];
|
|
|
|
static char global_bookmark[MAX_BOOKMARK_SIZE];
|
2004-12-07 14:20:37 +00:00
|
|
|
static char global_filename[MAX_PATH];
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This is the interface function from the main menu. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
bool bookmark_create_menu(void)
|
|
|
|
{
|
|
|
|
write_bookmark(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function acts as the load interface from the main menu */
|
|
|
|
/* This function determines the bookmark file name and then loads that file*/
|
|
|
|
/* for the user. The user can then select a bookmark to load. */
|
|
|
|
/* If no file/directory is currently playing, the menu item does not work. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
2005-06-23 01:31:26 +00:00
|
|
|
bool bookmark_load_menu(void)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
int offset;
|
|
|
|
int seed;
|
|
|
|
int index;
|
|
|
|
char* bookmark;
|
|
|
|
|
|
|
|
if(!system_check())
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
char* name = playlist_get_name(NULL, global_temp_buffer,
|
2004-01-14 00:13:04 +00:00
|
|
|
sizeof(global_temp_buffer));
|
2004-06-22 06:23:14 +00:00
|
|
|
if (generate_bookmark_file_name(name))
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
bookmark = select_bookmark(global_bookmark_file_name);
|
|
|
|
if (!bookmark)
|
|
|
|
return false; /* User exited without selecting a bookmark */
|
|
|
|
|
|
|
|
success = parse_bookmark(bookmark,
|
|
|
|
&index,
|
|
|
|
&offset,
|
|
|
|
&seed,
|
|
|
|
NULL,
|
|
|
|
global_temp_buffer,
|
|
|
|
sizeof(global_temp_buffer),
|
|
|
|
NULL,
|
|
|
|
&global_settings.repeat_mode,
|
|
|
|
&global_settings.playlist_shuffle,
|
2004-12-07 14:20:37 +00:00
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* something bad happened while creating bookmark name*/
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
2004-12-07 14:20:37 +00:00
|
|
|
bookmark_play(global_temp_buffer, index, offset, seed,
|
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Gives the user a list of the Most Recent Bookmarks. This is an */
|
|
|
|
/* interface function */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
bool bookmark_mrb_load()
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
int offset;
|
|
|
|
int seed;
|
|
|
|
int index;
|
|
|
|
char* bookmark;
|
|
|
|
|
|
|
|
bookmark = select_bookmark(RECENT_BOOKMARK_FILE);
|
|
|
|
if (!bookmark)
|
|
|
|
return false; /* User exited without selecting a bookmark */
|
|
|
|
|
|
|
|
success = parse_bookmark(bookmark,
|
|
|
|
&index,
|
|
|
|
&offset,
|
|
|
|
&seed,
|
|
|
|
NULL,
|
|
|
|
global_temp_buffer,
|
|
|
|
sizeof(global_temp_buffer),
|
|
|
|
NULL,
|
|
|
|
&global_settings.repeat_mode,
|
|
|
|
&global_settings.playlist_shuffle,
|
2004-12-07 14:20:37 +00:00
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
if (success)
|
2004-12-07 14:20:37 +00:00
|
|
|
bookmark_play(global_temp_buffer, index, offset, seed,
|
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function handles an autobookmark creation. This is an interface */
|
|
|
|
/* function. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
bool bookmark_autobookmark(void)
|
|
|
|
{
|
|
|
|
if (!system_check())
|
|
|
|
return false;
|
|
|
|
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_pause(); /* first pause playback */
|
2004-01-14 00:13:04 +00:00
|
|
|
switch (global_settings.autocreatebookmark)
|
|
|
|
{
|
|
|
|
case BOOKMARK_YES:
|
|
|
|
return write_bookmark(true);
|
|
|
|
|
|
|
|
case BOOKMARK_NO:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case BOOKMARK_RECENT_ONLY_YES:
|
|
|
|
return write_bookmark(false);
|
|
|
|
}
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-12-07 09:04:13 +00:00
|
|
|
unsigned char *lines[]={str(LANG_AUTO_BOOKMARK_QUERY)};
|
2005-12-07 09:14:58 +00:00
|
|
|
struct text_message message={(char **)lines, 1};
|
2004-01-14 00:13:04 +00:00
|
|
|
#else
|
2005-12-05 22:44:42 +00:00
|
|
|
unsigned char *lines[]={str(LANG_AUTO_BOOKMARK_QUERY),
|
|
|
|
str(LANG_RESUME_CONFIRM_PLAYER)};
|
|
|
|
struct text_message message={(char **)lines, 2};
|
2006-07-15 14:23:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
show_main_backdrop(); /* switch to main backdrop as we may come from wps */
|
2004-01-14 00:13:04 +00:00
|
|
|
#endif
|
2005-11-20 01:02:14 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
|
|
|
if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2005-11-20 01:02:14 +00:00
|
|
|
if (global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
|
|
|
|
return write_bookmark(false);
|
|
|
|
else
|
|
|
|
return write_bookmark(true);
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
2004-10-24 21:45:37 +00:00
|
|
|
return false;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function takes the current current resume information and writes */
|
|
|
|
/* that to the beginning of the bookmark file. */
|
|
|
|
/* This file will contain N number of bookmarks in the following format: */
|
|
|
|
/* resume_index*resume_offset*resume_seed*resume_first_index* */
|
|
|
|
/* resume_file*milliseconds*MP3 Title* */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
|
|
|
static bool write_bookmark(bool create_bookmark_file)
|
|
|
|
{
|
|
|
|
bool success=false;
|
|
|
|
char* bookmark;
|
|
|
|
|
|
|
|
if (!system_check())
|
|
|
|
return false; /* something didn't happen correctly, do nothing */
|
|
|
|
|
|
|
|
bookmark = create_bookmark();
|
|
|
|
if (!bookmark)
|
|
|
|
return false; /* something didn't happen correctly, do nothing */
|
|
|
|
|
|
|
|
if (global_settings.usemrb)
|
|
|
|
success = add_bookmark(RECENT_BOOKMARK_FILE, bookmark);
|
|
|
|
|
|
|
|
|
|
|
|
/* writing the bookmark */
|
|
|
|
if (create_bookmark_file)
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
char* name = playlist_get_name(NULL, global_temp_buffer,
|
2004-01-14 00:13:04 +00:00
|
|
|
sizeof(global_temp_buffer));
|
2004-06-22 06:23:14 +00:00
|
|
|
if (generate_bookmark_file_name(name))
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
success = add_bookmark(global_bookmark_file_name, bookmark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
2005-11-16 15:12:15 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_BOOKMARK_CREATE_SUCCESS));
|
2004-01-14 00:13:04 +00:00
|
|
|
else
|
2005-11-16 15:12:15 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_BOOKMARK_CREATE_FAILURE));
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function adds a bookmark to a file. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool add_bookmark(const char* bookmark_file_name, const char* bookmark)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int temp_bookmark_file = 0;
|
|
|
|
int bookmark_file = 0;
|
|
|
|
int bookmark_count = 0;
|
|
|
|
char* playlist = NULL;
|
|
|
|
char* cp;
|
2004-03-21 13:42:18 +00:00
|
|
|
char* tmp;
|
2004-01-14 00:13:04 +00:00
|
|
|
int len = 0;
|
|
|
|
bool unique = false;
|
|
|
|
|
|
|
|
/* Opening up a temp bookmark file */
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
|
|
|
|
"%s.tmp", bookmark_file_name);
|
|
|
|
temp_bookmark_file = open(global_temp_buffer,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC);
|
|
|
|
if (temp_bookmark_file < 0)
|
|
|
|
return false; /* can't open the temp file */
|
|
|
|
|
|
|
|
if (!strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE) &&
|
|
|
|
(global_settings.usemrb == BOOKMARK_UNIQUE_ONLY))
|
|
|
|
{
|
|
|
|
playlist = strchr(bookmark,'/');
|
|
|
|
cp = strrchr(bookmark,';');
|
|
|
|
len = cp - playlist;
|
|
|
|
unique = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writing the new bookmark to the begining of the temp file */
|
|
|
|
write(temp_bookmark_file, bookmark, strlen(bookmark));
|
|
|
|
write(temp_bookmark_file, "\n", 1);
|
2004-03-02 13:50:35 +00:00
|
|
|
bookmark_count++;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
/* Reading in the previous bookmarks and writing them to the temp file */
|
|
|
|
bookmark_file = open(bookmark_file_name, O_RDONLY);
|
|
|
|
if (bookmark_file >= 0)
|
|
|
|
{
|
|
|
|
while (read_line(bookmark_file, global_read_buffer,
|
|
|
|
sizeof(global_read_buffer)))
|
|
|
|
{
|
2004-03-02 13:50:35 +00:00
|
|
|
/* The MRB has a max of MAX_BOOKMARKS in it */
|
|
|
|
/* This keeps it from getting too large */
|
|
|
|
if ((strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE)==0))
|
|
|
|
{
|
|
|
|
if(bookmark_count >= MAX_BOOKMARKS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-21 13:42:18 +00:00
|
|
|
cp = strchr(global_read_buffer,'/');
|
|
|
|
tmp = strrchr(global_read_buffer,';');
|
|
|
|
if (check_bookmark(global_read_buffer) &&
|
|
|
|
(!unique || len != tmp -cp || strncmp(playlist,cp,len)))
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2004-03-21 13:42:18 +00:00
|
|
|
bookmark_count++;
|
|
|
|
write(temp_bookmark_file, global_read_buffer,
|
|
|
|
strlen(global_read_buffer));
|
|
|
|
write(temp_bookmark_file, "\n", 1);
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close(bookmark_file);
|
|
|
|
}
|
|
|
|
close(temp_bookmark_file);
|
|
|
|
|
|
|
|
remove(bookmark_file_name);
|
|
|
|
rename(global_temp_buffer, bookmark_file_name);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function takes the system resume data and formats it into a valid */
|
|
|
|
/* bookmark. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
static char* create_bookmark()
|
|
|
|
{
|
|
|
|
int resume_index = 0;
|
|
|
|
char *file;
|
|
|
|
|
|
|
|
/* grab the currently playing track */
|
2005-04-04 12:06:29 +00:00
|
|
|
struct mp3entry *id3 = audio_current_track();
|
2004-01-14 00:13:04 +00:00
|
|
|
if(!id3)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Get some basic resume information */
|
|
|
|
/* queue_resume and queue_resume_index are not used and can be ignored.*/
|
|
|
|
playlist_get_resume_info(&resume_index);
|
|
|
|
|
|
|
|
/* Get the currently playing file minus the path */
|
|
|
|
/* This is used when displaying the available bookmarks */
|
|
|
|
file = strrchr(id3->path,'/');
|
|
|
|
if(NULL == file)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* create the bookmark */
|
|
|
|
snprintf(global_bookmark, sizeof(global_bookmark),
|
2005-09-10 12:28:16 +00:00
|
|
|
"%d;%ld;%d;%d;%ld;%d;%d;%s;%s",
|
2004-01-14 00:13:04 +00:00
|
|
|
resume_index,
|
|
|
|
id3->offset,
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist_get_seed(NULL),
|
2004-01-14 00:13:04 +00:00
|
|
|
0,
|
|
|
|
id3->elapsed,
|
|
|
|
global_settings.repeat_mode,
|
|
|
|
global_settings.playlist_shuffle,
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist_get_name(NULL, global_temp_buffer,
|
|
|
|
sizeof(global_temp_buffer)),
|
2004-01-14 00:13:04 +00:00
|
|
|
file+1);
|
|
|
|
|
|
|
|
/* checking to see if the bookmark is valid */
|
|
|
|
if (check_bookmark(global_bookmark))
|
|
|
|
return global_bookmark;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool check_bookmark(const char* bookmark)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
return parse_bookmark(bookmark,
|
|
|
|
NULL,NULL,NULL, NULL,
|
|
|
|
NULL,0,NULL,NULL,
|
2004-12-07 14:20:37 +00:00
|
|
|
NULL, NULL);
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function will determine if an autoload is necessary. This is an */
|
|
|
|
/* interface function. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
bool bookmark_autoload(const char* file)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int key;
|
|
|
|
int fd;
|
2006-07-18 19:11:56 +00:00
|
|
|
int i;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
if(global_settings.autoloadbookmark == BOOKMARK_NO)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*Checking to see if a bookmark file exists.*/
|
2004-06-22 06:23:14 +00:00
|
|
|
if(!generate_bookmark_file_name(file))
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fd = open(global_bookmark_file_name, O_RDONLY);
|
|
|
|
if(fd<0)
|
|
|
|
return false;
|
|
|
|
if(-1 == lseek(fd, 0, SEEK_END))
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
if(global_settings.autoloadbookmark == BOOKMARK_YES)
|
|
|
|
{
|
|
|
|
return bookmark_load(global_bookmark_file_name, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Prompting user to confirm bookmark load */
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].clear_display();
|
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2006-07-18 19:11:56 +00:00
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2004-01-14 00:13:04 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-07-18 19:11:56 +00:00
|
|
|
screens[i].setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
screens[i].puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY));
|
|
|
|
screens[i].puts(0,1, str(LANG_CONFIRM_WITH_PLAY_RECORDER));
|
|
|
|
screens[i].puts(0,2, str(LANG_BOOKMARK_SELECT_LIST_BOOKMARKS));
|
|
|
|
screens[i].puts(0,3, str(LANG_CANCEL_WITH_ANY_RECORDER));
|
|
|
|
screens[i].update();
|
2004-01-14 00:13:04 +00:00
|
|
|
#else
|
2006-07-18 19:11:56 +00:00
|
|
|
screens[i].puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY));
|
|
|
|
screens[i].puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER));
|
2004-01-14 00:13:04 +00:00
|
|
|
#endif
|
2006-07-18 19:11:56 +00:00
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2006-08-20 17:25:56 +00:00
|
|
|
/* Wait for a key to be pushed */
|
|
|
|
key = get_action(CONTEXT_BOOKMARKSCREEN,TIMEOUT_BLOCK);
|
|
|
|
switch(key)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-08-20 17:25:56 +00:00
|
|
|
case ACTION_STD_NEXT:
|
2006-09-17 17:18:07 +00:00
|
|
|
action_signalscreenchange();
|
2006-08-20 17:25:56 +00:00
|
|
|
return bookmark_load(global_bookmark_file_name, false);
|
2006-07-18 19:11:56 +00:00
|
|
|
#endif
|
2006-08-23 13:01:19 +00:00
|
|
|
case ACTION_BMS_SELECT:
|
2006-09-17 17:18:07 +00:00
|
|
|
action_signalscreenchange();
|
2006-08-20 17:25:56 +00:00
|
|
|
return bookmark_load(global_bookmark_file_name, true);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
2006-08-20 17:25:56 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
2005-05-17 23:34:16 +00:00
|
|
|
return false;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function loads the bookmark information into the resume memory. */
|
|
|
|
/* This is an interface function. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
bool bookmark_load(const char* file, bool autoload)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
bool success = true;
|
|
|
|
int offset;
|
|
|
|
int seed;
|
|
|
|
int index;
|
|
|
|
char* bookmark = NULL;;
|
|
|
|
|
|
|
|
if(autoload)
|
|
|
|
{
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
if(fd >= 0)
|
|
|
|
{
|
|
|
|
if(read_line(fd, global_read_buffer, sizeof(global_read_buffer)))
|
|
|
|
bookmark=global_read_buffer;
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is not an auto-load, so list the bookmarks */
|
|
|
|
bookmark=select_bookmark(file);
|
|
|
|
if(!bookmark)
|
|
|
|
return true; /* User exited without selecting a bookmark */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bookmark)
|
|
|
|
{
|
|
|
|
success = parse_bookmark(bookmark,
|
|
|
|
&index,
|
|
|
|
&offset,
|
|
|
|
&seed,
|
|
|
|
NULL,
|
|
|
|
global_temp_buffer,
|
|
|
|
sizeof(global_temp_buffer),
|
|
|
|
NULL,
|
|
|
|
&global_settings.repeat_mode,
|
|
|
|
&global_settings.playlist_shuffle,
|
2004-12-07 14:20:37 +00:00
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(success)
|
2004-12-07 14:20:37 +00:00
|
|
|
bookmark_play(global_temp_buffer, index, offset, seed,
|
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-18 01:09:31 +00:00
|
|
|
static int get_bookmark_count(const char* bookmark_file_name)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int read_count = 0;
|
|
|
|
int file = open(bookmark_file_name, O_RDONLY);
|
|
|
|
|
|
|
|
if(file < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Get the requested bookmark */
|
|
|
|
while(read_line(file, global_read_buffer, sizeof(global_read_buffer)))
|
|
|
|
{
|
|
|
|
if(check_bookmark(global_read_buffer))
|
|
|
|
read_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(file);
|
|
|
|
return read_count;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This displays a the bookmarks in a file and allows the user to */
|
|
|
|
/* select one to play. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* select_bookmark(const char* bookmark_file_name)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int bookmark_id = 0;
|
2004-03-21 13:35:54 +00:00
|
|
|
int bookmark_id_prev = -1;
|
2005-05-17 23:34:16 +00:00
|
|
|
int key;
|
2004-03-21 13:35:54 +00:00
|
|
|
char* bookmark = NULL;
|
2004-01-14 00:13:04 +00:00
|
|
|
int bookmark_count = 0;
|
|
|
|
|
2004-03-21 13:35:54 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-07-18 19:11:56 +00:00
|
|
|
int i;
|
2005-06-23 01:31:26 +00:00
|
|
|
int x = lcd_getxmargin();
|
|
|
|
int y = lcd_getymargin();
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].setmargins(0, 0);
|
2004-03-21 13:35:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bookmark_count = get_bookmark_count(bookmark_file_name);
|
2006-08-21 07:03:15 +00:00
|
|
|
action_signalscreenchange();
|
2004-01-14 00:13:04 +00:00
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
if(bookmark_id < 0)
|
2004-09-27 19:23:18 +00:00
|
|
|
bookmark_id = bookmark_count -1;
|
|
|
|
if(bookmark_id >= bookmark_count)
|
2004-01-14 00:13:04 +00:00
|
|
|
bookmark_id = 0;
|
|
|
|
|
2004-03-21 13:35:54 +00:00
|
|
|
if (bookmark_id != bookmark_id_prev)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2004-03-21 13:35:54 +00:00
|
|
|
bookmark = get_bookmark(bookmark_file_name, bookmark_id);
|
|
|
|
bookmark_id_prev = bookmark_id;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!bookmark)
|
|
|
|
{
|
|
|
|
/* if there were no bookmarks in the file, delete the file and exit. */
|
2004-09-27 19:23:18 +00:00
|
|
|
if(bookmark_id <= 0)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2005-11-16 15:12:15 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_BOOKMARK_LOAD_EMPTY));
|
2004-01-14 00:13:04 +00:00
|
|
|
remove(bookmark_file_name);
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
2004-01-14 00:13:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-21 13:35:54 +00:00
|
|
|
bookmark_id_prev = bookmark_id;
|
2004-01-14 00:13:04 +00:00
|
|
|
bookmark_id--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
display_bookmark(bookmark, bookmark_id, bookmark_count);
|
2004-04-12 12:29:44 +00:00
|
|
|
if (global_settings.talk_menu) /* for voice UI */
|
|
|
|
say_bookmark(bookmark, bookmark_id);
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* waiting for the user to click a button */
|
2006-08-15 12:27:07 +00:00
|
|
|
key = get_action(CONTEXT_BOOKMARKSCREEN,TIMEOUT_BLOCK);
|
2004-01-14 00:13:04 +00:00
|
|
|
switch(key)
|
|
|
|
{
|
2006-08-21 07:03:15 +00:00
|
|
|
case ACTION_BMS_SELECT:
|
2004-01-14 00:13:04 +00:00
|
|
|
/* User wants to use this bookmark */
|
2004-04-21 19:06:48 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if (global_settings.statusbar)
|
2006-07-18 19:11:56 +00:00
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
}
|
2004-04-21 19:06:48 +00:00
|
|
|
else
|
2006-07-18 19:11:56 +00:00
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].setmargins(0, 0);
|
|
|
|
}
|
2004-04-21 19:06:48 +00:00
|
|
|
#endif
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
2004-01-14 00:13:04 +00:00
|
|
|
return bookmark;
|
2006-08-15 12:27:07 +00:00
|
|
|
|
2006-08-21 07:03:15 +00:00
|
|
|
case ACTION_BMS_DELETE:
|
2004-01-14 00:13:04 +00:00
|
|
|
/* User wants to delete this bookmark */
|
2004-03-21 13:35:54 +00:00
|
|
|
delete_bookmark(bookmark_file_name, bookmark_id);
|
2004-09-27 19:23:18 +00:00
|
|
|
bookmark_id_prev=-2;
|
2004-03-21 13:35:54 +00:00
|
|
|
bookmark_count--;
|
2004-09-27 19:23:18 +00:00
|
|
|
if(bookmark_id >= bookmark_count)
|
|
|
|
bookmark_id = bookmark_count -1;
|
2004-01-14 00:13:04 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-21 07:03:15 +00:00
|
|
|
case ACTION_STD_PREV:
|
|
|
|
case ACTION_STD_PREVREPEAT:
|
2004-01-14 00:13:04 +00:00
|
|
|
bookmark_id--;
|
|
|
|
break;
|
|
|
|
|
2006-08-21 07:03:15 +00:00
|
|
|
case ACTION_STD_NEXT:
|
|
|
|
case ACTION_STD_NEXTREPEAT:
|
2004-01-14 00:13:04 +00:00
|
|
|
bookmark_id++;
|
|
|
|
break;
|
|
|
|
|
2006-08-21 07:03:15 +00:00
|
|
|
case ACTION_BMS_EXIT:
|
2005-06-23 01:31:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].setmargins(x, y);
|
2004-04-04 16:44:40 +00:00
|
|
|
#endif
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
2004-01-14 00:13:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
2004-07-26 16:06:59 +00:00
|
|
|
default:
|
|
|
|
if(default_event_handler(key) == SYS_USB_CONNECTED)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
action_signalscreenchange();
|
2004-07-26 16:06:59 +00:00
|
|
|
return NULL;
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
2004-07-26 16:06:59 +00:00
|
|
|
break;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
2004-01-14 00:13:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function takes a location in a bookmark file and deletes that */
|
|
|
|
/* bookmark. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int temp_bookmark_file = 0;
|
|
|
|
int bookmark_file = 0;
|
|
|
|
int bookmark_count = 0;
|
|
|
|
|
|
|
|
/* Opening up a temp bookmark file */
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
|
|
|
|
"%s.tmp", bookmark_file_name);
|
|
|
|
temp_bookmark_file = open(global_temp_buffer,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC);
|
|
|
|
bookmark_file = open(bookmark_file_name, O_RDONLY);
|
|
|
|
|
|
|
|
if (temp_bookmark_file < 0 || bookmark_file < 0)
|
|
|
|
return false; /* can't open one of the files */
|
|
|
|
|
|
|
|
/* Reading in the previous bookmarks and writing them to the temp file */
|
|
|
|
while (read_line(bookmark_file, global_read_buffer,
|
|
|
|
sizeof(global_read_buffer)))
|
|
|
|
{
|
2004-03-02 13:50:35 +00:00
|
|
|
/* The MRB has a max of MAX_BOOKMARKS in it */
|
|
|
|
/* This keeps it from getting too large */
|
|
|
|
if ((strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE)==0))
|
|
|
|
{
|
|
|
|
if(bookmark_count >= MAX_BOOKMARKS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
if (check_bookmark(global_read_buffer))
|
|
|
|
{
|
|
|
|
if (bookmark_id != bookmark_count)
|
|
|
|
{
|
|
|
|
write(temp_bookmark_file, global_read_buffer,
|
|
|
|
strlen(global_read_buffer));
|
|
|
|
write(temp_bookmark_file, "\n", 1);
|
|
|
|
}
|
|
|
|
bookmark_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(bookmark_file);
|
|
|
|
close(temp_bookmark_file);
|
|
|
|
|
|
|
|
remove(bookmark_file_name);
|
|
|
|
rename(global_temp_buffer, bookmark_file_name);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function parses a bookmark and displays it for the user. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static void display_bookmark(const char* bookmark,
|
2004-01-14 00:13:04 +00:00
|
|
|
int bookmark_id,
|
|
|
|
int bookmark_count)
|
|
|
|
{
|
|
|
|
int resume_index = 0;
|
2005-02-09 10:56:54 +00:00
|
|
|
long ms = 0;
|
2004-01-14 00:13:04 +00:00
|
|
|
int repeat_mode = 0;
|
|
|
|
bool playlist_shuffle = false;
|
|
|
|
int len;
|
|
|
|
char *dot;
|
2006-07-18 19:11:56 +00:00
|
|
|
int i;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
/* getting the index and the time into the file */
|
|
|
|
parse_bookmark(bookmark,
|
|
|
|
&resume_index, NULL, NULL, NULL, NULL, 0,
|
|
|
|
&ms, &repeat_mode, &playlist_shuffle,
|
2004-12-07 14:20:37 +00:00
|
|
|
global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].clear_display();
|
|
|
|
screens[i].stop_scroll();
|
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* bookmark shuffle and repeat states*/
|
|
|
|
switch (repeat_mode)
|
|
|
|
{
|
2006-01-21 23:43:57 +00:00
|
|
|
#if (AB_REPEAT_ENABLE == 1)
|
2005-08-21 23:01:12 +00:00
|
|
|
case REPEAT_AB:
|
|
|
|
statusbar_icon_play_mode(Icon_RepeatAB);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
case REPEAT_ONE:
|
|
|
|
statusbar_icon_play_mode(Icon_RepeatOne);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REPEAT_ALL:
|
|
|
|
statusbar_icon_play_mode(Icon_Repeat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(playlist_shuffle)
|
|
|
|
statusbar_icon_shuffle();
|
|
|
|
|
|
|
|
/* File Name */
|
2004-12-07 14:20:37 +00:00
|
|
|
len=strlen(global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
if (len>3)
|
2004-12-07 14:20:37 +00:00
|
|
|
dot=strrchr(global_filename + len - 4, '.');
|
2004-01-14 00:13:04 +00:00
|
|
|
else
|
|
|
|
dot=NULL;
|
|
|
|
if (dot)
|
|
|
|
*dot='\0';
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, 0, (unsigned char *)global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
if (dot)
|
|
|
|
*dot='.';
|
|
|
|
|
|
|
|
/* bookmark number */
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %2d/%2d",
|
|
|
|
str(LANG_BOOKMARK_SELECT_BOOKMARK_TEXT),
|
|
|
|
bookmark_id + 1, bookmark_count);
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, 1, (unsigned char *)global_temp_buffer);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
/* bookmark resume index */
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %2d",
|
|
|
|
str(LANG_BOOKMARK_SELECT_INDEX_TEXT), resume_index+1);
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, 2, (unsigned char *)global_temp_buffer);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
/* elapsed time*/
|
2004-07-14 10:18:11 +00:00
|
|
|
if ( ms < 3600000 )
|
|
|
|
{
|
2005-02-09 10:56:54 +00:00
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %ld:%02d",
|
2004-07-14 10:18:11 +00:00
|
|
|
str(LANG_BOOKMARK_SELECT_TIME_TEXT),
|
|
|
|
ms / 60000,
|
2005-02-09 10:56:54 +00:00
|
|
|
(unsigned int)(ms % 60000) / 1000);
|
|
|
|
/* unsigned int: hinting for 16bits archs */
|
2004-07-14 10:18:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
|
2005-02-09 10:56:54 +00:00
|
|
|
"%s: %ld:%02ld:%02d",
|
|
|
|
str(LANG_BOOKMARK_SELECT_TIME_TEXT),
|
|
|
|
ms / 3600000,
|
|
|
|
ms % 3600000 / 60000,
|
|
|
|
(unsigned int)(ms % 60000) / 1000);
|
2004-07-14 10:18:11 +00:00
|
|
|
}
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, 3, (unsigned char *)global_temp_buffer);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
/* commands */
|
2006-07-18 19:11:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].puts_scroll(0, 4, str(LANG_BOOKMARK_SELECT_PLAY));
|
|
|
|
screens[i].puts_scroll(0, 5, str(LANG_BOOKMARK_SELECT_EXIT));
|
|
|
|
screens[i].puts_scroll(0, 6, str(LANG_BOOKMARK_SELECT_DELETE));
|
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
#else
|
2004-01-14 00:38:45 +00:00
|
|
|
(void)bookmark_id;
|
2004-12-07 14:20:37 +00:00
|
|
|
len=strlen(global_filename);
|
2004-01-14 00:13:04 +00:00
|
|
|
if (len>3)
|
2004-12-07 14:20:37 +00:00
|
|
|
dot=strrchr(global_filename+len-4,'.');
|
2004-01-14 00:13:04 +00:00
|
|
|
else
|
|
|
|
dot=NULL;
|
|
|
|
if (dot)
|
|
|
|
*dot='\0';
|
2004-07-14 10:18:11 +00:00
|
|
|
if ( ms < 3600000 )
|
|
|
|
{
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
|
2005-02-09 11:18:31 +00:00
|
|
|
"%2d, %ld:%02ld, %s,",
|
2004-07-14 10:18:11 +00:00
|
|
|
(bookmark_count+1),
|
|
|
|
ms / 60000,
|
|
|
|
ms % 60000 / 1000,
|
2004-12-07 14:20:37 +00:00
|
|
|
global_filename);
|
2004-07-14 10:18:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
|
2005-02-09 11:18:31 +00:00
|
|
|
"%2d, %ld:%02ld:%02ld, %s,",
|
2004-01-14 00:13:04 +00:00
|
|
|
(bookmark_count+1),
|
|
|
|
ms / 60000,
|
2004-07-14 10:18:11 +00:00
|
|
|
ms % 3600000 / 60000,
|
2004-01-14 00:13:04 +00:00
|
|
|
ms % 60000 / 1000,
|
2004-12-07 14:20:37 +00:00
|
|
|
global_filename);
|
2004-07-14 10:18:11 +00:00
|
|
|
}
|
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2006-07-18 19:11:56 +00:00
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].puts_scroll(0,0,global_temp_buffer);
|
|
|
|
screens[i].puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER));
|
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
if (dot)
|
|
|
|
*dot='.';
|
|
|
|
#endif
|
2006-07-18 19:11:56 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].update();
|
|
|
|
#endif
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 12:29:44 +00:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function parses a bookmark, says the voice UI part of it. */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static void say_bookmark(const char* bookmark,
|
2004-04-12 12:29:44 +00:00
|
|
|
int bookmark_id)
|
|
|
|
{
|
|
|
|
int resume_index;
|
2005-02-09 10:56:54 +00:00
|
|
|
long ms;
|
2004-04-12 12:29:44 +00:00
|
|
|
char dir[MAX_PATH];
|
|
|
|
bool enqueue = false; /* only the first voice is not queued */
|
|
|
|
|
|
|
|
parse_bookmark(bookmark,
|
|
|
|
&resume_index,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
dir, sizeof(dir),
|
|
|
|
&ms, NULL, NULL,
|
2004-12-07 14:20:37 +00:00
|
|
|
NULL);
|
2004-04-12 12:29:44 +00:00
|
|
|
/* disabled, because transition between talkbox and voice UI clip is not nice */
|
|
|
|
#if 0
|
|
|
|
if (global_settings.talk_dir >= 3)
|
|
|
|
{ /* "talkbox" enabled */
|
|
|
|
char* last = strrchr(dir, '/');
|
|
|
|
if (last)
|
|
|
|
{ /* compose filename for talkbox */
|
|
|
|
strncpy(last + 1, dir_thumbnail_name, sizeof(dir)-(last-dir)-1);
|
|
|
|
talk_file(dir, enqueue);
|
|
|
|
enqueue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
talk_id(VOICE_EXT_BMARK, enqueue);
|
|
|
|
talk_number(bookmark_id + 1, true);
|
|
|
|
talk_id(LANG_BOOKMARK_SELECT_INDEX_TEXT, true);
|
|
|
|
talk_number(resume_index + 1, true);
|
|
|
|
talk_id(LANG_BOOKMARK_SELECT_TIME_TEXT, true);
|
|
|
|
if (ms / 60000)
|
|
|
|
talk_value(ms / 60000, UNIT_MIN, true);
|
|
|
|
talk_value((ms % 60000) / 1000, UNIT_SEC, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function retrieves a given bookmark from a file. */
|
|
|
|
/* If the bookmark requested is beyond the number of bookmarks available */
|
|
|
|
/* in the file, it will return the last one. */
|
|
|
|
/* It also returns the index number of the bookmark in the file */
|
|
|
|
/* ------------------------------------------------------------------------*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* get_bookmark(const char* bookmark_file, int bookmark_count)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
int read_count = -1;
|
|
|
|
int result = 0;
|
|
|
|
int file = open(bookmark_file, O_RDONLY);
|
|
|
|
|
|
|
|
if (file < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2004-09-27 19:23:18 +00:00
|
|
|
if (bookmark_count < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
/* Get the requested bookmark */
|
|
|
|
while (read_count < bookmark_count)
|
|
|
|
{
|
|
|
|
/*Reading in a single bookmark */
|
|
|
|
result = read_line(file,
|
|
|
|
global_read_buffer,
|
|
|
|
sizeof(global_read_buffer));
|
|
|
|
|
|
|
|
/* Reading past the last bookmark in the file
|
|
|
|
causes the loop to stop */
|
|
|
|
if (result <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
read_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(file);
|
|
|
|
if (read_count == bookmark_count)
|
|
|
|
return global_read_buffer;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function takes a bookmark and parses it. This function also */
|
|
|
|
/* validates the bookmark. Passing in NULL for an output variable */
|
|
|
|
/* indicates that value is not requested. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool parse_bookmark(const char *bookmark,
|
2004-01-14 00:13:04 +00:00
|
|
|
int *resume_index,
|
|
|
|
int *resume_offset,
|
|
|
|
int *resume_seed,
|
|
|
|
int *resume_first_index,
|
|
|
|
char* resume_file,
|
|
|
|
unsigned int resume_file_size,
|
2005-02-09 10:56:54 +00:00
|
|
|
long* ms,
|
2004-01-14 00:13:04 +00:00
|
|
|
int * repeat_mode, bool *shuffle,
|
2004-12-07 14:20:37 +00:00
|
|
|
char* file_name)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
/* First check to see if a valid line was passed in. */
|
|
|
|
int bookmark_len = strlen(bookmark);
|
|
|
|
int local_resume_index = 0;
|
|
|
|
int local_resume_offset = 0;
|
|
|
|
int local_resume_seed = 0;
|
|
|
|
int local_resume_first_index = 0;
|
|
|
|
int local_mS = 0;
|
|
|
|
int local_shuffle = 0;
|
|
|
|
int local_repeat_mode = 0;
|
|
|
|
char* local_resume_file = NULL;
|
|
|
|
char* local_file_name = NULL;
|
|
|
|
char* field;
|
|
|
|
char* end;
|
|
|
|
static char bookmarkcopy[MAX_BOOKMARK_SIZE];
|
|
|
|
|
|
|
|
/* Don't do anything if the bookmark length is 0 */
|
|
|
|
if (bookmark_len <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Making a dup of the bookmark to use with strtok_r */
|
|
|
|
strncpy(bookmarkcopy, bookmark, sizeof(bookmarkcopy));
|
|
|
|
bookmarkcopy[sizeof(bookmarkcopy) - 1] = 0;
|
|
|
|
|
|
|
|
/* resume_index */
|
|
|
|
if ((field = strtok_r(bookmarkcopy, ";", &end)))
|
|
|
|
local_resume_index = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* resume_offset */
|
|
|
|
if ((field = strtok_r(NULL, ";", &end)))
|
|
|
|
local_resume_offset = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* resume_seed */
|
|
|
|
if ((field = strtok_r(NULL, ";", &end)))
|
|
|
|
local_resume_seed = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* resume_first_index */
|
|
|
|
if ((field = strtok_r(NULL, ";", &end)))
|
|
|
|
local_resume_first_index = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Milliseconds into MP3. Used for the bookmark select menu */
|
|
|
|
if ((field = strtok_r(NULL, ";", &end)))
|
|
|
|
local_mS = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* repeat_mode */
|
|
|
|
if ((field = strtok_r(NULL, ";", &end)))
|
|
|
|
local_repeat_mode = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* shuffle mode */
|
|
|
|
if ((field = strtok_r(NULL, ";", &end)))
|
|
|
|
local_shuffle = atoi(field);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* resume_file & file_name (for the bookmark select menu)*/
|
|
|
|
if (end)
|
|
|
|
{
|
|
|
|
local_resume_file = strtok_r(NULL, ";", &end);
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
local_file_name = strtok_r(NULL, ";", &end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Only return the values the calling function wants */
|
|
|
|
if (resume_index)
|
|
|
|
*resume_index = local_resume_index;
|
|
|
|
|
|
|
|
if (resume_offset)
|
|
|
|
*resume_offset = local_resume_offset;
|
|
|
|
|
|
|
|
if (resume_seed)
|
|
|
|
*resume_seed = local_resume_seed;
|
|
|
|
|
|
|
|
if (resume_first_index)
|
|
|
|
*resume_first_index = local_resume_first_index;
|
|
|
|
|
|
|
|
if (resume_file && local_resume_file)
|
|
|
|
{
|
|
|
|
strncpy(resume_file, local_resume_file,
|
|
|
|
MIN(strlen(local_resume_file), resume_file_size-1));
|
|
|
|
resume_file[MIN(strlen(local_resume_file), resume_file_size-1)]=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ms)
|
|
|
|
*ms = local_mS;
|
|
|
|
|
|
|
|
if (shuffle)
|
|
|
|
*shuffle = local_shuffle;
|
|
|
|
|
|
|
|
if (repeat_mode)
|
|
|
|
*repeat_mode = local_repeat_mode;
|
|
|
|
|
|
|
|
if (file_name && local_file_name)
|
|
|
|
{
|
2004-12-07 14:20:37 +00:00
|
|
|
strncpy(file_name, local_file_name,MAX_PATH-1);
|
|
|
|
file_name[MAX_PATH-1] = 0;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* This function is used by multiple functions and is used to generate a */
|
|
|
|
/* bookmark named based off of the input. */
|
|
|
|
/* Changing this function could result in how the bookmarks are stored. */
|
|
|
|
/* it would be here that the centralized/decentralized bookmark code */
|
|
|
|
/* could be placed. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool generate_bookmark_file_name(const char *in)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2004-06-22 06:23:14 +00:00
|
|
|
int len = strlen(in);
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2004-06-22 06:23:14 +00:00
|
|
|
/* if this is a root dir MP3, rename the bookmark file root_dir.bmark */
|
2004-01-14 00:13:04 +00:00
|
|
|
/* otherwise, name it based on the in variable */
|
2004-06-22 06:23:14 +00:00
|
|
|
if (!strcmp("/", in))
|
|
|
|
strcpy(global_bookmark_file_name, "/root_dir.bmark");
|
2004-01-14 00:13:04 +00:00
|
|
|
else
|
2004-06-22 06:23:14 +00:00
|
|
|
{
|
|
|
|
strcpy(global_bookmark_file_name, in);
|
|
|
|
if(global_bookmark_file_name[len-1] == '/')
|
|
|
|
len--;
|
|
|
|
strcpy(&global_bookmark_file_name[len], ".bmark");
|
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Returns the bookmark name for the current playlist */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
bool bookmark_exist(void)
|
|
|
|
{
|
|
|
|
bool exist=false;
|
|
|
|
|
|
|
|
if(system_check())
|
|
|
|
{
|
|
|
|
char* name = playlist_get_name(NULL, global_temp_buffer,
|
|
|
|
sizeof(global_temp_buffer));
|
|
|
|
if (generate_bookmark_file_name(name))
|
|
|
|
{
|
|
|
|
int fd=open(global_bookmark_file_name, O_RDONLY);
|
|
|
|
if (fd >=0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
exist=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Checks the current state of the system and returns if it is in a */
|
|
|
|
/* bookmarkable state. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Inputs: */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Outputs: */
|
|
|
|
/* return bool: Indicates if the system was in a bookmarkable state */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
static bool system_check(void)
|
|
|
|
{
|
|
|
|
int resume_index = 0;
|
2005-04-04 12:06:29 +00:00
|
|
|
struct mp3entry *id3 = audio_current_track();
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
if (!id3)
|
|
|
|
{
|
|
|
|
/* no track playing */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checking to see if playing a queued track */
|
|
|
|
if (playlist_get_resume_info(&resume_index) == -1)
|
|
|
|
{
|
|
|
|
/* something bad happened while getting the queue information */
|
|
|
|
return false;
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
else if (playlist_modified(NULL))
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
|
|
|
/* can't bookmark while in the queue */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|