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 ***************************************************************************/
25 #define CATCOMP_NUMBERS
28 #include <graphics/gfxbase.h>
30 #include <libraries/openurl.h>
36 /**************************************************************************/
38 LONG __stack
= 32000; /* I think this is OK for every env */
40 struct IntuitionBase
*IntuitionBase
= NULL
;
41 struct GfxBase
*GfxBase
= NULL
;
42 struct Library
*MUIMasterBase
= NULL
;
43 struct Library
*UtilityBase
= NULL
;
44 struct Library
*IconBase
= NULL
;
45 struct Library
*OpenURLBase
= NULL
;
46 #if !defined(__MORPHOS__)
47 struct LocaleBase
*LocaleBase
= NULL
;
49 struct Library
*LocaleBase
= NULL
;
52 #if defined(__amigaos4__)
53 struct IntuitionIFace
*IIntuition
= NULL
;
54 struct GraphicsIFace
*IGraphics
= NULL
;
55 struct MUIMasterIFace
*IMUIMaster
= NULL
;
56 struct UtilityIFace
*IUtility
= NULL
;
57 struct IconIFace
*IIcon
= NULL
;
58 struct OpenURLIFace
*IOpenURL
= NULL
;
59 struct LocaleIFace
*ILocale
= NULL
;
60 #endif /* __amigaos4__ */
62 struct MUI_CustomClass
*g_appClass
= NULL
;
63 struct MUI_CustomClass
*g_aboutClass
= NULL
;
64 struct MUI_CustomClass
*g_winClass
= NULL
;
65 struct MUI_CustomClass
*g_appListClass
= NULL
;
66 struct MUI_CustomClass
*g_browserEditWinClass
= NULL
;
67 struct MUI_CustomClass
*g_mailerEditWinClass
= NULL
;
68 struct MUI_CustomClass
*g_FTPEditWinClass
= NULL
;
69 struct MUI_CustomClass
*g_popportClass
= NULL
;
70 struct MUI_CustomClass
*g_popphClass
= NULL
;
73 struct Catalog
*g_cat
= NULL
;
76 /**************************************************************************/
78 static ULONG
openStuff(ULONG
*arg0
, ULONG
*arg1
)
82 if((MUIMasterBase
= OpenLibrary("muimaster.library",19)) == NULL
||
83 !GETINTERFACE(IMUIMaster
, MUIMasterBase
))
89 if(MUIMasterBase
->lib_Version
< 20)
91 else if (MUIMasterBase
->lib_Version
==20)
92 g_MUI4
= MUIMasterBase
->lib_Revision
>5341;
96 #if defined(__amigaos4__)
97 g_pool
= AllocSysObjectTags(ASOT_MEMPOOL
,
98 ASOPOOL_MFlags
, MEMF_SHARED
|MEMF_CLEAR
,
100 ASOPOOL_Threshold
, 4196,
101 ASOPOOL_Name
, (ULONG
)"OpenURL shared pool",
102 ASOPOOL_LockMem
, FALSE
,
105 g_pool
= CreatePool(MEMF_PUBLIC
|MEMF_CLEAR
,8192,4196);
108 return MSG_Err_NoMem
;
112 if((IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",37)) == NULL
||
113 !GETINTERFACE(IIntuition
, IntuitionBase
))
114 return MSG_Err_NoIntuition
;
116 if((GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",37)) == NULL
||
117 !GETINTERFACE(IGraphics
, GfxBase
))
118 return MSG_Err_NoGfx
;
120 if((UtilityBase
= OpenLibrary("utility.library",37)) == NULL
||
121 !GETINTERFACE(IUtility
, UtilityBase
))
122 return MSG_Err_NoUtility
;
124 if((IconBase
= OpenLibrary("icon.library",37)) == NULL
||
125 !GETINTERFACE(IIcon
, IconBase
))
126 return MSG_Err_NoIcon
;
128 if((OpenURLBase
= OpenLibrary(OPENURLNAME
,OPENURLVER
)) == NULL
||
129 !GETINTERFACE(IOpenURL
, OpenURLBase
) ||
130 ((OpenURLBase
->lib_Version
==7) && (OpenURLBase
->lib_Revision
<1)))
131 //((OpenURLBase->lib_Version==OPENURLREV) && (OpenURLBase->lib_Revision<OPENURLREV)))
136 return MSG_Err_NoOpenURL
;
139 #if defined(__amigaos4__)
140 // setup the AmiUpdate variable
141 SetAmiUpdateENVVariable( "OpenURL" );
142 #endif /* __amigaos4__ */
147 /**************************************************************************/
149 static void closeStuff(void)
158 DROPINTERFACE(ILocale
);
159 CloseLibrary((struct Library
*)LocaleBase
);
165 DROPINTERFACE(IOpenURL
);
166 CloseLibrary(OpenURLBase
);
172 DROPINTERFACE(IIcon
);
173 CloseLibrary(IconBase
);
179 DROPINTERFACE(IUtility
);
180 CloseLibrary(UtilityBase
);
186 DROPINTERFACE(IGraphics
);
187 CloseLibrary((struct Library
*)GfxBase
);
193 DROPINTERFACE(IIntuition
);
194 CloseLibrary((struct Library
*)IntuitionBase
);
195 IntuitionBase
= NULL
;
200 DROPINTERFACE(IMUIMaster
);
201 CloseLibrary(MUIMasterBase
);
202 MUIMasterBase
= NULL
;
207 #if defined(__amigaos4__)
208 FreeSysObject(ASOT_MEMPOOL
, g_pool
);
215 /**************************************************************************/
217 static ULONG
createClasses(void)
219 if (initPopphClass() == FALSE
) return MSG_Err_PopphClass
;
220 if (initPopportClass() == FALSE
) return MSG_Err_PopupPortClass
;
221 if (initFTPEditWinClass() == FALSE
) return MSG_Err_NoFTPEditWinClass
;
222 if (initMailerEditWinClass() == FALSE
) return MSG_Err_NoMailerEditWinClass
;
223 if (initBrowserEditWinClass() == FALSE
) return MSG_Err_NoBrowserEditWinClass
;
224 if (initAppListClass() == FALSE
) return MSG_Err_NoAppListClass
;
225 if (initWinClass() == FALSE
) return MSG_Err_NoWinClass
;
226 if (initAppClass() == FALSE
) return MSG_Err_NoAppClass
;
231 /**************************************************************************/
233 static void disposeClasses(void)
235 if (g_popphClass
) disposePopphClass();
236 if (g_popportClass
) disposePopportClass();
237 if (g_FTPEditWinClass
) disposeFTPEditWinClass();
238 if (g_mailerEditWinClass
) disposeMailerEditWinClass();
239 if (g_browserEditWinClass
) disposeBrowserEditWinClass();
240 if (g_appListClass
) disposeAppListClass();
241 if (g_winClass
) disposeWinClass();
242 if (g_aboutClass
) disposeAboutClass();
243 if (g_appClass
) disposeAppClass();
246 /**************************************************************************/
250 ULONG error
, arg0
=0, arg1
=0;
251 int res
= RETURN_FAIL
;
253 // setup the debugging stuff
260 if (!(error
= openStuff(&arg0
,&arg1
)))
262 if (!(error
= createClasses()))
266 if((app
= appObject
, End
) != NULL
)
270 for (signals
= 0; (LONG
)DoMethod(app
,MUIM_Application_NewInput
,(IPTR
)&signals
) != (LONG
)MUIV_Application_ReturnID_Quit
; )
271 if (signals
&& ((signals
= Wait(signals
| SIGBREAKF_CTRL_C
)) & SIGBREAKF_CTRL_C
)) break;
273 MUI_DisposeObject(app
);
277 else error
= MSG_Err_NoApp
;
287 snprintf(buf
, sizeof(buf
), getString(error
), arg0
, arg1
);
291 Object
*app
= ApplicationObject
,
292 MUIA_Application_UseCommodities
, FALSE
,
293 MUIA_Application_UseRexx
, FALSE
,
296 MUI_RequestA(app
,NULL
,0,getString(MSG_ErrReqTitle
),getString(MSG_ErrReqGadget
),buf
,NULL
);
298 if (app
) MUI_DisposeObject(app
);
300 else printf("%s\n", buf
);
308 /**************************************************************************/