2010-06-05 10:30:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Gilles Roux
|
|
|
|
* 2003 Garrett Derner
|
|
|
|
* 2010 Yoshihisa Uchida
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "tv_preferences.h"
|
|
|
|
|
2010-06-23 13:56:08 +00:00
|
|
|
|
2010-06-05 10:30:08 +00:00
|
|
|
static struct tv_preferences prefs;
|
2010-06-23 13:56:08 +00:00
|
|
|
/* read-only preferences pointer, for access by other files */
|
|
|
|
const struct tv_preferences * const preferences = &prefs;
|
2010-06-20 21:53:47 +00:00
|
|
|
|
2010-06-05 10:30:08 +00:00
|
|
|
static int listner_count = 0;
|
|
|
|
|
2010-06-27 11:36:37 +00:00
|
|
|
#define TV_MAX_LISTNERS 5
|
2010-06-29 11:05:36 +00:00
|
|
|
static int (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
|
2010-06-05 10:30:08 +00:00
|
|
|
|
2010-06-29 11:05:36 +00:00
|
|
|
static bool tv_notify_change_preferences(const struct tv_preferences *oldp)
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
2010-06-29 11:05:36 +00:00
|
|
|
int res = TV_CALLBACK_OK;
|
2010-06-05 10:30:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the following items do not check.
|
|
|
|
* - alignment
|
2010-06-07 11:04:09 +00:00
|
|
|
* - horizontal_scroll_mode
|
|
|
|
* - vertical_scroll_mode
|
2010-06-29 12:23:41 +00:00
|
|
|
* - overlap_page_mode
|
2010-06-05 10:30:08 +00:00
|
|
|
* - font
|
|
|
|
* - autoscroll_speed
|
2010-06-09 11:28:43 +00:00
|
|
|
* - narrow_mode
|
2010-06-05 10:30:08 +00:00
|
|
|
*/
|
2010-06-20 21:53:47 +00:00
|
|
|
if ((oldp == NULL) ||
|
|
|
|
(oldp->word_mode != preferences->word_mode) ||
|
|
|
|
(oldp->line_mode != preferences->line_mode) ||
|
|
|
|
(oldp->windows != preferences->windows) ||
|
|
|
|
(oldp->horizontal_scrollbar != preferences->horizontal_scrollbar) ||
|
|
|
|
(oldp->vertical_scrollbar != preferences->vertical_scrollbar) ||
|
|
|
|
(oldp->encoding != preferences->encoding) ||
|
|
|
|
(oldp->indent_spaces != preferences->indent_spaces) ||
|
2010-06-05 10:30:08 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-20 21:53:47 +00:00
|
|
|
(oldp->header_mode != preferences->header_mode) ||
|
|
|
|
(oldp->footer_mode != preferences->footer_mode) ||
|
2010-06-26 12:17:01 +00:00
|
|
|
(oldp->statusbar != preferences->statusbar) ||
|
2010-06-20 21:53:47 +00:00
|
|
|
(rb->strcmp(oldp->font_name, preferences->font_name)) ||
|
2010-06-05 10:30:08 +00:00
|
|
|
#endif
|
2010-06-20 21:53:47 +00:00
|
|
|
(rb->strcmp(oldp->file_name, preferences->file_name)))
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
2010-06-26 09:14:53 +00:00
|
|
|
/* callback functions are called as FILO */
|
|
|
|
for (i = listner_count - 1; i >= 0; i--)
|
2010-06-29 11:05:36 +00:00
|
|
|
if ((res = listners[i](oldp)) != TV_CALLBACK_OK)
|
|
|
|
break;
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
2010-06-29 11:05:36 +00:00
|
|
|
return (res != TV_CALLBACK_ERROR);
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-29 11:05:36 +00:00
|
|
|
bool tv_set_preferences(const struct tv_preferences *new_prefs)
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
2010-06-20 21:53:47 +00:00
|
|
|
static struct tv_preferences old_prefs;
|
2010-06-05 10:30:08 +00:00
|
|
|
struct tv_preferences *oldp = NULL;
|
2010-06-20 21:53:47 +00:00
|
|
|
static bool is_initialized = false;
|
2010-06-05 10:30:08 +00:00
|
|
|
|
2010-06-20 21:53:47 +00:00
|
|
|
if (is_initialized)
|
|
|
|
tv_copy_preferences((oldp = &old_prefs));
|
|
|
|
is_initialized = true;
|
|
|
|
|
2010-06-23 13:56:08 +00:00
|
|
|
rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
|
2010-06-29 11:05:36 +00:00
|
|
|
return tv_notify_change_preferences(oldp);
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tv_copy_preferences(struct tv_preferences *copy_prefs)
|
|
|
|
{
|
2010-06-20 21:53:47 +00:00
|
|
|
rb->memcpy(copy_prefs, preferences, sizeof(struct tv_preferences));
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tv_set_default_preferences(struct tv_preferences *p)
|
|
|
|
{
|
2010-06-24 12:58:46 +00:00
|
|
|
p->word_mode = WM_WRAP;
|
|
|
|
p->line_mode = LM_NORMAL;
|
2010-06-06 08:44:27 +00:00
|
|
|
p->windows = 1;
|
2010-06-24 12:58:46 +00:00
|
|
|
p->alignment = AL_LEFT;
|
|
|
|
p->horizontal_scroll_mode = HS_SCREEN;
|
|
|
|
p->vertical_scroll_mode = VS_PAGE;
|
2010-06-29 12:23:41 +00:00
|
|
|
p->overlap_page_mode = false;
|
|
|
|
p->horizontal_scrollbar = false;
|
|
|
|
p->vertical_scrollbar = false;
|
2010-06-05 10:30:08 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-29 12:23:41 +00:00
|
|
|
p->header_mode = true;
|
|
|
|
p->footer_mode = true;
|
2010-06-26 12:17:01 +00:00
|
|
|
p->statusbar = true;
|
2010-06-05 10:30:08 +00:00
|
|
|
rb->strlcpy(p->font_name, rb->global_settings->font_file, MAX_PATH);
|
|
|
|
p->font = rb->font_get(FONT_UI);
|
|
|
|
#else
|
2010-06-29 12:23:41 +00:00
|
|
|
p->header_mode = false;
|
|
|
|
p->footer_mode = false;
|
2010-06-26 12:17:01 +00:00
|
|
|
p->statusbar = false;
|
2010-06-05 10:30:08 +00:00
|
|
|
#endif
|
|
|
|
p->autoscroll_speed = 1;
|
2010-06-09 11:28:43 +00:00
|
|
|
p->narrow_mode = NM_PAGE;
|
2010-06-11 11:13:02 +00:00
|
|
|
p->indent_spaces = 2;
|
2010-06-05 10:30:08 +00:00
|
|
|
/* Set codepage to system default */
|
|
|
|
p->encoding = rb->global_settings->default_codepage;
|
|
|
|
p->file_name[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2010-06-29 11:05:36 +00:00
|
|
|
void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp))
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
|
|
|
if (listner_count < TV_MAX_LISTNERS)
|
|
|
|
listners[listner_count++] = listner;
|
|
|
|
}
|