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 <Button.h> 36 #include <Debug.h> 37 #include <Message.h> 38 #include <RadioButton.h> 39 #include <Window.h> 40 41 #include "AutoMounter.h" 42 #include "AutoMounterSettings.h" 43 44 const uint32 kDone = 'done'; 45 const uint32 kMountAllNow = 'done'; 46 const uint32 kAutomountSettingsChanged = 'achg'; 47 const uint32 kBootMountSettingsChanged = 'bchg'; 48 const uint32 kAutoAll = 'aall'; 49 const uint32 kAutoBFS = 'abfs'; 50 const uint32 kAutoHFS = 'ahfs'; 51 const uint32 kInitAll = 'iall'; 52 const uint32 kInitBFS = 'ibfs'; 53 const uint32 kInitHFS = 'ihfs'; 54 55 const BPoint kButtonSize(80, 20); 56 const BPoint kSmallButtonSize(60, 20); 57 const rgb_color kLightGray = { 216, 216, 216, 255}; 58 59 const int32 kCheckBoxSpacing = 20; 60 61 AutomountSettingsDialog *AutomountSettingsDialog::oneCopyOnly = NULL; 62 63 void 64 AutomountSettingsDialog::RunAutomountSettings(AutoMounter *target) 65 { 66 // either activate an existing mount settings dialog or create a new one 67 if (oneCopyOnly) { 68 oneCopyOnly->Activate(); 69 return; 70 } 71 72 BMessage message; 73 target->GetSettings(&message); 74 (new AutomountSettingsDialog(&message, target))->Show(); 75 } 76 77 AutomountSettingsPanel::AutomountSettingsPanel(BRect frame, 78 BMessage *settings, AutoMounter *target) 79 : BBox(frame, "", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS 80 | B_NAVIGABLE_JUMP, B_PLAIN_BORDER), 81 fTarget(target) 82 { 83 SetViewColor(kLightGray); 84 85 BRect checkBoxRect(Bounds()); 86 87 BRect boxRect(Bounds()); 88 boxRect.InsetBy(10, 15); 89 boxRect.bottom = boxRect.top + 85; 90 BBox *box = new BBox(boxRect, "autoMountBox", B_FOLLOW_ALL, 91 B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); 92 box->SetLabel("Automatic Disk Mounting:"); 93 AddChild(box); 94 95 checkBoxRect = box->Bounds(); 96 checkBoxRect.InsetBy(10, 18); 97 98 checkBoxRect.bottom = checkBoxRect.top + 20; 99 100 scanningDisabledCheck = new BRadioButton(checkBoxRect, "scanningOff", 101 "Don't Automount", new BMessage(kAutomountSettingsChanged)); 102 box->AddChild(scanningDisabledCheck); 103 104 checkBoxRect.OffsetBy(0, kCheckBoxSpacing); 105 autoMountAllBFSCheck = new BRadioButton(checkBoxRect, "autoBFS", 106 "All BeOS Disks", new BMessage(kAutomountSettingsChanged)); 107 box->AddChild(autoMountAllBFSCheck); 108 109 checkBoxRect.OffsetBy(0, kCheckBoxSpacing); 110 autoMountAllCheck = new BRadioButton(checkBoxRect, "autoAll", 111 "All Disks", new BMessage(kAutomountSettingsChanged)); 112 box->AddChild(autoMountAllCheck); 113 114 115 boxRect.OffsetTo(boxRect.left, boxRect.bottom + 15); 116 boxRect.bottom = boxRect.top + 105; 117 box = new BBox(boxRect, "", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS 118 | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); 119 box->SetLabel("Disk Mounting During Boot:"); 120 AddChild(box); 121 122 checkBoxRect = box->Bounds(); 123 checkBoxRect.InsetBy(10, 18); 124 125 checkBoxRect.bottom = checkBoxRect.top + 20; 126 initialDontMountCheck = new BRadioButton(checkBoxRect, "initialNone", 127 "Only The Boot Disk", new BMessage(kBootMountSettingsChanged)); 128 box->AddChild(initialDontMountCheck); 129 130 checkBoxRect.OffsetBy(0, kCheckBoxSpacing); 131 initialMountRestoreCheck = new BRadioButton(checkBoxRect, "initialRestore", 132 "Previously Mounted Disks", new BMessage(kBootMountSettingsChanged)); 133 box->AddChild(initialMountRestoreCheck); 134 135 checkBoxRect.OffsetBy(0, kCheckBoxSpacing); 136 initialMountAllBFSCheck = new BRadioButton(checkBoxRect, "initialBFS", 137 "All BeOS Disks", new BMessage(kBootMountSettingsChanged)); 138 box->AddChild(initialMountAllBFSCheck); 139 140 checkBoxRect.OffsetBy(0, kCheckBoxSpacing); 141 initialMountAllCheck = new BRadioButton(checkBoxRect, "initialAll", 142 "All Disks", new BMessage(kBootMountSettingsChanged)); 143 box->AddChild(initialMountAllCheck); 144 145 146 BRect buttonRect(Bounds()); 147 buttonRect.InsetBy(15, 15); 148 buttonRect.SetLeftTop(buttonRect.RightBottom() - kSmallButtonSize); 149 fDone = new BButton(buttonRect, "done", "Done", new BMessage(kDone)); 150 151 buttonRect.OffsetTo(buttonRect.left - 15 - buttonRect.Width(), buttonRect.top); 152 buttonRect.left = buttonRect.left - 60; 153 fMountAllNow = new BButton(buttonRect, "mountAll", "Mount all disks now", 154 new BMessage(kMountAllNow)); 155 156 AddChild(fMountAllNow); 157 158 AddChild(fDone); 159 fDone->MakeDefault(true); 160 161 bool result; 162 if (settings->FindBool("autoMountAll", &result) == B_OK && result) 163 autoMountAllCheck->SetValue(1); 164 else if (settings->FindBool("autoMountAllBFS", &result) == B_OK && result) 165 autoMountAllBFSCheck->SetValue(1); 166 else 167 scanningDisabledCheck->SetValue(1); 168 169 if (settings->FindBool("suspended", &result) == B_OK && result) 170 scanningDisabledCheck->SetValue(1); 171 172 if (settings->FindBool("initialMountAll", &result) == B_OK && result) 173 initialMountAllCheck->SetValue(1); 174 else if (settings->FindBool("initialMountRestore", &result) == B_OK && result) 175 initialMountRestoreCheck->SetValue(1); 176 else if (settings->FindBool("initialMountAllBFS", &result) == B_OK && result) 177 initialMountAllBFSCheck->SetValue(1); 178 else 179 initialDontMountCheck->SetValue(1); 180 181 } 182 183 AutomountSettingsPanel::~AutomountSettingsPanel() 184 { 185 } 186 187 void 188 AutomountSettingsPanel::SendSettings(bool rescan) 189 { 190 BMessage message(kSetAutomounterParams); 191 192 message.AddBool("autoMountAll", (bool)autoMountAllCheck->Value()); 193 message.AddBool("autoMountAllBFS", (bool)autoMountAllBFSCheck->Value()); 194 if (autoMountAllBFSCheck->Value()) 195 message.AddBool("autoMountAllHFS", false); 196 197 message.AddBool("suspended", (bool)scanningDisabledCheck->Value()); 198 message.AddBool("rescanNow", rescan); 199 200 message.AddBool("initialMountAll", (bool)initialMountAllCheck->Value()); 201 message.AddBool("initialMountAllBFS", (bool)initialMountAllBFSCheck->Value()); 202 message.AddBool("initialMountRestore", (bool)initialMountRestoreCheck->Value()); 203 if (initialDontMountCheck->Value()) 204 message.AddBool("initialMountAllHFS", false); 205 206 fTarget->PostMessage(&message, NULL); 207 } 208 209 void 210 AutomountSettingsPanel::AttachedToWindow() 211 { 212 initialMountAllCheck->SetTarget(this); 213 initialMountAllBFSCheck->SetTarget(this); 214 initialMountRestoreCheck->SetTarget(this); 215 initialDontMountCheck->SetTarget(this); 216 autoMountAllCheck->SetTarget(this); 217 autoMountAllBFSCheck->SetTarget(this); 218 scanningDisabledCheck->SetTarget(this); 219 fDone->SetTarget(this); 220 fMountAllNow->SetTarget(fTarget); 221 } 222 223 void 224 AutomountSettingsPanel::MessageReceived(BMessage *message) 225 { 226 switch (message->what) { 227 case kDone: 228 case B_QUIT_REQUESTED: 229 Window()->Quit(); 230 break; 231 232 case kAutomountSettingsChanged: 233 SendSettings(true); 234 break; 235 236 case kBootMountSettingsChanged: 237 SendSettings(false); 238 break; 239 240 default: 241 _inherited::MessageReceived(message); 242 break; 243 } 244 } 245 246 AutomountSettingsDialog::AutomountSettingsDialog(BMessage *settings, 247 AutoMounter *target) 248 : BWindow(BRect(100, 100, 320, 370), "Disk Mount Settings", 249 B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 250 { 251 AddChild(new AutomountSettingsPanel(Bounds(), settings, target)); 252 ASSERT(!oneCopyOnly); 253 oneCopyOnly = this; 254 } 255 256 AutomountSettingsDialog::~AutomountSettingsDialog() 257 { 258 ASSERT(oneCopyOnly); 259 oneCopyOnly = NULL; 260 } 261 262