Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / prefs / serial / sereditor.c
blobc7db6f3ad94abfc2b4d266f7e5b5c2a59f01be37
1 /*
2 Copyright 2003-2008, The AROS Development Team. All rights reserved.
3 $Id: ipeditor.c 21816 2007-09-25 12:35:29Z chodorowski, dariusb $
4 */
6 // #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/asl.h>
11 #include <libraries/mui.h>
12 #include <prefs/serial.h>
13 #include <prefs/prefhdr.h>
14 /* #define DEBUG 1 */
15 #include <zune/customclasses.h>
16 #include <zune/prefseditor.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/utility.h>
21 #include <proto/muimaster.h>
22 #include <proto/dos.h>
23 #include <proto/iffparse.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include <stdlib.h>
29 #include <aros/debug.h>
31 #include "global.h"
32 #include "locale.h"
33 #include "sereditor.h"
35 /*** String Data ************************************************************/
37 CONST_STRPTR BaudrateLabels[] =
39 (CONST_STRPTR) "50",
40 (CONST_STRPTR) "75",
41 (CONST_STRPTR) "110",
42 (CONST_STRPTR) "134",
43 (CONST_STRPTR) "150",
44 (CONST_STRPTR) "200",
45 (CONST_STRPTR) "300",
46 (CONST_STRPTR) "600",
47 (CONST_STRPTR) "1200",
48 (CONST_STRPTR) "2400",
49 (CONST_STRPTR) "4800",
50 (CONST_STRPTR) "9600",
51 (CONST_STRPTR) "19200",
52 (CONST_STRPTR) "38400",
53 (CONST_STRPTR) "57600",
54 (CONST_STRPTR)"115200",
55 (CONST_STRPTR) NULL
58 CONST_STRPTR StopBitsLabels[] =
60 (CONST_STRPTR) "1",
61 (CONST_STRPTR) "1.5",
62 (CONST_STRPTR) "2",
63 NULL
66 CONST_STRPTR DataBitsLabels[] =
68 (CONST_STRPTR) "8",
69 (CONST_STRPTR) "7",
70 (CONST_STRPTR) "6",
71 (CONST_STRPTR) "5",
72 NULL
75 CONST_STRPTR BufferSizeLabels[] =
77 (CONST_STRPTR) "512",
78 (CONST_STRPTR) "1024",
79 (CONST_STRPTR) "2048",
80 (CONST_STRPTR) "4096",
81 NULL
84 /*** Instance Data **********************************************************/
86 struct SerEditor_DATA
88 int i;
90 CONST_STRPTR ParityLabels[5];
91 Object *child;
92 Object *baudrate;
93 Object *stopbits;
94 Object *databits;
95 Object *parity;
96 Object *inputbuffersize;
97 Object *outputbuffersize;
101 struct SerialPrefs serialprefs;
103 STATIC VOID SerPrefs2Gadgets(struct SerEditor_DATA *data);
104 STATIC VOID Gadgets2SerPrefs(struct SerEditor_DATA *data);
105 VOID ShowMsg(char *msg);
108 /*** Macros *****************************************************************/
109 #define SETUP_INST_DATA struct SerEditor_DATA *data = INST_DATA(CLASS, self)
111 /*** Methods ****************************************************************/
112 Object *SerEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
114 #if SHOWICON
115 Object *icon;
116 #endif
118 D(bug("[seredit class] SerEdit Class New\n"));
121 * we create self first and then create the child,
122 * so we have self->data available already
125 self = (Object *) DoSuperNewTags(
126 CLASS, self, NULL,
127 MUIA_PrefsEditor_Name, MSG(MSG_WINTITLE),
128 MUIA_PrefsEditor_Path, (IPTR) "SYS/Serial.prefs",
129 TAG_DONE
132 if (self == NULL)
134 printf("UPS..TODO\n");
135 return NULL;
138 SETUP_INST_DATA;
140 data->ParityLabels[0] = MSG(MSG_PARITY_NONE);
141 data->ParityLabels[1] = MSG(MSG_PARITY_EVEN);
142 data->ParityLabels[2] = MSG(MSG_PARITY_ODD);
143 data->ParityLabels[3] = MSG(MSG_PARITY_MARK);
144 data->ParityLabels[4] = MSG(MSG_PARITY_SPACE);
145 data->ParityLabels[5] = NULL;
147 #if SHOWPIC
148 icon=MUI_NewObject("Dtpic.mui",MUIA_Dtpic_Name,"PROGDIR:Serial.info",TAG_DONE);
150 if(!icon) icon=HVSpace;
151 #endif
153 data->child=
154 #if SHOWPIC
155 HGroup,
156 Child,
157 icon,
158 Child,
159 #endif
161 VGroup,
162 Child,
163 ColGroup(2),
164 Child, Label1("Baudrate"),
165 Child, data->baudrate = CycleObject,
166 MUIA_Cycle_Entries, BaudrateLabels,
167 End,
168 Child, Label1("Data Bits"),
169 Child, data->databits = CycleObject,
170 MUIA_Cycle_Entries, DataBitsLabels,
171 End,
172 Child, Label1("Parity"),
173 Child, data->parity = CycleObject,
174 MUIA_Cycle_Entries, data->ParityLabels,
175 End,
176 Child, Label1("Stop Bits"),
177 Child, data->stopbits = CycleObject,
178 MUIA_Cycle_Entries, StopBitsLabels,
179 End,
180 Child, Label1("Input Buffer Size"),
181 Child, data->inputbuffersize = CycleObject,
182 MUIA_Cycle_Entries, BufferSizeLabels,
183 End,
184 Child, Label1("Output Buffer Size"),
185 Child, data->outputbuffersize = CycleObject,
186 MUIA_Cycle_Entries, BufferSizeLabels,
187 End,
189 End, /* ColGroup */
190 #if SHOWPIC
191 End,
192 #endif
193 End;
195 DoMethod(self,OM_ADDMEMBER,(ULONG) data->child);
197 DoMethod(data->baudrate, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
198 DoMethod(data->stopbits, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
199 DoMethod(data->databits, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
200 DoMethod(data->parity, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
201 DoMethod(data->inputbuffersize, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
202 DoMethod(data->outputbuffersize, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
204 SerPrefs2Gadgets(data);
206 return self;
210 * update struct serialprefs with actual data selected in gadgets
212 STATIC VOID Gadgets2SerPrefs (struct SerEditor_DATA *data)
214 D(bug("Gadgets2SerPrefs\n"));
216 serialprefs.sp_BaudRate = atol((char *)
217 BaudrateLabels[
218 XGET(data->baudrate,
219 MUIA_Cycle_Active)
222 serialprefs.sp_BitsPerChar = XGET(data->databits, MUIA_Cycle_Active);
224 serialprefs.sp_Parity = XGET(data->parity,MUIA_Cycle_Active);
226 serialprefs.sp_StopBits = XGET(data->stopbits,MUIA_Cycle_Active);
228 serialprefs.sp_InputBuffer = atol((char *)
229 BufferSizeLabels[
230 XGET(data->inputbuffersize,
231 MUIA_Cycle_Active)
233 serialprefs.sp_OutputBuffer = atol((char *)
234 BufferSizeLabels[
235 XGET(data->outputbuffersize,
236 MUIA_Cycle_Active)
239 D(bug("Gadgets2SerPrefs left\n"));
243 * helper for SerPrefs2Gadgets
245 STATIC VOID RefreshGadget(Object *obj, ULONG value, CONST_STRPTR *labels)
247 ULONG i = 0;
249 while (NULL != labels[i]) {
250 if (atol((char *) labels[i]) == value) {
251 set(obj, MUIA_Cycle_Active, i);
252 return;
254 i++;
256 set(obj, MUIA_Cycle_Active, 0);
260 * update gadgets with values of struct serialprefs
262 STATIC VOID SerPrefs2Gadgets(struct SerEditor_DATA *data)
264 RefreshGadget(data->baudrate,
265 serialprefs.sp_BaudRate,
266 BaudrateLabels);
268 set(data->databits, MUIA_Cycle_Active, serialprefs.sp_BitsPerChar);
270 set(data->parity, MUIA_Cycle_Active, serialprefs.sp_Parity);
272 set(data->stopbits, MUIA_Cycle_Active, serialprefs.sp_StopBits);
274 RefreshGadget(data->inputbuffersize,
275 serialprefs.sp_InputBuffer,
276 BufferSizeLabels);
278 RefreshGadget(data->outputbuffersize,
279 serialprefs.sp_OutputBuffer,
280 BufferSizeLabels);
283 IPTR SerEditor__MUIM_PrefsEditor_ImportFH (
284 Class *CLASS, Object *self,
285 struct MUIP_PrefsEditor_ImportFH *message
288 SETUP_INST_DATA;
290 D(bug("[seredit class] SerEdit Class Import\n"));
292 if (!LoadPrefsFH(message->fh)) {
293 D(bug("[seredit class] SerEditor__MUIM_PrefsEditor_ImportFH failed\n"));
294 return FALSE;
297 BackupPrefs();
298 SerPrefs2Gadgets(data);
299 SET(self, MUIA_PrefsEditor_Changed, FALSE);
300 SET(self, MUIA_PrefsEditor_Testing, FALSE);
302 return TRUE;
305 IPTR SerEditor__MUIM_PrefsEditor_ExportFH
307 Class *CLASS, Object *self,
308 struct MUIP_PrefsEditor_ExportFH *message
311 SETUP_INST_DATA;
312 D(bug("[seredit class] SerEdit Class Export\n"));
314 Gadgets2SerPrefs(data);
315 return SavePrefsFH(message->fh);
318 IPTR SerEditor__MUIM_PrefsEditor_Test
320 Class *CLASS, Object *self, Msg message
323 SETUP_INST_DATA;
324 BOOL result;
326 D(bug("[seredit class] SerEdit Class Test\n"));
328 Gadgets2SerPrefs(data);
330 result=SaveEnv();
332 if(result) { /* TRUE -> success */
333 SET(self, MUIA_PrefsEditor_Changed, FALSE);
334 SET(self, MUIA_PrefsEditor_Testing, TRUE);
337 return result;
341 IPTR SerEditor__MUIM_PrefsEditor_Revert
343 Class *CLASS, Object *self, Msg message
346 SETUP_INST_DATA;
347 BOOL result;
349 D(bug("[seredit class] SerEdit Class Revert\n"));
351 RestorePrefs();
352 SerPrefs2Gadgets(data);
354 result=SaveEnv();
356 if(result) {
357 SET(self, MUIA_PrefsEditor_Changed, FALSE);
358 SET(self, MUIA_PrefsEditor_Testing, FALSE);
361 return result;
364 /*** Setup ******************************************************************/
365 ZUNE_CUSTOMCLASS_5
367 SerEditor, NULL, MUIC_PrefsEditor, NULL,
368 OM_NEW, struct opSet *,
369 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
370 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
371 MUIM_PrefsEditor_Test, Msg,
372 MUIM_PrefsEditor_Revert, Msg