3 #include <clib/alib_protos.h>
4 #include <devices/trackdisk.h>
5 #include <dos/dosextens.h>
6 #include <intuition/imageclass.h>
7 #include <libraries/iffparse.h>
8 #include <libraries/mui.h>
9 #include <utility/tagitem.h>
10 #include <workbench/startup.h>
12 #include <proto/dos.h>
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/muimaster.h>
20 #include <aros/debug.h>
21 #include <prefs/trackdisk.h>
23 #include "prefs_common.h"
26 #include "trackdisk_prefs.h"
35 struct DriveControls Drives
[TD_NUMUNITS
];
36 struct WindowGroup MainGrp
;
37 struct TrackdiskPrefs TDPrefs
;
38 struct IORequest TDIO
;
49 D(bug("[Trackdisk.Prefs] Main()\n"));
53 for (i
= 0; i
< TD_NUMUNITS
; i
++)
54 InitUnitPrefs(&TDPrefs
.UnitPrefs
[i
], i
);
56 for (i
= 0; i
< TD_NUMUNITS
; i
++) {
57 MainGrp
.DriveGroup
[i
].ti_Tag
= MUIA_Group_Child
;
58 MainGrp
.DriveGroup
[i
].ti_Data
= (ULONG
)CreateDriveControls(&Drives
[i
], i
);
60 MainGrp
.TagChild
= MUIA_Group_Child
;
61 MainGrp
.ButtonsGroup
= MUI_NewObject("Group.mui", MUIA_Group_Horiz
, TRUE
,
63 SaveButton
= MUI_NewObject("Text.mui", MUIA_InputMode
, MUIV_InputMode_RelVerify
,
64 MUIA_CycleChain
, TRUE
,
65 MUIA_Text_Contents
, _(MSG_SAVE
),
66 MUIA_Text_PreParse
, "\33c",
67 MUIA_Background
, MUII_ButtonBack
,
68 MUIA_Frame
, MUIV_Frame_Button
,
71 UseButton
= MUI_NewObject("Text.mui", MUIA_InputMode
, MUIV_InputMode_RelVerify
,
72 MUIA_CycleChain
, TRUE
,
73 MUIA_Text_Contents
, _(MSG_USE
),
74 MUIA_Text_PreParse
, "\33c",
75 MUIA_Background
, MUII_ButtonBack
,
76 MUIA_Frame
, MUIV_Frame_Button
,
79 CancelButton
= MUI_NewObject("Text.mui", MUIA_InputMode
, MUIV_InputMode_RelVerify
,
80 MUIA_CycleChain
, TRUE
,
81 MUIA_Text_Contents
, _(MSG_CANCEL
),
82 MUIA_Text_PreParse
, "\33c",
83 MUIA_Background
, MUII_ButtonBack
,
84 MUIA_Frame
, MUIV_Frame_Button
,
87 MainGrp
.TagDone
= TAG_DONE
;
88 App
= MUI_NewObject("Application.mui", MUIA_Application_Author
, "Pavel Fedin and Team AROS",
89 MUIA_Application_Base
, (IPTR
)"TRACKDISKPREFS",
90 MUIA_Application_Copyright
, (IPTR
)"(c) 2006-2007 Pavel Fedin and Team AROS",
91 MUIA_Application_Description
, __(MSG_DESCRIPTION
),
92 MUIA_Application_SingleTask
, TRUE
,
93 MUIA_Application_Title
, __(MSG_NAME
),
94 MUIA_Application_Version
, (IPTR
)"$VER: Trackdisk 41.5 (30.11.2007) ©2007 Pavel Fedin and Team AROS",
95 MUIA_Application_Window
,
96 MainWin
= MUI_NewObject("Window.mui", MUIA_Window_ID
, MAKE_ID('M', 'A', 'I', 'N'),
97 MUIA_Window_Title
,__(MSG_WINDOW_TITLE
),
98 MUIA_Window_RootObject
, MUI_NewObjectA("Group.mui", (struct TagItem
*)&MainGrp
),
102 DoMethod(SaveButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
, App
, 2, MUIM_Application_ReturnID
, 1);
103 DoMethod(UseButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
, App
, 2, MUIM_Application_ReturnID
, 2);
104 DoMethod(CancelButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
, App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
105 DoMethod(MainWin
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
, App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
106 SetAttrs(MainWin
, MUIA_Window_Open
, TRUE
, TAG_DONE
);
107 while (retval
!= MUIV_Application_ReturnID_Quit
) {
108 retval
= DoMethod(App
, MUIM_Application_NewInput
, &signals
);
109 if (retval
&& (retval
!= MUIV_Application_ReturnID_Quit
)) {
110 for (i
= 0; i
< TD_NUMUNITS
; i
++)
111 ControlsToPrefs(&Drives
[i
], &TDPrefs
.UnitPrefs
[i
]);
115 retval
= MUIV_Application_ReturnID_Quit
;
118 signals
= Wait(signals
);
120 MUI_DisposeObject(App
);
121 } else res
= RETURN_ERROR
;
122 Locale_Deinitialize();
126 void InitUnitPrefs(struct TDU_Prefs
*UnitPrefs
, int nunit
)
128 D(bug("[Trackdisk.Prefs] InitUnitPrefs()\n"));
129 UnitPrefs
->TagUnitNum
= TDPR_UnitNum
;
130 UnitPrefs
->Unit
= nunit
;
131 UnitPrefs
->TagPubFlags
= TDPR_PubFlags
;
132 UnitPrefs
->PubFlags
= 0;
133 UnitPrefs
->TagRetryCnt
= TDPR_RetryCnt
;
134 UnitPrefs
->RetryCnt
= 3;
137 Object
*CreateDriveControls(struct DriveControls
*dc
, int ndrive
)
139 D(bug("[Trackdisk.Prefs] CreateDriveControls()\n"));
140 sprintf(dc
->DriveLabel
, _(MSG_DRIVE
), ndrive
);
141 return MUI_NewObject("Group.mui", MUIA_Group_Horiz
, TRUE
,
142 MUIA_Disabled
, dc
->Disabled
,
143 MUIA_FrameTitle
, dc
->DriveLabel
,
144 MUIA_Background
, MUII_GroupBack
,
145 MUIA_Frame
, MUIV_Frame_Group
,
146 MUIA_Group_Child
, MUI_MakeObject(MUIO_Label
, _(MSG_NOCLICK
), 0),
148 dc
->NoClickSwitch
= MUI_NewObject("Image.mui", MUIA_Image_Spec
, MUII_CheckMark
,
149 MUIA_InputMode
, MUIV_InputMode_Toggle
,
150 MUIA_Selected
, TDPrefs
.UnitPrefs
[ndrive
].PubFlags
& TDPF_NOCLICK
,
151 MUIA_CycleChain
, TRUE
,
152 MUIA_Frame
, MUIV_Frame_ImageButton
,
153 MUIA_ShowSelState
, FALSE
,
155 MUIA_Group_Child
, MUI_MakeObject(MUIO_Label
, _(MSG_RETRIES
), 0),
157 dc
->RetriesSlider
= MUI_NewObject("Slider.mui", MUIA_CycleChain
, TRUE
,
158 MUIA_Numeric_Min
, 1, MUIA_Numeric_Max
, 10,
159 MUIA_Numeric_Value
, TDPrefs
.UnitPrefs
[ndrive
].RetryCnt
,
167 struct TDU_PublicUnit
*tdu
= NULL
;
169 D(bug("[Trackdisk.Prefs] LoadPrefs()\n"));
171 for (i
= 0; i
< TD_NUMUNITS
; i
++) {
172 if (OpenDevice("trackdisk.device", i
, &TDIO
, 0))
173 Drives
[i
].Disabled
= TRUE
;
175 tdu
= (struct TDU_PublicUnit
*)TDIO
.io_Unit
;
176 TDPrefs
.UnitPrefs
[i
].PubFlags
= tdu
->tdu_PubFlags
;
177 TDPrefs
.UnitPrefs
[i
].RetryCnt
= tdu
->tdu_RetryCnt
;
179 Drives
[i
].Disabled
= FALSE
;
184 void ControlsToPrefs(struct DriveControls
*dc
, struct TDU_Prefs
*pr
)
188 D(bug("[Trackdisk.Prefs] ControlsToPrefs()\n"));
190 GetAttr(MUIA_Selected
, dc
->NoClickSwitch
, &NoClick
);
191 pr
->PubFlags
= NoClick
? TDPF_NOCLICK
: 0 ;
192 GetAttr(MUIA_Numeric_Value
, dc
->RetriesSlider
, &pr
->RetryCnt
);
200 D(bug("[Trackdisk.Prefs] SavePrefs()\n"));
202 cf
= Open(TRACKDISK_PREFS_NAME
, MODE_NEWFILE
);
204 TDPrefs
.TagDone
= TAG_DONE
;
205 Write(cf
, &TDPrefs
, sizeof(TDPrefs
));
213 struct TDU_PublicUnit
*tdu
= NULL
;
215 D(bug("[Trackdisk.Prefs] UsePrefs()\n"));
217 for (i
= 0; i
< TD_NUMUNITS
; i
++) {
218 if ((!Drives
[i
].Disabled
) && (!OpenDevice("trackdisk.device", i
, &TDIO
, 0))) {
219 tdu
= (struct TDU_PublicUnit
*)TDIO
.io_Unit
;
220 tdu
->tdu_PubFlags
= TDPrefs
.UnitPrefs
[i
].PubFlags
;
221 tdu
->tdu_RetryCnt
= TDPrefs
.UnitPrefs
[i
].RetryCnt
;