Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / openurl / prefs / OpenURL.c
blobda4a4795d0c0ff36a4b3fef7f13c4c6806155fa5
1 /*
2 ** OpenURL - MUI preferences for openurl.library
3 **
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
6 **
7 ** Developed by:
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
13 ** Main
17 #include "OpenURL.h"
18 #define CATCOMP_NUMBERS
19 #include "loc.h"
20 #include <graphics/gfxbase.h>
22 #include <libraries/openurl.h>
24 /**************************************************************************/
26 LONG __stack = 32000; /* I think this is OK in every env */
28 struct IntuitionBase *IntuitionBase = NULL;
29 struct GfxBase *GfxBase = NULL;
30 struct Library *MUIMasterBase = NULL;
31 #ifdef __AROS__
32 struct UtilityBase *UtilityBase = NULL;
33 #else
34 struct Library *UtilityBase = NULL;
35 #endif
36 struct Library *IconBase = NULL;
37 struct Library *OpenURLBase = NULL;
38 struct LocaleBase *LocaleBase = NULL;
40 #if defined(__amigaos4__)
41 struct IntuitionIFace *IIntuition = NULL;
42 struct GraphicsIFace *IGraphics = NULL;
43 struct MUIMasterIFace *IMUIMaster = NULL;
44 struct UtilityIFace *IUtility = NULL;
45 struct IconIFace *IIcon = NULL;
46 struct OpenURLIFace *IOpenURL = NULL;
47 struct LocaleIFace *ILocale = NULL;
48 #endif
50 struct MUI_CustomClass *g_appClass = NULL;
51 struct MUI_CustomClass *g_pensClass = NULL;
52 struct MUI_CustomClass *g_aboutClass = NULL;
53 struct MUI_CustomClass *g_winClass = NULL;
54 struct MUI_CustomClass *g_appListClass = NULL;
55 struct MUI_CustomClass *g_browserEditWinClass = NULL;
56 struct MUI_CustomClass *g_mailerEditWinClass = NULL;
57 struct MUI_CustomClass *g_FTPEditWinClass = NULL;
58 struct MUI_CustomClass *g_popportClass = NULL;
59 struct MUI_CustomClass *g_popphClass = NULL;
61 APTR g_pool = NULL;
62 struct Catalog *g_cat = NULL;
63 //ULONG g_MUI4 = FALSE;
65 /**************************************************************************/
67 static ULONG
68 openStuff(ULONG *arg0,ULONG *arg1)
70 *arg1 = 0;
72 if (!(MUIMasterBase = OpenLibrary("muimaster.library",19)) || (MUIMasterBase->lib_Version<19))
74 *arg0 = 19;
75 return MSG_Err_NoMUI;
77 #if defined(__amigaos4__)
78 if (!(IMUIMaster = (struct MUIMasterIFace *)GetInterface( MUIMasterBase, "main", 1L, NULL))) return MSG_Err_NoMUI;
79 #endif
80 if (!(g_pool = CreatePool(MEMF_PUBLIC|MEMF_CLEAR,8192,4196))) return MSG_Err_NoMem;
82 *arg0 = 37;
84 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37))) return MSG_Err_NoIntuition;
85 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37))) return MSG_Err_NoGfx;
86 if (!(UtilityBase = OpenLibrary("utility.library",37))) return MSG_Err_NoUtility;
87 if (!(IconBase = OpenLibrary("icon.library",37))) return MSG_Err_NoIcon;
89 #if defined(__amigaos4__)
90 if (!(IIntuition = (struct IntuitionIFace *)GetInterface( (struct Library*)IntuitionBase, "main", 1L, NULL))) return MSG_Err_NoIntuition;
91 if (!(IGraphics = (struct GraphicsIFace *)GetInterface( (struct Library*)GfxBase, "main", 1L, NULL))) return MSG_Err_NoGfx;
92 if (!(IUtility = (struct UtilityIFace *)GetInterface( UtilityBase, "main", 1L, NULL))) return MSG_Err_NoUtility;
93 if (!(IIcon = (struct IconIFace *)GetInterface( IconBase, "main", 1L, NULL))) return MSG_Err_NoIcon;
94 #endif
96 if (!(OpenURLBase = OpenLibrary(OPENURLNAME,6)) /*||
97 ((OpenURLBase->lib_Version==OPENURLREV) && (OpenURLBase->lib_Revision<OPENURLREV))*/)
99 *arg0 = OPENURLVER;
100 *arg1 = OPENURLREV;
102 return MSG_Err_NoOpenURL;
105 #if defined(__amigaos4__)
106 if (!(IOpenURL = (struct OpenURLIFace *)GetInterface( OpenURLBase, "main", 1L, NULL)))
108 *arg0 = OPENURLVER;
109 *arg1 = OPENURLREV;
111 return MSG_Err_NoOpenURL;
114 // setup the AmiUpdate variable
115 SetAmiUpdateENVVariable( "Open URL" );
116 #endif
118 return 0;
121 /**************************************************************************/
123 static void
124 closeStuff(void)
126 if (LocaleBase)
128 uninitStrings();
130 if (g_cat) CloseCatalog(g_cat);
132 #if defined(__amigaos4__)
133 if (ILocale)
135 DropInterface((struct Interface*)ILocale);
136 ILocale = NULL;
138 #endif
140 CloseLibrary((struct Library *)LocaleBase);
141 LocaleBase = NULL;
144 #if defined(__amigaos4__)
145 if (IMUIMaster)
147 DropInterface((struct Interface*)IMUIMaster);
148 IMUIMaster = NULL;
150 if (IIntuition)
152 DropInterface((struct Interface*)IIntuition);
153 IIntuition = NULL;
155 if (IUtility)
157 DropInterface((struct Interface*)IUtility);
158 IUtility = NULL;
160 if (IIcon)
162 DropInterface((struct Interface*)IIcon);
163 IIcon = NULL;
165 if (IOpenURL)
167 DropInterface((struct Interface*)IOpenURL);
168 IOpenURL = NULL;
170 #endif
172 if (OpenURLBase) CloseLibrary(OpenURLBase);
173 if (IconBase) CloseLibrary(IconBase);
174 if (UtilityBase) CloseLibrary(UtilityBase);
175 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
176 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
177 if (MUIMasterBase) CloseLibrary(MUIMasterBase);
179 if (g_pool) DeletePool(g_pool);
182 /**************************************************************************/
184 static ULONG
185 createClasses(void)
187 if (!initPopphClass()) return MSG_Err_PopphClass;
188 if (!initPopportClass()) return MSG_Err_PopupPortClass;
189 if (!initFTPEditWinClass()) return MSG_Err_NoFTPEditWinClass;
190 if (!initMailerEditWinClass()) return MSG_Err_NoMailerEditWinClass;
191 if (!initBrowserEditWinClass()) return MSG_Err_NoBrowserEditWinClass;
192 if (!initAppListClass()) return MSG_Err_NoAppListClass;
193 if (!initPensClass()) return MSG_Err_NoPensClass;
194 if (!initWinClass()) return MSG_Err_NoWinClass;
195 if (!initAppClass()) return MSG_Err_NoAppClass;
197 return 0;
200 /**************************************************************************/
202 static void
203 disposeClasses(void)
205 if (g_popphClass) disposePopphClass();
206 if (g_popportClass) disposePopportClass();
207 if (g_FTPEditWinClass) disposeFTPEditWinClass();
208 if (g_mailerEditWinClass) disposeMailerEditWinClass();
209 if (g_browserEditWinClass) disposeBrowserEditWinClass();
210 if (g_appListClass) disposeAppListClass();
211 if (g_winClass) disposeWinClass();
212 if (g_pensClass) disposePensClass();
213 if (g_aboutClass) disposeAboutClass();
214 if (g_appClass) disposeAppClass();
217 /**************************************************************************/
219 #ifdef __MORPHOS__
221 realMain(int argc,char **argv)
222 #else
224 main(int argc,char **argv)
225 #endif
227 ULONG error, arg0, arg1;
228 int res = RETURN_FAIL;
230 initStrings();
232 if (!(error = openStuff(&arg0,&arg1)))
234 if (!(error = createClasses()))
236 Object *app;
238 if (app = appObject, End)
240 ULONG signals;
242 for (signals = 0; DoMethod(app,MUIM_Application_NewInput,(ULONG)&signals)!=MUIV_Application_ReturnID_Quit; )
243 if (signals && ((signals = Wait(signals | SIGBREAKF_CTRL_C)) & SIGBREAKF_CTRL_C)) break;
245 MUI_DisposeObject(app);
247 res = RETURN_OK;
249 else error = MSG_Err_NoApp;
251 disposeClasses();
255 if (error)
257 TEXT buf[256];
259 msnprintf(buf,sizeof(buf),getString(error),arg0,arg1);
261 if (MUIMasterBase)
263 Object *app = ApplicationObject,
264 MUIA_Application_UseCommodities, FALSE,
265 MUIA_Application_UseRexx, FALSE,
266 End;
268 MUI_RequestA(app,NULL,0,getString(MSG_ErrReqTitle),getString(MSG_ErrReqGadget),buf,NULL);
270 if (app) MUI_DisposeObject(app);
272 else Printf("%s\n",(ULONG)buf);
275 closeStuff();
277 return res;
280 /**************************************************************************/
282 #ifdef __MORPHOS__
283 #define MIN68KSTACKSIZE 16000
286 main(int argc,char **argv)
288 struct Task *me = FindTask(NULL);
289 ULONG size;
291 if (!NewGetTaskAttrsA(me,&size,sizeof(size),TASKINFOTYPE_STACKSIZE_M68K,NULL))
292 return RETURN_ERROR;
294 if (size<MIN68KSTACKSIZE)
296 struct StackSwapStruct *sss;
298 if (sss = AllocMem(sizeof(*sss)+MIN68KSTACKSIZE,MEMF_PUBLIC))
300 int res;
302 sss->stk_Lower = sss+1;
303 sss->stk_Upper = (ULONG)(((UBYTE *)(sss + 1))+MIN68KSTACKSIZE);
304 sss->stk_Pointer = (APTR)sss->stk_Upper;
305 StackSwap(sss);
306 res = realMain(argc,argv);
307 StackSwap(sss);
308 FreeMem(sss,sizeof(*sss)+MIN68KSTACKSIZE);
310 return res;
314 return realMain(argc,argv);
317 #endif
319 /***********************************************************************/