2 Copyright 2003-2008, The AROS Development Team. All rights reserved.
3 $Id: ipeditor.c 21816 2007-09-25 12:35:29Z chodorowski, dariusb $
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>
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>
29 #include <aros/debug.h>
33 #include "sereditor.h"
35 /*** String Data ************************************************************/
37 CONST_STRPTR BaudrateLabels
[] =
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",
58 CONST_STRPTR StopBitsLabels
[] =
66 CONST_STRPTR DataBitsLabels
[] =
75 CONST_STRPTR BufferSizeLabels
[] =
78 (CONST_STRPTR
) "1024",
79 (CONST_STRPTR
) "2048",
80 (CONST_STRPTR
) "4096",
84 /*** Instance Data **********************************************************/
90 CONST_STRPTR ParityLabels
[5];
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
)
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(
127 MUIA_PrefsEditor_Name
, MSG(MSG_WINTITLE
),
128 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/Serial.prefs",
134 printf("UPS..TODO\n");
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
;
148 icon
=MUI_NewObject("Dtpic.mui",MUIA_Dtpic_Name
,"PROGDIR:Serial.info",TAG_DONE
);
150 if(!icon
) icon
=HVSpace
;
164 Child
, Label1("Baudrate"),
165 Child
, data
->baudrate
= CycleObject
,
166 MUIA_Cycle_Entries
, BaudrateLabels
,
168 Child
, Label1("Data Bits"),
169 Child
, data
->databits
= CycleObject
,
170 MUIA_Cycle_Entries
, DataBitsLabels
,
172 Child
, Label1("Parity"),
173 Child
, data
->parity
= CycleObject
,
174 MUIA_Cycle_Entries
, data
->ParityLabels
,
176 Child
, Label1("Stop Bits"),
177 Child
, data
->stopbits
= CycleObject
,
178 MUIA_Cycle_Entries
, StopBitsLabels
,
180 Child
, Label1("Input Buffer Size"),
181 Child
, data
->inputbuffersize
= CycleObject
,
182 MUIA_Cycle_Entries
, BufferSizeLabels
,
184 Child
, Label1("Output Buffer Size"),
185 Child
, data
->outputbuffersize
= CycleObject
,
186 MUIA_Cycle_Entries
, BufferSizeLabels
,
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
);
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 *)
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 *)
230 XGET(data
->inputbuffersize
,
233 serialprefs
.sp_OutputBuffer
= atol((char *)
235 XGET(data
->outputbuffersize
,
239 D(bug("Gadgets2SerPrefs left\n"));
243 * helper for SerPrefs2Gadgets
245 STATIC VOID
RefreshGadget(Object
*obj
, ULONG value
, CONST_STRPTR
*labels
)
249 while (NULL
!= labels
[i
]) {
250 if (atol((char *) labels
[i
]) == value
) {
251 set(obj
, MUIA_Cycle_Active
, 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
,
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
,
278 RefreshGadget(data
->outputbuffersize
,
279 serialprefs
.sp_OutputBuffer
,
283 IPTR
SerEditor__MUIM_PrefsEditor_ImportFH (
284 Class
*CLASS
, Object
*self
,
285 struct MUIP_PrefsEditor_ImportFH
*message
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"));
298 SerPrefs2Gadgets(data
);
299 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
300 SET(self
, MUIA_PrefsEditor_Testing
, FALSE
);
305 IPTR SerEditor__MUIM_PrefsEditor_ExportFH
307 Class
*CLASS
, Object
*self
,
308 struct MUIP_PrefsEditor_ExportFH
*message
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
326 D(bug("[seredit class] SerEdit Class Test\n"));
328 Gadgets2SerPrefs(data
);
332 if(result
) { /* TRUE -> success */
333 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
334 SET(self
, MUIA_PrefsEditor_Testing
, TRUE
);
341 IPTR SerEditor__MUIM_PrefsEditor_Revert
343 Class
*CLASS
, Object
*self
, Msg message
349 D(bug("[seredit class] SerEdit Class Revert\n"));
352 SerPrefs2Gadgets(data
);
357 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
358 SET(self
, MUIA_PrefsEditor_Testing
, FALSE
);
364 /*** Setup ******************************************************************/
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