Changeset 27609 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Mar 22, 2010 6:34:46 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 59154
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxDefs.cpp
r27335 r27609 39 39 const char* VBoxDefs::GUI_MiniToolBarAutoHide = "GUI/MiniToolBarAutoHide"; 40 40 const char* VBoxDefs::GUI_LastCloseAction = "GUI/LastCloseAction"; 41 const char* VBoxDefs::GUI_RestrictedCloseActions = "GUI/RestrictedCloseActions"; 41 42 const char* VBoxDefs::GUI_SuppressMessages = "GUI/SuppressMessages"; 42 43 const char* VBoxDefs::GUI_PermanentSharedFoldersAtRuntime = "GUI/PermanentSharedFoldersAtRuntime"; -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxDefs.h
r27335 r27609 157 157 static const char* GUI_MiniToolBarAutoHide; 158 158 static const char* GUI_LastCloseAction; 159 static const char* GUI_RestrictedCloseActions; 159 160 static const char* GUI_SuppressMessages; 160 161 static const char* GUI_PermanentSharedFoldersAtRuntime; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
r27374 r27609 145 145 case KMachineState_TeleportingPausedVM: // TODO: Test this! 146 146 { 147 /* Get the machine: */ 148 CMachine machine = session().GetMachine(); 149 150 /* Prepare close dialog: */ 151 VBoxCloseVMDlg dlg(machineWindow()); 152 153 /* Assign close-dialog pixmap: */ 154 dlg.pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(machine.GetOSTypeId())); 155 156 /* Check which close actions are disallowed: */ 157 QStringList restictedActionsList = machine.GetExtraData(VBoxDefs::GUI_RestrictedCloseActions).split(','); 158 bool fIsStateSavingAllowed = !restictedActionsList.contains("SaveState", Qt::CaseInsensitive); 159 bool fIsACPIShutdownAllowed = !restictedActionsList.contains("Shutdown", Qt::CaseInsensitive); 160 bool fIsPowerOffAllowed = (uisession()->machineState() == KMachineState_Stuck) || 161 (!restictedActionsList.contains("PowerOff", Qt::CaseInsensitive)); 162 bool fIsPowerOffAndRestoreAllowed = fIsPowerOffAllowed && restictedActionsList.contains("Restore", Qt::CaseInsensitive); 163 164 /* Make Save State button visible/hidden depending on restriction: */ 165 dlg.mRbSave->setVisible(fIsStateSavingAllowed); 166 dlg.mTxSave->setVisible(fIsStateSavingAllowed); 167 /* Make Save State button enabled/disabled depending on machine state: */ 168 dlg.mRbSave->setEnabled(uisession()->machineState() != KMachineState_Stuck); 169 170 /* Make ACPI shutdown button visible/hidden depending on restriction: */ 171 dlg.mRbShutdown->setVisible(fIsACPIShutdownAllowed); 172 dlg.mTxShutdown->setVisible(fIsACPIShutdownAllowed); 173 /* Make ACPI shutdown button enabled/disabled depending on ACPI state & machine state: */ 174 bool isACPIEnabled = session().GetConsole().GetGuestEnteredACPIMode(); 175 dlg.mRbShutdown->setEnabled(isACPIEnabled && uisession()->machineState() != KMachineState_Stuck); 176 177 /* Make Power Off button visible/hidden depending on restriction: */ 178 dlg.mRbPowerOff->setVisible(fIsPowerOffAllowed); 179 dlg.mTxPowerOff->setVisible(fIsPowerOffAllowed); 180 181 /* Make the Restore Snapshot checkbox visible/hidden depending on snapshots count & restrictions: */ 182 dlg.mCbDiscardCurState->setVisible(fIsPowerOffAndRestoreAllowed && machine.GetSnapshotCount() > 0); 183 if (!machine.GetCurrentSnapshot().isNull()) 184 dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(machine.GetCurrentSnapshot().GetName())); 185 186 /* Choice string tags for close-dialog: */ 187 QString strSave("save"); 188 QString strShutdown("shutdown"); 189 QString strPowerOff("powerOff"); 190 QString strDiscardCurState("discardCurState"); 191 192 /* Read the last user's choice for the given VM: */ 193 QStringList lastAction = machine.GetExtraData(VBoxDefs::GUI_LastCloseAction).split(','); 194 195 /* Check which button should be initially chosen: */ 196 QRadioButton *pRadioButton = 0; 197 198 /* If chosing 'last choice' is possible: */ 199 if (lastAction[0] == strSave && fIsStateSavingAllowed) 200 { 201 pRadioButton = dlg.mRbSave; 202 } 203 else if (lastAction[0] == strShutdown && fIsACPIShutdownAllowed && isACPIEnabled) 204 { 205 pRadioButton = dlg.mRbShutdown; 206 } 207 else if (lastAction[0] == strPowerOff && fIsPowerOffAllowed) 208 { 209 pRadioButton = dlg.mRbPowerOff; 210 if (fIsPowerOffAndRestoreAllowed) 211 dlg.mCbDiscardCurState->setChecked(lastAction.count() > 1 && lastAction[1] == strDiscardCurState); 212 } 213 /* Else 'default choice' will be used: */ 214 else 215 { 216 if (fIsACPIShutdownAllowed && isACPIEnabled) 217 pRadioButton = dlg.mRbShutdown; 218 else if (fIsPowerOffAllowed) 219 pRadioButton = dlg.mRbPowerOff; 220 else if (fIsStateSavingAllowed) 221 pRadioButton = dlg.mRbSave; 222 } 223 224 /* If some radio button was chosen: */ 225 if (pRadioButton) 226 { 227 /* Check and focus it: */ 228 pRadioButton->setChecked(true); 229 pRadioButton->setFocus(); 230 } 231 /* If no one of radio buttons was chosen: */ 232 else 233 { 234 /* Just break and leave: */ 235 break; 236 } 237 238 /* This flag will keep the status of every further logical operation: */ 147 239 bool success = true; 148 240 149 /* Get the ACPI status early before pausing VM: */ 150 bool isACPIEnabled = session().GetConsole().GetGuestEnteredACPIMode(); 151 241 /* Pause before showing dialog if necessary: */ 152 242 bool fWasPaused = uisession()->isPaused() || uisession()->machineState() == KMachineState_Stuck; 153 243 if (!fWasPaused) 154 {155 /* Suspend the VM and ignore the close event if failed to do so.156 * pause() will show the error message to the user: */157 244 success = uisession()->pause(); 158 }159 245 160 246 if (success) 161 247 { 162 success = false; 163 164 /* Preventing closure right after we had paused: */ 248 /* Preventing auto-closure: */ 165 249 machineLogic()->setPreventAutoClose(true); 166 167 /* Get the machine: */168 CMachine machine = session().GetMachine();169 170 /* Prepare close dialog: */171 VBoxCloseVMDlg dlg(machineWindow());172 QString typeId = machine.GetOSTypeId();173 dlg.pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(typeId));174 175 /* Make the discard checkbox invisible if there are no snapshots: */176 dlg.mCbDiscardCurState->setVisible(machine.GetSnapshotCount() > 0);177 if (!machine.GetCurrentSnapshot().isNull())178 dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(machine.GetCurrentSnapshot().GetName()));179 180 /* Choice string tags for close-dialog: */181 QString strSave("save");182 QString strShutdown("shutdown");183 QString strPowerOff("powerOff");184 QString strDiscardCurState("discardCurState");185 186 if (uisession()->machineState() != KMachineState_Stuck)187 {188 /* Read the last user's choice for the given VM: */189 QStringList lastAction = machine.GetExtraData(VBoxDefs::GUI_LastCloseAction).split(',');190 AssertWrapperOk(machine);191 if (lastAction[0] == strSave)192 {193 dlg.mRbShutdown->setEnabled(isACPIEnabled);194 dlg.mRbSave->setChecked(true);195 dlg.mRbSave->setFocus();196 }197 else if (lastAction[0] == strPowerOff || !isACPIEnabled)198 {199 dlg.mRbShutdown->setEnabled(isACPIEnabled);200 dlg.mRbPowerOff->setChecked(true);201 dlg.mRbPowerOff->setFocus();202 }203 else /* The default is ACPI Shutdown: */204 {205 dlg.mRbShutdown->setChecked(true);206 dlg.mRbShutdown->setFocus();207 }208 dlg.mCbDiscardCurState->setChecked(lastAction.count() > 1 && lastAction [1] == strDiscardCurState);209 }210 else211 {212 /* The stuck VM can only be powered off; disable anything else and choose PowerOff: */213 dlg.mRbSave->setEnabled(false);214 dlg.mRbShutdown->setEnabled(false);215 dlg.mRbPowerOff->setChecked(true);216 }217 218 bool fWasShutdown = false;219 250 220 251 /* If close dialog accepted: */ 221 252 if (dlg.exec() == QDialog::Accepted) 222 253 { 254 /* Get current console: */ 223 255 CConsole console = session().GetConsole(); 256 257 success = false; 224 258 225 259 if (dlg.mRbSave->isChecked()) … … 227 261 CProgress progress = console.SaveState(); 228 262 229 if (console.isOk()) 263 if (!console.isOk()) 264 vboxProblem().cannotSaveMachineState(console); 265 else 230 266 { 231 267 /* Show the "VM saving" progress dialog: */ … … 236 272 success = true; 237 273 } 238 else 239 vboxProblem().cannotSaveMachineState(console); 274 275 if (success) 276 fCloseApplication = true; 240 277 } 241 278 else if (dlg.mRbShutdown->isChecked()) … … 247 284 /* Signal ACPI shutdown (if there is no ACPI device, the operation will fail): */ 248 285 console.PowerButton(); 249 fWasShutdown = console.isOk(); 250 if (!fWasShutdown) 286 if (!console.isOk()) 251 287 vboxProblem().cannotACPIShutdownMachine(console); 252 /* Success is always false because we never accept the close 253 * window action when doing ACPI shutdown: */ 254 success = false; 288 else 289 success = true; 255 290 } 256 291 else if (dlg.mRbPowerOff->isChecked()) … … 258 293 CProgress progress = console.PowerDown(); 259 294 260 if (console.isOk()) 295 if (!console.isOk()) 296 vboxProblem().cannotStopMachine(console); 297 else 261 298 { 262 299 /* Show the power down progress dialog: */ … … 267 304 success = true; 268 305 } 269 else270 vboxProblem().cannotStopMachine(console);271 306 272 307 if (success) … … 275 310 if (dlg.mCbDiscardCurState->isChecked() && dlg.mCbDiscardCurState->isVisibleTo(&dlg)) 276 311 { 312 success = false; 277 313 CSnapshot snapshot = machine.GetCurrentSnapshot(); 278 314 CProgress progress = console.RestoreSnapshot(snapshot); 279 if (console.isOk()) 315 if (!console.isOk()) 316 vboxProblem().cannotRestoreSnapshot(console, snapshot.GetName()); 317 else 280 318 { 281 319 /* Show the progress dialog: */ … … 283 321 if (progress.GetResultCode() != 0) 284 322 vboxProblem().cannotRestoreSnapshot(progress, snapshot.GetName()); 323 else 324 success = true; 285 325 } 286 else287 vboxProblem().cannotRestoreSnapshot(console, snapshot.GetName());288 326 } 289 327 } 328 329 if (success) 330 fCloseApplication = true; 290 331 } 291 332 292 if (success || fWasShutdown)333 if (success) 293 334 { 294 335 /* Read the last user's choice for the given VM: */ … … 298 339 if (dlg.mRbSave->isChecked()) 299 340 lastAction = strSave; 300 else if ( dlg.mRbShutdown->isChecked() ||301 (dlg.mRbPowerOff->isChecked() && prevAction 341 else if ((dlg.mRbShutdown->isChecked()) || 342 (dlg.mRbPowerOff->isChecked() && prevAction[0] == strShutdown && !isACPIEnabled)) 302 343 lastAction = strShutdown; 303 344 else if (dlg.mRbPowerOff->isChecked()) … … 307 348 if (dlg.mCbDiscardCurState->isChecked()) 308 349 (lastAction += ",") += strDiscardCurState; 309 machine.SetExtraData 350 machine.SetExtraData(VBoxDefs::GUI_LastCloseAction, lastAction); 310 351 AssertWrapperOk(machine); 311 352 } 312 313 fCloseApplication = success;314 353 } 315 } 316 317 if (!success) 318 { 354 319 355 /* Restore the running state if needed: */ 320 if ( !fWasPaused && uisession()->machineState() == KMachineState_Paused)356 if (success && !fCloseApplication && !fWasPaused && uisession()->machineState() == KMachineState_Paused) 321 357 uisession()->unpause(); 322 } 358 359 /* Allowing auto-closure: */ 360 machineLogic()->setPreventAutoClose(false); 361 } 362 323 363 break; 324 364 } … … 327 367 break; 328 368 } 329 330 /* Allowing closure: */331 machineLogic()->setPreventAutoClose(false);332 369 333 370 if (fCloseApplication)
Note:
See TracChangeset
for help on using the changeset viewer.