adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the Contiki desktop environment |
| 34 | * |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame^] | 35 | * $Id: configedit.c,v 1.4 2003/08/09 23:40:17 adamdunkels Exp $ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 36 | * |
| 37 | */ |
| 38 | |
| 39 | #include "uip_main.h" |
| 40 | #include "uip.h" |
| 41 | #include "uip_arp.h" |
| 42 | #include "resolv.h" |
| 43 | #include "ctk.h" |
| 44 | #include "ctk-draw.h" |
| 45 | #include "dispatcher.h" |
| 46 | |
| 47 | #include "uip-signal.h" |
| 48 | |
| 49 | #include "program-handler.h" |
| 50 | |
| 51 | #include "c64-fs.h" |
| 52 | |
| 53 | #include "loader.h" |
| 54 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 55 | #include <stdio.h> |
| 56 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 57 | /* TCP/IP configuration window. */ |
| 58 | static struct ctk_window window; |
| 59 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 60 | #define LABELMAXWIDTH 12 |
| 61 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 62 | static struct ctk_label themelabel = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 63 | {CTK_LABEL(0, 1, LABELMAXWIDTH, 1, "CTK theme")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 64 | static char theme[25]; |
| 65 | static struct ctk_textentry themetextentry = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 66 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 1, 16, 1, theme, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 67 | |
| 68 | static struct ctk_label driverlabel = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 69 | {CTK_LABEL(0, 3, LABELMAXWIDTH, 1, "Net driver")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 70 | static char driver[25]; |
| 71 | static struct ctk_textentry drivertextentry = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 72 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 3, 16, 1, driver, 24)}; |
| 73 | |
| 74 | static struct ctk_label screensaverlabel = |
| 75 | {CTK_LABEL(0, 5, LABELMAXWIDTH, 1, "Screensaver")}; |
| 76 | static char screensaver[25]; |
| 77 | static struct ctk_textentry screensavertextentry = |
| 78 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 5, 16, 1, screensaver, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 79 | |
| 80 | |
| 81 | static struct ctk_label ipaddrlabel = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 82 | {CTK_LABEL(0, 7, LABELMAXWIDTH, 1, "IP address")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 83 | static char ipaddr[25]; |
| 84 | static struct ctk_textentry ipaddrtextentry = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 85 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 7, 16, 1, ipaddr, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 86 | static struct ctk_label netmasklabel = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 87 | {CTK_LABEL(0, 9, LABELMAXWIDTH, 1, "Netmask")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 88 | static char netmask[25]; |
| 89 | static struct ctk_textentry netmasktextentry = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 90 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 9, 16, 1, netmask, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 91 | static struct ctk_label gatewaylabel = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 92 | {CTK_LABEL(0, 11, LABELMAXWIDTH, 1, "Gateway")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 93 | static char gateway[25]; |
| 94 | static struct ctk_textentry gatewaytextentry = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 95 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 11, 16, 1, gateway, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 96 | static struct ctk_label dnsserverlabel = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 97 | {CTK_LABEL(0, 13, LABELMAXWIDTH, 1, "DNS server")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 98 | static char dnsserver[25]; |
| 99 | static struct ctk_textentry dnsservertextentry = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 100 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 13, 16, 1, dnsserver, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 101 | |
| 102 | static struct ctk_button savebutton = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 103 | {CTK_BUTTON(0, 15, 12, "Save & close")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 104 | |
| 105 | |
| 106 | static struct ctk_button applybutton = |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 107 | {CTK_BUTTON(17, 15, 13, "Apply & close")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 108 | |
| 109 | static DISPATCHER_SIGHANDLER(configedit_sighandler, s, data); |
| 110 | static struct dispatcher_proc p = |
| 111 | {DISPATCHER_PROC("Config editor", NULL, configedit_sighandler, NULL)}; |
| 112 | static ek_id_t id; |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | /*-----------------------------------------------------------------------------------*/ |
| 118 | struct ptentry { |
| 119 | char c; |
| 120 | char * (* pfunc)(char *str); |
| 121 | }; |
| 122 | |
| 123 | /*-----------------------------------------------------------------------------------*/ |
| 124 | static char * |
| 125 | parse(char *str, struct ptentry *t) |
| 126 | { |
| 127 | struct ptentry *p; |
| 128 | |
| 129 | /* Loop over the parse table entries in t in order to find one that |
| 130 | matches the first character in str. */ |
| 131 | for(p = t; p->c != 0; ++p) { |
| 132 | if(*str == p->c) { |
| 133 | /* Skip rest of the characters up to the first space. */ |
| 134 | while(*str != ' ') { |
| 135 | ++str; |
| 136 | } |
| 137 | |
| 138 | /* Skip all spaces.*/ |
| 139 | while(*str == ' ') { |
| 140 | ++str; |
| 141 | } |
| 142 | |
| 143 | /* Call parse table entry function and return. */ |
| 144 | return p->pfunc(str); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* Did not find matching entry in parse table. We just call the |
| 149 | default handler supplied by the caller and return. */ |
| 150 | return p->pfunc(str); |
| 151 | } |
| 152 | /*-----------------------------------------------------------------------------------*/ |
| 153 | static char * |
| 154 | skipnewline(char *str) |
| 155 | { |
| 156 | /* Skip all characters until the newline. */ |
| 157 | while(*str != '\n') { |
| 158 | ++str; |
| 159 | } |
| 160 | |
| 161 | /* Return a pointer to the first character after the newline. */ |
| 162 | return str + 1; |
| 163 | } |
| 164 | /*-----------------------------------------------------------------------------------*/ |
| 165 | static char * |
| 166 | nullterminate(char *str) |
| 167 | { |
| 168 | char *nt; |
| 169 | |
| 170 | /* Nullterminate string. Start with finding newline character. */ |
| 171 | for(nt = str; *nt != '\r' && |
| 172 | *nt != '\n'; ++nt); |
| 173 | |
| 174 | /* Replace newline with a null char. */ |
| 175 | *nt = 0; |
| 176 | |
| 177 | /* Return pointer to null char. */ |
| 178 | return nt; |
| 179 | } |
| 180 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 181 | static char * __fastcall__ |
| 182 | copystr(char *dst, char *src, int len) |
| 183 | { |
| 184 | char *nt = nullterminate(src); |
| 185 | strncpy(dst, src, len); |
| 186 | return nt + 1; |
| 187 | } |
| 188 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 189 | static char * |
| 190 | loaddriver(char *str) |
| 191 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 192 | return copystr(driver, str, sizeof(driver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 193 | } |
| 194 | /*-----------------------------------------------------------------------------------*/ |
| 195 | static char * |
| 196 | loadtheme(char *str) |
| 197 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 198 | return copystr(theme, str, sizeof(theme)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 199 | } |
| 200 | /*-----------------------------------------------------------------------------------*/ |
| 201 | static char * |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame^] | 202 | loadscreensaver(char *str) |
| 203 | { |
| 204 | return copystr(screensaver, str, sizeof(screensaver)); |
| 205 | } |
| 206 | /*-----------------------------------------------------------------------------------*/ |
| 207 | static char * |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 208 | ipaddrconf(char *str) |
| 209 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 210 | return copystr(ipaddr, str, sizeof(ipaddr)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 211 | } |
| 212 | /*-----------------------------------------------------------------------------------*/ |
| 213 | static char * |
| 214 | netmaskconf(char *str) |
| 215 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 216 | return copystr(netmask, str, sizeof(netmask)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 217 | } |
| 218 | /*-----------------------------------------------------------------------------------*/ |
| 219 | static char * |
| 220 | drconf(char *str) |
| 221 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 222 | return copystr(gateway, str, sizeof(gateway)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 223 | } |
| 224 | /*-----------------------------------------------------------------------------------*/ |
| 225 | static char * |
| 226 | dnsconf(char *str) |
| 227 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 228 | return copystr(dnsserver, str, sizeof(dnsserver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 229 | } |
| 230 | /*-----------------------------------------------------------------------------------*/ |
| 231 | static struct ptentry initparsetab[] = |
| 232 | {{'l', loaddriver}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 233 | {'t', loadtheme}, |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame^] | 234 | {'s', loadscreensaver}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 235 | {'i', ipaddrconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 236 | {'n', netmaskconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 237 | {'r', drconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 238 | {'d', dnsconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 239 | {'#', skipnewline}, |
| 240 | |
| 241 | /* Default action */ |
| 242 | {0, skipnewline}}; |
| 243 | static void |
| 244 | initscript(void) |
| 245 | { |
| 246 | char line[40], *lineptr; |
| 247 | struct c64_fs_file f; |
| 248 | |
adamdunkels | e89927e | 2003-08-06 23:14:20 +0000 | [diff] [blame] | 249 | if(c64_fs_open("config.cfg", &f) == -1) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | line[0] = ' '; |
| 253 | while(line[0] != '.' && |
| 254 | line[0] != 0) { |
| 255 | lineptr = line; |
| 256 | do { |
| 257 | if(c64_fs_read(&f, lineptr, 1) != 1) { |
| 258 | c64_fs_close(&f); |
| 259 | return; |
| 260 | } |
| 261 | ++lineptr; |
| 262 | } while(*(lineptr - 1) != '\n' && |
| 263 | *(lineptr - 1) != '\r'); |
| 264 | |
| 265 | *lineptr = 0; |
| 266 | |
| 267 | if(line[0] != '.' && |
| 268 | line[0] != 0) { |
| 269 | parse(line, initparsetab); |
| 270 | } |
| 271 | |
| 272 | } |
| 273 | c64_fs_close(&f); |
| 274 | return; |
| 275 | } |
| 276 | /*-----------------------------------------------------------------------------------*/ |
| 277 | static void |
| 278 | savescript(void) |
| 279 | { |
| 280 | char line[40]; |
| 281 | struct c64_fs_file f; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 282 | |
adamdunkels | e89927e | 2003-08-06 23:14:20 +0000 | [diff] [blame] | 283 | if(c64_fs_open("config.cfg", &f) == -1) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 284 | return; |
| 285 | } |
| 286 | if(theme[0] != 0) { |
| 287 | sprintf(line, "t %s\n", theme); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 288 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 289 | } |
| 290 | if(driver[0] != 0) { |
| 291 | sprintf(line, "l %s\n", driver); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 292 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 293 | } |
| 294 | if(ipaddr[0] != 0) { |
| 295 | sprintf(line, "i %s\n", ipaddr); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 296 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 297 | } |
| 298 | if(netmask[0] != 0) { |
| 299 | sprintf(line, "n %s\n", netmask); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 300 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 301 | } |
| 302 | if(gateway[0] != 0) { |
| 303 | sprintf(line, "r %s\n", gateway); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 304 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 305 | } |
| 306 | if(dnsserver[0] != 0) { |
| 307 | sprintf(line, "d %s\n", dnsserver); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 308 | c64_fs_write(&f, line, strlen(line)); |
| 309 | } |
| 310 | |
| 311 | if(screensaver[0] != 0) { |
| 312 | sprintf(line, "s %s\n", screensaver); |
| 313 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | sprintf(line, ".\n\0\n\n\n"); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 317 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 318 | |
| 319 | c64_fs_close(&f); |
| 320 | |
| 321 | } |
| 322 | /*-----------------------------------------------------------------------------------*/ |
| 323 | LOADER_INIT_FUNC(configedit_init) |
| 324 | { |
| 325 | if(id == EK_ID_NONE) { |
| 326 | id = dispatcher_start(&p); |
| 327 | |
| 328 | /* Create window. */ |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 329 | ctk_window_new(&window, 32, 16, "Config editor"); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 330 | |
| 331 | CTK_WIDGET_ADD(&window, &themelabel); |
| 332 | CTK_WIDGET_ADD(&window, &themetextentry); |
| 333 | |
| 334 | CTK_WIDGET_ADD(&window, &driverlabel); |
| 335 | CTK_WIDGET_ADD(&window, &drivertextentry); |
| 336 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 337 | CTK_WIDGET_ADD(&window, &screensaverlabel); |
| 338 | CTK_WIDGET_ADD(&window, &screensavertextentry); |
| 339 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 340 | CTK_WIDGET_ADD(&window, &ipaddrlabel); |
| 341 | CTK_WIDGET_ADD(&window, &ipaddrtextentry); |
| 342 | CTK_WIDGET_ADD(&window, &netmasklabel); |
| 343 | CTK_WIDGET_ADD(&window, &netmasktextentry); |
| 344 | CTK_WIDGET_ADD(&window, &gatewaylabel); |
| 345 | CTK_WIDGET_ADD(&window, &gatewaytextentry); |
| 346 | CTK_WIDGET_ADD(&window, &dnsserverlabel); |
| 347 | CTK_WIDGET_ADD(&window, &dnsservertextentry); |
| 348 | |
| 349 | CTK_WIDGET_ADD(&window, &savebutton); |
| 350 | CTK_WIDGET_ADD(&window, &applybutton); |
| 351 | |
| 352 | CTK_WIDGET_FOCUS(&window, &themetextentry); |
| 353 | |
| 354 | /* Fill the configuration strings with values from the current |
| 355 | configuration */ |
| 356 | initscript(); |
| 357 | |
| 358 | dispatcher_listen(ctk_signal_button_activate); |
| 359 | dispatcher_listen(ctk_signal_window_close); |
| 360 | } |
| 361 | ctk_window_open(&window); |
| 362 | } |
| 363 | /*-----------------------------------------------------------------------------------*/ |
| 364 | |
| 365 | /*-----------------------------------------------------------------------------------*/ |
| 366 | static void |
| 367 | configedit_quit(void) |
| 368 | { |
| 369 | dispatcher_exit(&p); |
| 370 | id = EK_ID_NONE; |
| 371 | LOADER_UNLOAD(); |
| 372 | } |
| 373 | /*-----------------------------------------------------------------------------------*/ |
| 374 | static |
| 375 | DISPATCHER_SIGHANDLER(configedit_sighandler, s, data) |
| 376 | { |
| 377 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
| 378 | |
| 379 | if(s == ctk_signal_button_activate) { |
| 380 | if(data == (ek_data_t)&savebutton) { |
| 381 | savescript(); |
| 382 | ctk_window_close(&window); |
| 383 | configedit_quit(); |
| 384 | } else if(data == (ek_data_t)&applybutton) { |
| 385 | savescript(); |
| 386 | ctk_window_close(&window); |
| 387 | configedit_quit(); |
| 388 | dispatcher_emit(uip_signal_uninstall, NULL, |
| 389 | DISPATCHER_BROADCAST); |
adamdunkels | e89927e | 2003-08-06 23:14:20 +0000 | [diff] [blame] | 390 | program_handler_load("config.prg"); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 391 | } |
| 392 | } else if(s == ctk_signal_window_close || |
| 393 | s == dispatcher_signal_quit) { |
| 394 | ctk_window_close(&window); |
| 395 | configedit_quit(); |
| 396 | } |
| 397 | } |
| 398 | /*-----------------------------------------------------------------------------------*/ |