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 #include "AutoMounterSettings.h" 36 37 #include <Alert.h> 38 #include <Box.h> 39 #include <Button.h> 40 #include <Catalog.h> 41 #include <CheckBox.h> 42 #include <ControlLook.h> 43 #include <Debug.h> 44 #include <LayoutBuilder.h> 45 #include <Locale.h> 46 #include <Message.h> 47 #include <RadioButton.h> 48 #include <SeparatorView.h> 49 #include <SpaceLayoutItem.h> 50 #include <Window.h> 51 52 #include <MountServer.h> 53 54 55 const uint32 kAutomountSettingsChanged = 'achg'; 56 const uint32 kBootMountSettingsChanged = 'bchg'; 57 const uint32 kEjectWhenUnmountingChanged = 'ejct'; 58 59 #undef B_TRANSLATE_CONTEXT 60 #define B_TRANSLATE_CONTEXT "AutoMounterSettings" 61 62 class AutomountSettingsPanel : public BBox { 63 public: 64 AutomountSettingsPanel(BMessage* settings, 65 const BMessenger& target); 66 virtual ~AutomountSettingsPanel(); 67 68 protected: 69 virtual void MessageReceived(BMessage* message); 70 virtual void AttachedToWindow(); 71 72 private: 73 void _SendSettings(bool rescan); 74 75 BRadioButton* fInitialDontMountCheck; 76 BRadioButton* fInitialMountAllBFSCheck; 77 BRadioButton* fInitialMountAllCheck; 78 BRadioButton* fInitialMountRestoreCheck; 79 80 BRadioButton* fScanningDisabledCheck; 81 BRadioButton* fAutoMountAllBFSCheck; 82 BRadioButton* fAutoMountAllCheck; 83 84 BCheckBox* fEjectWhenUnmountingCheckBox; 85 86 BButton* fDone; 87 BButton* fMountAllNow; 88 89 BMessenger fTarget; 90 91 typedef BBox _inherited; 92 }; 93 94 95 AutomountSettingsDialog* AutomountSettingsDialog::sOneCopyOnly = NULL; 96 97 98 AutomountSettingsPanel::AutomountSettingsPanel(BMessage* settings, 99 const BMessenger& target) 100 : 101 BBox("", B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER), 102 fTarget(target) 103 { 104 const float spacing = be_control_look->DefaultItemSpacing(); 105 106 // "Automatic Disk Mounting" group 107 108 BBox* autoMountBox = new BBox("autoMountBox", B_WILL_DRAW | B_FRAME_EVENTS 109 | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); 110 autoMountBox->SetLabel(B_TRANSLATE("Automatic disk mounting")); 111 BGroupLayout* autoMountLayout = new BGroupLayout(B_VERTICAL, 0); 112 autoMountBox->SetLayout(autoMountLayout); 113 autoMountLayout->SetInsets(spacing, 114 autoMountBox->InnerFrame().top + spacing / 2, spacing, spacing); 115 116 fScanningDisabledCheck = new BRadioButton("scanningOff", 117 B_TRANSLATE("Don't automount"), 118 new BMessage(kAutomountSettingsChanged)); 119 120 fAutoMountAllBFSCheck = new BRadioButton("autoBFS", 121 B_TRANSLATE("All BeOS disks"), new BMessage(kAutomountSettingsChanged)); 122 123 fAutoMountAllCheck = new BRadioButton("autoAll", 124 B_TRANSLATE("All disks"), new BMessage(kAutomountSettingsChanged)); 125 126 // "Disk Mounting During Boot" group 127 128 BBox* bootMountBox = new BBox("", B_WILL_DRAW | B_FRAME_EVENTS 129 | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); 130 bootMountBox->SetLabel(B_TRANSLATE("Disk mounting during boot")); 131 BGroupLayout* bootMountLayout = new BGroupLayout(B_VERTICAL, 0); 132 bootMountBox->SetLayout(bootMountLayout); 133 bootMountLayout->SetInsets(spacing, 134 bootMountBox->InnerFrame().top + spacing / 2, spacing, spacing); 135 136 fInitialDontMountCheck = new BRadioButton("initialNone", 137 B_TRANSLATE("Only the boot disk"), 138 new BMessage(kBootMountSettingsChanged)); 139 140 fInitialMountRestoreCheck = new BRadioButton("initialRestore", 141 B_TRANSLATE("Previously mounted disks"), 142 new BMessage(kBootMountSettingsChanged)); 143 144 fInitialMountAllBFSCheck = new BRadioButton("initialBFS", 145 B_TRANSLATE("All BeOS disks"), 146 new BMessage(kBootMountSettingsChanged)); 147 148 fInitialMountAllCheck = new BRadioButton("initialAll", 149 B_TRANSLATE("All disks"), new BMessage(kBootMountSettingsChanged)); 150 151 fEjectWhenUnmountingCheckBox = new BCheckBox("ejectWhenUnmounting", 152 B_TRANSLATE("Eject when unmounting"), 153 new BMessage(kEjectWhenUnmountingChanged)); 154 155 // Buttons 156 157 fDone = new BButton(B_TRANSLATE("Done"), new BMessage(B_QUIT_REQUESTED)); 158 159 fMountAllNow = new BButton("mountAll", B_TRANSLATE("Mount all disks now"), 160 new BMessage(kMountAllNow)); 161 162 fDone->MakeDefault(true); 163 164 // Layout the controls 165 BGroupView* contentView = new BGroupView(B_VERTICAL, 0); 166 AddChild(contentView); 167 BLayoutBuilder::Group<>(contentView) 168 .AddGroup(B_VERTICAL, spacing) 169 .SetInsets(spacing, spacing, spacing, spacing) 170 .AddGroup(autoMountLayout) 171 .Add(fScanningDisabledCheck) 172 .Add(fAutoMountAllBFSCheck) 173 .Add(fAutoMountAllCheck) 174 .End() 175 .AddGroup(bootMountLayout) 176 .Add(fInitialDontMountCheck) 177 .Add(fInitialMountRestoreCheck) 178 .Add(fInitialMountAllBFSCheck) 179 .Add(fInitialMountAllCheck) 180 .End() 181 .AddGroup(B_HORIZONTAL) 182 .AddStrut(spacing - 1) 183 .Add(fEjectWhenUnmountingCheckBox) 184 .End() 185 .End() 186 .Add(new BSeparatorView(B_HORIZONTAL/*, B_FANCY_BORDER*/)) 187 .AddGroup(B_HORIZONTAL, spacing) 188 .SetInsets(0, spacing, spacing, spacing) 189 .AddGlue() 190 .Add(fMountAllNow) 191 .Add(fDone); 192 193 // Apply the settings 194 195 bool result; 196 if (settings->FindBool("autoMountAll", &result) == B_OK && result) 197 fAutoMountAllCheck->SetValue(B_CONTROL_ON); 198 else if (settings->FindBool("autoMountAllBFS", &result) == B_OK && result) 199 fAutoMountAllBFSCheck->SetValue(B_CONTROL_ON); 200 else 201 fScanningDisabledCheck->SetValue(B_CONTROL_ON); 202 203 if (settings->FindBool("suspended", &result) == B_OK && result) 204 fScanningDisabledCheck->SetValue(B_CONTROL_ON); 205 206 if (settings->FindBool("initialMountAll", &result) == B_OK && result) 207 fInitialMountAllCheck->SetValue(B_CONTROL_ON); 208 else if (settings->FindBool("initialMountRestore", &result) == B_OK 209 && result) { 210 fInitialMountRestoreCheck->SetValue(B_CONTROL_ON); 211 } else if (settings->FindBool("initialMountAllBFS", &result) == B_OK 212 && result) { 213 fInitialMountAllBFSCheck->SetValue(B_CONTROL_ON); 214 } else 215 fInitialDontMountCheck->SetValue(B_CONTROL_ON); 216 217 if (settings->FindBool("ejectWhenUnmounting", &result) == B_OK && result) 218 fEjectWhenUnmountingCheckBox->SetValue(B_CONTROL_ON); 219 } 220 221 222 AutomountSettingsPanel::~AutomountSettingsPanel() 223 { 224 } 225 226 227 void 228 AutomountSettingsPanel::AttachedToWindow() 229 { 230 fInitialMountAllCheck->SetTarget(this); 231 fInitialMountAllBFSCheck->SetTarget(this); 232 fInitialMountRestoreCheck->SetTarget(this); 233 fInitialDontMountCheck->SetTarget(this); 234 235 fAutoMountAllCheck->SetTarget(this); 236 fAutoMountAllBFSCheck->SetTarget(this); 237 fScanningDisabledCheck->SetTarget(this); 238 fEjectWhenUnmountingCheckBox->SetTarget(this); 239 240 fDone->SetTarget(this); 241 fMountAllNow->SetTarget(fTarget); 242 } 243 244 245 void 246 AutomountSettingsPanel::MessageReceived(BMessage* message) 247 { 248 switch (message->what) { 249 case B_QUIT_REQUESTED: 250 Window()->Quit(); 251 break; 252 253 case kAutomountSettingsChanged: 254 _SendSettings(true); 255 break; 256 257 case kBootMountSettingsChanged: 258 case kEjectWhenUnmountingChanged: 259 _SendSettings(false); 260 break; 261 262 default: 263 _inherited::MessageReceived(message); 264 break; 265 } 266 } 267 268 269 void 270 AutomountSettingsPanel::_SendSettings(bool rescan) 271 { 272 BMessage message(kSetAutomounterParams); 273 274 message.AddBool("autoMountAll", (bool)fAutoMountAllCheck->Value()); 275 message.AddBool("autoMountAllBFS", (bool)fAutoMountAllBFSCheck->Value()); 276 if (fAutoMountAllBFSCheck->Value()) 277 message.AddBool("autoMountAllHFS", false); 278 279 message.AddBool("suspended", (bool)fScanningDisabledCheck->Value()); 280 message.AddBool("rescanNow", rescan); 281 282 message.AddBool("initialMountAll", (bool)fInitialMountAllCheck->Value()); 283 message.AddBool("initialMountAllBFS", 284 (bool)fInitialMountAllBFSCheck->Value()); 285 message.AddBool("initialMountRestore", 286 (bool)fInitialMountRestoreCheck->Value()); 287 if (fInitialDontMountCheck->Value()) 288 message.AddBool("initialMountAllHFS", false); 289 290 message.AddBool("ejectWhenUnmounting", 291 (bool)fEjectWhenUnmountingCheckBox->Value()); 292 293 fTarget.SendMessage(&message); 294 } 295 296 297 // #pragma mark - 298 299 300 AutomountSettingsDialog::AutomountSettingsDialog(BMessage* settings, 301 const BMessenger& target) 302 : 303 BWindow(BRect(100, 100, 320, 370), B_TRANSLATE("Disk mount settings"), 304 B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE 305 | B_AUTO_UPDATE_SIZE_LIMITS) 306 { 307 SetLayout(new BGroupLayout(B_HORIZONTAL)); 308 BView* view = new AutomountSettingsPanel(settings, target); 309 AddChild(view); 310 311 ASSERT(!sOneCopyOnly); 312 sOneCopyOnly = this; 313 } 314 315 316 AutomountSettingsDialog::~AutomountSettingsDialog() 317 { 318 ASSERT(sOneCopyOnly); 319 sOneCopyOnly = NULL; 320 } 321 322 323 void 324 AutomountSettingsDialog::RunAutomountSettings(const BMessenger& target) 325 { 326 // either activate an existing mount settings dialog or create a new one 327 if (sOneCopyOnly) { 328 sOneCopyOnly->Activate(); 329 return; 330 } 331 332 BMessage message(kGetAutomounterParams); 333 BMessage reply; 334 status_t ret = target.SendMessage(&message, &reply, 2500000); 335 if (ret != B_OK) { 336 (new BAlert(B_TRANSLATE("Mount server error"), 337 B_TRANSLATE("The mount server could not be contacted."), 338 B_TRANSLATE("OK"), 339 NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); 340 return; 341 } 342 343 (new AutomountSettingsDialog(&reply, target))->Show(); 344 } 345 346