1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 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: 14 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. 17 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. 24 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. 28 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. 32 All rights reserved. 33 */ 34 35 36 #include <Alert.h> 37 #include <Box.h> 38 #include <Button.h> 39 #include <Catalog.h> 40 #include <CheckBox.h> 41 #include <ControlLook.h> 42 #include <Debug.h> 43 #include <LayoutBuilder.h> 44 #include <Locale.h> 45 #include <Message.h> 46 #include <RadioButton.h> 47 #include <SeparatorView.h> 48 #include <SpaceLayoutItem.h> 49 #include <Window.h> 50 51 #include <MountServer.h> 52 53 #include "SettingsViews.h" 54 55 56 #undef B_TRANSLATION_CONTEXT 57 #define B_TRANSLATION_CONTEXT "AutoMounterSettings" 58 59 60 const uint32 kAutomountSettingsChanged = 'achg'; 61 const uint32 kBootMountSettingsChanged = 'bchg'; 62 const uint32 kEjectWhenUnmountingChanged = 'ejct'; 63 64 65 // #pragma mark - AutomountSettingsPanel 66 67 68 AutomountSettingsPanel::AutomountSettingsPanel() 69 : 70 SettingsView(""), 71 fTarget(kMountServerSignature) 72 { 73 const float spacing = be_control_look->DefaultItemSpacing(); 74 75 // "Automatic Disk Mounting" group 76 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); 84 85 fScanningDisabledCheck = new BRadioButton("scanningOff", 86 B_TRANSLATE("Don't automount"), 87 new BMessage(kAutomountSettingsChanged)); 88 89 fAutoMountAllBFSCheck = new BRadioButton("autoBFS", 90 B_TRANSLATE("All Haiku disks"), 91 new BMessage(kAutomountSettingsChanged)); 92 93 fAutoMountAllCheck = new BRadioButton("autoAll", 94 B_TRANSLATE("All disks"), new BMessage(kAutomountSettingsChanged)); 95 96 // "Disk Mounting During Boot" group 97 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); 105 106 fInitialDontMountCheck = new BRadioButton("initialNone", 107 B_TRANSLATE("Only the boot disk"), 108 new BMessage(kBootMountSettingsChanged)); 109 110 fInitialMountRestoreCheck = new BRadioButton("initialRestore", 111 B_TRANSLATE("Previously mounted disks"), 112 new BMessage(kBootMountSettingsChanged)); 113 114 fInitialMountAllBFSCheck = new BRadioButton("initialBFS", 115 B_TRANSLATE("All Haiku disks"), 116 new BMessage(kBootMountSettingsChanged)); 117 118 fInitialMountAllCheck = new BRadioButton("initialAll", 119 B_TRANSLATE("All disks"), new BMessage(kBootMountSettingsChanged)); 120 121 fEjectWhenUnmountingCheckBox = new BCheckBox("ejectWhenUnmounting", 122 B_TRANSLATE("Eject when unmounting"), 123 new BMessage(kEjectWhenUnmountingChanged)); 124 125 // Buttons 126 127 fMountAllNow = new BButton("mountAll", B_TRANSLATE("Mount all disks now"), 128 new BMessage(kMountAllNow)); 129 130 // Layout the controls 131 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) 141 .End() 142 .AddGroup(bootMountLayout) 143 .Add(fInitialDontMountCheck) 144 .Add(fInitialMountRestoreCheck) 145 .Add(fInitialMountAllBFSCheck) 146 .Add(fInitialMountAllCheck) 147 .End() 148 .Add(fEjectWhenUnmountingCheckBox) 149 .End() 150 .Add(new BSeparatorView(B_HORIZONTAL/*, B_FANCY_BORDER*/)) 151 .AddGroup(B_HORIZONTAL, spacing) 152 .SetInsets(spacing, spacing, spacing, spacing) 153 .Add(fMountAllNow) 154 .AddGlue(); 155 156 ShowCurrentSettings(); 157 } 158 159 160 AutomountSettingsPanel::~AutomountSettingsPanel() 161 { 162 } 163 164 165 bool 166 AutomountSettingsPanel::IsDefaultable() const 167 { 168 return false; 169 } 170 171 172 void 173 AutomountSettingsPanel::Revert() 174 { 175 _ParseSettings(fInitialSettings); 176 _SendSettings(false); 177 } 178 179 180 void 181 AutomountSettingsPanel::ShowCurrentSettings() 182 { 183 // Apply the settings 184 BMessage settings; 185 _GetSettings(&settings); 186 _ParseSettings(settings); 187 } 188 189 190 void 191 AutomountSettingsPanel::RecordRevertSettings() 192 { 193 _GetSettings(&fInitialSettings); 194 } 195 196 197 bool 198 AutomountSettingsPanel::IsRevertable() const 199 { 200 BMessage currentSettings; 201 _GetSettings(¤tSettings); 202 203 return !currentSettings.HasSameData(fInitialSettings); 204 } 205 206 207 void 208 AutomountSettingsPanel::AttachedToWindow() 209 { 210 fInitialMountAllCheck->SetTarget(this); 211 fInitialMountAllBFSCheck->SetTarget(this); 212 fInitialMountRestoreCheck->SetTarget(this); 213 fInitialDontMountCheck->SetTarget(this); 214 215 fAutoMountAllCheck->SetTarget(this); 216 fAutoMountAllBFSCheck->SetTarget(this); 217 fScanningDisabledCheck->SetTarget(this); 218 fEjectWhenUnmountingCheckBox->SetTarget(this); 219 220 fMountAllNow->SetTarget(fTarget); 221 } 222 223 224 void 225 AutomountSettingsPanel::MessageReceived(BMessage* message) 226 { 227 switch (message->what) { 228 case B_QUIT_REQUESTED: 229 Window()->Quit(); 230 break; 231 232 case kAutomountSettingsChanged: 233 _SendSettings(true); 234 break; 235 236 case kBootMountSettingsChanged: 237 case kEjectWhenUnmountingChanged: 238 _SendSettings(false); 239 break; 240 241 default: 242 _inherited::MessageReceived(message); 243 break; 244 } 245 } 246 247 248 void 249 AutomountSettingsPanel::_SendSettings(bool rescan) 250 { 251 BMessage message(kSetAutomounterParams); 252 253 message.AddBool("autoMountAll", (bool)fAutoMountAllCheck->Value()); 254 message.AddBool("autoMountAllBFS", (bool)fAutoMountAllBFSCheck->Value()); 255 if (fAutoMountAllBFSCheck->Value()) 256 message.AddBool("autoMountAllHFS", false); 257 258 message.AddBool("suspended", (bool)fScanningDisabledCheck->Value()); 259 message.AddBool("rescanNow", rescan); 260 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); 268 269 message.AddBool("ejectWhenUnmounting", 270 (bool)fEjectWhenUnmountingCheckBox->Value()); 271 272 fTarget.SendMessage(&message); 273 274 // Tell the settings window the contents have changed: 275 Window()->PostMessage(kSettingsContentsModified); 276 } 277 278 279 void 280 AutomountSettingsPanel::_GetSettings(BMessage* reply) const 281 { 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."), 286 B_TRANSLATE("OK"), 287 NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); 288 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 289 alert->Go(); 290 } 291 } 292 293 294 void 295 AutomountSettingsPanel::_ParseSettings(const BMessage& settings) 296 { 297 bool result; 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); 302 else 303 fScanningDisabledCheck->SetValue(B_CONTROL_ON); 304 305 if (settings.FindBool("suspended", &result) == B_OK && result) 306 fScanningDisabledCheck->SetValue(B_CONTROL_ON); 307 308 if (settings.FindBool("initialMountAll", &result) == B_OK && result) 309 fInitialMountAllCheck->SetValue(B_CONTROL_ON); 310 else if (settings.FindBool("initialMountRestore", &result) == B_OK 311 && result) { 312 fInitialMountRestoreCheck->SetValue(B_CONTROL_ON); 313 } else if (settings.FindBool("initialMountAllBFS", &result) == B_OK 314 && result) { 315 fInitialMountAllBFSCheck->SetValue(B_CONTROL_ON); 316 } else 317 fInitialDontMountCheck->SetValue(B_CONTROL_ON); 318 319 if (settings.FindBool("ejectWhenUnmounting", &result) == B_OK && result) 320 fEjectWhenUnmountingCheckBox->SetValue(B_CONTROL_ON); 321 } 322 323