Corrections to SVN properties.
[AROS.git] / external / openurl / prefs / OpenURL.c
blob3ec345b089d2b3125bebf18c5605ab04a7dfd29d
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-2009 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/
17 $Id$
19 ***************************************************************************/
21 #include <stdio.h>
23 #include "openurl.h"
25 #define CATCOMP_NUMBERS
26 #include "locale.h"
28 #include <graphics/gfxbase.h>
30 #include <libraries/openurl.h>
32 #include "macros.h"
34 #include "debug.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;
48 #else
49 struct Library *LocaleBase = NULL;
50 #endif
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;
72 APTR g_pool = NULL;
73 struct Catalog *g_cat = NULL;
74 BOOL g_MUI4 = FALSE;
76 /**************************************************************************/
78 static ULONG openStuff(ULONG *arg0, ULONG *arg1)
80 *arg1 = 0;
82 if((MUIMasterBase = OpenLibrary("muimaster.library",19)) == NULL ||
83 !GETINTERFACE(IMUIMaster, MUIMasterBase))
85 *arg0 = 19;
86 return MSG_Err_NoMUI;
89 if(MUIMasterBase->lib_Version < 20)
90 g_MUI4 = FALSE;
91 else if (MUIMasterBase->lib_Version==20)
92 g_MUI4 = MUIMasterBase->lib_Revision>5341;
93 else
94 g_MUI4 = TRUE;
96 #if defined(__amigaos4__)
97 g_pool = AllocSysObjectTags(ASOT_MEMPOOL,
98 ASOPOOL_MFlags, MEMF_SHARED|MEMF_CLEAR,
99 ASOPOOL_Puddle, 8192,
100 ASOPOOL_Threshold, 4196,
101 ASOPOOL_Name, (ULONG)"OpenURL shared pool",
102 ASOPOOL_LockMem, FALSE,
103 TAG_DONE);
104 #else
105 g_pool = CreatePool(MEMF_PUBLIC|MEMF_CLEAR,8192,4196);
106 #endif
107 if(g_pool == NULL)
108 return MSG_Err_NoMem;
110 *arg0 = 37;
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)))
133 *arg0 = OPENURLVER;
134 *arg1 = OPENURLREV;
136 return MSG_Err_NoOpenURL;
139 #if defined(__amigaos4__)
140 // setup the AmiUpdate variable
141 SetAmiUpdateENVVariable( "OpenURL" );
142 #endif /* __amigaos4__ */
144 return 0;
147 /**************************************************************************/
149 static void closeStuff(void)
151 if (LocaleBase)
153 uninitStrings();
155 if(g_cat)
156 CloseCatalog(g_cat);
158 DROPINTERFACE(ILocale);
159 CloseLibrary((struct Library *)LocaleBase);
160 LocaleBase = NULL;
163 if(OpenURLBase)
165 DROPINTERFACE(IOpenURL);
166 CloseLibrary(OpenURLBase);
167 OpenURLBase = NULL;
170 if(IconBase)
172 DROPINTERFACE(IIcon);
173 CloseLibrary(IconBase);
174 IconBase = NULL;
177 if(UtilityBase)
179 DROPINTERFACE(IUtility);
180 CloseLibrary(UtilityBase);
181 UtilityBase = NULL;
184 if(GfxBase)
186 DROPINTERFACE(IGraphics);
187 CloseLibrary((struct Library *)GfxBase);
188 GfxBase = NULL;
191 if(IntuitionBase)
193 DROPINTERFACE(IIntuition);
194 CloseLibrary((struct Library *)IntuitionBase);
195 IntuitionBase = NULL;
198 if(MUIMasterBase)
200 DROPINTERFACE(IMUIMaster);
201 CloseLibrary(MUIMasterBase);
202 MUIMasterBase = NULL;
205 if(g_pool != NULL)
207 #if defined(__amigaos4__)
208 FreeSysObject(ASOT_MEMPOOL, g_pool);
209 #else
210 DeletePool(g_pool);
211 #endif
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;
228 return 0;
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 /**************************************************************************/
248 int main(void)
250 ULONG error, arg0=0, arg1=0;
251 int res = RETURN_FAIL;
253 // setup the debugging stuff
254 #if defined(DEBUG)
255 SetupDebug();
256 #endif
258 initStrings();
260 if (!(error = openStuff(&arg0,&arg1)))
262 if (!(error = createClasses()))
264 Object *app;
266 if((app = appObject, End) != NULL)
268 ULONG signals;
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);
275 res = RETURN_OK;
277 else error = MSG_Err_NoApp;
279 disposeClasses();
283 if (error)
285 TEXT buf[256];
287 snprintf(buf, sizeof(buf), getString(error), arg0, arg1);
289 if (MUIMasterBase)
291 Object *app = ApplicationObject,
292 MUIA_Application_UseCommodities, FALSE,
293 MUIA_Application_UseRexx, FALSE,
294 End;
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);
303 closeStuff();
305 return res;
308 /**************************************************************************/