managewidget.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "managewidget.h"
  2. #include "ui_managewidget.h"
  3. #include "models/lotromanager.h"
  4. #include "models/filesystem.h"
  5. #include "widgets/mainwindow.h"
  6. #include <QMessageBox>
  7. #include <QFileDialog>
  8. #include <QDebug>
  9. ManageWidget::ManageWidget(LotroManager* mgr, QSettings* settings, QWidget *parent) :
  10. QWidget(parent), lotro_manager(mgr), settings(settings), ui(new Ui::ManageWidget)
  11. {
  12. ui->setupUi(this);
  13. connect(lotro_manager, &LotroManager::processFinished, this, &ManageWidget::onLotroManagerProcessFinished, Qt::QueuedConnection);
  14. }
  15. ManageWidget::~ManageWidget()
  16. {
  17. delete ui;
  18. }
  19. void ManageWidget::updateUI()
  20. {
  21. if (lotro_manager->initialised()) {
  22. ui->open_status_title->show();
  23. ui->close_status_title->hide();
  24. ui->initButton_common->hide();
  25. ui->deinitButton_common->show();
  26. ui->changeLocaleButton_common->setEnabled(true);
  27. ui->createCoreStatusFile_button_common->setEnabled(true);
  28. ui->activate_category_button->setEnabled(true);
  29. ui->deactivate_category_button->setEnabled(true);
  30. emit enableMenuItems();
  31. // Updating patched status label
  32. if (lotro_manager->notPatched())
  33. ui->not_patched_status_title->show();
  34. else
  35. ui->not_patched_status_title->hide();
  36. // Updating current locale status label
  37. if (lotro_manager->currentLocale() == int(LOTRO_DAT::DatLocaleManager::PATCHED)) {
  38. ui->original_locale_title->hide();
  39. ui->patched_locale_title->show();
  40. } else {
  41. ui->original_locale_title->show();
  42. ui->patched_locale_title->hide();
  43. }
  44. } else {
  45. ui->initButton_common->show();
  46. ui->deinitButton_common->hide();
  47. ui->changeLocaleButton_common->setEnabled(false);
  48. ui->createCoreStatusFile_button_common->setEnabled(false);
  49. ui->activate_category_button->setEnabled(false);
  50. ui->deactivate_category_button->setEnabled(false);
  51. emit disableMenuItems();
  52. ui->open_status_title->hide();
  53. ui->close_status_title->show();
  54. ui->not_patched_status_title->hide();
  55. }
  56. }
  57. void ManageWidget::onLotroManagerProcessFinished(QString proc_name, QVector<QVariant> data) {
  58. if (proc_name == "initialiseDatFile" && data[0].toString() == "Success") {
  59. settings->setValue("advanced/dat_path", data[1].toString());
  60. settings->sync();
  61. ui->datfile_name_common->setText(data[1].toString());
  62. }
  63. if (proc_name == "initialiseDatFile" && data[0].toString() == "Error") {
  64. settings->setValue("advanced/dat_path", "");
  65. settings->sync();
  66. ui->datfile_name_common->setText("Ошибка инициализации, файл не выбран");
  67. }
  68. updateUI();
  69. }
  70. void ManageWidget::on_change_folder_button_clicked()
  71. {
  72. QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
  73. QString template_path = known_paths.size() > 0 ? known_paths[0] : "";
  74. QString fileName = QFileDialog::getOpenFileName(0, "Расположение файла .dat", template_path, "*.dat");
  75. if (fileName.isEmpty())
  76. return;
  77. QMetaObject::invokeMethod(lotro_manager, "initialiseDatFile", Qt::QueuedConnection,
  78. Q_ARG(QString, fileName));
  79. }
  80. void ManageWidget::on_changeLocaleButton_common_clicked()
  81. {
  82. QMetaObject::invokeMethod(lotro_manager, "changeLocale", Qt::QueuedConnection);
  83. }
  84. void ManageWidget::on_createCoreStatusFile_button_common_clicked()
  85. {
  86. QString fileName = QFileDialog::getSaveFileName(this->parentWidget(), "Сохранение файла",
  87. settings->value("advanced/export_path", "").toString(), "Файл ядра Наследия (*.txt);;Все файлы (*)");
  88. if (fileName.isEmpty())
  89. return;
  90. settings->setValue("advanced/export_path", fileName.left(std::max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'))));
  91. settings->sync();
  92. qDebug() << "Saving export path to " << settings->value("advanced/export_path", "").toString();
  93. QMetaObject::invokeMethod(lotro_manager, "createCoreStatusFile", Qt::QueuedConnection,
  94. Q_ARG(QString, fileName));
  95. }
  96. void ManageWidget::on_initButton_common_clicked()
  97. {
  98. QMetaObject::invokeMethod(lotro_manager, "initialiseDatFile", Qt::QueuedConnection,
  99. Q_ARG(QString, settings->value("advanced/dat_path", "").toString()));
  100. }
  101. void ManageWidget::on_deinitButton_common_clicked()
  102. {
  103. QMetaObject::invokeMethod(lotro_manager, "deinitialiseDatFile", Qt::QueuedConnection);
  104. }