1 /***************************************************************************
3 openurl.library - universal URL display and browser launcher library
4 Copyright (C) 1998-2005 by Troels Walsted Hansen, et al.
5 Copyright (C) 2005-2013 by openurl.library Open Source Team
7 This library is free software; it has been placed in the public domain
8 and you can freely redistribute it and/or modify it. Please note, however,
9 that some components may be under the LGPL or GPL license.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 openurl.library project: http://sourceforge.net/projects/openurllib/
19 ***************************************************************************/
21 #include <proto/openurl.h>
25 #define CATCOMP_NUMBERS
28 #include <libraries/openurl.h>
35 /**************************************************************************/
74 /**************************************************************************/
76 static STRPTR tabs
[] =
78 (STRPTR
)MSG_Win_Labels_Browsers
,
79 (STRPTR
)MSG_Win_Labels_Mailers
,
80 (STRPTR
)MSG_Win_Labels_FTPs
,
81 (STRPTR
)MSG_Win_Labels_Misc
,
85 static IPTR
mNew(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
89 memset(&temp
,0,sizeof(temp
));
91 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
93 MUIA_Window_ID
, MAKE_ID('M', 'W', 'I', 'N'),
94 MUIA_Window_Title
, getString(MSG_Win_WinTitle
),
95 MUIA_Window_ScreenTitle
, getString(MSG_App_ScreenTitle
),
97 WindowContents
, VGroup
,
98 Child
, temp
.reg
= RegisterObject
,
99 MUIA_Background
, MUII_RegisterBack
,
100 MUIA_CycleChain
, TRUE
,
101 MUIA_Register_Titles
, tabs
,
104 Child
, temp
.browsers
= appListObject
,
105 MUIA_AppList_Type
, MUIV_AppList_Type_Browser
,
109 Child
, temp
.mailers
= appListObject
,
110 MUIA_AppList_Type
, MUIV_AppList_Type_Mailer
,
114 Child
, temp
.FTPs
= appListObject
,
115 MUIA_AppList_Type
, MUIV_AppList_Type_FTP
,
119 Child
, temp
.misc
= VGroup
,
120 MUIA_HelpNode
, "MISCS",
124 GroupFrameT(getString(MSG_Misc_Defaults
)),
127 Child
, temp
.show
= ocheckmark(MSG_Misc_Show
,MSG_Misc_Show_Help
),
128 Child
, ollabel1(MSG_Misc_Show
),
129 Child
, temp
.toFront
= ocheckmark(MSG_Misc_Bring
,MSG_Misc_Bring_Help
),
130 Child
, ollabel1(MSG_Misc_Bring
),
131 Child
, temp
.newWin
= ocheckmark(MSG_Misc_Open
,MSG_Misc_Open_Help
),
132 Child
, ollabel1(MSG_Misc_Open
),
133 Child
, temp
.launch
= ocheckmark(MSG_Misc_Launch
,MSG_Misc_Launch_Help
),
134 Child
, ollabel1(MSG_Misc_Launch
),
143 GroupFrameT(getString(MSG_Misc_Options
)),
146 Child
, temp
.prepend
= ocheckmark(MSG_Misc_Prepend
,MSG_Misc_Prepend_Help
),
147 Child
, ollabel1(MSG_Misc_Prepend
),
148 Child
, temp
.mailto
= ocheckmark(MSG_Misc_UseMailer
,MSG_Misc_UseMailer_Help
),
149 Child
, ollabel1(MSG_Misc_UseMailer
),
150 Child
, temp
.useFTP
= ocheckmark(MSG_Misc_UseFTP
,MSG_Misc_UseFTP_Help
),
151 Child
, ollabel1(MSG_Misc_UseFTP
),
161 Child
, temp
.save
= obutton(MSG_Win_Save
,MSG_Win_Save_Help
),
163 Child
, temp
.use
= obutton(MSG_Win_Use
,MSG_Win_Use_Help
),
165 Child
, temp
.apply
= obutton(MSG_Win_Apply
,MSG_Win_Apply_Help
),
167 Child
, temp
.cancel
= obutton(MSG_Win_Cancel
,MSG_Win_Cancel_Help
),
171 TAG_MORE
, msg
->ops_AttrList
)) != NULL
)
173 struct data
*data
= INST_DATA(cl
,obj
);
175 /* init instance data */
176 CopyMem(&temp
,data
,sizeof(*data
));
178 data
->browserList
= (Object
*)xget(data
->browsers
, MUIA_AppList_ListObj
);
179 data
->mailerList
= (Object
*)xget(data
->mailers
, MUIA_AppList_ListObj
);
180 data
->FTPList
= (Object
*)xget(data
->FTPs
, MUIA_AppList_ListObj
);
183 set(obj
,MUIA_Window_DefaultObject
,data
->browserList
);
185 /* window notifies */
186 DoMethod(obj
,MUIM_Notify
,MUIA_Window_CloseRequest
,TRUE
,MUIV_Notify_Application
,2,
187 MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
189 /* buttons notifies */
190 DoMethod(data
->save
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(IPTR
)obj
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Save
);
191 DoMethod(data
->use
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(IPTR
)obj
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Use
);
192 DoMethod(data
->apply
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(IPTR
)obj
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Apply
);
193 DoMethod(data
->cancel
,MUIM_Notify
,MUIA_Pressed
,FALSE
,MUIV_Notify_Application
,2,MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
199 /**************************************************************************/
201 static IPTR
mGetPrefs(struct IClass
*cl
,Object
*obj
, struct MUIP_Win_GetPrefs
*msg
)
203 struct data
*data
= INST_DATA(cl
,obj
);
205 struct URL_BrowserNode
*bn
;
206 struct URL_MailerNode
*mn
;
207 struct URL_FTPNode
*fn
;
208 ULONG mode
, error
= 0;
210 /* get the openurl.library prefs */
214 case MUIV_Win_GetPrefs_InUse
: mode
= URL_GetPrefs_Mode_InUse
; break;
215 case MUIV_Win_GetPrefs_LastSaveds
: mode
= URL_GetPrefs_Mode_Envarc
; break;
216 case MUIV_Win_GetPrefs_Restore
: mode
= URL_GetPrefs_Mode_Env
; break;
217 case MUIV_Win_GetPrefs_Defaults
: mode
= URL_GetPrefs_Mode_Default
; break;
218 default: return FALSE
;
221 p
= URL_GetPrefs(URL_GetPrefs_Mode
,mode
,TAG_DONE
);
222 if (!p
) error
= MSG_Err_NoPrefs
;
223 else if (p
->up_Version
!=PREFS_VERSION
) error
= MSG_Err_BadPrefs
;
227 MUI_Request(_app(obj
),NULL
,0,getString(MSG_ErrReqTitle
),
228 getString(MSG_ErrReqGadget
),
230 p
? p
->up_Version
: 0);
232 if (p
) URL_FreePrefsA(p
,NULL
);
238 set(data
->browserList
,MUIA_List_Quiet
,TRUE
);
239 DoMethod(data
->browserList
,MUIM_List_Clear
);
241 for (bn
= (struct URL_BrowserNode
*)p
->up_BrowserList
.mlh_Head
;
242 bn
->ubn_Node
.mln_Succ
;
243 bn
= (struct URL_BrowserNode
*)bn
->ubn_Node
.mln_Succ
)
245 DoMethod(data
->browserList
,MUIM_List_InsertSingle
,(IPTR
)bn
,MUIV_List_Insert_Bottom
);
248 set(data
->browserList
,MUIA_List_Quiet
,FALSE
);
251 set(data
->mailerList
,MUIA_List_Quiet
,TRUE
);
252 DoMethod(data
->mailerList
,MUIM_List_Clear
);
254 for (mn
= (struct URL_MailerNode
*)p
->up_MailerList
.mlh_Head
;
255 mn
->umn_Node
.mln_Succ
;
256 mn
= (struct URL_MailerNode
*)mn
->umn_Node
.mln_Succ
)
258 DoMethod(data
->mailerList
,MUIM_List_InsertSingle
,(IPTR
)mn
,MUIV_List_Insert_Bottom
);
261 set(data
->mailerList
,MUIA_List_Quiet
,FALSE
);
264 set(data
->FTPList
,MUIA_List_Quiet
,TRUE
);
265 DoMethod(data
->FTPList
,MUIM_List_Clear
);
267 for (fn
= (struct URL_FTPNode
*)p
->up_FTPList
.mlh_Head
;
268 fn
->ufn_Node
.mln_Succ
;
269 fn
= (struct URL_FTPNode
*)fn
->ufn_Node
.mln_Succ
)
271 DoMethod(data
->FTPList
,MUIM_List_InsertSingle
,(IPTR
)fn
,MUIV_List_Insert_Bottom
);
274 set(data
->FTPList
,MUIA_List_Quiet
,FALSE
);
277 set(data
->prepend
, MUIA_Selected
, isFlagSet(p
->up_Flags
, UPF_PREPENDHTTP
));
278 set(data
->mailto
, MUIA_Selected
, isFlagSet(p
->up_Flags
, UPF_DOMAILTO
));
279 set(data
->useFTP
, MUIA_Selected
, isFlagSet(p
->up_Flags
, UPF_DOFTP
));
281 set(data
->show
, MUIA_Selected
, p
->up_DefShow
);
282 set(data
->toFront
, MUIA_Selected
, p
->up_DefBringToFront
);
283 set(data
->newWin
, MUIA_Selected
, p
->up_DefNewWindow
);
284 set(data
->launch
, MUIA_Selected
, p
->up_DefLaunch
);
286 /* Activate the first entry */
287 DoSuperMethod(cl
,obj
,MUIM_MultiSet
,MUIA_List_Active
,MUIV_List_Active_Top
,
288 (IPTR
)data
->browserList
,
289 (IPTR
)data
->mailerList
,
293 URL_FreePrefsA(p
,NULL
);
298 /**************************************************************************/
300 static IPTR
mStorePrefs(struct IClass
*cl
, Object
*obj
, struct MUIP_Win_StorePrefs
*msg
)
302 struct data
*data
= INST_DATA(cl
,obj
);
306 set(_app(obj
),MUIA_Application_Sleep
,TRUE
);
308 /* Copy settings from gadgets into structure */
309 up
.up_Version
= PREFS_VERSION
;
310 NewList((struct List
*)&up
.up_BrowserList
);
311 NewList((struct List
*)&up
.up_MailerList
);
312 NewList((struct List
*)&up
.up_FTPList
);
317 struct URL_BrowserNode
*bn
;
319 DoMethod(data
->browserList
,MUIM_List_GetEntry
,i
,(IPTR
)&bn
);
322 if(isFlagClear(bn
->ubn_Flags
, UNF_NEW
))
323 AddTail((struct List
*)&up
.up_BrowserList
,(struct Node
*)bn
);
329 struct URL_MailerNode
*mn
;
331 DoMethod(data
->mailerList
,MUIM_List_GetEntry
,i
,(IPTR
)&mn
);
334 if(isFlagClear(mn
->umn_Flags
, UNF_NEW
))
335 AddTail((struct List
*)&up
.up_MailerList
,(struct Node
*)mn
);
341 struct URL_FTPNode
*fn
;
343 DoMethod(data
->FTPList
,MUIM_List_GetEntry
,i
,(IPTR
)&fn
);
346 if(isFlagClear(fn
->ufn_Flags
, UNF_NEW
))
347 AddTail((struct List
*)&up
.up_FTPList
,(struct Node
*)fn
);
351 if (xget(data
->prepend
,MUIA_Selected
))
352 SET_FLAG(up
.up_Flags
, UPF_PREPENDHTTP
);
354 CLEAR_FLAG(up
.up_Flags
, UPF_PREPENDHTTP
);
356 if (xget(data
->mailto
,MUIA_Selected
))
357 SET_FLAG(up
.up_Flags
, UPF_DOMAILTO
);
359 CLEAR_FLAG(up
.up_Flags
, UPF_DOMAILTO
);
361 if (xget(data
->useFTP
,MUIA_Selected
))
362 SET_FLAG(up
.up_Flags
, UPF_DOFTP
);
364 CLEAR_FLAG(up
.up_Flags
, UPF_DOFTP
);
366 up
.up_DefShow
= (ULONG
)xget(data
->show
,MUIA_Selected
);
367 up
.up_DefBringToFront
= (ULONG
)xget(data
->toFront
,MUIA_Selected
);
368 up
.up_DefNewWindow
= (ULONG
)xget(data
->newWin
,MUIA_Selected
);
369 up
.up_DefLaunch
= (ULONG
)xget(data
->launch
,MUIA_Selected
);
372 if (!URL_SetPrefs(&up
,URL_SetPrefs_Save
,msg
->How
==MUIV_Win_StorePrefs_Save
,TAG_DONE
))
373 MUI_RequestA(_app(obj
),obj
,0,getString(MSG_ErrReqTitle
),getString(MSG_ErrReqGadget
),getString(MSG_Err_FailedSave
),NULL
);
375 set(_app(obj
),MUIA_Application_Sleep
,FALSE
);
378 if (msg
->How
!=MUIV_Win_StorePrefs_Apply
)
379 DoMethod(_app(obj
),MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
384 /**************************************************************************/
386 static IPTR
mDelete(struct IClass
*cl
, Object
*obj
, struct MUIP_Win_Delete
*msg
)
388 struct data
*data
= INST_DATA(cl
,obj
);
390 if (!delEntry(data
->browserList
,msg
->entry
))
391 if (!delEntry(data
->mailerList
,msg
->entry
))
392 delEntry(data
->FTPList
,msg
->entry
);
397 /**************************************************************************/
399 static IPTR
mCheckSave(struct IClass
*cl
, Object
*obj
, UNUSED Msg msg
)
401 struct data
*data
= INST_DATA(cl
,obj
);
403 return (IPTR
)(DoMethod(data
->browsers
,MUIM_App_CheckSave
) ||
404 DoMethod(data
->mailers
,MUIM_App_CheckSave
) ||
405 DoMethod(data
->FTPs
,MUIM_App_CheckSave
));
408 /**************************************************************************/
410 SDISPATCHER(dispatcher
)
412 switch (msg
->MethodID
)
414 case OM_NEW
: return mNew(cl
,obj
,(APTR
)msg
);
416 case MUIM_Win_GetPrefs
: return mGetPrefs(cl
,obj
,(APTR
)msg
);
417 case MUIM_Win_StorePrefs
: return mStorePrefs(cl
,obj
,(APTR
)msg
);
418 case MUIM_Win_Delete
: return mDelete(cl
,obj
,(APTR
)msg
);
419 case MUIM_App_CheckSave
: return mCheckSave(cl
,obj
,(APTR
)msg
);
420 //case 0x80426771: return FALSE;
422 default: return DoSuperMethodA(cl
,obj
,msg
);
426 /**************************************************************************/
428 BOOL
initWinClass(void)
430 BOOL success
= FALSE
;
434 if((g_winClass
= MUI_CreateCustomClass(NULL
, MUIC_Window
, NULL
, sizeof(struct data
), ENTRY(dispatcher
))) != NULL
)
436 localizeStrings(tabs
);
444 /**************************************************************************/
446 void disposeWinClass(void)
450 if(g_winClass
!= NULL
)
451 MUI_DeleteCustomClass(g_winClass
);
456 /**************************************************************************/