1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
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
),
66 static TEXT image_path
[5][IMG_PATH_LEN
];
68 BOOL
CreateGUI (void) {
70 CONST_STRPTR window_title
;
71 CONST_STRPTR about_window_title
;
72 CONST_STRPTR device_window_title
;
73 CONST_STRPTR about_window_text
;
75 struct MsgPort
*broker_mp
;
77 if (Gui
.initialised
) {
81 Gui
.initialised
= TRUE
;
83 Gui
.pool
= CreatePool(MEMF_ANY
, 4096, 1024);
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]) {
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
) {
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
,
127 Child
, Gui
.gad
[GID_INSERT
] = MakeImageButton(
129 GetString(&LocaleInfo
, MSG_INSERT_GAD
),
132 Child
, Gui
.gad
[GID_EJECT
] = MakeImageButton(
134 GetString(&LocaleInfo
, MSG_EJECT_GAD
),
137 Child
, Gui
.gad
[GID_WRITEPROTECT
] = MakeImageButton(
139 GetString(&LocaleInfo
, MSG_WRITEPROTECT_GAD
),
142 Child
, Gui
.gad
[GID_SETDEVICETYPE
] = MakeImageButton(
144 GetString(&LocaleInfo
, MSG_SETDEVICETYPE_GAD
),
147 Child
, Gui
.gad
[GID_REFRESH
] = MakeImageButton(
149 GetString(&LocaleInfo
, MSG_REFRESH_GAD
),
152 Child
, RectangleObject
,
155 Child
, Gui
.gad
[GID_DRIVELIST
] = ListviewObject
,
156 MUIA_Listview_List
, NewObject(DriveListClass
->mcc_Class
, NULL
,
158 MUIA_List_Pool
, Gui
.pool
,
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
,
172 MUIA_List_Pool
, Gui
.pool
,
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
,
183 MUIA_Text_PreParse
, "\33c",
184 MUIA_Text_Contents
, about_window_text
,
187 Child
, RectangleObject
,
189 Child
, Gui
.gad
[GID_ABOUT_OK
] = TextObject
,
192 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
193 MUIA_Text_PreParse
, "\33c",
194 MUIA_Text_Contents
, GetString(&LocaleInfo
, MSG_OK_GAD
),
196 Child
, RectangleObject
,
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
,
206 Child
, Label(GetString(&LocaleInfo
, MSG_DEVICETYPE_GAD
)),
207 Child
, Gui
.gad
[GID_DEVICETYPE
] =
208 MUI_MakeObject(MUIO_Cycle
, 0, device_types_array
),
211 Child
, Gui
.gad
[GID_SETDEVICETYPE_SAVE
] =
212 SimpleButton(GetString(&LocaleInfo
, MSG_SAVE_GAD
)),
213 Child
, RectangleObject
,
215 Child
, Gui
.gad
[GID_SETDEVICETYPE_CANCEL
] =
216 SimpleButton(GetString(&LocaleInfo
, MSG_CANCEL_GAD
)),
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
) {
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
);
281 void CleanupGUI (void) {
282 if (Gui
.initialised
) {
284 MUI_DisposeObject(Gui
.app
);
288 DeletePool(Gui
.pool
);
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
);
302 set(Gui
.wnd
[wnd_id
], MUIA_Window_Sleep
, busy
);