| 513 | } |
| 514 | |
| 515 | void Client::openDatabaseFile(QString const& fileName) { |
| 516 | if (!QFile::exists(fileName)) { |
| 517 | QMessageBox::warning(this, tr("Database file does not exist"), tr("The selected database file \"%1\" does not exist. Please check the access permissions!").arg(fileName)); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | QString password; |
| 522 | while (true) { |
| 523 | QString password; |
| 524 | bool ok = false; |
| 525 | if (m_optionTryEmptyPassword) { |
| 526 | password = ""; |
| 527 | ok = true; |
| 528 | } else if (m_optionUsePasswordFile) { |
| 529 | password = m_optionPasswordFromFile; |
| 530 | ok = true; |
| 531 | } else { |
| 532 | password = QInputDialog::getText(this, tr("Database password"), tr("Please enter the database password for file \"%1\":").arg(fileName), QLineEdit::Password, QString(), &ok); |
| 533 | if (password.isNull()) { |
| 534 | password = QString(""); |
| 535 | } |
| 536 | } |
| 537 | if (ok) { |
| 538 | QDir location(fileName); |
| 539 | location.cdUp(); |
| 540 | |
| 541 | int databaseOpenSuccess = -1; |
| 542 | |
| 543 | if (!QMetaObject::invokeMethod(m_databaseThread.getQObjectPtr(), "openDatabase", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, databaseOpenSuccess), Q_ARG(QString const&, fileName), Q_ARG(QString const&, password), Q_ARG(QDir const&, location), Q_ARG(bool, false))) { |
| 544 | throw openmittsu::exceptions::InternalErrorException() << "Could not invoke Database open, terminating."; |
| 545 | } else if (databaseOpenSuccess != 0) { |
| 546 | if (databaseOpenSuccess == 1) { |
| 547 | // Try compat options |
| 548 | if (!QMetaObject::invokeMethod(m_databaseThread.getQObjectPtr(), "openDatabase", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, databaseOpenSuccess), Q_ARG(QString const&, fileName), Q_ARG(QString const&, password), Q_ARG(QDir const&, location), Q_ARG(bool, true))) { |
| 549 | throw openmittsu::exceptions::InternalErrorException() << "Could not invoke Database open, terminating."; |
| 550 | } else if (databaseOpenSuccess != 0) { |
| 551 | if (databaseOpenSuccess == 1) { |
| 552 | if (m_optionTryEmptyPassword) { |
| 553 | QMessageBox::information(this, tr("Invalid password"), tr("Tried the empty password for opening the database (commandline option set), but it was rejected.")); |
| 554 | m_optionTryEmptyPassword = false; |
| 555 | } else if (m_optionUsePasswordFile) { |
| 556 | QMessageBox::information(this, tr("Invalid password"), tr("Tried the password from the given file for opening the database (commandline option set), but it was rejected.")); |
| 557 | m_optionUsePasswordFile = false; |
| 558 | } else { |
| 559 | QMessageBox::information(this, tr("Invalid password"), tr("The entered database password was invalid.")); |
| 560 | } |
| 561 | } else { |
| 562 | askForDatabaseRemovalFromConfig(fileName); |
| 563 | break; |
| 564 | } |
| 565 | } |
| 566 | } else { |
| 567 | askForDatabaseRemovalFromConfig(fileName); |
| 568 | break; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | if (databaseOpenSuccess == 0) { |
nothing calls this directly
no test coverage detected