20 #define __STDCPP_WANT_MATH_SPEC_FUNCS__ 0 33 #define LOCALE_DIR "/system/locale" 34 #define KEYMAP_DIR "/system/keymaps" 36 extern "C" int pedigree_load_keymap(
char *buffer,
size_t len);
38 #define LOCALE_DIR "./build/locale" 39 #define KEYMAP_DIR "./images/base/system/keymaps" 41 int pedigree_load_keymap(
char *buffer,
size_t len)
47 int scan_into_vector(
const char *path, std::vector<std::string> &vec)
49 struct dirent **namelist;
50 int count = scandir(path, &namelist, 0, alphasort);
58 for (
int i = 0; i < count; ++i)
60 if (!strcmp(namelist[i]->d_name,
".") ||
61 !strcmp(namelist[i]->d_name,
".."))
67 vec.push_back(std::string(namelist[i]->d_name));
77 void load_keymap(
const char *path)
79 std::string real_path = std::string(KEYMAP_DIR
"/") + std::string(path);
80 FILE *stream = fopen(real_path.c_str(),
"r");
87 fseek(stream, 0, SEEK_END);
88 size_t len = ftell(stream);
89 fseek(stream, 0, SEEK_SET);
91 char *buffer = (
char *) malloc(len);
92 fread(buffer, len, 1, stream);
95 pedigree_load_keymap(buffer, len);
102 std::vector<std::string> languages;
103 if (scan_into_vector(LOCALE_DIR, languages) < 0)
108 char **languages_menu = (
char **) calloc(languages.size(),
sizeof(
char *));
109 for (
size_t i = 0; i < languages.size(); ++i)
111 languages_menu[i] =
const_cast<char *
>(languages[i].c_str());
116 int current_item = 0;
117 dialog_vars.nocancel = TRUE;
118 dialog_vars.default_item =
const_cast<char *
>(
"en");
119 dialog_vars.no_items = TRUE;
120 dialog_vars.item_help = FALSE;
121 int status = dialog_menu(
122 "Language Selection",
123 "Please select your preferred language from the list below.", 0, 0, 0,
124 languages.size(), languages_menu);
126 free(languages_menu);
129 std::string chosen_language = std::string(dialog_vars.input_result);
132 setenv(
"LC_ALL", chosen_language.c_str(), 1);
139 std::vector<std::string> keymaps;
140 if (scan_into_vector(KEYMAP_DIR, keymaps) < 0)
146 char **keymaps_menu = (
char **) calloc(keymaps.size(),
sizeof(
char *));
147 for (
size_t i = 0; i < keymaps.size(); ++i)
149 keymaps_menu[i] =
const_cast<char *
>(keymaps[i].c_str());
154 dialog_vars.nocancel = TRUE;
155 dialog_vars.ok_label = gettext(
"OK");
156 dialog_vars.no_items = TRUE;
157 dialog_vars.item_help = FALSE;
159 gettext(
"Keyboard Layout Selection"),
160 gettext(
"Please select your preferred keyboard layout from the list " 162 0, 0, 0, keymaps.size(), keymaps_menu);
167 load_keymap(dialog_vars.input_result);
172 dialog_vars.ok_label = gettext(
"OK");
173 dialog_vars.nocancel = 1;
175 gettext(
"Ready to Go"),
176 gettext(
"Configuration is complete.\n\nPedigree is ready for you."), 0,
182 int main(
int argc,
char *argv[])
184 setlocale(LC_ALL,
"");
185 bindtextdomain(
"live", LOCALE_DIR);
186 bind_textdomain_codeset(
"live",
"UTF-8");
189 if (argc < 1 || argc > 2)
194 init_dialog(stdin, stdout);
195 dialog_vars.colors = TRUE;
196 int status = dialog_yesno(
197 "Welcome to Pedigree",
198 "Thanks for trying out Pedigree. This Live CD version supports a few " 199 "languages and keyboard mappings, so we're going to ask some questions " 201 "find your preferences and apply them.\n\nAlternatively, you can just " 202 "accept the default configuration (English language, EN-US keyboard).\n" 203 "\nDo you want to accept the defaults?",
206 if (status != DLG_EXIT_OK)
222 execl(
"/applications/login",
"/applications/login", 0);