6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
41 #include <ControlLook.h>
43 #include <LayoutBuilder.h>
46 #include <RadioButton.h>
47 #include <SeparatorView.h>
48 #include <SpaceLayoutItem.h>
51 #include <MountServer.h>
53 #include "SettingsViews.h"
56 #undef B_TRANSLATION_CONTEXT
57 #define B_TRANSLATION_CONTEXT "AutoMounterSettings"
60 const uint32 kAutomountSettingsChanged
= 'achg';
61 const uint32 kBootMountSettingsChanged
= 'bchg';
62 const uint32 kEjectWhenUnmountingChanged
= 'ejct';
65 // #pragma mark - AutomountSettingsPanel
68 AutomountSettingsPanel::AutomountSettingsPanel()
71 fTarget(kMountServerSignature
)
73 const float spacing
= be_control_look
->DefaultItemSpacing();
75 // "Automatic Disk Mounting" group
77 BBox
* autoMountBox
= new BBox("autoMountBox", B_WILL_DRAW
| B_FRAME_EVENTS
78 | B_PULSE_NEEDED
| B_NAVIGABLE_JUMP
);
79 autoMountBox
->SetLabel(B_TRANSLATE("Automatic disk mounting"));
80 BGroupLayout
* autoMountLayout
= new BGroupLayout(B_VERTICAL
, 0);
81 autoMountBox
->SetLayout(autoMountLayout
);
82 autoMountLayout
->SetInsets(spacing
,
83 autoMountBox
->InnerFrame().top
+ spacing
/ 2, spacing
, spacing
);
85 fScanningDisabledCheck
= new BRadioButton("scanningOff",
86 B_TRANSLATE("Don't automount"),
87 new BMessage(kAutomountSettingsChanged
));
89 fAutoMountAllBFSCheck
= new BRadioButton("autoBFS",
90 B_TRANSLATE("All Haiku disks"),
91 new BMessage(kAutomountSettingsChanged
));
93 fAutoMountAllCheck
= new BRadioButton("autoAll",
94 B_TRANSLATE("All disks"), new BMessage(kAutomountSettingsChanged
));
96 // "Disk Mounting During Boot" group
98 BBox
* bootMountBox
= new BBox("", B_WILL_DRAW
| B_FRAME_EVENTS
99 | B_PULSE_NEEDED
| B_NAVIGABLE_JUMP
);
100 bootMountBox
->SetLabel(B_TRANSLATE("Disk mounting during boot"));
101 BGroupLayout
* bootMountLayout
= new BGroupLayout(B_VERTICAL
, 0);
102 bootMountBox
->SetLayout(bootMountLayout
);
103 bootMountLayout
->SetInsets(spacing
,
104 bootMountBox
->InnerFrame().top
+ spacing
/ 2, spacing
, spacing
);
106 fInitialDontMountCheck
= new BRadioButton("initialNone",
107 B_TRANSLATE("Only the boot disk"),
108 new BMessage(kBootMountSettingsChanged
));
110 fInitialMountRestoreCheck
= new BRadioButton("initialRestore",
111 B_TRANSLATE("Previously mounted disks"),
112 new BMessage(kBootMountSettingsChanged
));
114 fInitialMountAllBFSCheck
= new BRadioButton("initialBFS",
115 B_TRANSLATE("All Haiku disks"),
116 new BMessage(kBootMountSettingsChanged
));
118 fInitialMountAllCheck
= new BRadioButton("initialAll",
119 B_TRANSLATE("All disks"), new BMessage(kBootMountSettingsChanged
));
121 fEjectWhenUnmountingCheckBox
= new BCheckBox("ejectWhenUnmounting",
122 B_TRANSLATE("Eject when unmounting"),
123 new BMessage(kEjectWhenUnmountingChanged
));
127 fMountAllNow
= new BButton("mountAll", B_TRANSLATE("Mount all disks now"),
128 new BMessage(kMountAllNow
));
130 // Layout the controls
132 BGroupView
* contentView
= new BGroupView(B_VERTICAL
, 0);
133 AddChild(contentView
);
134 BLayoutBuilder::Group
<>(contentView
)
135 .AddGroup(B_VERTICAL
, spacing
)
136 .SetInsets(spacing
, spacing
, spacing
, spacing
)
137 .AddGroup(autoMountLayout
)
138 .Add(fScanningDisabledCheck
)
139 .Add(fAutoMountAllBFSCheck
)
140 .Add(fAutoMountAllCheck
)
142 .AddGroup(bootMountLayout
)
143 .Add(fInitialDontMountCheck
)
144 .Add(fInitialMountRestoreCheck
)
145 .Add(fInitialMountAllBFSCheck
)
146 .Add(fInitialMountAllCheck
)
148 .Add(fEjectWhenUnmountingCheckBox
)
150 .Add(new BSeparatorView(B_HORIZONTAL
/*, B_FANCY_BORDER*/))
151 .AddGroup(B_HORIZONTAL
, spacing
)
152 .SetInsets(spacing
, spacing
, spacing
, spacing
)
156 ShowCurrentSettings();
160 AutomountSettingsPanel::~AutomountSettingsPanel()
166 AutomountSettingsPanel::IsDefaultable() const
173 AutomountSettingsPanel::Revert()
175 _ParseSettings(fInitialSettings
);
176 _SendSettings(false);
181 AutomountSettingsPanel::ShowCurrentSettings()
183 // Apply the settings
185 _GetSettings(&settings
);
186 _ParseSettings(settings
);
191 AutomountSettingsPanel::RecordRevertSettings()
193 _GetSettings(&fInitialSettings
);
198 AutomountSettingsPanel::IsRevertable() const
200 BMessage currentSettings
;
201 _GetSettings(¤tSettings
);
203 return !currentSettings
.HasSameData(fInitialSettings
);
208 AutomountSettingsPanel::AttachedToWindow()
210 fInitialMountAllCheck
->SetTarget(this);
211 fInitialMountAllBFSCheck
->SetTarget(this);
212 fInitialMountRestoreCheck
->SetTarget(this);
213 fInitialDontMountCheck
->SetTarget(this);
215 fAutoMountAllCheck
->SetTarget(this);
216 fAutoMountAllBFSCheck
->SetTarget(this);
217 fScanningDisabledCheck
->SetTarget(this);
218 fEjectWhenUnmountingCheckBox
->SetTarget(this);
220 fMountAllNow
->SetTarget(fTarget
);
225 AutomountSettingsPanel::MessageReceived(BMessage
* message
)
227 switch (message
->what
) {
228 case B_QUIT_REQUESTED
:
232 case kAutomountSettingsChanged
:
236 case kBootMountSettingsChanged
:
237 case kEjectWhenUnmountingChanged
:
238 _SendSettings(false);
242 _inherited::MessageReceived(message
);
249 AutomountSettingsPanel::_SendSettings(bool rescan
)
251 BMessage
message(kSetAutomounterParams
);
253 message
.AddBool("autoMountAll", (bool)fAutoMountAllCheck
->Value());
254 message
.AddBool("autoMountAllBFS", (bool)fAutoMountAllBFSCheck
->Value());
255 if (fAutoMountAllBFSCheck
->Value())
256 message
.AddBool("autoMountAllHFS", false);
258 message
.AddBool("suspended", (bool)fScanningDisabledCheck
->Value());
259 message
.AddBool("rescanNow", rescan
);
261 message
.AddBool("initialMountAll", (bool)fInitialMountAllCheck
->Value());
262 message
.AddBool("initialMountAllBFS",
263 (bool)fInitialMountAllBFSCheck
->Value());
264 message
.AddBool("initialMountRestore",
265 (bool)fInitialMountRestoreCheck
->Value());
266 if (fInitialDontMountCheck
->Value())
267 message
.AddBool("initialMountAllHFS", false);
269 message
.AddBool("ejectWhenUnmounting",
270 (bool)fEjectWhenUnmountingCheckBox
->Value());
272 fTarget
.SendMessage(&message
);
274 // Tell the settings window the contents have changed:
275 Window()->PostMessage(kSettingsContentsModified
);
280 AutomountSettingsPanel::_GetSettings(BMessage
* reply
) const
282 BMessage
message(kGetAutomounterParams
);
283 if (fTarget
.SendMessage(&message
, reply
, 2500000) != B_OK
) {
284 BAlert
* alert
= new BAlert(B_TRANSLATE("Mount server error"),
285 B_TRANSLATE("The mount server could not be contacted."),
287 NULL
, NULL
, B_WIDTH_AS_USUAL
, B_STOP_ALERT
);
288 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
295 AutomountSettingsPanel::_ParseSettings(const BMessage
& settings
)
298 if (settings
.FindBool("autoMountAll", &result
) == B_OK
&& result
)
299 fAutoMountAllCheck
->SetValue(B_CONTROL_ON
);
300 else if (settings
.FindBool("autoMountAllBFS", &result
) == B_OK
&& result
)
301 fAutoMountAllBFSCheck
->SetValue(B_CONTROL_ON
);
303 fScanningDisabledCheck
->SetValue(B_CONTROL_ON
);
305 if (settings
.FindBool("suspended", &result
) == B_OK
&& result
)
306 fScanningDisabledCheck
->SetValue(B_CONTROL_ON
);
308 if (settings
.FindBool("initialMountAll", &result
) == B_OK
&& result
)
309 fInitialMountAllCheck
->SetValue(B_CONTROL_ON
);
310 else if (settings
.FindBool("initialMountRestore", &result
) == B_OK
312 fInitialMountRestoreCheck
->SetValue(B_CONTROL_ON
);
313 } else if (settings
.FindBool("initialMountAllBFS", &result
) == B_OK
315 fInitialMountAllBFSCheck
->SetValue(B_CONTROL_ON
);
317 fInitialDontMountCheck
->SetValue(B_CONTROL_ON
);
319 if (settings
.FindBool("ejectWhenUnmounting", &result
) == B_OK
&& result
)
320 fEjectWhenUnmountingCheckBox
->SetValue(B_CONTROL_ON
);