added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / trackdisk / trackdisk_prefs.c
blob8c3b40d17b5e353b269d82a6f24595dfb7947ef9
1 #define DEBUG 0
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>
17 #include <stdio.h>
19 #if defined(__AROS__)
20 #include <aros/debug.h>
21 #include <prefs/trackdisk.h>
22 #else
23 #include "prefs_common.h"
24 #define D(x)
25 #endif
26 #include "trackdisk_prefs.h"
28 #include "locale.h"
30 Object *App = NULL,
31 *MainWin = NULL,
32 *SaveButton = NULL,
33 *UseButton = NULL,
34 *CancelButton = NULL;
35 struct DriveControls Drives[TD_NUMUNITS];
36 struct WindowGroup MainGrp;
37 struct TrackdiskPrefs TDPrefs;
38 struct IORequest TDIO;
39 int res = RETURN_OK;
41 int __nocommandline;
43 int main(void)
45 ULONG signals;
46 int i;
47 ULONG retval = 0;
49 D(bug("[Trackdisk.Prefs] Main()\n"));
51 Locale_Initialize();
53 for (i = 0; i < TD_NUMUNITS; i++)
54 InitUnitPrefs(&TDPrefs.UnitPrefs[i], i);
55 LoadPrefs();
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,
62 MUIA_Group_Child,
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,
69 TAG_DONE),
70 MUIA_Group_Child,
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,
77 TAG_DONE),
78 MUIA_Group_Child,
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,
85 TAG_DONE),
86 TAG_DONE);
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),
99 TAG_DONE),
100 TAG_DONE);
101 if (App) {
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]);
112 if (retval == 1)
113 SavePrefs();
114 UsePrefs();
115 retval = MUIV_Application_ReturnID_Quit;
117 if (signals)
118 signals = Wait(signals);
120 MUI_DisposeObject(App);
121 } else res = RETURN_ERROR;
122 Locale_Deinitialize();
123 return res;
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),
147 MUIA_Group_Child,
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,
154 TAG_DONE),
155 MUIA_Group_Child, MUI_MakeObject(MUIO_Label, _(MSG_RETRIES), 0),
156 MUIA_Group_Child,
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,
160 TAG_DONE),
161 TAG_DONE);
164 void LoadPrefs(void)
166 ULONG i;
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;
174 else {
175 tdu = (struct TDU_PublicUnit *)TDIO.io_Unit;
176 TDPrefs.UnitPrefs[i].PubFlags = tdu->tdu_PubFlags;
177 TDPrefs.UnitPrefs[i].RetryCnt = tdu->tdu_RetryCnt;
178 CloseDevice(&TDIO);
179 Drives[i].Disabled = FALSE;
184 void ControlsToPrefs(struct DriveControls *dc, struct TDU_Prefs *pr)
186 ULONG NoClick;
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);
196 void SavePrefs(void)
198 BPTR cf;
200 D(bug("[Trackdisk.Prefs] SavePrefs()\n"));
202 cf = Open(TRACKDISK_PREFS_NAME, MODE_NEWFILE);
203 if (cf) {
204 TDPrefs.TagDone = TAG_DONE;
205 Write(cf, &TDPrefs, sizeof(TDPrefs));
206 Close(cf);
210 void UsePrefs(void)
212 ULONG i;
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;
222 CloseDevice(&TDIO);