2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
7 #define MUIMASTER_YES_INLINE_STDARG
9 #include <utility/tagitem.h>
10 #include <libraries/mui.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>
33 #include "loginwindow.h"
34 #include "loginwindow_private.h"
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
)
55 return GetCatalogStr(catalog
, id
, CatCompArray
[id
].cca_Str
);
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
78 IPTR logoFrame
= NULL
,
80 BOOL localLogins
= TRUE
,
82 methodtypeset
= FALSE
;
83 STRPTR localLoginStr
= NULL
,
88 char *authmethodList
[20] = { NULL
};
89 struct LoginWindow_DATA
*data
= NULL
;
90 struct TagItem
*tstate
= message
->ops_AttrList
,
92 struct Catalog
*catalog
= NULL
;
93 Object
*imageGroup
= 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
)
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
;
127 case MUIA_LoginWindow_UserName
:
128 //if (user) FreeVec(user);
129 user
= StrDup((STRPTR
) tag
->ti_Data
);
130 if (user
== NULL
) user
= StrDup("<USERNAME>");
133 case MUIA_LoginWindow_LoginLogo
:
134 img_logo
= (Object
*) tag
->ti_Data
;
137 case MUIA_LoginWindow_Method
:
138 authmethodList
[authm_count
] = StrDup((STRPTR
) tag
->ti_Data
);
142 case MUIA_LoginWindow_UserName_Status
:
143 if (nametypeset
) break;
144 nametype
= tag
->ti_Data
;
148 case MUIA_LoginWindow_Method_Status
:
149 if (methodtypeset
) break;
150 methodtype
= tag
->ti_Data
;
151 methodtypeset
= TRUE
;
154 case MUIA_LoginWindow_LocalLogin_Disabled
:
155 localLogins
= (BOOL
) tag
->ti_Data
;
158 case MUIA_LoginWindow_LogoFrame
:
159 logoFrame
= (IPTR
) tag
->ti_Data
;
162 case MUIA_LoginWindow_DetailsFrame
:
163 detailsFrame
= (IPTR
) tag
->ti_Data
;
167 contents
= (Object
*) tag
->ti_Data
;
171 continue; /* Don't supress non-processed tags */
174 tag
->ti_Tag
= TAG_IGNORE
;
181 nameUser
= TextObject
,
182 MUIA_Text_Editable
, FALSE
,
183 MUIA_Text_Multiline
, FALSE
,
186 case LWA_UNT_Disabled
:
187 nameUser
= StringObject
,
190 MUIA_String_AdvanceOnCR
,TRUE
,
191 MUIA_CycleChain
, TRUE
,
198 nameUser
= StringObject
,
200 MUIA_String_AdvanceOnCR
,TRUE
,
201 MUIA_CycleChain
, TRUE
,
208 case LWA_METH_Disabled
:
209 logonMethod
= PoplistObject
,
211 MUIA_Popstring_String
, (IPTR
) StringObject
, StringFrame
, End
,
212 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
217 logonMethod
= HVSpace
;
220 logonMethod
= PoplistObject
,
221 MUIA_Popstring_String
, (IPTR
) StringObject
, StringFrame
, End
,
222 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
227 D(bug("LOGINWINDOW checking LoginStr..\n"));
233 authmethodList
[authm_count
] = localLoginStr
;
239 authmethodList
[authm_count
] = NULL
;
241 D(bug("LOGINWINDOW checking contents..\n"));
246 char tmpversion
[8] ="\0",
247 tmphostname
[32] ="\0",
248 strbuff
[1024] = "\0";
249 STRPTR version
= 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( "?" );
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
),
280 D(bug("LOGINWINDOW checking Logo..\n"));
282 /* Setup image ---------------------------------------------------------*/
285 if ((lock
= Lock(LOGOTYPE_IMAGE
, ACCESS_READ
)) != NULL
)
287 img_logo
= ImageObject
,
288 MUIA_Image_Spec
, (IPTR
)"3:"LOGOTYPE_IMAGE
,
293 else img_logo
= HVSpace
;
295 else img_logo
= HVSpace
;
299 if ((lock
= Lock(USERTYPE_IMAGE
, ACCESS_READ
)) != NULL
)
301 img_user
= ImageObject
,
302 MUIA_Image_Spec
, (IPTR
)"3:"USERTYPE_IMAGE
,
307 else img_user
= HVSpace
;
309 D(bug("LOGINWINDOW Creating window..\n"));
311 self
= (Object
*) DoSuperNewTags
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
,
323 Child
, (IPTR
) HVSpace
,
324 Child
, (IPTR
) img_logo
,
325 Child
, (IPTR
) HVSpace
,
327 Child
, (IPTR
) VGroup
,
328 Child
, (IPTR
) RectangleObject
,
332 Child
, (IPTR
) contents
,
334 Child
, (IPTR
) RectangleObject
,
338 Child
, (IPTR
) imageGroup
= HGroup
,
340 Child
, (IPTR
) img_user
,
341 Child
, (IPTR
) nameUser
= StringObject
,
343 MUIA_String_Contents
, (IPTR
) user
,
344 MUIA_String_AdvanceOnCR
, TRUE
,
345 MUIA_CycleChain
, TRUE
,
349 Child
, (IPTR
) passUser
= StringObject
,
351 MUIA_String_Contents
, (IPTR
) pass
,
352 MUIA_String_Secret
, TRUE
,
353 MUIA_String_AdvanceOnCR
,TRUE
,
354 MUIA_CycleChain
, TRUE
,
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
,
363 Child
, (IPTR
) HGroup
,
364 MUIA_Group_SameWidth
, TRUE
,
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"),
373 TAG_MORE
, (IPTR
) message
->ops_AttrList
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
);
419 case LWA_UNT_Disabled
:
420 D(bug("LOGINWINDOW updateing name string..\n"));
421 set(data
->lwd_UNInput
, MUIA_String_Contents
, user
);
424 D(bug("LOGINWINDOW updateing name text..\n"));
425 set(data
->lwd_UNInput
, MUIA_Text_Contents
, user
);
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 -------------------------------------------*/
446 self
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
447 (IPTR
) cancelButton
, 2, MUIA_Pressed
, FALSE
452 okButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
453 (IPTR
) self
, 2, MUIM_Application_ReturnID
, LWA_RV_OK
457 cancelButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
458 (IPTR
) self
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
463 D(bug("LOGINWINDOW failed to create window..\n"));
464 if (catalog
!= NULL
) CloseCatalog(catalog
);
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];
486 // *authmethodList = data->lwd_MethodList;
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
,
512 while ((tag
= NextTagItem(&tstate
)) != NULL
)
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
);
524 case MUIA_LoginWindow_Cancel_Disabled
:
525 set(data
->lwd_CancelButton
, MUIA_Disabled
, tag
->ti_Data
);
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
;
542 switch (message
->opg_AttrID
)
545 case MUIA_LoginWindow_Method
:
546 *store
= (IPTR
) data
->lwd_DoMethod
;
549 case MUIA_LoginWindow_UserName
:
550 *store
= (IPTR
) data
->lwd_UserName
;
553 case MUIA_LoginWindow_UserPass
:
554 *store
= (IPTR
) data
->lwd_UserPass
;
557 case MUIA_LoginWindow_Cancel_Disabled
:
558 *store
= XGET(data
->lwd_CancelButton
, MUIA_Disabled
);
562 rv
= DoSuperMethodA(CLASS
, self
, (Msg
) message
);