text_viewer: cleanup & bugfix
[kugel-rb.git] / apps / plugins / text_viewer / tv_preferences.c
blobb1045fba7d2c1b384dff9dae3a746bf34ef6f08e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Gilles Roux
11 * 2003 Garrett Derner
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 ****************************************************************************/
23 #include "plugin.h"
24 #include "tv_preferences.h"
26 /* global preferences */
27 static struct tv_preferences prefs;
28 struct tv_preferences *preferences = &prefs;
30 static int listner_count = 0;
32 #define TV_MAX_LISTNERS 4
33 static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
35 static void tv_notify_change_preferences(const struct tv_preferences *oldp)
37 int i;
40 * the following items do not check.
41 * - alignment
42 * - horizontal_scroll_mode
43 * - vertical_scroll_mode
44 * - page_mode
45 * - font
46 * - autoscroll_speed
47 * - narrow_mode
49 if ((oldp == NULL) ||
50 (oldp->word_mode != preferences->word_mode) ||
51 (oldp->line_mode != preferences->line_mode) ||
52 (oldp->windows != preferences->windows) ||
53 (oldp->horizontal_scrollbar != preferences->horizontal_scrollbar) ||
54 (oldp->vertical_scrollbar != preferences->vertical_scrollbar) ||
55 (oldp->encoding != preferences->encoding) ||
56 (oldp->indent_spaces != preferences->indent_spaces) ||
57 #ifdef HAVE_LCD_BITMAP
58 (oldp->header_mode != preferences->header_mode) ||
59 (oldp->footer_mode != preferences->footer_mode) ||
60 (rb->strcmp(oldp->font_name, preferences->font_name)) ||
61 #endif
62 (rb->strcmp(oldp->file_name, preferences->file_name)))
64 for (i = 0; i < listner_count; i++)
65 listners[i](oldp);
69 static void tv_check_header_and_footer(void)
71 if (rb->global_settings->statusbar != STATUSBAR_TOP)
73 if (preferences->header_mode == HD_SBAR)
74 preferences->header_mode = HD_NONE;
75 else if (preferences->header_mode == HD_BOTH)
76 preferences->header_mode = HD_PATH;
78 if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
80 if (preferences->footer_mode == FT_SBAR)
81 preferences->footer_mode = FT_NONE;
82 else if (preferences->footer_mode == FT_BOTH)
83 preferences->footer_mode = FT_PAGE;
87 void tv_set_preferences(const struct tv_preferences *new_prefs)
89 static struct tv_preferences old_prefs;
90 struct tv_preferences *oldp = NULL;
91 static bool is_initialized = false;
93 if (is_initialized)
94 tv_copy_preferences((oldp = &old_prefs));
95 is_initialized = true;
97 rb->memcpy(preferences, new_prefs, sizeof(struct tv_preferences));
98 tv_check_header_and_footer();
99 tv_notify_change_preferences(oldp);
102 void tv_copy_preferences(struct tv_preferences *copy_prefs)
104 rb->memcpy(copy_prefs, preferences, sizeof(struct tv_preferences));
107 void tv_set_default_preferences(struct tv_preferences *p)
109 p->word_mode = WRAP;
110 p->line_mode = NORMAL;
111 p->windows = 1;
112 p->alignment = LEFT;
113 p->horizontal_scroll_mode = SCREEN;
114 p->vertical_scroll_mode = PAGE;
115 p->page_mode = NO_OVERLAP;
116 p->horizontal_scrollbar = SB_OFF;
117 p->vertical_scrollbar = SB_OFF;
118 #ifdef HAVE_LCD_BITMAP
119 p->header_mode = HD_BOTH;
120 p->footer_mode = FT_BOTH;
121 rb->strlcpy(p->font_name, rb->global_settings->font_file, MAX_PATH);
122 p->font = rb->font_get(FONT_UI);
123 #else
124 p->header_mode = HD_NONE;
125 p->footer_mode = FT_NONE;
126 #endif
127 p->autoscroll_speed = 1;
128 p->narrow_mode = NM_PAGE;
129 p->indent_spaces = 2;
130 /* Set codepage to system default */
131 p->encoding = rb->global_settings->default_codepage;
132 p->file_name[0] = '\0';
135 void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp))
137 if (listner_count < TV_MAX_LISTNERS)
138 listners[listner_count++] = listner;