text viewer: some modify text viewer's layout and preferences.
[kugel-rb.git] / apps / plugins / text_viewer / tv_preferences.c
bloba90c72d8e97e8d020a17b717c09f0db04c439e33
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"
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)
38 int i;
41 * the following items do not check.
42 * - alignment
43 * - horizontal_scroll_mode
44 * - vertical_scroll_mode
45 * - page_mode
46 * - font
47 * - autoscroll_speed
48 * - narrow_mode
50 if ((oldp == NULL) ||
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 (oldp->statusbar != preferences->statusbar) ||
62 (rb->strcmp(oldp->font_name, preferences->font_name)) ||
63 #endif
64 (rb->strcmp(oldp->file_name, preferences->file_name)))
66 /* callback functions are called as FILO */
67 for (i = listner_count - 1; i >= 0; i--)
68 listners[i](oldp);
72 void tv_set_preferences(const struct tv_preferences *new_prefs)
74 static struct tv_preferences old_prefs;
75 struct tv_preferences *oldp = NULL;
76 static bool is_initialized = false;
78 if (is_initialized)
79 tv_copy_preferences((oldp = &old_prefs));
80 is_initialized = true;
82 rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
83 tv_notify_change_preferences(oldp);
86 void tv_copy_preferences(struct tv_preferences *copy_prefs)
88 rb->memcpy(copy_prefs, preferences, sizeof(struct tv_preferences));
91 void tv_set_default_preferences(struct tv_preferences *p)
93 p->word_mode = WM_WRAP;
94 p->line_mode = LM_NORMAL;
95 p->windows = 1;
96 p->alignment = AL_LEFT;
97 p->horizontal_scroll_mode = HS_SCREEN;
98 p->vertical_scroll_mode = VS_PAGE;
99 p->page_mode = PM_NO_OVERLAP;
100 p->horizontal_scrollbar = SB_OFF;
101 p->vertical_scrollbar = SB_OFF;
102 #ifdef HAVE_LCD_BITMAP
103 p->header_mode = HD_PATH;
104 p->footer_mode = FT_PAGE;
105 p->statusbar = true;
106 rb->strlcpy(p->font_name, rb->global_settings->font_file, MAX_PATH);
107 p->font = rb->font_get(FONT_UI);
108 #else
109 p->header_mode = HD_NONE;
110 p->footer_mode = FT_NONE;
111 p->statusbar = false;
112 #endif
113 p->autoscroll_speed = 1;
114 p->narrow_mode = NM_PAGE;
115 p->indent_spaces = 2;
116 /* Set codepage to system default */
117 p->encoding = rb->global_settings->default_codepage;
118 p->file_name[0] = '\0';
121 void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp))
123 if (listner_count < TV_MAX_LISTNERS)
124 listners[listner_count++] = listner;