Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / zune_gui / gui.c
blob1cbf1686912d14c68804bdf4e94d6dffb8304405
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 // ensure that DiskImageBase is struct Library *
28 #define __DISKIMAGE_STDLIBBASE__
30 #include "diskimagegui.h"
31 #include <proto/exec.h>
32 #include <proto/intuition.h>
33 #include <proto/muimaster.h>
34 #include <proto/commodities.h>
35 #include <proto/diskimage.h>
36 #include <clib/alib_protos.h>
37 #include "rev/DiskImageGUI_rev.h"
39 struct GUIElements Gui;
41 BOOL translate_gui = TRUE;
43 static struct NewMenu main_newmenu[] = {
44 { NM_TITLE, STR_ID(-1), NULL, 0, 0, MENU_ID(0) },
45 { NM_ITEM, STR_ID(MSG_PROJECT_ABOUT), "?", 0, 0, MENU_ID(MID_ABOUT) },
46 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
47 { NM_ITEM, STR_ID(MSG_PROJECT_HIDE), "H", 0, 0, MENU_ID(MID_HIDE) },
48 { NM_ITEM, STR_ID(MSG_PROJECT_ICONIFY), "I", 0, 0, MENU_ID(MID_ICONIFY) },
49 // { NM_ITEM, STR_ID(MSG_PROJECT_SNAPSHOT), NULL, 0, 0, MENU_ID(MID_SNAPSHOT) },
50 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
51 { NM_ITEM, STR_ID(MSG_PROJECT_QUIT), "Q", 0, 0, MENU_ID(MID_QUIT) },
52 { NM_TITLE, STR_ID(MSG_SETTINGS_MENU), NULL, 0, 0, MENU_ID(0) },
53 { NM_ITEM, STR_ID(MSG_SETTINGS_CHANGETEMPDIR), NULL, 0, 0, MENU_ID(MID_CHANGETEMPDIR) },
54 { NM_ITEM, STR_ID(MSG_SETTINGS_PLUGINS), "P", 0, 0, MENU_ID(MID_PLUGINS) },
55 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
56 { NM_ITEM, STR_ID(MSG_SETTINGS_SAVE), NULL, 0, 0, MENU_ID(MID_SAVESETTINGS) },
57 { NM_END, STR_ID(-1), NULL, 0, 0, MENU_ID(0) }
60 CONST_STRPTR device_types_array[] = {
61 STR_ID(MSG_DEVICETYPE_DIRECT_ACCESS),
62 STR_ID(MSG_DEVICETYPE_CDROM),
63 NULL
66 static TEXT image_path[5][IMG_PATH_LEN];
68 BOOL CreateGUI (void) {
69 STRPTR popkey;
70 CONST_STRPTR window_title;
71 CONST_STRPTR about_window_title;
72 CONST_STRPTR device_window_title;
73 CONST_STRPTR about_window_text;
74 CxObj *broker;
75 struct MsgPort *broker_mp;
77 if (Gui.initialised) {
78 return TRUE;
81 Gui.initialised = TRUE;
83 Gui.pool = CreatePool(MEMF_ANY, 4096, 1024);
84 if (!Gui.pool) {
85 goto error;
88 if (translate_gui) {
89 translate_gui = FALSE;
90 TranslateMenus(&LocaleInfo, main_newmenu);
91 main_newmenu[0].nm_Label = PROGNAME;
92 TranslateArray(&LocaleInfo, device_types_array);
95 popkey = TTString(Icon, "CX_POPKEY", NULL);
96 if (!popkey || !TrimStr(popkey)[0]) {
97 popkey = NULL;
99 window_title = ASPrintfPooled(Gui.pool, GetString(&LocaleInfo, MSG_MAIN_WND), PROGNAME, popkey ? popkey : (STRPTR)"none");
100 about_window_title = ASPrintfPooled(Gui.pool, GetString(&LocaleInfo, MSG_ABOUT_WND), PROGNAME);
101 device_window_title = ASPrintfPooled(Gui.pool, GetString(&LocaleInfo, MSG_SETDEVICETYPE_WND), PROGNAME);
102 about_window_text = ASPrintfPooled(Gui.pool, GetString(&LocaleInfo, MSG_ABOUT_REQ),
103 DiskImageBase->lib_Node.ln_Name, (LONG)DiskImageBase->lib_Version,
104 (LONG)DiskImageBase->lib_Revision, PROGNAME, (LONG)VERSION, (LONG)REVISION);
105 if (!window_title || !about_window_title || !about_window_text) {
106 goto error;
109 Gui.app = ApplicationObject,
110 MUIA_Application_Title, PROGNAME,
111 MUIA_Application_Description, GetString(&LocaleInfo, MSG_APPDESCRIPTION),
112 MUIA_Application_Version, &verstag[1],
113 MUIA_Application_SingleTask, TRUE,
114 MUIA_Application_BrokerPri, TTInteger(Icon, "CX_PRIORITY", 0),
115 MUIA_Application_BrokerHook, &BrokerHook,
116 MUIA_Application_Base, (IPTR)"DISKIMAGE",
117 MUIA_Application_DiskObject, Icon,
118 SubWindow, Gui.wnd[WID_MAIN] = WindowObject,
119 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
120 MUIA_Window_Title, window_title,
121 MUIA_Window_Width, 320,
122 MUIA_Window_Height, 200,
123 MUIA_Window_Menustrip, MUI_MakeObject(MUIO_MenustripNM, main_newmenu, 0),
124 WindowContents, VGroup,
125 Child, HGroup,
126 GroupFrame,
127 Child, Gui.gad[GID_INSERT] = MakeImageButton(
128 "Insert",
129 GetString(&LocaleInfo, MSG_INSERT_GAD),
130 TRUE,
131 image_path[0]),
132 Child, Gui.gad[GID_EJECT] = MakeImageButton(
133 "Eject",
134 GetString(&LocaleInfo, MSG_EJECT_GAD),
135 TRUE,
136 image_path[1]),
137 Child, Gui.gad[GID_WRITEPROTECT] = MakeImageButton(
138 "Protect",
139 GetString(&LocaleInfo, MSG_WRITEPROTECT_GAD),
140 TRUE,
141 image_path[2]),
142 Child, Gui.gad[GID_SETDEVICETYPE] = MakeImageButton(
143 "Prefs",
144 GetString(&LocaleInfo, MSG_SETDEVICETYPE_GAD),
145 TRUE,
146 image_path[3]),
147 Child, Gui.gad[GID_REFRESH] = MakeImageButton(
148 "Refresh",
149 GetString(&LocaleInfo, MSG_REFRESH_GAD),
150 FALSE,
151 image_path[4]),
152 Child, RectangleObject,
153 End,
154 End,
155 Child, Gui.gad[GID_DRIVELIST] = ListviewObject,
156 MUIA_Listview_List, NewObject(DriveListClass->mcc_Class, NULL,
157 InputListFrame,
158 MUIA_List_Pool, Gui.pool,
159 TAG_END),
160 End,
161 End,
162 End,
163 SubWindow, Gui.wnd[WID_PLUGINS] = WindowObject,
164 MUIA_Window_ID, MAKE_ID('P','L','U','G'),
165 MUIA_Window_Title, GetString(&LocaleInfo, MSG_PLUGINS_WND),
166 MUIA_Window_Width, 320,
167 MUIA_Window_Height, 200,
168 WindowContents, VGroup,
169 Child, Gui.gad[GID_PLUGINLIST] = ListviewObject,
170 MUIA_Listview_List, NewObject(PluginListClass->mcc_Class, NULL,
171 InputListFrame,
172 MUIA_List_Pool, Gui.pool,
173 TAG_END),
174 End,
175 End,
176 End,
177 SubWindow, Gui.wnd[WID_ABOUT] = WindowObject,
178 MUIA_Window_Title, about_window_title,
179 MUIA_Window_ID, MAKE_ID('A','B','O','U'),
180 WindowContents, VGroup,
181 Child, TextObject,
182 NoFrame,
183 MUIA_Text_PreParse, "\33c",
184 MUIA_Text_Contents, about_window_text,
185 End,
186 Child, HGroup,
187 Child, RectangleObject,
188 End,
189 Child, Gui.gad[GID_ABOUT_OK] = TextObject,
190 ButtonFrame,
191 MUIA_HorizWeight, 0,
192 MUIA_InputMode, MUIV_InputMode_RelVerify,
193 MUIA_Text_PreParse, "\33c",
194 MUIA_Text_Contents, GetString(&LocaleInfo, MSG_OK_GAD),
195 End,
196 Child, RectangleObject,
197 End,
198 End,
199 End,
200 End,
201 SubWindow, Gui.wnd[WID_SETDEVICETYPE] = WindowObject,
202 MUIA_Window_Title, device_window_title,
203 MUIA_Window_ID, MAKE_ID('W','D','E','V'),
204 WindowContents, VGroup,
205 Child, HGroup,
206 Child, Label(GetString(&LocaleInfo, MSG_DEVICETYPE_GAD)),
207 Child, Gui.gad[GID_DEVICETYPE] =
208 MUI_MakeObject(MUIO_Cycle, 0, device_types_array),
209 End,
210 Child, HGroup,
211 Child, Gui.gad[GID_SETDEVICETYPE_SAVE] =
212 SimpleButton(GetString(&LocaleInfo, MSG_SAVE_GAD)),
213 Child, RectangleObject,
214 End,
215 Child, Gui.gad[GID_SETDEVICETYPE_CANCEL] =
216 SimpleButton(GetString(&LocaleInfo, MSG_CANCEL_GAD)),
217 End,
218 End,
219 End,
220 End;
221 if (!Gui.app) {
222 goto error;
224 broker = (CxObj *)XGET(Gui.app, MUIA_Application_Broker);
225 broker_mp = (struct MsgPort *)XGET(Gui.app, MUIA_Application_BrokerPort);
226 if (broker && broker_mp && popkey) {
227 CxObj *filter, *sender, *translate;
228 filter = CxFilter(popkey);
229 sender = CxSender(broker_mp, EVT_POPKEY);
230 translate = CxTranslate(NULL);
231 AttachCxObj(broker, filter);
232 AttachCxObj(filter, sender);
233 AttachCxObj(sender, translate);
234 if (!broker || !filter || !sender) {
235 goto error;
239 DoMethod(Gui.wnd[WID_MAIN], MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
240 Gui.wnd[WID_MAIN], 3, MUIM_Set, MUIA_Window_Open, FALSE);
241 DoMethod(Gui.wnd[WID_MAIN], MUIM_Notify, MUIA_Window_MenuAction, MUIV_EveryTime,
242 Gui.app, 3, MUIM_CallHook, &MenuHook, MUIV_TriggerValue);
243 DoMethod(Gui.gad[GID_INSERT], MUIM_Notify, MUIA_Pressed, FALSE,
244 Gui.app, 2, MUIM_CallHook, &InsertHook);
245 DoMethod(Gui.gad[GID_EJECT], MUIM_Notify, MUIA_Pressed, FALSE,
246 Gui.app, 2, MUIM_CallHook, &EjectHook);
247 DoMethod(Gui.gad[GID_WRITEPROTECT], MUIM_Notify, MUIA_Pressed, FALSE,
248 Gui.app, 2, MUIM_CallHook, &WriteProtectHook);
249 DoMethod(Gui.gad[GID_SETDEVICETYPE], MUIM_Notify, MUIA_Pressed, FALSE,
250 Gui.app, 2, MUIM_CallHook, &SetDeviceTypeHook);
251 DoMethod(Gui.gad[GID_REFRESH], MUIM_Notify, MUIA_Pressed, FALSE,
252 Gui.app, 4, MUIM_CallHook, &SignalHook, FindTask(NULL), (1UL << DiskChangeSignal));
253 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
254 Gui.app, 2, MUIM_CallHook, &DriveList_ActiveHook);
255 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
256 Gui.app, 2, MUIM_CallHook, &DriveList_DoubleClickHook);
257 DoMethod(Gui.wnd[WID_PLUGINS], MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
258 Gui.wnd[WID_PLUGINS], 3, MUIM_Set, MUIA_Window_Open, FALSE);
259 DoMethod(Gui.wnd[WID_ABOUT], MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
260 Gui.wnd[WID_ABOUT], 3, MUIM_Set, MUIA_Window_Open, FALSE);
261 DoMethod(Gui.gad[GID_ABOUT_OK], MUIM_Notify, MUIA_Pressed, FALSE,
262 Gui.wnd[WID_ABOUT], 3, MUIM_Set, MUIA_Window_Open, FALSE);
263 DoMethod(Gui.wnd[WID_SETDEVICETYPE], MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
264 Gui.wnd[WID_SETDEVICETYPE], 3, MUIM_Set, MUIA_Window_Open, FALSE);
265 DoMethod(Gui.gad[GID_SETDEVICETYPE_SAVE], MUIM_Notify, MUIA_Pressed, FALSE,
266 Gui.app, 2, MUIM_CallHook, &DoSetDeviceTypeHook);
267 DoMethod(Gui.gad[GID_SETDEVICETYPE_CANCEL], MUIM_Notify, MUIA_Pressed, FALSE,
268 Gui.wnd[WID_SETDEVICETYPE], 3, MUIM_Set, MUIA_Window_Open, FALSE);
269 DoMethod(Gui.app, MUIM_Notify, MUIA_Application_DoubleStart, TRUE,
270 Gui.app, 3, MUIM_Set, MUIA_Application_Iconified, FALSE);
271 DoMethod(Gui.app, MUIM_Notify, MUIA_Application_DoubleStart, TRUE,
272 Gui.wnd[WID_MAIN], 3, MUIM_Set, MUIA_Window_Open, TRUE);
274 return TRUE;
275 error:
276 CleanupGUI();
278 return FALSE;
281 void CleanupGUI (void) {
282 if (Gui.initialised) {
283 if (Gui.app) {
284 MUI_DisposeObject(Gui.app);
285 Gui.app = NULL;
287 if (Gui.pool) {
288 DeletePool(Gui.pool);
289 Gui.pool = NULL;
291 Gui.initialised = FALSE;
295 void SetWindowBusy (ULONG wnd_id, ULONG busy) {
296 if (Gui.initialised) {
297 if (wnd_id == (ULONG)-1) {
298 SetWindowBusy(WID_MAIN, busy);
299 SetWindowBusy(WID_PLUGINS, busy);
300 SetWindowBusy(WID_ABOUT, busy);
301 } else {
302 set(Gui.wnd[wnd_id], MUIA_Window_Sleep, busy);