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 | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame^] | 35 | * $Id: configedit.c,v 1.7 2003/08/24 22:35:22 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 | |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 102 | static struct ctk_button cancelbutton = |
| 103 | {CTK_BUTTON(0, 15, 6, "Cancel")}; |
| 104 | |
| 105 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 106 | static struct ctk_button savebutton = |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 107 | {CTK_BUTTON(18, 15, 12, "Save & 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 | |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 177 | /* Remove trailing spaces. */ |
| 178 | while(nt > str && *(nt - 1) == ' ') { |
| 179 | *(nt - 1) = 0; |
| 180 | --nt; |
| 181 | } |
| 182 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 183 | /* Return pointer to null char. */ |
| 184 | return nt; |
| 185 | } |
| 186 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 187 | static char * __fastcall__ |
| 188 | copystr(char *dst, char *src, int len) |
| 189 | { |
| 190 | char *nt = nullterminate(src); |
| 191 | strncpy(dst, src, len); |
| 192 | return nt + 1; |
| 193 | } |
| 194 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 195 | static char * |
| 196 | loaddriver(char *str) |
| 197 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 198 | return copystr(driver, str, sizeof(driver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 199 | } |
| 200 | /*-----------------------------------------------------------------------------------*/ |
| 201 | static char * |
| 202 | loadtheme(char *str) |
| 203 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 204 | return copystr(theme, str, sizeof(theme)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 205 | } |
| 206 | /*-----------------------------------------------------------------------------------*/ |
| 207 | static char * |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame] | 208 | loadscreensaver(char *str) |
| 209 | { |
| 210 | return copystr(screensaver, str, sizeof(screensaver)); |
| 211 | } |
| 212 | /*-----------------------------------------------------------------------------------*/ |
| 213 | static char * |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 214 | ipaddrconf(char *str) |
| 215 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 216 | return copystr(ipaddr, str, sizeof(ipaddr)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 217 | } |
| 218 | /*-----------------------------------------------------------------------------------*/ |
| 219 | static char * |
| 220 | netmaskconf(char *str) |
| 221 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 222 | return copystr(netmask, str, sizeof(netmask)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 223 | } |
| 224 | /*-----------------------------------------------------------------------------------*/ |
| 225 | static char * |
| 226 | drconf(char *str) |
| 227 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 228 | return copystr(gateway, str, sizeof(gateway)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 229 | } |
| 230 | /*-----------------------------------------------------------------------------------*/ |
| 231 | static char * |
| 232 | dnsconf(char *str) |
| 233 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 234 | return copystr(dnsserver, str, sizeof(dnsserver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 235 | } |
| 236 | /*-----------------------------------------------------------------------------------*/ |
| 237 | static struct ptentry initparsetab[] = |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 238 | {{'n', loaddriver}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 239 | {'t', loadtheme}, |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame] | 240 | {'s', loadscreensaver}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 241 | {'i', ipaddrconf}, |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 242 | {'m', netmaskconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 243 | {'r', drconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 244 | {'d', dnsconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 245 | {'#', skipnewline}, |
| 246 | |
| 247 | /* Default action */ |
| 248 | {0, skipnewline}}; |
| 249 | static void |
| 250 | initscript(void) |
| 251 | { |
| 252 | char line[40], *lineptr; |
| 253 | struct c64_fs_file f; |
| 254 | |
adamdunkels | e89927e | 2003-08-06 23:14:20 +0000 | [diff] [blame] | 255 | if(c64_fs_open("config.cfg", &f) == -1) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 256 | return; |
| 257 | } |
| 258 | line[0] = ' '; |
| 259 | while(line[0] != '.' && |
| 260 | line[0] != 0) { |
| 261 | lineptr = line; |
| 262 | do { |
| 263 | if(c64_fs_read(&f, lineptr, 1) != 1) { |
| 264 | c64_fs_close(&f); |
| 265 | return; |
| 266 | } |
| 267 | ++lineptr; |
| 268 | } while(*(lineptr - 1) != '\n' && |
| 269 | *(lineptr - 1) != '\r'); |
| 270 | |
| 271 | *lineptr = 0; |
| 272 | |
| 273 | if(line[0] != '.' && |
| 274 | line[0] != 0) { |
| 275 | parse(line, initparsetab); |
| 276 | } |
| 277 | |
| 278 | } |
| 279 | c64_fs_close(&f); |
| 280 | return; |
| 281 | } |
| 282 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 283 | static int |
| 284 | makeline(char *line, char c, char *str) |
| 285 | { |
| 286 | int len; |
| 287 | |
| 288 | len = strlen(str); |
| 289 | |
| 290 | line[0] = c; |
| 291 | line[1] = ' '; |
| 292 | strcpy(&line[2], str); |
| 293 | line[2 + len] = '\n'; |
| 294 | line[3 + len] = 0; |
| 295 | return len + 3; |
| 296 | } |
| 297 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 298 | static void |
| 299 | savescript(void) |
| 300 | { |
| 301 | char line[40]; |
| 302 | struct c64_fs_file f; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 303 | |
adamdunkels | e89927e | 2003-08-06 23:14:20 +0000 | [diff] [blame] | 304 | if(c64_fs_open("config.cfg", &f) == -1) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | if(theme[0] != 0) { |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 308 | c64_fs_write(&f, line, makeline(line, 't', theme)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 309 | } |
| 310 | if(driver[0] != 0) { |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 311 | c64_fs_write(&f, line, makeline(line, 'n', driver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 312 | } |
| 313 | if(ipaddr[0] != 0) { |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 314 | c64_fs_write(&f, line, makeline(line, 'i', ipaddr)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 315 | } |
| 316 | if(netmask[0] != 0) { |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 317 | c64_fs_write(&f, line, makeline(line, 'm', netmask)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 318 | } |
| 319 | if(gateway[0] != 0) { |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 320 | c64_fs_write(&f, line, makeline(line, 'r', gateway)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 321 | } |
| 322 | if(dnsserver[0] != 0) { |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 323 | c64_fs_write(&f, line, makeline(line, 'd', dnsserver)); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | if(screensaver[0] != 0) { |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 327 | c64_fs_write(&f, line, makeline(line, 's', screensaver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 328 | } |
| 329 | |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 330 | strcpy(line, ".\n\0\n\n\n"); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 331 | c64_fs_write(&f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 332 | |
| 333 | c64_fs_close(&f); |
| 334 | |
| 335 | } |
| 336 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame^] | 337 | LOADER_INIT_FUNC(configedit_init, arg) |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 338 | { |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame^] | 339 | arg_free(arg); |
| 340 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 341 | if(id == EK_ID_NONE) { |
| 342 | id = dispatcher_start(&p); |
| 343 | |
| 344 | /* Create window. */ |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 345 | ctk_window_new(&window, 32, 16, "Config editor"); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 346 | |
| 347 | CTK_WIDGET_ADD(&window, &themelabel); |
| 348 | CTK_WIDGET_ADD(&window, &themetextentry); |
| 349 | |
| 350 | CTK_WIDGET_ADD(&window, &driverlabel); |
| 351 | CTK_WIDGET_ADD(&window, &drivertextentry); |
| 352 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 353 | CTK_WIDGET_ADD(&window, &screensaverlabel); |
| 354 | CTK_WIDGET_ADD(&window, &screensavertextentry); |
| 355 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 356 | CTK_WIDGET_ADD(&window, &ipaddrlabel); |
| 357 | CTK_WIDGET_ADD(&window, &ipaddrtextentry); |
| 358 | CTK_WIDGET_ADD(&window, &netmasklabel); |
| 359 | CTK_WIDGET_ADD(&window, &netmasktextentry); |
| 360 | CTK_WIDGET_ADD(&window, &gatewaylabel); |
| 361 | CTK_WIDGET_ADD(&window, &gatewaytextentry); |
| 362 | CTK_WIDGET_ADD(&window, &dnsserverlabel); |
| 363 | CTK_WIDGET_ADD(&window, &dnsservertextentry); |
| 364 | |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 365 | CTK_WIDGET_ADD(&window, &cancelbutton); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 366 | CTK_WIDGET_ADD(&window, &savebutton); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 367 | |
| 368 | CTK_WIDGET_FOCUS(&window, &themetextentry); |
| 369 | |
| 370 | /* Fill the configuration strings with values from the current |
| 371 | configuration */ |
| 372 | initscript(); |
| 373 | |
| 374 | dispatcher_listen(ctk_signal_button_activate); |
| 375 | dispatcher_listen(ctk_signal_window_close); |
| 376 | } |
| 377 | ctk_window_open(&window); |
| 378 | } |
| 379 | /*-----------------------------------------------------------------------------------*/ |
| 380 | |
| 381 | /*-----------------------------------------------------------------------------------*/ |
| 382 | static void |
| 383 | configedit_quit(void) |
| 384 | { |
| 385 | dispatcher_exit(&p); |
| 386 | id = EK_ID_NONE; |
| 387 | LOADER_UNLOAD(); |
| 388 | } |
| 389 | /*-----------------------------------------------------------------------------------*/ |
| 390 | static |
| 391 | DISPATCHER_SIGHANDLER(configedit_sighandler, s, data) |
| 392 | { |
| 393 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
| 394 | |
| 395 | if(s == ctk_signal_button_activate) { |
| 396 | if(data == (ek_data_t)&savebutton) { |
| 397 | savescript(); |
| 398 | ctk_window_close(&window); |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 399 | configedit_quit(); |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame^] | 400 | program_handler_load("config.prg", NULL); |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 401 | } else if(data == (ek_data_t)&cancelbutton) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 402 | ctk_window_close(&window); |
| 403 | configedit_quit(); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 404 | } |
| 405 | } else if(s == ctk_signal_window_close || |
| 406 | s == dispatcher_signal_quit) { |
| 407 | ctk_window_close(&window); |
| 408 | configedit_quit(); |
| 409 | } |
| 410 | } |
| 411 | /*-----------------------------------------------------------------------------------*/ |