Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / prefs / TCPPrefs / fpeditor.c
blob542bd563024697e09eeb53535feb2272fb7b41fe
1 /*
2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
3 $Id: fpeditor.c 21816 2004-06-25 12:35:29Z chodorowski $
4 */
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>
26 #include <string.h>
27 #include <stdio.h>
29 #include "misc.h"
30 #include "locale.h"
31 #include "fpeditor.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,
48 *fped_IPString,
49 *fped_maskString,
50 *fped_gateString,
51 *fped_DNSString[2],
52 *fped_hostString,
53 *fped_domainString,
54 *fped_DHCPState,
55 *fped_Self;
59 /*** Macros *****************************************************************/
60 //#define FP(i) (&(data->fped_FontPrefs[(i)]))
63 void FlipDHCP()
65 //printf("DEBUG: Jestem w DHCFlip\n");
67 LONG lng = 0;
69 GetAttr(MUIA_Cycle_Active, DHCPState, &lng);
71 if (lng==1) {
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);
77 } else {
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);
86 void BumpTCP()
88 // execute s:arostcpd stop
89 // execute s:arostcpd start
92 static ULONG DHCPNotify(struct Hook *hook, Object *object, IPTR *params)
94 Object *self;
95 Class *CLASS;
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);
104 FlipDHCP();
106 return 1;
109 BOOL Gadgets2FontPrefs(struct FPEditor_DATA *data)
112 STRPTR str = NULL;
113 LONG lng = 0;
115 GET(data->fped_interfString, MUIA_String_Contents, &str);
116 SetInterf(str);
117 GET(data->fped_IPString, MUIA_String_Contents, &str);
118 SetIP(str);
119 GET(data->fped_maskString, MUIA_String_Contents, &str);
120 SetMask(str);
121 GET(data->fped_gateString, MUIA_String_Contents, &str);
122 SetGate(str);
123 GET(data->fped_DNSString[0], MUIA_String_Contents, &str);
124 SetDNS(0, str);
125 GET(data->fped_DNSString[1], MUIA_String_Contents, &str);
126 SetDNS(1, str);
127 GET(data->fped_hostString, MUIA_String_Contents, &str);
128 SetHost(str);
129 GET(data->fped_domainString, MUIA_String_Contents, &str);
130 SetDomain(str);
131 GET(data->fped_DHCPState, MUIA_Cycle_Active, &lng);
132 SetDHCP(lng);
134 return TRUE;
137 BOOL FontPrefs2Gadgets
139 struct FPEditor_DATA *data
142 TEXT buffer[1000];
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);
155 FlipDHCP();
157 return 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
170 CLASS, self, NULL,
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),
184 End,
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),
192 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),
197 End,
199 End, // register
201 TAG_DONE
205 if (self != NULL) {
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 -------------------------------------------*/
220 DoMethod
222 interfString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
223 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
225 DoMethod
227 IPString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
228 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
230 DoMethod
232 maskString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
233 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
236 DoMethod
238 gateString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
239 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
241 DoMethod
243 DNSString[0], MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
244 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
246 DoMethod
248 DNSString[1], MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
249 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
251 DoMethod
253 hostString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
254 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
256 DoMethod
258 domainString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
259 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
261 DoMethod
263 DHCPState, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
264 (IPTR)self, 4, MUIM_CallHook, (IPTR)&DHCPHook, (IPTR)self, (IPTR)CLASS
269 return self;
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");
280 return FALSE;
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);
296 BumpTCP();
297 return TRUE;
300 return 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);
310 BOOL success = TRUE;
312 FontPrefs2Gadgets(data);
314 return success;
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;
326 BOOL success = TRUE;
327 LONG error = 0;
329 FontPrefs2Gadgets(data);
331 return success;
336 /*** Setup ******************************************************************/
337 ZUNE_CUSTOMCLASS_5
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 *