revert between 56095 -> 55830 in arch
[AROS.git] / external / openurl / prefs / app.c
blob985e377ec4fcddd87e9d882a1e7aa898201464d3
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/
17 $Id$
19 ***************************************************************************/
21 #include "openurl.h"
23 #define CATCOMP_NUMBERS
24 #include "locale.h"
25 #include "version.h"
27 #include <libraries/openurl.h>
29 #include "SDI_hook.h"
31 #include "debug.h"
33 /**************************************************************************/
35 struct data
37 Object *win;
38 Object *about;
40 struct DiskObject *icon;
43 /**************************************************************************/
45 ** Menus
48 static struct NewMenu menu[] =
50 MTITLE(MSG_Menu_Project),
51 MITEM(MSG_Menu_About),
52 MITEM(MSG_Menu_AboutMUI),
53 MBAR,
54 MITEM(MSG_Menu_Hide),
55 MBAR,
56 MITEM(MSG_Menu_Quit),
58 MTITLE(MSG_Menu_Prefs),
59 MITEM(MSG_Menu_Save),
60 MITEM(MSG_Menu_Use),
61 MBAR,
62 MITEM(MSG_Menu_LastSaved),
63 MITEM(MSG_Menu_Restore),
64 MITEM(MSG_Menu_Defaults),
65 MBAR,
66 MITEM(MSG_Menu_MUI),
68 MEND
72 ** Used classes
75 static CONST_STRPTR usedClasses[] =
77 "Urltext.mcc",
78 NULL
82 ** Here we go
84 static IPTR mNew(struct IClass *cl, Object *obj, struct opSet *msg)
86 Object *strip, *win;
88 if((obj = (Object *)DoSuperNew(cl,obj,
89 MUIA_Application_Title, "OpenURL-Prefs",
90 MUIA_Application_Version, "$VER: OpenURL-Prefs " LIB_REV_STRING " [" SYSTEMSHORT "/" CPU "] (" LIB_DATE ") " LIB_COPYRIGHT,
91 MUIA_Application_Author, APPAUTHOR,
92 MUIA_Application_Copyright, getString(MSG_App_Copyright),
93 MUIA_Application_Description, getString(MSG_App_Description),
94 MUIA_Application_HelpFile, APPHELP,
95 MUIA_Application_Base, APPBASENAME,
96 MUIA_Application_Menustrip, strip = MUI_MakeObject(MUIO_MenustripNM,(IPTR)menu,MUIO_MenustripNM_CommandKeyCheck),
97 MUIA_Application_UsedClasses, usedClasses,
98 MUIA_Application_Window, win = winObject, End,
99 TAG_MORE,msg->ops_AttrList)) != NULL)
101 struct data *data = INST_DATA(cl,obj);
104 ** Setup data
107 data->win = win;
109 if((data->icon = GetDiskObject((STRPTR)"PROGDIR:OpenURL")) != NULL)
110 superset(cl,obj,MUIA_Application_DiskObject,data->icon);
112 /* Menus */
114 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_About),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,1,MUIM_App_About);
115 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_AboutMUI),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)MUIV_Notify_Application,2,MUIM_Application_AboutMUI,(IPTR)win);
116 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_Hide),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,3,MUIM_Set,MUIA_Application_Iconified,TRUE);
117 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_Quit),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
119 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_Save),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)win,2,MUIM_Win_StorePrefs,MUIV_Win_StorePrefs_Save);
120 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_Use),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)win,2,MUIM_Win_StorePrefs,MUIV_Win_StorePrefs_Use);
121 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_LastSaved),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,2,MUIM_App_GetPrefs,MUIV_App_GetPrefs_LastSaveds);
122 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_Restore),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,2,MUIM_App_GetPrefs,MUIV_App_GetPrefs_Restore);
123 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_Defaults),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,2,MUIM_App_GetPrefs,MUIV_App_GetPrefs_Defaults);
124 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MSG_Menu_MUI),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,(IPTR)obj,2,MUIM_Application_OpenConfigWindow,0);
126 /* Menus help */
127 DoSuperMethod(cl,obj,MUIM_Notify,MUIA_Application_MenuHelp,MUIV_EveryTime,MUIV_Notify_Self,
128 5,MUIM_Application_ShowHelp,(IPTR)win,(IPTR)APPHELP,(IPTR)"MENUS",0);
131 ** Load list formats
133 DoSuperMethod(cl,obj,MUIM_Application_Load,(IPTR)MUIV_Application_Load_ENV);
136 ** Try to get OpenURL prefs and open window
138 if (!DoMethod(win,MUIM_Win_GetPrefs,MUIV_Win_GetPrefs_Restore) || !openWindow(obj,win))
140 CoerceMethod(cl,obj,OM_DISPOSE);
142 return 0;
146 return (IPTR)obj;
149 /***********************************************************************/
151 static IPTR mDispose(struct IClass *cl, Object *obj, Msg msg)
153 struct data *data = INST_DATA(cl,obj);
154 struct DiskObject *icon = data->icon;
155 IPTR res;
158 ** Because of users hate an app that saves on disc
159 ** at any exit, we check if you must save something
161 if (DoMethod(data->win,MUIM_App_CheckSave))
163 DoSuperMethod(cl,obj,MUIM_Application_Save,(IPTR)MUIV_Application_Save_ENV);
164 DoSuperMethod(cl,obj,MUIM_Application_Save,(IPTR)MUIV_Application_Save_ENVARC);
167 res = DoSuperMethodA(cl,obj,msg);
169 if (icon) FreeDiskObject(icon);
171 return res;
174 /***********************************************************************/
176 static Object *findWinObjByAttr(Object *app, ULONG attr, IPTR val)
178 struct List *winlist;
179 Object *obj;
180 Object *state;
182 /* return the window object which supports OM_GET on attr, and
183 whose value of attr == val */
185 winlist = (struct List *)xget(app,MUIA_Application_WindowList);
186 state = (Object *)winlist->lh_Head;
188 while((obj = NextObject(&state)) != NULL)
190 IPTR value;
192 if((value = xget(obj,attr)) != 0 && (value == val))
193 break;
196 return obj;
199 /**************************************************************************/
201 static IPTR mOpenWin(UNUSED struct IClass *cl, Object *obj, struct MUIP_App_OpenWin *msg)
203 Object *win = findWinObjByAttr(obj,msg->IDAttr,msg->IDVal);
205 if (!win)
207 set(obj,MUIA_Application_Sleep,TRUE);
209 win = NewObject(msg->Class, NULL,
210 msg->IDAttr, msg->IDVal,
211 TAG_MORE, &msg->InitAttrs);
213 if (win) DoMethod(obj,OM_ADDMEMBER,(IPTR)win);
215 set(obj,MUIA_Application_Sleep,FALSE);
218 return openWindow(obj,win);
221 /**************************************************************************/
223 static IPTR mCloseWin(struct IClass *cl, Object *obj, struct MUIP_App_CloseWin *msg)
225 struct data *data = INST_DATA(cl,obj);
226 Object *win = findWinObjByAttr(obj,msg->IDAttr,msg->IDVal);
228 if (win)
230 set(win,MUIA_Window_Open,FALSE);
231 DoMethod(obj,OM_REMMEMBER,(IPTR)win);
232 MUI_DisposeObject(win);
234 if (isFlagSet(((struct URL_Node *)msg->IDVal)->Flags, UNF_NEW))
235 DoMethod(data->win,MUIM_Win_Delete,msg->IDVal);
238 return TRUE;
241 /**************************************************************************/
243 static IPTR mOpenConfigWindow(struct IClass *cl, Object *obj, Msg msg)
245 IPTR res;
247 set(obj,MUIA_Application_Sleep,TRUE);
248 res = DoSuperMethodA(cl,obj,(Msg)msg);
249 set(obj,MUIA_Application_Sleep,FALSE);
251 return res;
254 /***********************************************************************/
256 static IPTR mDisposeWin(struct IClass *cl, Object *obj, struct MUIP_App_DisposeWin *msg)
258 struct data *data = INST_DATA(cl,obj);
259 Object *win = msg->win;
261 set(win,MUIA_Window_Open,FALSE);
262 DoSuperMethod(cl,obj,OM_REMMEMBER,(IPTR)win);
263 MUI_DisposeObject(win);
265 if(win==data->about)
266 data->about = NULL;
268 return 0;
271 /***********************************************************************/
273 static IPTR mAbout(struct IClass *cl, Object *obj, UNUSED Msg msg)
275 struct data *data = INST_DATA(cl,obj);
277 superset(cl,obj,MUIA_Application_Sleep,TRUE);
279 if(data->about == NULL)
281 if(g_aboutClass != NULL || initAboutClass() == TRUE)
283 if((data->about = aboutObject,
284 MUIA_Aboutmui_Application, obj,
285 MUIA_Window_RefWindow, data->win,
286 End) != NULL)
288 DoSuperMethod(cl,obj,OM_ADDMEMBER,(IPTR)data->about);
289 DoMethod(data->about,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,(IPTR)obj,5,
290 MUIM_Application_PushMethod,(IPTR)obj,2,MUIM_App_DisposeWin,(IPTR)data->about);
295 openWindow(obj,data->about);
297 superset(cl,obj,MUIA_Application_Sleep,FALSE);
299 return 0;
302 /***********************************************************************/
304 static void closeAllWindows(Object *app)
306 BOOL loop;
308 ENTER();
312 struct List *list;
313 Object *mstate;
314 Object *win;
316 loop = FALSE;
318 list = (struct List *)xget(app, MUIA_Application_WindowList);
319 mstate = (Object *)list->lh_Head;
321 while((win = NextObject(&mstate)) != NULL)
323 ULONG ok = FALSE;
325 ok = xget(win, MUIA_App_IsSubWin);
326 if(ok)
328 set(win, MUIA_Window_Open, FALSE);
329 DoMethod(app, OM_REMMEMBER, (IPTR)win);
330 MUI_DisposeObject(win);
331 loop = TRUE;
332 break;
336 while(loop == TRUE);
338 LEAVE();
341 /***********************************************************************/
343 static IPTR mGetPrefs(struct IClass *cl, Object *obj, struct MUIP_App_GetPrefs *msg)
345 struct data *data = INST_DATA(cl,obj);
347 set(obj,MUIA_Application_Sleep,TRUE);
349 closeAllWindows(obj);
350 DoMethod(data->win,MUIM_Win_GetPrefs,msg->mode);
352 set(obj,MUIA_Application_Sleep,FALSE);
354 return 0;
357 /***********************************************************************/
359 SDISPATCHER(dispatcher)
361 switch (msg->MethodID)
363 case OM_NEW: return mNew(cl,obj,(APTR)msg);
364 case OM_DISPOSE: return mDispose(cl,obj,(APTR)msg);
366 case MUIM_Application_OpenConfigWindow: return mOpenConfigWindow(cl,obj,(APTR)msg);
368 case MUIM_App_OpenWin: return mOpenWin(cl,obj,(APTR)msg);
369 case MUIM_App_CloseWin: return mCloseWin(cl,obj,(APTR)msg);
370 case MUIM_App_About: return mAbout(cl,obj,(APTR)msg);
371 case MUIM_App_DisposeWin: return mDisposeWin(cl,obj,(APTR)msg);
372 case MUIM_App_GetPrefs: return mGetPrefs(cl,obj,(APTR)msg);
374 default: return DoSuperMethodA(cl,obj,msg);
378 /**************************************************************************/
380 BOOL initAppClass(void)
382 BOOL success = FALSE;
384 ENTER();
386 if((g_appClass = MUI_CreateCustomClass(NULL, MUIC_Application, NULL, sizeof(struct data), ENTRY(dispatcher))) != NULL)
388 localizeNewMenu(menu);
389 success = TRUE;
392 RETURN(success);
393 return success;
396 /**************************************************************************/
398 void disposeAppClass(void)
400 if(g_appClass != NULL)
401 MUI_DeleteCustomClass(g_appClass);
404 /**************************************************************************/