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_action.h"
25 #include "tv_bookmark.h"
27 #include "tv_screen_pos.h"
28 #include "tv_settings.h"
29 #include "tv_window.h"
31 bool bookmarks_changed
= false;
32 bool scrolled
= false;
34 bool tv_init_action(unsigned char **buf
, size_t *size
)
36 /* initialize bookmarks and window modules */
37 return tv_init_bookmark(buf
, size
) && tv_init_window(buf
, size
);
40 static void tv_finalize_action(void)
42 /* finalize bookmark modules */
43 tv_finalize_bookmark();
45 /* finalize window modules */
51 /* save preference and bookmarks */
52 DEBUGF("preferences_changed=%d\tbookmarks_changed=%d\tscrolled=%d\n",preferences_changed
,bookmarks_changed
,scrolled
);
53 if ( preferences_changed
|| bookmarks_changed
54 #ifndef HAVE_DISK_STORAGE
59 DEBUGF("Saving settings\n");
60 if (!tv_save_settings())
61 rb
->splash(HZ
, "Can't save preferences and bookmarks");
64 DEBUGF("Skip saving settings\n");
66 /* finalize modules */
70 bool tv_load_file(const unsigned char *file
)
72 /* load the preferences and bookmark */
73 if (!tv_load_settings(file
))
76 /* select to read the page */
84 struct tv_screen_pos pos
;
86 tv_copy_screen_pos(&pos
);
91 tv_move_screen(pos
.page
, pos
.line
, SEEK_SET
);
94 void tv_scroll_up(unsigned mode
)
99 if ((mode
== TV_VERTICAL_SCROLL_PAGE
) ||
100 (mode
== TV_VERTICAL_SCROLL_PREFS
&& preferences
->vertical_scroll_mode
== VS_PAGE
))
103 #ifdef HAVE_LCD_BITMAP
104 offset_line
= (preferences
->overlap_page_mode
)? 1:0;
107 tv_move_screen(offset_page
, offset_line
, SEEK_CUR
);
111 void tv_scroll_down(unsigned mode
)
116 if ((mode
== TV_VERTICAL_SCROLL_PAGE
) ||
117 (mode
== TV_VERTICAL_SCROLL_PREFS
&& preferences
->vertical_scroll_mode
== VS_PAGE
))
120 #ifdef HAVE_LCD_BITMAP
121 offset_line
= (preferences
->overlap_page_mode
)? -1:0;
124 tv_move_screen(offset_page
, offset_line
, SEEK_CUR
);
128 void tv_scroll_left(unsigned mode
)
130 int offset_window
= 0;
131 int offset_column
= 0;
133 if ((mode
== TV_HORIZONTAL_SCROLL_COLUMN
) ||
134 (mode
== TV_HORIZONTAL_SCROLL_PREFS
&& preferences
->horizontal_scroll_mode
== HS_COLUMN
))
136 /* Scroll left one column */
141 /* Scroll left one window */
144 tv_move_window(offset_window
, offset_column
);
148 void tv_scroll_right(unsigned mode
)
150 int offset_window
= 0;
151 int offset_column
= 0;
153 if ((mode
== TV_HORIZONTAL_SCROLL_COLUMN
) ||
154 (mode
== TV_HORIZONTAL_SCROLL_PREFS
&& preferences
->horizontal_scroll_mode
== HS_COLUMN
))
156 /* Scroll right one column */
161 /* Scroll right one window */
164 tv_move_window(offset_window
, offset_column
);
170 tv_move_screen(0, 0, SEEK_SET
);
175 tv_move_screen(0, 0, SEEK_END
);
176 if (preferences
->vertical_scroll_mode
== VS_PAGE
)
177 tv_move_screen(0, -tv_get_screen_pos()->line
, SEEK_CUR
);
180 unsigned tv_menu(void)
183 struct tv_screen_pos cur_pos
;
184 off_t cur_file_pos
= tv_get_screen_pos()->file_pos
;
186 res
= tv_display_menu();
188 if (res
== TV_MENU_RESULT_EXIT_MENU
)
190 tv_convert_fpos(cur_file_pos
, &cur_pos
);
192 tv_move_screen(cur_pos
.page
, cur_pos
.line
, SEEK_SET
);
194 else if (res
== TV_MENU_RESULT_MOVE_PAGE
)
195 res
= TV_MENU_RESULT_EXIT_MENU
;
200 void tv_add_or_remove_bookmark(void)
202 tv_toggle_bookmark();
203 bookmarks_changed
= true;