| 1378 | } |
| 1379 | |
| 1380 | void MainWindow::closeEvent(QCloseEvent* event) |
| 1381 | { |
| 1382 | if (isVisible()) { |
| 1383 | // this is messy |
| 1384 | // |
| 1385 | // the main problem this is solving is when closing MO, then getting the |
| 1386 | // lock overlay because processes are still running, then pressing the X |
| 1387 | // again |
| 1388 | // |
| 1389 | // in this case, closeEvent() is _not_ called for the second event and the |
| 1390 | // window is immediately hidden |
| 1391 | // |
| 1392 | // this always saves the settings here; in the event where a lock overlay |
| 1393 | // is then shown, it might save settings multiple times, but it's harmless |
| 1394 | onBeforeClose(); |
| 1395 | } |
| 1396 | |
| 1397 | // this happens for two reasons: |
| 1398 | // 1) the user requested to close the window, such as clicking the X |
| 1399 | // 2) close() is called in runApplication() after application.exec() |
| 1400 | // returns, which happens when qApp->exit() is called |
| 1401 | // |
| 1402 | // the window must never actually close for 1), because settings haven't been |
| 1403 | // saved yet: the state of many widgets is saved to the ini, which relies on |
| 1404 | // the window still being onscreen (or else everything is considered hidden) |
| 1405 | // |
| 1406 | // for 2), the settings have been saved and the window can just close |
| 1407 | |
| 1408 | if (ModOrganizerCanCloseNow()) { |
| 1409 | // the user has confirmed if necessary and all settings have been saved, |
| 1410 | // just close it |
| 1411 | QMainWindow::closeEvent(event); |
| 1412 | return; |
| 1413 | } |
| 1414 | |
| 1415 | if (UILocker::instance().locked()) { |
| 1416 | // don't bother asking the user to confirm if the ui is already locked |
| 1417 | event->ignore(); |
| 1418 | ExitModOrganizer(Exit::Force); |
| 1419 | return; |
| 1420 | } |
| 1421 | |
| 1422 | if (ModOrganizerExiting()) { |
| 1423 | // ignore repeated attempts |
| 1424 | event->ignore(); |
| 1425 | return; |
| 1426 | } |
| 1427 | |
| 1428 | // never close the window because settings might need to be changed |
| 1429 | event->ignore(); |
| 1430 | |
| 1431 | // start the process of exiting, which may require confirmation by calling |
| 1432 | // canExit(), among other things |
| 1433 | ExitModOrganizer(); |
| 1434 | } |
| 1435 | |
| 1436 | bool MainWindow::canExit() |
| 1437 | { |
nothing calls this directly
no test coverage detected