2 Copyright 2003-2008, The AROS Development Team. All rights reserved.
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/locale.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 "registertab.h"
34 #include "page_language.h"
35 #include "page_country.h"
36 #include "page_timezone.h"
38 /*** Instance Data **********************************************************/
40 struct LocaleRegister_DATA
49 char *LocaleRegisterLabels
[3];
53 STATIC VOID
LocalePrefs2Gadgets(struct LocaleRegister_DATA
*data
);
54 STATIC VOID
Gadgets2LocalePrefs(struct LocaleRegister_DATA
*data
);
55 VOID
ShowMsg(char *msg
);
58 /*** Macros *****************************************************************/
59 #define SETUP_INST_DATA struct LocaleRegister_DATA *data = INST_DATA(CLASS, self)
61 /*** Methods ****************************************************************/
64 static Object
*handle_New_error(Object
*obj
, struct IClass
*cl
, char *error
)
66 struct LocaleRegister_DATA
*data
;
69 D(bug("[Register class] %s\n",error
));
74 data
= INST_DATA(cl
, obj
);
78 D(bug("[Register class] DisposeObject(data->language);\n"));
79 DisposeObject(data
->language
);
85 D(bug("[Register class] DisposeObject(data->country);\n"));
86 DisposeObject(data
->country
);
92 D(bug("[Register class] DisposeObject(data->timezone);\n"));
93 DisposeObject(data
->timezone
);
99 FreeVec(data
->tab_label
);
100 data
->tab_label
=NULL
;
103 CoerceMethod(cl
, obj
, OM_DISPOSE
);
107 Object
*LocaleRegister__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
109 D(bug("[register class] LocaleRegister Class New\n"));
112 * we create self first and then create the child,
113 * so we have self->data available already
116 self
= (Object
*) DoSuperNewTags(
118 MUIA_PrefsEditor_Name
, MSG(MSG_WINTITLE
),
119 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/locale.prefs",
124 return handle_New_error(self
, CLASS
, "ERROR: Unable to create register object!\n");
129 data
->language
=NewObject(Language_CLASS
->mcc_Class
,NULL
,
130 MA_PrefsObject
, (ULONG
) self
,
134 return handle_New_error(self
,CLASS
,"ERROR: Unable to create language object!\n");
136 data
->country
= ListviewObject
, MUIA_Listview_List
,
137 NewObject(Country_CLASS
->mcc_Class
,0,
138 MA_PrefsObject
, (ULONG
) self
,
143 return handle_New_error(self
,CLASS
,"ERROR: Unable to create country object!\n");
145 data
->timezone
=NewObject(Timezone_CLASS
->mcc_Class
,NULL
,
146 MA_PrefsObject
, (ULONG
) self
,
151 D(bug("icall register handle error\n"));
152 return handle_New_error(self
,CLASS
,"ERROR: Unable to create timezone object!\n");
157 * Maybe, it would be easier to change the catalog,
158 * but for me it's easier this way ;)
160 data
->tab_label
=AllocVec( strlen(MSG(MSG_GAD_TAB_LANGUAGE
)) +
161 strlen(MSG(MSG_GAD_TAB_COUNTRY
)) +
166 return handle_New_error(self
,CLASS
,"ERROR: Unable to allocate tab_label!\n");
168 sprintf(data
->tab_label
,"%s / %s",MSG(MSG_GAD_TAB_COUNTRY
),
169 MSG(MSG_GAD_TAB_LANGUAGE
));
171 data
->LocaleRegisterLabels
[0]=data
->tab_label
;
172 data
->LocaleRegisterLabels
[1]=MSG(MSG_GAD_TAB_TIMEZONE
);
173 data
->LocaleRegisterLabels
[2]=NULL
;
176 RegisterGroup(data
->LocaleRegisterLabels
),
177 MUIA_Register_Frame
, TRUE
,
180 MUIA_Group_SameSize
, TRUE
,
183 MUIA_Frame
, MUIV_Frame_Group
,
184 MUIA_FrameTitle
, MSG(MSG_GAD_TAB_COUNTRY
),
190 MUIA_Frame
, MUIV_Frame_Group
,
191 MUIA_FrameTitle
, MSG(MSG_GAD_TAB_LANGUAGE
),
201 return handle_New_error(self
, CLASS
, "ERROR: unable to create registergroup\n");
203 DoMethod(self
,OM_ADDMEMBER
,(ULONG
) data
->child
);
205 DoMethod(data
->country
,COUNTRY_FILL
);
207 LocalePrefs2Gadgets(data
);
213 * update struct localprefs with actual data selected in gadgets:
217 * struct LocalePrefs {
218 * char lp_CountryName[32];
219 * char lp_PreferredLanguages[10][30];
223 * struct CountryPrefs lp_CountryData;
227 STATIC VOID
Gadgets2LocalePrefs (struct LocaleRegister_DATA
*data
)
233 if(get(data
->country
,MA_CountryName
,&tmp
))
235 strncpy(localeprefs
.lp_CountryName
,tmp
,32);
238 if(get(data
->language
,MA_Preferred
,&preferred
))
244 strncpy(localeprefs
.lp_PreferredLanguages
[i
],preferred
[i
],30);
248 localeprefs
.lp_PreferredLanguages
[i
][0]=(char) 0;
253 get(data
->timezone
, MA_TimeOffset
, &localeprefs
.lp_GMTOffset
);
257 * update gadgets with values of struct localeprefs
259 STATIC VOID
LocalePrefs2Gadgets(struct LocaleRegister_DATA
*data
)
262 set(data
->country
, MA_CountryName
, localeprefs
.lp_CountryName
);
264 set(data
->language
, MA_Preferred
, TRUE
);
266 set(data
->timezone
, MA_TimeOffset
, -localeprefs
.lp_GMTOffset
);
270 IPTR
LocaleRegister__MUIM_PrefsEditor_ImportFH (
271 Class
*CLASS
, Object
*self
,
272 struct MUIP_PrefsEditor_ImportFH
*message
277 if (!LoadPrefsFH(message
->fh
)) {
278 D(bug("[register class] LocaleRegister__MUIM_PrefsEditor_ImportFH failed\n"));
283 LocalePrefs2Gadgets(data
);
284 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
285 SET(self
, MUIA_PrefsEditor_Testing
, FALSE
);
290 IPTR LocaleRegister__MUIM_PrefsEditor_ExportFH
292 Class
*CLASS
, Object
*self
,
293 struct MUIP_PrefsEditor_ExportFH
*message
297 D(bug("[register class] SerEdit Class Export\n"));
299 Gadgets2LocalePrefs(data
);
300 return SavePrefsFH(message
->fh
);
303 IPTR LocaleRegister__MUIM_PrefsEditor_Test
305 Class
*CLASS
, Object
*self
, Msg message
311 D(bug("[register class] SerEdit Class Test\n"));
313 Gadgets2LocalePrefs(data
);
317 if(result
) { /* TRUE -> success */
318 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
319 SET(self
, MUIA_PrefsEditor_Testing
, TRUE
);
325 IPTR LocaleRegister__MUIM_PrefsEditor_Revert
327 Class
*CLASS
, Object
*self
, Msg message
333 D(bug("[register class] SerEdit Class Revert\n"));
336 LocalePrefs2Gadgets(data
);
341 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
342 SET(self
, MUIA_PrefsEditor_Testing
, FALSE
);
348 IPTR
LocaleRegister__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
354 FreeVec(data
->tab_label
);
355 data
->tab_label
=NULL
;
358 return DoSuperMethodA(CLASS
, self
, message
);
361 /*** Setup ******************************************************************/
364 LocaleRegister
, NULL
, MUIC_PrefsEditor
, NULL
,
365 OM_NEW
, struct opSet
*,
367 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
368 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
369 MUIM_PrefsEditor_Test
, Msg
,
370 MUIM_PrefsEditor_Revert
, Msg