Subversion Repositories freemyipod

Rev

Rev 823 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
808 theseven 1
//
2
//
3
//    Copyright 2011 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcoreapp.h"
25
#include "libui.h"
26
#include "settingchooser.h"
27
#include "main.h"
28
#include "util.h"
29
#include "settings.h"
30
 
31
 
32
static struct chooser_renderer_list_itemdata settingchooser_rparams_toolchooser =
33
{
34
    .size = LIBUI_POINT(260, 10),
35
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
36
    .fill_color = 0xa0000000,
37
    .fill_color_selected = 0x60ffffff,
38
    .icon_pos = LIBUI_POINT(0, 0),
39
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
40
                          LIBUI_POINT(0, 0)),
41
    .icon_opacity = 0,
42
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
43
                                   LIBUI_POINT(0, 0)),
44
    .icon_selected_opacity = 0,
45
    .text = "Return to tools menu",
46
    .text_pos = LIBUI_POINT(1, 1),
47
    .text_color = 0xffffffff,
48
    .text_color_selected = 0xff7fffff
49
};
50
 
51
static struct chooser_renderer_list_itemdata settingchooser_rparams_timeout_initial =
52
{
53
    .size = LIBUI_POINT(260, 10),
54
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
55
    .fill_color = 0xa0000000,
56
    .fill_color_selected = 0x60ffffff,
57
    .icon_pos = LIBUI_POINT(0, 0),
58
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
59
                          LIBUI_POINT(0, 0)),
60
    .icon_opacity = 0,
61
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
62
                                   LIBUI_POINT(0, 0)),
63
    .icon_selected_opacity = 0,
64
    .text = "Initial timeout",
65
    .text_pos = LIBUI_POINT(1, 1),
66
    .text_color = 0xffffffff,
67
    .text_color_selected = 0xff7fffff
68
};
69
 
70
static struct chooser_renderer_list_itemdata settingchooser_rparams_timeout_idle =
71
{
72
    .size = LIBUI_POINT(260, 10),
73
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
74
    .fill_color = 0xa0000000,
75
    .fill_color_selected = 0x60ffffff,
76
    .icon_pos = LIBUI_POINT(0, 0),
77
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
78
                          LIBUI_POINT(0, 0)),
79
    .icon_opacity = 0,
80
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
81
                                   LIBUI_POINT(0, 0)),
82
    .icon_selected_opacity = 0,
83
    .text = "Idle timeout",
84
    .text_pos = LIBUI_POINT(1, 1),
85
    .text_color = 0xffffffff,
86
    .text_color_selected = 0xff7fffff
87
};
88
 
89
static struct chooser_renderer_list_itemdata settingchooser_rparams_timeout_item =
90
{
91
    .size = LIBUI_POINT(260, 10),
92
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
93
    .fill_color = 0xa0000000,
94
    .fill_color_selected = 0x60ffffff,
95
    .icon_pos = LIBUI_POINT(0, 0),
96
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
97
                          LIBUI_POINT(0, 0)),
98
    .icon_opacity = 0,
99
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
100
                                   LIBUI_POINT(0, 0)),
101
    .icon_selected_opacity = 0,
102
    .text = "Timeout boot option",
103
    .text_pos = LIBUI_POINT(1, 1),
104
    .text_color = 0xffffffff,
105
    .text_color_selected = 0xff7fffff
106
};
107
 
108
static struct chooser_renderer_list_itemdata settingchooser_rparams_default_item =
109
{
110
    .size = LIBUI_POINT(260, 10),
111
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
112
    .fill_color = 0xa0000000,
113
    .fill_color_selected = 0x60ffffff,
114
    .icon_pos = LIBUI_POINT(0, 0),
115
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
116
                          LIBUI_POINT(0, 0)),
117
    .icon_opacity = 0,
118
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
119
                                   LIBUI_POINT(0, 0)),
120
    .icon_selected_opacity = 0,
121
    .text = "Default boot option",
122
    .text_pos = LIBUI_POINT(1, 1),
123
    .text_color = 0xffffffff,
124
    .text_color_selected = 0xff7fffff
125
};
126
 
127
static struct chooser_renderer_list_itemdata settingchooser_rparams_fastboot_item =
128
{
129
    .size = LIBUI_POINT(260, 10),
130
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
131
    .fill_color = 0xa0000000,
132
    .fill_color_selected = 0x60ffffff,
133
    .icon_pos = LIBUI_POINT(0, 0),
134
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
135
                          LIBUI_POINT(0, 0)),
136
    .icon_opacity = 0,
137
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
138
                                   LIBUI_POINT(0, 0)),
139
    .icon_selected_opacity = 0,
140
    .text = "Fastboot boot option",
141
    .text_pos = LIBUI_POINT(1, 1),
142
    .text_color = 0xffffffff,
143
    .text_color_selected = 0xff7fffff
144
};
145
 
146
static struct chooser_renderer_list_params settingchooser_rparams =
147
{
148
    .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
149
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
150
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
151
                              LIBUI_POINT(320, 240)),
152
    .bg_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
153
    .bg_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
154
                            LIBUI_POINT(0, 0)),
155
    .bg_opacity = 0,
156
    .fill_dest = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
157
                               LIBUI_POINT(0, 0)),
158
    .fill_color = 0,
159
    .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(30, 50)),
160
                              LIBUI_POINT(260, 160)),
161
    .blit_dest = LIBUI_POINT(0, 0),
162
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
163
                              LIBUI_POINT(320, 240)),
164
    .preblit = update_display,
165
    .postblit = NULL
166
};
167
 
168
static struct chooser_action_handler_wheel_params settingchooser_aparams =
169
{
170
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
171
    .stepsperitem = 128,
172
    .eventfilter = NULL,
173
    .timeout_initial = TIMEOUT_BLOCK,
174
    .timeout_idle = TIMEOUT_BLOCK,
175
    .timeout_item = 0,
176
    .tick_force_redraw = false,
177
    .buttoncount = 5,
178
    .buttonmap =
179
    {
180
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
181
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NONE,
182
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL,
183
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
184
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
185
    }
186
};
187
 
188
static struct chooser_info settingchooser =
189
{
190
    .version = CHOOSER_INFO_VERSION,
191
    .actionhandler = NULL,
192
    .actionhandlerparams = &settingchooser_aparams,
193
    .renderer = NULL,
194
    .rendererparams = &settingchooser_rparams,
195
    .userparams = NULL,
196
    .tickinterval = 10000000,
197
    .itemcount = 6,
198
    .defaultitem = 0,
199
    .items =
200
    {
201
        {
202
            .user = (void*)0,
203
            .actionparams = NULL,
204
            .renderparams = &settingchooser_rparams_toolchooser
205
        },
206
        {
207
            .user = (void*)1,
208
            .actionparams = NULL,
209
            .renderparams = &settingchooser_rparams_timeout_initial
210
        },
211
        {
212
            .user = (void*)2,
213
            .actionparams = NULL,
214
            .renderparams = &settingchooser_rparams_timeout_idle
215
        },
216
        {
217
            .user = (void*)3,
218
            .actionparams = NULL,
219
            .renderparams = &settingchooser_rparams_timeout_item
220
        },
221
        {
222
            .user = (void*)4,
223
            .actionparams = NULL,
224
            .renderparams = &settingchooser_rparams_default_item
225
        },
226
        {
227
            .user = (void*)5,
228
            .actionparams = NULL,
229
            .renderparams = &settingchooser_rparams_fastboot_item
230
        }
231
    }
232
};
233
 
234
void run_settingchooser(void** firmware, void** app, int* size)
235
{
236
    while (true)
237
    {
238
        const struct chooser_item* result = ui->chooser_run(&settingchooser);
239
        if (!result || !result->user)
240
        {
241
            rendertext(framebuf, 106, 140, 320, 0xff33ffff, 0xa0000000, "Saving settings...");
242
            displaylcd(0, 0, 320, 240, framebuf, 0, 0, 320);
243
            settings_validate_all();
244
            settings_save();
245
            settings_apply();
246
            return;
247
        }
248
        int new;
249
        switch ((int)result->user)
250
        {
251
            case 3:
252
                new = run_bootoptionchooser(settings.timeout_item, "Power off", "Rockbox", "UMSboot", "emCORE console");
253
                if (new != -1) settings.timeout_item = new;
254
                break;
255
 
256
            case 4:
257
                new = run_bootoptionchooser(settings.default_item, "Power off", "Rockbox", "emCORE console", "Tools");
258
                if (new != -1) settings.default_item = new;
259
                break;
260
 
261
            case 5:
262
                new = run_bootoptionchooser(settings.fastboot_item, "Disabled", "Rockbox", "UMSboot", "emCORE console");
263
                if (new != -1) settings.fastboot_item = new;
264
                break;
265
        }
266
    }
267
}
268
 
269
void settingchooser_init()
270
{
271
    settingchooser.actionhandler = ui->chooser_action_handler_wheel;
272
    settingchooser.renderer = ui->chooser_renderer_list;
273
    settingchooser_rparams.copy_dest.buf.addr = framebuf;
274
    settingchooser_rparams.copy_src.loc.buf.addr = bg;
275
    settingchooser_rparams.viewport.loc.buf.addr = framebuf;
276
    settingchooser_rparams.blit_src.loc.buf.addr = framebuf;
277
}