added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / classes / zune / loginwindow / loginwindow.c
blob5955740cf49c2be987774a89f44cf142dedb1098
1 /*
2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
4 $Id$
5 */
7 #define MUIMASTER_YES_INLINE_STDARG
9 #include <utility/tagitem.h>
10 #include <libraries/mui.h>
11 #include <dos/dos.h>
12 #include <zune/iconimage.h>
13 #include <exec/memory.h>
14 #include <intuition/gadgetclass.h>
15 #include <intuition/icclass.h>
17 #include <aros/inquire.h>
18 #include <proto/aros.h>
20 #include <proto/exec.h>
21 #include <proto/muimaster.h>
22 #include <proto/intuition.h>
23 #include <proto/utility.h>
24 #include <proto/locale.h>
25 #include <proto/dos.h>
26 #include <proto/alib.h>
27 #include <proto/graphics.h>
30 #include <string.h>
33 #include "loginwindow.h"
34 #include "loginwindow_private.h"
36 #define CATCOMP_ARRAY
37 #include "strings.h"
39 #define DEBUG 1
40 #include <aros/debug.h>
42 #define LOGOTYPE_IMAGE "IMAGES:Logos/login.logo"
43 #define USERTYPE_IMAGE "IMAGES:Gadgets/System/sys_user"
45 #define ENV ((IPTR) "ENV:")
47 /*** Macros and Defines *****************************************************/
48 #define IGNORE ((APTR)(1UL))
50 /*** Locale functions *******************************************************/
51 CONST_STRPTR MSG(struct Catalog *catalog, ULONG id)
53 if (catalog != NULL)
55 return GetCatalogStr(catalog, id, CatCompArray[id].cca_Str);
57 else
59 return CatCompArray[id].cca_Str;
63 #define _(id) MSG(catalog,id)
66 /*** Methods ****************************************************************/
67 Object *LoginWindow__OM_NEW
69 Class *CLASS, Object *self, struct opSet *message
72 int authm_count = 0,
73 local_login = 0,
74 nametype = 0,
75 methodtype = 0;
76 APTR pool = NULL;
77 BPTR lock = NULL;
78 IPTR logoFrame = NULL,
79 detailsFrame = NULL;
80 BOOL localLogins = TRUE,
81 nametypeset = FALSE,
82 methodtypeset = FALSE;
83 STRPTR localLoginStr = NULL,
84 title = NULL,
85 logonString = NULL,
86 user = NULL,
87 pass = NULL;
88 char *authmethodList[20] = { NULL };
89 struct LoginWindow_DATA *data = NULL;
90 struct TagItem *tstate = message->ops_AttrList,
91 *tag = NULL;
92 struct Catalog *catalog = NULL;
93 Object *imageGroup = NULL,
94 *img_logo = NULL,
95 *img_user = NULL,
96 *contents = NULL,
97 *nameUser = NULL,
98 *passUser = NULL,
99 *logonMethod = NULL,
100 *okButton = NULL,
101 *cancelButton = NULL;
103 /* Allocate memory pool ------------------------------------------------*/
104 pool = CreatePool(MEMF_ANY, 4096, 4096);
105 if (pool == NULL) return NULL;
107 /* Initialize locale ---------------------------------------------------*/
108 catalog = OpenCatalogA(NULL, "System/security.catalog", NULL);
110 tag = FindTagItem(WindowContents, message->ops_AttrList);
112 localLoginStr = StrDup("Local Logon\0");
113 title = StrDup(_(MSG_LOGINREQ_GUI));
115 D(bug("LOGINWINDOW checking tags..\n"));
117 while ((tag = NextTagItem(&tstate)) != NULL)
119 switch (tag->ti_Tag)
121 case MUIA_LoginWindow_Title:
122 //if ((title)&&(title!=IGNORE)) FreeVec(title);
123 title = StrDup((STRPTR) tag->ti_Data);
124 if (title == NULL) title = IGNORE;
125 break;
127 case MUIA_LoginWindow_UserName:
128 //if (user) FreeVec(user);
129 user = StrDup((STRPTR) tag->ti_Data);
130 if (user == NULL) user = StrDup("<USERNAME>");
131 break;
133 case MUIA_LoginWindow_LoginLogo:
134 img_logo = (Object *) tag->ti_Data;
135 break;
137 case MUIA_LoginWindow_Method:
138 authmethodList[authm_count] = StrDup((STRPTR) tag->ti_Data);
139 authm_count++;
140 break;
142 case MUIA_LoginWindow_UserName_Status:
143 if (nametypeset) break;
144 nametype = tag->ti_Data;
145 nametypeset = TRUE;
146 break;
148 case MUIA_LoginWindow_Method_Status:
149 if (methodtypeset) break;
150 methodtype = tag->ti_Data;
151 methodtypeset = TRUE;
152 break;
154 case MUIA_LoginWindow_LocalLogin_Disabled:
155 localLogins = (BOOL) tag->ti_Data;
156 break;
158 case MUIA_LoginWindow_LogoFrame:
159 logoFrame = (IPTR) tag->ti_Data;
160 break;
162 case MUIA_LoginWindow_DetailsFrame:
163 detailsFrame = (IPTR) tag->ti_Data;
164 break;
166 case TAG_IGNORE:
167 contents = (Object*) tag->ti_Data;
168 break;
170 default:
171 continue; /* Don't supress non-processed tags */
174 tag->ti_Tag = TAG_IGNORE;
177 switch(nametype)
180 case LWA_UNT_Read:
181 nameUser = TextObject,
182 MUIA_Text_Editable, FALSE,
183 MUIA_Text_Multiline, FALSE,
184 End;
185 break;
186 case LWA_UNT_Disabled:
187 nameUser = StringObject,
188 StringFrame,
189 MUIA_Disabled, TRUE,
190 MUIA_String_AdvanceOnCR,TRUE,
191 MUIA_CycleChain, TRUE,
192 End;
193 break;
194 case LWA_UNT_None:
195 nameUser = HVSpace;
196 break;
197 default:
198 nameUser = StringObject,
199 StringFrame,
200 MUIA_String_AdvanceOnCR,TRUE,
201 MUIA_CycleChain, TRUE,
202 End;
203 break;
206 switch(methodtype)
208 case LWA_METH_Disabled:
209 logonMethod = PoplistObject,
210 MUIA_Disabled, TRUE,
211 MUIA_Popstring_String, (IPTR) StringObject, StringFrame, End,
212 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopUp),
213 End;
214 break;
215 case LWA_METH_None:
216 methodtype = 1;
217 logonMethod = HVSpace;
218 break;
219 default:
220 logonMethod = PoplistObject,
221 MUIA_Popstring_String, (IPTR) StringObject, StringFrame, End,
222 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopUp),
223 End;
224 break;
227 D(bug("LOGINWINDOW checking LoginStr..\n"));
229 if (localLoginStr)
231 if (localLogins)
233 authmethodList[authm_count] = localLoginStr;
234 authm_count++;
235 local_login = TRUE;
239 authmethodList[authm_count] = NULL;
241 D(bug("LOGINWINDOW checking contents..\n"));
243 if (!contents)
245 int i;
246 char tmpversion[8] ="\0",
247 tmphostname[32] ="\0",
248 strbuff[1024] = "\0";
249 STRPTR version = NULL,
250 hostname = NULL;
252 if (GetVar("Kickstart", &tmpversion[0], 8, GVF_GLOBAL_ONLY) == -1)
254 ArosInquire( AI_ArosVersion, (ULONG)&i, TAG_DONE);
255 __sprintf(&tmpversion[0],"%d\0",i);
257 version = StrDup( &tmpversion[0] );
259 if (GetVar("HostName", &tmphostname[0], 32, GVF_GLOBAL_ONLY) == -1) hostname = StrDup( "?" );
260 else
262 for (i = 0; tmphostname[i] && (tmphostname[i] != '.'); i++);
264 if (tmphostname[i] == '.') tmphostname[i] = '\0';
266 hostname = StrDup( &tmphostname[0] );
270 __sprintf(&strbuff[0],_(MSG_LOGINPROMPT_GUI),version,hostname);
272 if (hostname) FreeVec(hostname);
273 if (version) FreeVec(version);
275 contents = TextObject,
276 MUIA_Text_Contents, (IPTR)StrDup(strbuff),
277 End;
280 D(bug("LOGINWINDOW checking Logo..\n"));
282 /* Setup image ---------------------------------------------------------*/
283 if (!img_logo)
285 if ((lock = Lock(LOGOTYPE_IMAGE, ACCESS_READ)) != NULL)
287 img_logo = ImageObject,
288 MUIA_Image_Spec, (IPTR)"3:"LOGOTYPE_IMAGE,
289 End;
291 UnLock(lock);
293 else img_logo = HVSpace;
295 else img_logo = HVSpace;
297 lock = NULL;
299 if ((lock = Lock(USERTYPE_IMAGE, ACCESS_READ)) != NULL)
301 img_user = ImageObject,
302 MUIA_Image_Spec, (IPTR)"3:"USERTYPE_IMAGE,
303 End;
305 UnLock(lock);
307 else img_user = HVSpace;
309 D(bug("LOGINWINDOW Creating window..\n"));
311 self = (Object *) DoSuperNewTags
313 CLASS, self, NULL,
314 MUIA_Window_Title, (IPTR) title,
315 MUIA_Window_Activate, TRUE,
316 MUIA_Window_NoMenus, TRUE,
317 MUIA_Window_CloseGadget, FALSE,
319 WindowContents, (IPTR) VGroup,
320 Child, (IPTR) HGroup,
321 Child, (IPTR) imageGroup = VGroup,
322 MUIA_Weight, 0,
323 Child, (IPTR) HVSpace,
324 Child, (IPTR) img_logo,
325 Child, (IPTR) HVSpace,
326 End,
327 Child, (IPTR) VGroup,
328 Child, (IPTR) RectangleObject,
329 MUIA_Weight, 50,
330 End,
332 Child, (IPTR) contents,
334 Child, (IPTR) RectangleObject,
335 MUIA_Weight, 50,
336 End,
338 Child, (IPTR) imageGroup = HGroup,
339 MUIA_Weight, 0,
340 Child, (IPTR) img_user,
341 Child, (IPTR) nameUser = StringObject,
342 StringFrame,
343 MUIA_String_Contents, (IPTR) user,
344 MUIA_String_AdvanceOnCR, TRUE,
345 MUIA_CycleChain, TRUE,
346 End,
347 End,
349 Child, (IPTR) passUser = StringObject,
350 StringFrame,
351 MUIA_String_Contents, (IPTR) pass,
352 MUIA_String_Secret, TRUE,
353 MUIA_String_AdvanceOnCR,TRUE,
354 MUIA_CycleChain, TRUE,
355 End,
357 Child, (IPTR) logonMethod = PoplistObject,
358 MUIA_Popstring_String, (IPTR) StringObject, StringFrame, MUIA_String_Contents, (IPTR) logonString, End,
359 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopUp),
360 MUIA_Poplist_Array, (IPTR) authmethodList,
361 End,
363 Child, (IPTR) HGroup,
364 MUIA_Group_SameWidth, TRUE,
365 MUIA_Weight, 0,
366 Child, (IPTR) okButton = ImageButton(_(MSG_OK), "THEME:Images/Gadgets/Preferences/Test.png"),
367 Child, (IPTR) cancelButton = ImageButton(_(MSG_RESUME), "THEME:Images/Gadgets/Preferences/Revert.png"),
368 End,
369 End,
370 End,
371 End,
373 TAG_MORE, (IPTR) message->ops_AttrList
376 if (self != NULL)
378 D(bug("LOGINWINDOW Window created..\n"));
380 data = INST_DATA(CLASS, self);
381 data->lwd_Catalog = catalog;
382 data->lwd_Pool = pool;
383 data->lwd_Title = title;
384 data->lwd_OKButton = okButton;
385 data->lwd_CancelButton = cancelButton;
386 data->lwd_UNInput = nameUser;
387 data->lwd_UPInput = passUser;
389 data->lwd_UserName = user;
390 data->lwd_UserPass = pass;
392 data->lwd_LogonLogo = img_logo;
393 data->lwd_LogonHeader = contents;
394 data->lwd_Method = logonMethod;
395 data->lwd_DoMethod = logonString;
397 data->lwd_MethodList = authmethodList;
399 /*-- Handle initial attribute values -------------------------------*/
401 if (methodtype!=LWA_METH_None)
403 D(bug("LOGINWINDOW Setting LoginMethods..\n"));
404 //select the local login text
405 //if (logonString != NULL) FreeVec(logonString);
406 logonString = StrDup((STRPTR) localLoginStr);
407 //and then prevent changes to it
408 set(data->lwd_DoMethod, MUIA_Poplist_Array, (IPTR)authmethodList);
409 if ((local_login)&&(authm_count == 1)) set(data->lwd_DoMethod, MUIA_String_Contents, logonString);
412 if (!authm_count) set(data->lwd_OKButton, MUIA_Disabled, TRUE);
414 if (user)
416 switch (nametype)
418 case LWA_UNT_Input:
419 case LWA_UNT_Disabled:
420 D(bug("LOGINWINDOW updateing name string..\n"));
421 set(data->lwd_UNInput, MUIA_String_Contents, user);
422 break;
423 case LWA_UNT_Read:
424 D(bug("LOGINWINDOW updateing name text..\n"));
425 set(data->lwd_UNInput, MUIA_Text_Contents, user);
426 break;
427 default:
428 break;
432 SetAttrsA(self, message->ops_AttrList);
434 /*-- Set up the cycle group ----------------------------------------*/
436 if (nametype==LWA_UNT_Input) set(nameUser, MUIA_CycleChain, 1);
437 set(passUser, MUIA_CycleChain, 1);
438 if (methodtype!=LWA_METH_None) set(logonMethod, MUIA_CycleChain, 1);
439 set(okButton, MUIA_CycleChain, 1);
440 set(cancelButton, MUIA_CycleChain, 1);
442 /*-- Setup notifications -------------------------------------------*/
444 DoMethod
446 self, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
447 (IPTR) cancelButton, 2, MUIA_Pressed, FALSE
450 DoMethod
452 okButton, MUIM_Notify, MUIA_Pressed, FALSE,
453 (IPTR) self, 2, MUIM_Application_ReturnID, LWA_RV_OK
455 DoMethod
457 cancelButton, MUIM_Notify, MUIA_Pressed, FALSE,
458 (IPTR) self, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
461 else
463 D(bug("LOGINWINDOW failed to create window..\n"));
464 if (catalog != NULL) CloseCatalog(catalog);
467 return self;
470 IPTR LoginWindow__OM_DISPOSE
472 Class *CLASS, Object *self, Msg message
475 struct LoginWindow_DATA *data = INST_DATA(CLASS, self);
476 char *authmethodList[20];
477 UBYTE i;
478 APTR ptrs[] =
480 data->lwd_Title,
481 data->lwd_UserName,
482 data->lwd_UserPass,
483 data->lwd_DoMethod
486 // *authmethodList = data->lwd_MethodList;
487 // i = 0;
489 // while( authmethodList[i++] )FreeVec(authmethodList[i-1]);
491 for (i = 0; i < (sizeof(ptrs) / sizeof(APTR)); i++)
493 if (ptrs[i] != NULL) FreeVec(ptrs[i]);
496 if (data->lwd_Pool != NULL) DeletePool(data->lwd_Pool);
498 if (data->lwd_Catalog != NULL) CloseCatalog(data->lwd_Catalog);
500 return DoSuperMethodA(CLASS, self, message);
503 IPTR LoginWindow__OM_SET
505 Class *CLASS, Object *self, struct opSet *message
508 struct LoginWindow_DATA *data = INST_DATA(CLASS, self);
509 struct TagItem *tstate = message->ops_AttrList,
510 *tag;
512 while ((tag = NextTagItem(&tstate)) != NULL)
514 switch (tag->ti_Tag)
516 case MUIA_LoginWindow_UserName:
517 if ((IPTR)data->lwd_UserName != (IPTR)tag->ti_Data)
519 if (data->lwd_UserName != NULL) FreeVec(data->lwd_UserName);
520 data->lwd_UserName = StrDup((STRPTR) tag->ti_Data);
522 break;
524 case MUIA_LoginWindow_Cancel_Disabled:
525 set(data->lwd_CancelButton, MUIA_Disabled, tag->ti_Data);
526 break;
530 return DoSuperMethodA(CLASS, self, (Msg) message);
533 IPTR LoginWindow__OM_GET
535 Class *CLASS, Object *self, struct opGet *message
538 struct LoginWindow_DATA *data = INST_DATA(CLASS, self);
539 IPTR *store = message->opg_Storage;
540 IPTR rv = TRUE;
542 switch (message->opg_AttrID)
545 case MUIA_LoginWindow_Method:
546 *store = (IPTR) data->lwd_DoMethod;
547 break;
549 case MUIA_LoginWindow_UserName:
550 *store = (IPTR) data->lwd_UserName;
551 break;
553 case MUIA_LoginWindow_UserPass:
554 *store = (IPTR) data->lwd_UserPass;
555 break;
557 case MUIA_LoginWindow_Cancel_Disabled:
558 *store = XGET(data->lwd_CancelButton, MUIA_Disabled);
559 break;
561 default:
562 rv = DoSuperMethodA(CLASS, self, (Msg) message);
565 return rv;