Subversion Repositories freemyipod

Rev

Rev 808 | Rev 828 | Go to most recent revision | Details | Compare with Previous | 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
 
823 theseven 32
int settingchooser_time_to_str(char* buf, int buflen, void* setting, int value)
808 theseven 33
{
823 theseven 34
    if (value < SETTINGS_TIMEOUT_CUTOFF) return snprintf(buf, buflen, "%s", "Never");
35
    return snprintf(buf, buflen, "%dsec", value / 1000000);
36
}
808 theseven 37
 
823 theseven 38
static struct settingchooser_select_options settings_timeout_item_options =
808 theseven 39
{
823 theseven 40
    .optioncount = 4,
41
    .options =
42
    {
43
        SETTINGCHOOSER_SELECT_OPTION("Power off", "Power off", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
44
        SETTINGCHOOSER_SELECT_OPTION("Rockbox", "Rockbox", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
45
        SETTINGCHOOSER_SELECT_OPTION("UMSboot", "UMSboot", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
46
        SETTINGCHOOSER_SELECT_OPTION("Console", "emCORE console", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL)
47
    }
808 theseven 48
};
49
 
823 theseven 50
static struct settingchooser_select_options settings_default_item_options =
808 theseven 51
{
823 theseven 52
    .optioncount = 4,
53
    .options =
54
    {
55
        SETTINGCHOOSER_SELECT_OPTION("Power off", "Power off", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
56
        SETTINGCHOOSER_SELECT_OPTION("Rockbox", "Rockbox", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
57
        SETTINGCHOOSER_SELECT_OPTION("Console", "emCORE console", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
58
        SETTINGCHOOSER_SELECT_OPTION("Tools", "Tools", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL)
59
    }
808 theseven 60
};
61
 
823 theseven 62
static struct settingchooser_select_options settings_fastboot_item_options =
808 theseven 63
{
823 theseven 64
    .optioncount = 4,
65
    .options =
66
    {
67
        SETTINGCHOOSER_SELECT_OPTION("Disabled", "Disabled", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
68
        SETTINGCHOOSER_SELECT_OPTION("Rockbox", "Rockbox", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
69
        SETTINGCHOOSER_SELECT_OPTION("UMSboot", "UMSboot", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL),
70
        SETTINGCHOOSER_SELECT_OPTION("Console", "emCORE console", LIBUI_SURFACE_NULL, LIBUI_SURFACE_NULL)
71
    }
808 theseven 72
};
73
 
823 theseven 74
static struct settingchooser_info settingchooser =
808 theseven 75
{
823 theseven 76
    .version = SETTINGCHOOSER_INFO_VERSION,
77
    .rendererparams = 
78
    {
79
        .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
80
        .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
81
        .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
82
                                  LIBUI_POINT(320, 240)),
83
        .bg_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
84
        .bg_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
85
                                LIBUI_POINT(0, 0)),
86
        .bg_opacity = 0,
87
        .fill_dest = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
808 theseven 88
                                   LIBUI_POINT(0, 0)),
823 theseven 89
        .fill_color = 0,
90
        .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(30, 50)),
91
                                  LIBUI_POINT(260, 160)),
92
        .blit_dest = LIBUI_POINT(0, 0),
93
        .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
94
                                  LIBUI_POINT(320, 240)),
95
        .preblit = update_display,
96
        .postblit = NULL
97
    },
98
    .itemparams =
808 theseven 99
    {
823 theseven 100
        .size = LIBUI_POINT(260, 10),
101
        .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
102
        .fill_color = 0xa0000000,
103
        .fill_color_selected = 0x60ffffff,
104
        .fill_color_active = 0x60003f3f,
105
        .icon_pos = LIBUI_POINT_NULL,
106
        .icon_opacity = 0,
107
        .icon_selected_opacity = 0,
108
        .icon_active_opacity = 0,
109
        .text_pos = LIBUI_POINT(1, 1),
110
        .text_color = 0xffffffff,
111
        .text_color_selected = 0xff7fffff,
112
        .text_color_active = 0xffff7f7f
113
    },
114
    .returntext = "Return to tools menu",
808 theseven 115
    .tickinterval = 10000000,
823 theseven 116
    .itemcount = 5,
808 theseven 117
    .items =
118
    {
119
        {
823 theseven 120
            .text = "Initial timeout",
121
            .icon = LIBUI_SURFACE_NULL,
122
            .icon_selected = LIBUI_SURFACE_NULL,
123
            .type = SETTINGCHOOSER_TYPE_INTEGER,
124
            .setting = &settings.timeout_initial,
125
            .validator = setting_validate,
126
            .config.integer =
127
            {
128
                .min = SETTINGS_TIMEOUT_INITIAL_MIN,
129
                .max = SETTINGS_TIMEOUT_INITIAL_MAX,
130
                .step = SETTINGS_TIMEOUT_INITIAL_STEP,
131
                .tostring = settingchooser_time_to_str
132
            }
808 theseven 133
        },
134
        {
823 theseven 135
            .text = "Idle timeout",
136
            .icon = LIBUI_SURFACE_NULL,
137
            .icon_selected = LIBUI_SURFACE_NULL,
138
            .type = SETTINGCHOOSER_TYPE_INTEGER,
139
            .setting = &settings.timeout_idle,
140
            .validator = setting_validate,
141
            .config.integer =
142
            {
143
                .min = SETTINGS_TIMEOUT_IDLE_MIN,
144
                .max = SETTINGS_TIMEOUT_IDLE_MAX,
145
                .step = SETTINGS_TIMEOUT_IDLE_STEP,
146
                .tostring = settingchooser_time_to_str
147
            }
808 theseven 148
        },
149
        {
823 theseven 150
            .text = "Timeout action",
151
            .icon = LIBUI_SURFACE_NULL,
152
            .icon_selected = LIBUI_SURFACE_NULL,
153
            .type = SETTINGCHOOSER_TYPE_SELECT,
154
            .setting = &settings.timeout_item,
155
            .validator = setting_validate,
156
            .config.select =
157
            {
158
                .options = &settings_timeout_item_options
159
            }
808 theseven 160
        },
161
        {
823 theseven 162
            .text = "Default action",
163
            .icon = LIBUI_SURFACE_NULL,
164
            .icon_selected = LIBUI_SURFACE_NULL,
165
            .type = SETTINGCHOOSER_TYPE_SELECT,
166
            .setting = &settings.default_item,
167
            .validator = setting_validate,
168
            .config.select =
169
            {
170
                .options = &settings_default_item_options
171
            }
808 theseven 172
        },
173
        {
823 theseven 174
            .text = "Fastboot action",
175
            .icon = LIBUI_SURFACE_NULL,
176
            .icon_selected = LIBUI_SURFACE_NULL,
177
            .type = SETTINGCHOOSER_TYPE_SELECT,
178
            .setting = &settings.fastboot_item,
179
            .validator = setting_validate,
180
            .config.select =
181
            {
182
                .options = &settings_fastboot_item_options
183
            }
808 theseven 184
        }
185
    }
186
};
187
 
188
void run_settingchooser(void** firmware, void** app, int* size)
189
{
823 theseven 190
    bool changes = ui->settingchooser_run(&settingchooser);
191
    if (changes)
808 theseven 192
    {
823 theseven 193
        rendertext(framebuf, 106, 140, 320, 0xff33ffff, 0xa0000000, "Saving settings...");
194
        displaylcd(0, 0, 320, 240, framebuf, 0, 0, 320);
195
        settings_validate_all();
196
        settings_save();
197
        settings_apply();
808 theseven 198
    }
199
}
200
 
201
void settingchooser_init()
202
{
823 theseven 203
    settingchooser.rendererparams.copy_dest.buf.addr = framebuf;
204
    settingchooser.rendererparams.copy_src.loc.buf.addr = bg;
205
    settingchooser.rendererparams.viewport.loc.buf.addr = framebuf;
206
    settingchooser.rendererparams.blit_src.loc.buf.addr = framebuf;
808 theseven 207
}