2 ** OpenURL - MUI preferences for openurl.library
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
18 #define CATCOMP_NUMBERS
20 #include "libraries/openurl.h"
22 /**************************************************************************/
61 /**************************************************************************/
63 static STRPTR tabs
[] =
65 (STRPTR
)MSG_Win_Labels_Browsers
,
66 (STRPTR
)MSG_Win_Labels_Mailers
,
67 (STRPTR
)MSG_Win_Labels_FTPs
,
68 (STRPTR
)MSG_Win_Labels_Misc
,
73 mNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
77 memset(&temp
,0,sizeof(temp
));
79 if (obj
= (Object
*)DoSuperNew(cl
,obj
,
81 MUIA_Window_ID
, MAKE_ID('M', 'W', 'I', 'N'),
82 MUIA_Window_Title
, getString(MSG_Win_WinTitle
),
83 MUIA_Window_ScreenTitle
, getString(MSG_App_ScreenTitle
),
85 WindowContents
, VGroup
,
86 Child
, temp
.reg
= RegisterObject
,
87 MUIA_Background
, MUII_RegisterBack
,
88 MUIA_CycleChain
, TRUE
,
89 MUIA_Register_Titles
, tabs
,
92 Child
, temp
.browsers
= appListObject
,
93 MUIA_AppList_Type
, MUIV_AppList_Type_Browser
,
97 Child
, temp
.mailers
= appListObject
,
98 MUIA_AppList_Type
, MUIV_AppList_Type_Mailer
,
102 Child
, temp
.FTPs
= appListObject
,
103 MUIA_AppList_Type
, MUIV_AppList_Type_FTP
,
107 Child
, temp
.misc
= VGroup
,
108 MUIA_HelpNode
, "MISCS",
112 GroupFrameT(getString(MSG_Misc_Defaults
)),
115 Child
, temp
.show
= ocheckmark(MSG_Misc_Show
,MSG_Misc_Show_Help
),
116 Child
, ollabel1(MSG_Misc_Show
),
117 Child
, temp
.toFront
= ocheckmark(MSG_Misc_Bring
,MSG_Misc_Bring_Help
),
118 Child
, ollabel1(MSG_Misc_Bring
),
119 Child
, temp
.newWin
= ocheckmark(MSG_Misc_Open
,MSG_Misc_Open_Help
),
120 Child
, ollabel1(MSG_Misc_Open
),
121 Child
, temp
.launch
= ocheckmark(MSG_Misc_Launch
,MSG_Misc_Launch_Help
),
122 Child
, ollabel1(MSG_Misc_Launch
),
131 GroupFrameT(getString(MSG_Misc_Options
)),
134 Child
, temp
.prepend
= ocheckmark(MSG_Misc_Prepend
,MSG_Misc_Prepend_Help
),
135 Child
, ollabel1(MSG_Misc_Prepend
),
136 Child
, temp
.mailto
= ocheckmark(MSG_Misc_UseMailer
,MSG_Misc_UseMailer_Help
),
137 Child
, ollabel1(MSG_Misc_UseMailer
),
138 Child
, temp
.useFTP
= ocheckmark(MSG_Misc_UseFTP
,MSG_Misc_UseFTP_Help
),
139 Child
, ollabel1(MSG_Misc_UseFTP
),
149 Child
, temp
.save
= obutton(MSG_Win_Save
,MSG_Win_Save_Help
),
151 Child
, temp
.use
= obutton(MSG_Win_Use
,MSG_Win_Use_Help
),
153 Child
, temp
.apply
= obutton(MSG_Win_Apply
,MSG_Win_Apply_Help
),
155 Child
, temp
.cancel
= obutton(MSG_Win_Cancel
,MSG_Win_Cancel_Help
),
159 TAG_MORE
, msg
->ops_AttrList
))
161 struct data
*data
= INST_DATA(cl
,obj
);
163 /* init instance data */
164 CopyMem(&temp
,data
,sizeof(*data
));
166 get(data
->browsers
,MUIA_AppList_ListObj
,&data
->browserList
);
167 get(data
->mailers
,MUIA_AppList_ListObj
,&data
->mailerList
);
168 get(data
->FTPs
,MUIA_AppList_ListObj
,&data
->FTPList
);
171 set(obj
,MUIA_Window_DefaultObject
,data
->browserList
);
173 /* window notifies */
174 DoMethod(obj
,MUIM_Notify
,MUIA_Window_CloseRequest
,TRUE
,MUIV_Notify_Application
,2,
175 MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
177 /* buttons notifies */
178 DoMethod(data
->save
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(ULONG
)obj
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Save
);
179 DoMethod(data
->use
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(ULONG
)obj
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Use
);
180 DoMethod(data
->apply
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(ULONG
)obj
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Apply
);
181 DoMethod(data
->cancel
,MUIM_Notify
,MUIA_Pressed
,FALSE
,MUIV_Notify_Application
,2,MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
187 /**************************************************************************/
190 mSets(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
192 struct MUI_PenSpec
**specs
;
194 if (specs
= (struct MUI_PenSpec
**)GetTagData(MUIA_App_Pens
,0L,msg
->ops_AttrList
))
196 struct data
*data
= INST_DATA(cl
,obj
);
198 //Printf("PrefsWin [%s] [%s] [%s]\n",specs[0],specs[1],specs[2]);
200 set(data
->browserList
,MUIA_App_Pens
,specs
);
201 set(data
->mailerList
,MUIA_App_Pens
,specs
);
202 set(data
->FTPList
,MUIA_App_Pens
,specs
);
205 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
208 /***********************************************************************/
212 mGetPrefs(struct IClass
*cl
,Object
*obj
,struct MUIP_Win_GetPrefs
*msg
)
214 struct data
*data
= INST_DATA(cl
,obj
);
216 struct URL_BrowserNode
*bn
;
217 struct URL_MailerNode
*mn
;
218 struct URL_FTPNode
*fn
;
219 ULONG mode
, error
= 0;
221 /* get the openurl.library prefs */
225 case MUIV_Win_GetPrefs_InUse
: mode
= URL_GetPrefs_Mode_InUse
; break;
226 case MUIV_Win_GetPrefs_LastSaveds
: mode
= URL_GetPrefs_Mode_Envarc
; break;
227 case MUIV_Win_GetPrefs_Restore
: mode
= URL_GetPrefs_Mode_Env
; break;
228 case MUIV_Win_GetPrefs_Defaults
: mode
= URL_GetPrefs_Mode_Default
; break;
229 default: return FALSE
;
232 p
= URL_GetPrefs(URL_GetPrefs_Mode
,mode
,TAG_DONE
);
233 if (!p
) error
= MSG_Err_NoPrefs
;
234 else if (p
->up_Version
!=PREFS_VERSION
) error
= MSG_Err_BadPrefs
;
238 MUI_Request(_app(obj
),NULL
,0,getString(MSG_ErrReqTitle
),
239 getString(MSG_ErrReqGadget
),
241 p
? p
->up_Version
: 0);
243 if (p
) URL_FreePrefsA(p
,NULL
);
249 set(data
->browserList
,MUIA_List_Quiet
,TRUE
);
250 DoMethod(data
->browserList
,MUIM_List_Clear
);
252 for (bn
= (struct URL_BrowserNode
*)p
->up_BrowserList
.mlh_Head
;
253 bn
->ubn_Node
.mln_Succ
;
254 bn
= (struct URL_BrowserNode
*)bn
->ubn_Node
.mln_Succ
)
256 DoMethod(data
->browserList
,MUIM_List_InsertSingle
,(ULONG
)bn
,MUIV_List_Insert_Bottom
);
259 set(data
->browserList
,MUIA_List_Quiet
,FALSE
);
262 set(data
->mailerList
,MUIA_List_Quiet
,TRUE
);
263 DoMethod(data
->mailerList
,MUIM_List_Clear
);
265 for (mn
= (struct URL_MailerNode
*)p
->up_MailerList
.mlh_Head
;
266 mn
->umn_Node
.mln_Succ
;
267 mn
= (struct URL_MailerNode
*)mn
->umn_Node
.mln_Succ
)
269 DoMethod(data
->mailerList
,MUIM_List_InsertSingle
,(ULONG
)mn
,MUIV_List_Insert_Bottom
);
272 set(data
->mailerList
,MUIA_List_Quiet
,FALSE
);
275 set(data
->FTPList
,MUIA_List_Quiet
,TRUE
);
276 DoMethod(data
->FTPList
,MUIM_List_Clear
);
278 for (fn
= (struct URL_FTPNode
*)p
->up_FTPList
.mlh_Head
;
279 fn
->ufn_Node
.mln_Succ
;
280 fn
= (struct URL_FTPNode
*)fn
->ufn_Node
.mln_Succ
)
282 DoMethod(data
->FTPList
,MUIM_List_InsertSingle
,(ULONG
)fn
,MUIV_List_Insert_Bottom
);
285 set(data
->FTPList
,MUIA_List_Quiet
,FALSE
);
288 set(data
->prepend
,MUIA_Selected
,p
->up_Flags
& UPF_PREPENDHTTP
);
289 set(data
->mailto
,MUIA_Selected
,p
->up_Flags
& UPF_DOMAILTO
);
290 set(data
->useFTP
,MUIA_Selected
,p
->up_Flags
& UPF_DOFTP
);
292 set(data
->show
,MUIA_Selected
,p
->up_DefShow
);
293 set(data
->toFront
,MUIA_Selected
,p
->up_DefBringToFront
);
294 set(data
->newWin
,MUIA_Selected
,p
->up_DefNewWindow
);
295 set(data
->launch
,MUIA_Selected
,p
->up_DefLaunch
);
297 /* Activate the first entry */
298 DoSuperMethod(cl
,obj
,MUIM_MultiSet
,MUIA_List_Active
,MUIV_List_Active_Top
,
299 (ULONG
)data
->browserList
,
300 (ULONG
)data
->mailerList
,
301 (ULONG
)data
->FTPList
,
304 URL_FreePrefsA(p
,NULL
);
309 /**************************************************************************/
312 mStorePrefs(struct IClass
*cl
,Object
*obj
,struct MUIP_Win_StorePrefs
*msg
)
314 struct data
*data
= INST_DATA(cl
,obj
);
318 set(_app(obj
),MUIA_Application_Sleep
,TRUE
);
320 /* Copy settings from gadgets into structure */
321 up
.up_Version
= PREFS_VERSION
;
322 NewList((struct List
*)&up
.up_BrowserList
);
323 NewList((struct List
*)&up
.up_MailerList
);
324 NewList((struct List
*)&up
.up_FTPList
);
329 struct URL_BrowserNode
*bn
;
331 DoMethod(data
->browserList
,MUIM_List_GetEntry
,i
,(ULONG
)&bn
);
334 if (!(bn
->ubn_Flags
& UNF_NEW
))
335 AddTail((struct List
*)&up
.up_BrowserList
,(struct Node
*)bn
);
340 struct URL_MailerNode
*mn
;
342 DoMethod(data
->mailerList
,MUIM_List_GetEntry
,i
,(ULONG
)&mn
);
345 if (!(mn
->umn_Flags
& UNF_NEW
))
346 AddTail((struct List
*)&up
.up_MailerList
,(struct Node
*)mn
);
352 struct URL_FTPNode
*fn
;
354 DoMethod(data
->FTPList
,MUIM_List_GetEntry
,i
,(ULONG
)&fn
);
357 if (!(fn
->ufn_Flags
& UNF_NEW
))
358 AddTail((struct List
*)&up
.up_FTPList
,(struct Node
*)fn
);
362 if (xget(data
->prepend
,MUIA_Selected
)) up
.up_Flags
|= UPF_PREPENDHTTP
;
363 else up
.up_Flags
&= ~UPF_PREPENDHTTP
;
365 if (xget(data
->mailto
,MUIA_Selected
)) up
.up_Flags
|= UPF_DOMAILTO
;
366 else up
.up_Flags
&= ~UPF_DOMAILTO
;
368 if (xget(data
->useFTP
,MUIA_Selected
)) up
.up_Flags
|= UPF_DOFTP
;
369 else up
.up_Flags
&= ~UPF_DOFTP
;
371 up
.up_DefShow
= (ULONG
)xget(data
->show
,MUIA_Selected
);
372 up
.up_DefBringToFront
= (ULONG
)xget(data
->toFront
,MUIA_Selected
);
373 up
.up_DefNewWindow
= (ULONG
)xget(data
->newWin
,MUIA_Selected
);
374 up
.up_DefLaunch
= (ULONG
)xget(data
->launch
,MUIA_Selected
);
377 if (!URL_SetPrefs(&up
,URL_SetPrefs_Save
,msg
->How
==MUIV_Win_StorePrefs_Save
,TAG_DONE
))
378 MUI_RequestA(_app(obj
),obj
,0,getString(MSG_ErrReqTitle
),getString(MSG_ErrReqGadget
),getString(MSG_Err_FailedSave
),NULL
);
380 set(_app(obj
),MUIA_Application_Sleep
,FALSE
);
383 if (msg
->How
!=MUIV_Win_StorePrefs_Apply
)
384 DoMethod(_app(obj
),MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
389 /**************************************************************************/
392 mDelete(struct IClass
*cl
,Object
*obj
,struct MUIP_Win_Delete
*msg
)
394 struct data
*data
= INST_DATA(cl
,obj
);
396 if (!delEntry(data
->browserList
,msg
->entry
))
397 if (!delEntry(data
->mailerList
,msg
->entry
))
398 delEntry(data
->FTPList
,msg
->entry
);
403 /**************************************************************************/
406 mCheckSave(struct IClass
*cl
,Object
*obj
,Msg msg
)
408 struct data
*data
= INST_DATA(cl
,obj
);
410 return (ULONG
)(DoMethod(data
->browsers
,MUIM_App_CheckSave
) ||
411 DoMethod(data
->mailers
,MUIM_App_CheckSave
) ||
412 DoMethod(data
->FTPs
,MUIM_App_CheckSave
));
415 /**************************************************************************/
421 switch (msg
->MethodID
)
423 case OM_NEW
: return mNew(cl
,obj
,(APTR
)msg
);
424 case OM_SET
: return mSets(cl
,obj
,(APTR
)msg
);
426 case MUIM_Win_GetPrefs
: return mGetPrefs(cl
,obj
,(APTR
)msg
);
427 case MUIM_Win_StorePrefs
: return mStorePrefs(cl
,obj
,(APTR
)msg
);
428 case MUIM_Win_Delete
: return mDelete(cl
,obj
,(APTR
)msg
);
429 case MUIM_App_CheckSave
: return mCheckSave(cl
,obj
,(APTR
)msg
);
430 //case 0x80426771: return FALSE;
432 default: return DoSuperMethodA(cl
,obj
,msg
);
436 M_DISPEND(dispatcher
)
438 /**************************************************************************/
443 if (g_winClass
= MUI_CreateCustomClass(NULL
,MUIC_Window
,NULL
,sizeof(struct data
),DISP(dispatcher
)))
445 localizeStrings(tabs
);
453 /**************************************************************************/
456 disposeWinClass(void)
458 if (g_winClass
) MUI_DeleteCustomClass(g_winClass
);
461 /**************************************************************************/