30b5f5ce51d2b4b363c5a69e06151a9d5d736c88
1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Gilles Roux
12 * 2010 Yoshihisa Uchida
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "tv_preferences.h"
27 static struct tv_preferences prefs
;
28 /* read-only preferences pointer, for access by other files */
29 const struct tv_preferences
* const preferences
= &prefs
;
31 static int listner_count
= 0;
33 #define TV_MAX_LISTNERS 4
34 static void (*listners
[TV_MAX_LISTNERS
])(const struct tv_preferences
*oldp
);
36 static void tv_notify_change_preferences(const struct tv_preferences
*oldp
)
41 * the following items do not check.
43 * - horizontal_scroll_mode
44 * - vertical_scroll_mode
51 (oldp
->word_mode
!= preferences
->word_mode
) ||
52 (oldp
->line_mode
!= preferences
->line_mode
) ||
53 (oldp
->windows
!= preferences
->windows
) ||
54 (oldp
->horizontal_scrollbar
!= preferences
->horizontal_scrollbar
) ||
55 (oldp
->vertical_scrollbar
!= preferences
->vertical_scrollbar
) ||
56 (oldp
->encoding
!= preferences
->encoding
) ||
57 (oldp
->indent_spaces
!= preferences
->indent_spaces
) ||
58 #ifdef HAVE_LCD_BITMAP
59 (oldp
->header_mode
!= preferences
->header_mode
) ||
60 (oldp
->footer_mode
!= preferences
->footer_mode
) ||
61 (rb
->strcmp(oldp
->font_name
, preferences
->font_name
)) ||
63 (rb
->strcmp(oldp
->file_name
, preferences
->file_name
)))
65 for (i
= 0; i
< listner_count
; i
++)
70 void tv_set_preferences(const struct tv_preferences
*new_prefs
)
72 static struct tv_preferences old_prefs
;
73 struct tv_preferences
*oldp
= NULL
;
74 static bool is_initialized
= false;
77 tv_copy_preferences((oldp
= &old_prefs
));
78 is_initialized
= true;
80 rb
->memcpy(&prefs
, new_prefs
, sizeof(struct tv_preferences
));
81 tv_notify_change_preferences(oldp
);
84 void tv_copy_preferences(struct tv_preferences
*copy_prefs
)
86 rb
->memcpy(copy_prefs
, preferences
, sizeof(struct tv_preferences
));
89 void tv_set_default_preferences(struct tv_preferences
*p
)
91 p
->word_mode
= WM_WRAP
;
92 p
->line_mode
= LM_NORMAL
;
94 p
->alignment
= AL_LEFT
;
95 p
->horizontal_scroll_mode
= HS_SCREEN
;
96 p
->vertical_scroll_mode
= VS_PAGE
;
97 p
->page_mode
= PM_NO_OVERLAP
;
98 p
->horizontal_scrollbar
= SB_OFF
;
99 p
->vertical_scrollbar
= SB_OFF
;
100 #ifdef HAVE_LCD_BITMAP
101 p
->header_mode
= HD_BOTH
;
102 p
->footer_mode
= FT_BOTH
;
103 rb
->strlcpy(p
->font_name
, rb
->global_settings
->font_file
, MAX_PATH
);
104 p
->font
= rb
->font_get(FONT_UI
);
106 p
->header_mode
= HD_NONE
;
107 p
->footer_mode
= FT_NONE
;
109 p
->autoscroll_speed
= 1;
110 p
->narrow_mode
= NM_PAGE
;
111 p
->indent_spaces
= 2;
112 /* Set codepage to system default */
113 p
->encoding
= rb
->global_settings
->default_codepage
;
114 p
->file_name
[0] = '\0';
117 void tv_add_preferences_change_listner(void (*listner
)(const struct tv_preferences
*oldp
))
119 if (listner_count
< TV_MAX_LISTNERS
)
120 listners
[listner_count
++] = listner
;