2006-04-03 08:51:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jonathan Gordon
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-04-03 08:51:08 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
2008-11-20 11:27:31 +00:00
|
|
|
#include "lib/playback_control.h"
|
2006-04-03 08:51:08 +00:00
|
|
|
|
2006-05-20 10:16:03 +00:00
|
|
|
#define MAX_LINE_LEN 2048
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-04-03 08:51:08 +00:00
|
|
|
|
2010-07-01 12:08:47 +00:00
|
|
|
static unsigned char *buffer;
|
|
|
|
static size_t buffer_size;
|
|
|
|
static size_t char_count = 0;
|
2006-05-20 10:16:03 +00:00
|
|
|
static int line_count = 0;
|
|
|
|
static int last_action_line = 0;
|
|
|
|
static int last_char_index = 0;
|
2010-07-01 12:08:47 +00:00
|
|
|
static bool audio_buf = false;
|
2006-05-20 10:16:03 +00:00
|
|
|
|
2010-07-12 14:29:40 +00:00
|
|
|
static char temp_line[MAX_LINE_LEN];
|
|
|
|
static char copy_buffer[MAX_LINE_LEN];
|
|
|
|
static char filename[MAX_PATH];
|
|
|
|
static char eol[3];
|
|
|
|
static bool newfile;
|
|
|
|
|
2006-05-20 10:16:03 +00:00
|
|
|
#define ACTION_INSERT 0
|
|
|
|
#define ACTION_GET 1
|
|
|
|
#define ACTION_REMOVE 2
|
|
|
|
#define ACTION_UPDATE 3
|
|
|
|
#define ACTION_CONCAT 4
|
|
|
|
|
2010-07-12 14:29:40 +00:00
|
|
|
static char* _do_action(int action, char* str, int line);
|
2006-05-20 10:16:03 +00:00
|
|
|
#ifndef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
#define do_action _do_action
|
|
|
|
#else
|
2010-07-12 14:29:40 +00:00
|
|
|
static char* do_action(int action, char* str, int line)
|
2006-05-20 10:16:03 +00:00
|
|
|
{
|
2009-12-04 12:53:14 +00:00
|
|
|
char *r;
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->cpu_boost(1);
|
|
|
|
r = _do_action(action,str,line);
|
|
|
|
rb->cpu_boost(0);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-03 08:51:08 +00:00
|
|
|
|
2010-07-12 14:29:40 +00:00
|
|
|
static char* _do_action(int action, char* str, int line)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-03-20 18:59:03 +00:00
|
|
|
int len, lennew;
|
2006-05-20 10:16:03 +00:00
|
|
|
int i=0,c=0;
|
|
|
|
if (line>=last_action_line)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2006-05-20 10:16:03 +00:00
|
|
|
i = last_action_line;
|
|
|
|
c = last_char_index;
|
|
|
|
}
|
|
|
|
while (i<line && i<line_count)
|
|
|
|
{
|
|
|
|
c += rb->strlen(&buffer[c])+1;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_INSERT:
|
|
|
|
len = rb->strlen(str)+1;
|
2010-07-01 12:08:47 +00:00
|
|
|
if ( char_count+ len > buffer_size )
|
2009-12-04 12:53:14 +00:00
|
|
|
return NULL;
|
2009-03-20 18:59:03 +00:00
|
|
|
rb->memmove(&buffer[c+len],&buffer[c],char_count-c);
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->strcpy(&buffer[c],str);
|
|
|
|
char_count += len;
|
|
|
|
line_count++;
|
|
|
|
break;
|
|
|
|
case ACTION_GET:
|
|
|
|
if (line > line_count)
|
2009-12-04 12:53:14 +00:00
|
|
|
return &buffer[0];
|
2006-05-20 10:16:03 +00:00
|
|
|
break;
|
|
|
|
case ACTION_REMOVE:
|
|
|
|
if (line > line_count)
|
2009-12-18 14:17:28 +00:00
|
|
|
return NULL;
|
2006-05-20 10:16:03 +00:00
|
|
|
len = rb->strlen(&buffer[c])+1;
|
2009-03-20 18:59:03 +00:00
|
|
|
rb->memmove(&buffer[c],&buffer[c+len],char_count-c-len);
|
2006-05-20 10:16:03 +00:00
|
|
|
char_count -= len;
|
|
|
|
line_count--;
|
|
|
|
break;
|
|
|
|
case ACTION_UPDATE:
|
|
|
|
if (line > line_count)
|
2009-12-04 12:53:14 +00:00
|
|
|
return NULL;
|
2006-05-20 10:16:03 +00:00
|
|
|
len = rb->strlen(&buffer[c])+1;
|
2009-03-20 18:59:03 +00:00
|
|
|
lennew = rb->strlen(str)+1;
|
2010-07-01 12:08:47 +00:00
|
|
|
if ( char_count+ lennew-len > buffer_size )
|
2009-12-04 12:53:14 +00:00
|
|
|
return NULL;
|
2009-03-20 18:59:03 +00:00
|
|
|
rb->memmove(&buffer[c+lennew],&buffer[c+len],char_count-c-len);
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->strcpy(&buffer[c],str);
|
2009-03-20 18:59:03 +00:00
|
|
|
char_count += lennew-len;
|
2006-05-20 10:16:03 +00:00
|
|
|
break;
|
|
|
|
case ACTION_CONCAT:
|
|
|
|
if (line > line_count)
|
2009-12-04 12:53:14 +00:00
|
|
|
return NULL;
|
2009-03-20 18:59:03 +00:00
|
|
|
rb->memmove(&buffer[c-1],&buffer[c],char_count-c);
|
|
|
|
char_count--;
|
|
|
|
line_count--;
|
2006-05-20 10:16:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-12-04 12:53:14 +00:00
|
|
|
return NULL;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2006-05-20 10:16:03 +00:00
|
|
|
last_action_line = i;
|
|
|
|
last_char_index = c;
|
2009-12-04 12:53:14 +00:00
|
|
|
return &buffer[c];
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2009-08-20 16:47:44 +00:00
|
|
|
static const char* list_get_name_cb(int selected_item, void* data,
|
|
|
|
char* buf, size_t buf_len)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2006-05-20 10:16:03 +00:00
|
|
|
(void)data;
|
2009-12-04 12:53:14 +00:00
|
|
|
char *b = do_action(ACTION_GET, 0, selected_item);
|
2009-08-21 14:56:23 +00:00
|
|
|
/* strlcpy(dst, src, siz) returns strlen(src) */
|
|
|
|
if (rb->strlcpy(buf, b, buf_len) >= buf_len)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-08-21 14:56:23 +00:00
|
|
|
rb->strcpy(&buf[buf_len-10], " ...");
|
2006-05-20 10:16:03 +00:00
|
|
|
}
|
|
|
|
return buf;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2009-06-24 15:18:32 +00:00
|
|
|
|
2010-07-12 14:29:40 +00:00
|
|
|
static void get_eol_string(char* fn)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-08-21 14:56:23 +00:00
|
|
|
int fd;
|
2006-05-20 10:16:03 +00:00
|
|
|
char t;
|
2009-08-21 14:56:23 +00:00
|
|
|
|
|
|
|
/* assume LF first */
|
|
|
|
rb->strcpy(eol,"\n");
|
|
|
|
|
2009-06-24 15:18:32 +00:00
|
|
|
if (!fn || !fn[0])
|
2009-08-21 14:56:23 +00:00
|
|
|
return;
|
2009-01-07 09:53:46 +00:00
|
|
|
fd = rb->open(fn,O_RDONLY);
|
2006-05-20 10:16:03 +00:00
|
|
|
if (fd<0)
|
2009-08-21 14:56:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
while (1)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-08-21 14:56:23 +00:00
|
|
|
if (!rb->read(fd,&t,1) || t == '\n')
|
2006-05-20 10:16:03 +00:00
|
|
|
{
|
2009-08-21 14:56:23 +00:00
|
|
|
break;
|
2006-05-20 10:16:03 +00:00
|
|
|
}
|
|
|
|
if (t == '\r')
|
|
|
|
{
|
|
|
|
if (rb->read(fd,&t,1) && t=='\n')
|
|
|
|
rb->strcpy(eol,"\r\n");
|
2009-06-24 15:18:32 +00:00
|
|
|
else
|
|
|
|
rb->strcpy(eol,"\r");
|
2009-08-21 14:56:23 +00:00
|
|
|
break;
|
2006-05-20 10:16:03 +00:00
|
|
|
}
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->close(fd);
|
2009-08-21 14:56:23 +00:00
|
|
|
return;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 14:29:40 +00:00
|
|
|
static bool save_changes(int overwrite)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int i;
|
|
|
|
|
2009-07-21 14:35:29 +00:00
|
|
|
if (newfile || !overwrite)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-08-12 14:38:25 +00:00
|
|
|
if(rb->kbd_input(filename,MAX_PATH) < 0)
|
2009-07-21 14:35:29 +00:00
|
|
|
{
|
|
|
|
newfile = true;
|
|
|
|
return false;
|
|
|
|
}
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 17:35:13 +00:00
|
|
|
fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
2006-05-20 10:16:03 +00:00
|
|
|
if (fd < 0)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-07-21 14:35:29 +00:00
|
|
|
newfile = true;
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*2, "Changes NOT saved");
|
2009-07-21 14:35:29 +00:00
|
|
|
return false;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
2006-05-20 10:16:03 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(1);
|
|
|
|
#endif
|
2006-04-03 08:51:08 +00:00
|
|
|
for (i=0;i<line_count;i++)
|
|
|
|
{
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->fdprintf(fd,"%s%s", do_action(ACTION_GET, 0, i), eol);
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2006-05-20 10:16:03 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(0);
|
|
|
|
#endif
|
2006-04-03 08:51:08 +00:00
|
|
|
rb->close(fd);
|
2010-07-12 14:29:40 +00:00
|
|
|
|
|
|
|
if (newfile || !overwrite)
|
|
|
|
/* current directory may have changed */
|
|
|
|
rb->reload_directory();
|
|
|
|
|
2009-07-21 14:35:29 +00:00
|
|
|
newfile = false;
|
|
|
|
return true;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 14:29:40 +00:00
|
|
|
static void setup_lists(struct gui_synclist *lists, int sel)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2008-03-26 03:35:24 +00:00
|
|
|
rb->gui_synclist_init(lists,list_get_name_cb,0, false, 1, NULL);
|
2006-04-03 08:51:08 +00:00
|
|
|
rb->gui_synclist_set_icon_callback(lists,NULL);
|
|
|
|
rb->gui_synclist_set_nb_items(lists,line_count);
|
|
|
|
rb->gui_synclist_limit_scroll(lists,true);
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->gui_synclist_select_item(lists, sel);
|
2006-04-03 08:51:08 +00:00
|
|
|
rb->gui_synclist_draw(lists);
|
|
|
|
}
|
2009-08-21 14:56:23 +00:00
|
|
|
|
2006-04-03 08:51:08 +00:00
|
|
|
enum {
|
|
|
|
MENU_RET_SAVE = -1,
|
|
|
|
MENU_RET_NO_UPDATE,
|
|
|
|
MENU_RET_UPDATE,
|
|
|
|
};
|
2010-07-12 14:29:40 +00:00
|
|
|
static int do_item_menu(int cur_sel)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2009-12-18 14:17:28 +00:00
|
|
|
int ret = MENU_RET_NO_UPDATE;
|
2009-08-21 14:56:23 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Line Options", NULL,
|
2007-07-15 06:45:12 +00:00
|
|
|
"Cut/Delete", "Copy",
|
|
|
|
"Insert Above", "Insert Below",
|
2009-08-21 14:56:23 +00:00
|
|
|
"Concat To Above",
|
|
|
|
"Save", "Playback Control");
|
2006-04-03 08:51:08 +00:00
|
|
|
|
2008-03-26 03:35:24 +00:00
|
|
|
switch (rb->do_menu(&menu, NULL, NULL, false))
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
case 0: /* cut */
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->strlcpy(copy_buffer, do_action(ACTION_GET, 0, cur_sel),
|
|
|
|
MAX_LINE_LEN);
|
|
|
|
do_action(ACTION_REMOVE, 0, cur_sel);
|
2006-04-03 08:51:08 +00:00
|
|
|
ret = MENU_RET_UPDATE;
|
|
|
|
break;
|
|
|
|
case 1: /* copy */
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->strlcpy(copy_buffer, do_action(ACTION_GET, 0, cur_sel),
|
|
|
|
MAX_LINE_LEN);
|
2006-04-03 08:51:08 +00:00
|
|
|
ret = MENU_RET_NO_UPDATE;
|
|
|
|
break;
|
2007-07-15 06:45:12 +00:00
|
|
|
case 2: /* insert above */
|
2006-04-03 08:51:08 +00:00
|
|
|
if (!rb->kbd_input(copy_buffer,MAX_LINE_LEN))
|
|
|
|
{
|
2006-05-20 10:16:03 +00:00
|
|
|
do_action(ACTION_INSERT,copy_buffer,cur_sel);
|
2006-04-03 08:51:08 +00:00
|
|
|
copy_buffer[0]='\0';
|
|
|
|
ret = MENU_RET_UPDATE;
|
|
|
|
}
|
|
|
|
break;
|
2007-07-15 06:45:12 +00:00
|
|
|
case 3: /* insert below */
|
2006-04-03 08:51:08 +00:00
|
|
|
if (!rb->kbd_input(copy_buffer,MAX_LINE_LEN))
|
|
|
|
{
|
2006-05-20 10:16:03 +00:00
|
|
|
do_action(ACTION_INSERT,copy_buffer,cur_sel+1);
|
2006-04-03 08:51:08 +00:00
|
|
|
copy_buffer[0]='\0';
|
|
|
|
ret = MENU_RET_UPDATE;
|
|
|
|
}
|
|
|
|
break;
|
2007-07-15 06:45:12 +00:00
|
|
|
case 4: /* cat to above */
|
2006-04-03 08:51:08 +00:00
|
|
|
if (cur_sel>0)
|
|
|
|
{
|
2006-05-20 10:16:03 +00:00
|
|
|
do_action(ACTION_CONCAT,0,cur_sel);
|
2006-04-03 08:51:08 +00:00
|
|
|
ret = MENU_RET_UPDATE;
|
|
|
|
}
|
|
|
|
break;
|
2007-07-15 06:45:12 +00:00
|
|
|
case 5: /* save */
|
2006-04-03 08:51:08 +00:00
|
|
|
ret = MENU_RET_SAVE;
|
|
|
|
break;
|
2008-04-23 10:28:34 +00:00
|
|
|
case 6: /* playback menu */
|
2010-07-01 12:08:47 +00:00
|
|
|
if (!audio_buf)
|
|
|
|
playback_control(NULL);
|
|
|
|
else
|
|
|
|
rb->splash(HZ, "Cannot restart playback");
|
2009-03-20 18:59:03 +00:00
|
|
|
ret = MENU_RET_NO_UPDATE;
|
2008-04-23 10:28:34 +00:00
|
|
|
break;
|
2006-04-03 08:51:08 +00:00
|
|
|
default:
|
|
|
|
ret = MENU_RET_NO_UPDATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-06-18 13:37:57 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
/* in misc.h but no need to polute the api */
|
|
|
|
#define toupper(c) (((c >= 'a') && (c <= 'z'))?c+'A':c)
|
|
|
|
#define isxdigit(c) ((c>='a' && c<= 'f') || (c>='A' && c<= 'F') \
|
|
|
|
|| (c>='0' && c<= '9'))
|
|
|
|
#define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \
|
|
|
|
(toupper(c)) - 'A' + 10)
|
2010-07-12 14:29:40 +00:00
|
|
|
static int my_hex_to_rgb(const char* hex, int* color)
|
2007-06-18 13:37:57 +00:00
|
|
|
{ int ok = 1;
|
|
|
|
int i;
|
|
|
|
int red, green, blue;
|
|
|
|
|
|
|
|
if (rb->strlen(hex) == 6) {
|
|
|
|
for (i=0; i < 6; i++ ) {
|
|
|
|
if (!isxdigit(hex[i])) {
|
|
|
|
ok=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]);
|
|
|
|
green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]);
|
|
|
|
blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]);
|
2008-03-21 13:41:35 +00:00
|
|
|
*color = LCD_RGBPACK(red,green,blue);
|
|
|
|
return 0;
|
2007-06-18 13:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-21 13:41:35 +00:00
|
|
|
return -1;
|
2007-06-18 13:37:57 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_LCD_COLOR */
|
|
|
|
|
2006-04-03 08:51:08 +00:00
|
|
|
/* this is the plugin entry point */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
struct gui_synclist lists;
|
|
|
|
bool exit = false;
|
2006-09-01 02:58:44 +00:00
|
|
|
int button;
|
2006-04-03 08:51:08 +00:00
|
|
|
bool changed = false;
|
2006-05-20 10:16:03 +00:00
|
|
|
int cur_sel=0;
|
2007-06-18 13:37:57 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-06-18 13:57:05 +00:00
|
|
|
bool edit_colors_file = false;
|
2007-06-18 13:37:57 +00:00
|
|
|
#endif
|
2006-04-03 08:51:08 +00:00
|
|
|
|
2006-05-20 10:16:03 +00:00
|
|
|
copy_buffer[0]='\0';
|
|
|
|
|
2007-09-23 19:15:56 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
2010-07-01 12:08:47 +00:00
|
|
|
buffer = rb->plugin_get_buffer(&buffer_size);
|
2007-09-23 19:15:56 +00:00
|
|
|
|
2006-05-20 10:16:03 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(1);
|
|
|
|
#endif
|
2006-04-03 08:51:08 +00:00
|
|
|
if (parameter)
|
|
|
|
{
|
2007-06-18 13:37:57 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
char *c = NULL;
|
|
|
|
#endif
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->strlcpy(filename, (char*)parameter, MAX_PATH);
|
2009-08-21 14:56:23 +00:00
|
|
|
get_eol_string(filename);
|
2006-04-03 08:51:08 +00:00
|
|
|
fd = rb->open(filename,O_RDONLY);
|
|
|
|
if (fd<0)
|
|
|
|
{
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->splashf(HZ*2, "Couldnt open file: %s", filename);
|
2006-04-03 08:51:08 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
2007-06-18 13:37:57 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-06-18 13:57:05 +00:00
|
|
|
c = rb->strrchr(filename, '.');
|
2007-06-19 04:21:06 +00:00
|
|
|
if (c && !rb->strcmp(c, ".colours"))
|
2007-06-18 13:57:05 +00:00
|
|
|
edit_colors_file = true;
|
2007-06-18 13:37:57 +00:00
|
|
|
#endif
|
2010-07-01 12:08:47 +00:00
|
|
|
if (buffer_size <= (size_t)rb->filesize(fd) + 0x400)
|
|
|
|
{
|
|
|
|
buffer = rb->plugin_get_audio_buffer(&buffer_size);
|
|
|
|
audio_buf = true;
|
|
|
|
}
|
2006-04-03 08:51:08 +00:00
|
|
|
/* read in the file */
|
2009-08-21 14:56:23 +00:00
|
|
|
while (rb->read_line(fd,temp_line,MAX_LINE_LEN) > 0)
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2006-05-20 10:16:03 +00:00
|
|
|
if (!do_action(ACTION_INSERT,temp_line,line_count))
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ*2,"Error reading file: %s",(char*)parameter);
|
2006-04-03 08:51:08 +00:00
|
|
|
rb->close(fd);
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->close(fd);
|
2009-07-21 14:35:29 +00:00
|
|
|
newfile = false;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2006-05-20 10:16:03 +00:00
|
|
|
else
|
|
|
|
{
|
2009-07-21 14:35:29 +00:00
|
|
|
rb->strcpy(filename,"/");
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->strcpy(eol,"\n");
|
2009-07-21 14:35:29 +00:00
|
|
|
newfile = true;
|
2006-05-20 10:16:03 +00:00
|
|
|
}
|
2009-08-21 14:56:23 +00:00
|
|
|
|
2006-05-20 10:16:03 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(0);
|
|
|
|
#endif
|
2006-04-03 08:51:08 +00:00
|
|
|
/* now dump it in the list */
|
2006-05-20 10:16:03 +00:00
|
|
|
setup_lists(&lists,0);
|
|
|
|
rb->lcd_update();
|
2006-04-03 08:51:08 +00:00
|
|
|
while (!exit)
|
|
|
|
{
|
|
|
|
rb->gui_synclist_draw(&lists);
|
|
|
|
cur_sel = rb->gui_synclist_get_sel_pos(&lists);
|
2006-09-01 02:58:44 +00:00
|
|
|
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
|
2007-09-17 10:08:50 +00:00
|
|
|
if (rb->gui_synclist_do_button(&lists,&button,LIST_WRAP_UNLESS_HELD))
|
2006-04-03 08:51:08 +00:00
|
|
|
continue;
|
|
|
|
switch (button)
|
|
|
|
{
|
2006-09-01 02:58:44 +00:00
|
|
|
case ACTION_STD_OK:
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
if (line_count)
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->strlcpy(temp_line, do_action(ACTION_GET, 0, cur_sel),
|
|
|
|
MAX_LINE_LEN);
|
2007-06-18 13:37:57 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-03-20 18:59:03 +00:00
|
|
|
if (edit_colors_file && line_count)
|
2007-06-18 13:37:57 +00:00
|
|
|
{
|
|
|
|
char *name = temp_line, *value = NULL;
|
2010-10-01 14:40:28 +00:00
|
|
|
char extension[16];
|
2009-03-20 18:59:03 +00:00
|
|
|
int color, old_color;
|
2009-12-04 12:53:14 +00:00
|
|
|
bool temp_changed = false;
|
2010-10-01 14:40:28 +00:00
|
|
|
|
|
|
|
MENUITEM_STRINGLIST(menu, "Edit What?", NULL,
|
|
|
|
"Extension", "Colour");
|
|
|
|
|
2007-06-18 13:37:57 +00:00
|
|
|
rb->settings_parseline(temp_line, &name, &value);
|
2010-10-01 14:40:28 +00:00
|
|
|
rb->strlcpy(extension, name, sizeof(extension));
|
|
|
|
if (value)
|
|
|
|
my_hex_to_rgb(value, &color);
|
|
|
|
else
|
|
|
|
color = 0;
|
|
|
|
|
|
|
|
switch (rb->do_menu(&menu, NULL, NULL, false))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
temp_changed = !rb->kbd_input(extension, sizeof(extension));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
old_color = color;
|
|
|
|
rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1);
|
|
|
|
temp_changed = (value == NULL) || (color != old_color);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (temp_changed)
|
2007-06-18 13:37:57 +00:00
|
|
|
{
|
2010-10-01 14:40:28 +00:00
|
|
|
rb->snprintf(temp_line, MAX_LINE_LEN, "%s: %02X%02X%02X",
|
|
|
|
extension, RGB_UNPACK_RED(color),
|
|
|
|
RGB_UNPACK_GREEN(color),
|
|
|
|
RGB_UNPACK_BLUE(color));
|
|
|
|
do_action(ACTION_UPDATE, temp_line, cur_sel);
|
|
|
|
changed = true;
|
2007-06-18 13:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-20 18:59:03 +00:00
|
|
|
else
|
2007-06-18 13:37:57 +00:00
|
|
|
#endif
|
2009-03-20 18:59:03 +00:00
|
|
|
if (!rb->kbd_input(temp_line,MAX_LINE_LEN))
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
if (line_count)
|
2006-05-20 10:16:03 +00:00
|
|
|
do_action(ACTION_UPDATE,temp_line,cur_sel);
|
2009-03-20 18:59:03 +00:00
|
|
|
else
|
|
|
|
do_action(ACTION_INSERT,temp_line,cur_sel);
|
2006-04-03 08:51:08 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-08-02 11:07:06 +00:00
|
|
|
case ACTION_STD_CONTEXT:
|
2006-04-03 08:51:08 +00:00
|
|
|
if (!line_count) break;
|
2009-12-04 12:53:14 +00:00
|
|
|
rb->strlcpy(copy_buffer, do_action(ACTION_GET, 0, cur_sel),
|
|
|
|
MAX_LINE_LEN);
|
|
|
|
do_action(ACTION_REMOVE, 0, cur_sel);
|
2006-04-03 08:51:08 +00:00
|
|
|
changed = true;
|
|
|
|
break;
|
2006-09-01 02:58:44 +00:00
|
|
|
case ACTION_STD_MENU:
|
2010-07-12 14:29:40 +00:00
|
|
|
{
|
|
|
|
/* do the item menu */
|
|
|
|
switch (do_item_menu(cur_sel))
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
case MENU_RET_SAVE:
|
2009-07-21 14:35:29 +00:00
|
|
|
if(save_changes(1))
|
|
|
|
changed = false;
|
2006-04-03 08:51:08 +00:00
|
|
|
break;
|
|
|
|
case MENU_RET_UPDATE:
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
case MENU_RET_NO_UPDATE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-09-01 02:58:44 +00:00
|
|
|
case ACTION_STD_CANCEL:
|
2006-04-03 08:51:08 +00:00
|
|
|
if (changed)
|
|
|
|
{
|
2009-08-21 14:56:23 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Do What?", NULL,
|
2007-07-26 08:04:28 +00:00
|
|
|
"Return",
|
2009-08-21 14:56:23 +00:00
|
|
|
"Playback Control", "Save Changes",
|
2007-07-15 06:45:12 +00:00
|
|
|
"Save As...", "Save and Exit",
|
|
|
|
"Ignore Changes and Exit");
|
2008-03-26 03:35:24 +00:00
|
|
|
switch (rb->do_menu(&menu, NULL, NULL, false))
|
2006-04-03 08:51:08 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
2007-07-26 08:04:28 +00:00
|
|
|
case 1:
|
2010-07-01 12:08:47 +00:00
|
|
|
if (!audio_buf)
|
|
|
|
playback_control(NULL);
|
|
|
|
else
|
|
|
|
rb->splash(HZ, "Cannot restart playback");
|
2007-07-26 08:04:28 +00:00
|
|
|
break;
|
|
|
|
case 2: //save to disk
|
2009-07-21 14:35:29 +00:00
|
|
|
if(save_changes(1))
|
|
|
|
changed = 0;
|
2006-04-03 08:51:08 +00:00
|
|
|
break;
|
2007-07-26 08:04:28 +00:00
|
|
|
case 3:
|
2009-07-21 14:35:29 +00:00
|
|
|
if(save_changes(0))
|
|
|
|
changed = 0;
|
2006-04-03 08:51:08 +00:00
|
|
|
break;
|
2007-07-26 08:04:28 +00:00
|
|
|
case 4:
|
2009-07-21 14:35:29 +00:00
|
|
|
if(save_changes(1))
|
|
|
|
exit=1;
|
2006-04-03 08:51:08 +00:00
|
|
|
break;
|
2007-07-26 08:04:28 +00:00
|
|
|
case 5:
|
2006-04-03 08:51:08 +00:00
|
|
|
exit=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else exit=1;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-20 10:16:03 +00:00
|
|
|
rb->gui_synclist_set_nb_items(&lists,line_count);
|
2009-07-21 14:35:29 +00:00
|
|
|
if(line_count > 0 && line_count <= cur_sel)
|
|
|
|
rb->gui_synclist_select_item(&lists,line_count-1);
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|