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 bool preferences_changed
= false;
33 static int listner_count
= 0;
35 #define TV_MAX_LISTNERS 5
36 static int (*listners
[TV_MAX_LISTNERS
])(const struct tv_preferences
*oldp
);
38 static bool tv_notify_change_preferences(const struct tv_preferences
*oldp
)
41 int res
= TV_CALLBACK_OK
;
44 * the following items do not check.
46 * - horizontal_scroll_mode
47 * - vertical_scroll_mode
54 (oldp
->word_mode
!= preferences
->word_mode
) ||
55 (oldp
->line_mode
!= preferences
->line_mode
) ||
56 (oldp
->windows
!= preferences
->windows
) ||
57 (oldp
->horizontal_scrollbar
!= preferences
->horizontal_scrollbar
) ||
58 (oldp
->vertical_scrollbar
!= preferences
->vertical_scrollbar
) ||
59 (oldp
->encoding
!= preferences
->encoding
) ||
60 (oldp
->indent_spaces
!= preferences
->indent_spaces
) ||
61 #ifdef HAVE_LCD_BITMAP
62 (oldp
->header_mode
!= preferences
->header_mode
) ||
63 (oldp
->footer_mode
!= preferences
->footer_mode
) ||
64 (oldp
->statusbar
!= preferences
->statusbar
) ||
65 (rb
->strcmp(oldp
->font_name
, preferences
->font_name
)) ||
67 (rb
->strcmp(oldp
->file_name
, preferences
->file_name
)))
69 /* callback functions are called as FILO */
70 for (i
= listner_count
- 1; i
>= 0; i
--)
71 if ((res
= listners
[i
](oldp
)) != TV_CALLBACK_OK
)
74 return (res
!= TV_CALLBACK_ERROR
);
77 bool tv_set_preferences(const struct tv_preferences
*new_prefs
)
79 static struct tv_preferences old_prefs
;
80 struct tv_preferences
*oldp
= NULL
;
81 static bool is_initialized
= false;
84 tv_copy_preferences((oldp
= &old_prefs
));
85 is_initialized
= true;
87 rb
->memcpy(&prefs
, new_prefs
, sizeof(struct tv_preferences
));
88 return tv_notify_change_preferences(oldp
);
91 void tv_copy_preferences(struct tv_preferences
*copy_prefs
)
93 rb
->memcpy(copy_prefs
, preferences
, sizeof(struct tv_preferences
));
96 bool tv_compare_preferences(struct tv_preferences
*copy_prefs
)
98 return rb
->memcmp(copy_prefs
, preferences
, sizeof(struct tv_preferences
)) != 0;
101 void tv_set_default_preferences(struct tv_preferences
*p
)
103 p
->word_mode
= WM_WRAP
;
104 p
->line_mode
= LM_NORMAL
;
106 p
->alignment
= AL_LEFT
;
107 p
->horizontal_scroll_mode
= HS_SCREEN
;
108 p
->vertical_scroll_mode
= VS_PAGE
;
109 p
->overlap_page_mode
= false;
110 p
->horizontal_scrollbar
= false;
111 p
->vertical_scrollbar
= false;
112 #ifdef HAVE_LCD_BITMAP
113 p
->header_mode
= true;
114 p
->footer_mode
= true;
116 rb
->strlcpy(p
->font_name
, rb
->global_settings
->font_file
, MAX_PATH
);
117 p
->font
= rb
->font_get(FONT_UI
);
119 p
->header_mode
= false;
120 p
->footer_mode
= false;
121 p
->statusbar
= false;
123 p
->autoscroll_speed
= 1;
124 p
->narrow_mode
= NM_PAGE
;
125 p
->indent_spaces
= 2;
126 /* Set codepage to system default */
127 p
->encoding
= rb
->global_settings
->default_codepage
;
128 p
->file_name
[0] = '\0';
131 void tv_add_preferences_change_listner(int (*listner
)(const struct tv_preferences
*oldp
))
133 if (listner_count
< TV_MAX_LISTNERS
)
134 listners
[listner_count
++] = listner
;