2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
3 $Id: fpeditor.c 21816 2004-06-25 12:35:29Z chodorowski $
6 #define MUIMASTER_YES_INLINE_STDARG
8 //#define NO_INLINE_STDARG
10 #include <exec/types.h>
11 #include <utility/tagitem.h>
12 #include <libraries/asl.h>
13 #include <libraries/mui.h>
14 #include <prefs/prefhdr.h>
15 #include <prefs/font.h>
16 #include <zune/customclasses.h>
17 #include <zune/prefseditor.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/utility.h>
22 #include <proto/muimaster.h>
23 #include <proto/dos.h>
24 #include <proto/iffparse.h>
32 #include "AROSTCPPrefs.h"
34 #include <proto/alib.h>
35 #include <utility/hooks.h>
37 static const char *titles
[] = { "IP Config", "Computer Name", NULL
};
38 static const char *DHCPCycle
[] = { "Manual", "Get address from DHCP", NULL
};
39 static struct Hook DHCPHook
;
40 // this can probably be moved back to FPEditor__OM_NEW
41 Object
*interfString
, *IPString
, *maskString
, *gateString
, *DNSString
[2], *hostString
, *domainString
, *DHCPState
;
42 /*** Instance Data **********************************************************/
43 #define FP_COUNT (7) /* Number of entries in fped_FontPrefs array */
45 struct FPEditor_DATA
{
46 struct FontPrefs fped_FontPrefs
[FP_COUNT
];
47 Object
*fped_interfString
,
59 /*** Macros *****************************************************************/
60 //#define FP(i) (&(data->fped_FontPrefs[(i)]))
65 //printf("DEBUG: Jestem w DHCFlip\n");
69 GetAttr(MUIA_Cycle_Active
, DHCPState
, &lng
);
72 set(IPString
, MUIA_Disabled
, TRUE
);
73 set(gateString
, MUIA_Disabled
, TRUE
);
74 set(DNSString
[0], MUIA_Disabled
, TRUE
);
75 set(DNSString
[1], MUIA_Disabled
, TRUE
);
76 set(maskString
, MUIA_Disabled
, TRUE
);
78 set(IPString
, MUIA_Disabled
, FALSE
);
79 set(gateString
, MUIA_Disabled
, FALSE
);
80 set(DNSString
[0], MUIA_Disabled
, FALSE
);
81 set(DNSString
[1], MUIA_Disabled
, FALSE
);
82 set(maskString
, MUIA_Disabled
, FALSE
);
88 // execute s:arostcpd stop
89 // execute s:arostcpd start
92 static ULONG
DHCPNotify(struct Hook
*hook
, Object
*object
, IPTR
*params
)
97 self
= (Object
*)params
[0];
98 CLASS
= (Class
*)params
[1];
100 struct FPEditor_DATA
*data
= INST_DATA(CLASS
, *self
);
102 SET(self
, MUIA_PrefsEditor_Changed
, TRUE
);
109 BOOL
Gadgets2FontPrefs(struct FPEditor_DATA
*data
)
115 GET(data
->fped_interfString
, MUIA_String_Contents
, &str
);
117 GET(data
->fped_IPString
, MUIA_String_Contents
, &str
);
119 GET(data
->fped_maskString
, MUIA_String_Contents
, &str
);
121 GET(data
->fped_gateString
, MUIA_String_Contents
, &str
);
123 GET(data
->fped_DNSString
[0], MUIA_String_Contents
, &str
);
125 GET(data
->fped_DNSString
[1], MUIA_String_Contents
, &str
);
127 GET(data
->fped_hostString
, MUIA_String_Contents
, &str
);
129 GET(data
->fped_domainString
, MUIA_String_Contents
, &str
);
131 GET(data
->fped_DHCPState
, MUIA_Cycle_Active
, &lng
);
137 BOOL FontPrefs2Gadgets
139 struct FPEditor_DATA
*data
144 // FIXME: error checking
145 NNSET(data
->fped_interfString
, MUIA_String_Contents
, (IPTR
)GetInterf());
146 NNSET(data
->fped_IPString
, MUIA_String_Contents
, (IPTR
)GetIP());
147 NNSET(data
->fped_maskString
, MUIA_String_Contents
, (IPTR
)GetMask());
148 NNSET(data
->fped_gateString
, MUIA_String_Contents
, (IPTR
)GetGate());
149 NNSET(data
->fped_DNSString
[0], MUIA_String_Contents
, (IPTR
)GetDNS(0));
150 NNSET(data
->fped_DNSString
[1], MUIA_String_Contents
, (IPTR
)GetDNS(1));
151 NNSET(data
->fped_hostString
, MUIA_String_Contents
, (IPTR
)GetHost());
152 NNSET(data
->fped_domainString
, MUIA_String_Contents
, (IPTR
)GetDomain());
153 NNSET(data
->fped_DHCPState
, MUIA_Cycle_Active
, (IPTR
)GetDHCP());
154 NNSET(data
->fped_Self
,MUIA_PrefsEditor_Changed
,TRUE
);
160 /*** Methods ****************************************************************/
161 Object
*FPEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
163 //Object *interfString, *IPString, *maskString, *gateString, *DNSString[2], *hostString, *domainString, *DHCPState;
165 DHCPHook
.h_Entry
= HookEntry
;
166 DHCPHook
.h_SubEntry
= (HOOKFUNC
)DHCPNotify
;
168 self
= (Object
*)DoSuperNewTags
172 MUIA_PrefsEditor_Name
, "Proba",
173 MUIA_PrefsEditor_Path
, (IPTR
)"AROSTCP/arostcp.prefs",
176 Child
, RegisterGroup(titles
),
178 Child
, (IPTR
)ColGroup(2),
179 Child
, (IPTR
)Label2("Interface"),Child
, (IPTR
)PopaslObject
,
180 MUIA_Popasl_Type
, ASL_FileRequest
,
181 ASLFO_MaxHeight
, 100,
182 MUIA_Popstring_String
, (IPTR
)(interfString
= StringObject
, TextFrame
, MUIA_Background
, MUII_TextBack
, End
),
183 MUIA_Popstring_Button
, (IPTR
)PopButton(MUII_PopUp
),
186 Child
, (IPTR
)Label2("IP Configuration"), Child
, (IPTR
)(DHCPState
= CycleObject
, MUIA_Cycle_Entries
, DHCPCycle
, End
),
187 Child
, (IPTR
)Label2("IP"), Child
, (IPTR
)(IPString
= StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789.", End
),
188 Child
, (IPTR
)Label2("Mask"),Child
, (IPTR
)(maskString
= StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789.", End
),
189 Child
, (IPTR
)Label2("Gate"),Child
, (IPTR
)(gateString
= StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789.", End
),
190 Child
, (IPTR
)Label2("DNS 1"),Child
, (IPTR
)(DNSString
[0] = StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789.", End
),
191 Child
, (IPTR
)Label2("DNS 2"),Child
, (IPTR
)(DNSString
[1] = StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789.", End
),
194 Child
, (IPTR
)ColGroup(2),
195 Child
, (IPTR
)Label2("Name"), Child
, (IPTR
)(hostString
= StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789abcdefghijklmnopqrstuvwxyz-", End
),
196 Child
, (IPTR
)Label2("Domain"), Child
, (IPTR
)(domainString
= StringObject
, TextFrame
, MUIA_String_Accept
, "0123456789abcdefghijklmnopqrstuvwxyz-.", End
),
206 struct FPEditor_DATA
*data
= INST_DATA(CLASS
, self
);
207 data
->fped_interfString
= interfString
;
208 data
->fped_IPString
= IPString
;
209 data
->fped_maskString
= maskString
;
210 data
->fped_gateString
= gateString
;
212 data
->fped_DNSString
[0] = DNSString
[0];
213 data
->fped_DNSString
[1] = DNSString
[1];
214 data
->fped_hostString
= hostString
;
215 data
->fped_domainString
= domainString
;
216 data
->fped_DHCPState
= DHCPState
;
217 data
->fped_Self
= self
;
219 /*-- Setup notifications -------------------------------------------*/
222 interfString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
223 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
227 IPString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
228 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
232 maskString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
233 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
238 gateString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
239 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
243 DNSString
[0], MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
244 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
248 DNSString
[1], MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
249 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
253 hostString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
254 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
258 domainString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
259 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
263 DHCPState
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
264 (IPTR
)self
, 4, MUIM_CallHook
, (IPTR
)&DHCPHook
, (IPTR
)self
, (IPTR
)CLASS
273 IPTR FPEditor__MUIM_PrefsEditor_Save
275 Class
*CLASS
, Object
*self
, Msg message
278 if (DoMethod(self
, MUIM_PrefsEditor_Use
)) return WriteTCPPrefs("ENVARC:AROSTCP/db");
283 IPTR FPEditor__MUIM_PrefsEditor_Use
285 Class
*CLASS
, Object
*self
, Msg message
288 struct FPEditor_DATA
*data
= INST_DATA(CLASS
, self
);
289 Gadgets2FontPrefs(data
);
291 if (WriteTCPPrefs("ENV:AROSTCP/db")) {
293 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
294 SET(self
, MUIA_PrefsEditor_Testing
, FALSE
);
303 IPTR FPEditor__MUIM_PrefsEditor_ImportFH
305 Class
*CLASS
, Object
*self
,
306 struct MUIP_PrefsEditor_ImportFH
*message
309 struct FPEditor_DATA
*data
= INST_DATA(CLASS
, self
);
312 FontPrefs2Gadgets(data
);
317 IPTR FPEditor__MUIM_PrefsEditor_ExportFH
319 Class
*CLASS
, Object
*self
,
320 struct MUIP_PrefsEditor_ExportFH
*message
323 struct FPEditor_DATA
*data
= INST_DATA(CLASS
, self
);
324 struct PrefHeader header
;
325 struct IFFHandle
*handle
;
329 FontPrefs2Gadgets(data
);
336 /*** Setup ******************************************************************/
339 FPEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
340 OM_NEW
, struct opSet
*,
341 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
342 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
343 MUIM_PrefsEditor_Save
, struct MUIP_PrefsEditor_Save
*,
344 MUIM_PrefsEditor_Use
, struct MUIP_PrefsEditor_Use
*