settingswidget.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "gui\settingswidget.h"
  2. #include "ui_settingswidget.h"
  3. #include "legacyapp.h"
  4. #include "filesystem.h"
  5. #include <QDebug>
  6. #include <QFileDialog>
  7. #include <QMessageBox>
  8. SettingsWidget::SettingsWidget(LegacyApp *_app, QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::SettingsWidget),
  11. app(_app)
  12. {
  13. ui->setupUi(this);
  14. ui_update_timer.setInterval(500);
  15. connect(&ui_update_timer, &QTimer::timeout, this, &SettingsWidget::updateUI);
  16. ui_update_timer.start();
  17. }
  18. SettingsWidget::~SettingsWidget()
  19. {
  20. ui_update_timer.stop();
  21. delete ui;
  22. }
  23. void SettingsWidget::updateUI()
  24. {
  25. QString path = app->properties.value("settings/lotro_folder", "(не выбрана)").toString();
  26. ui->folder_value_common->setText(path);
  27. ui->data_protection_checkbox_common->setChecked(app->properties.value("settings/data_protection", 0).toBool());
  28. ui->restore_checkbox_common->setChecked(app->properties.value("settings/auto_restore", 0).toBool());
  29. ui->download_updates_checkbox_common->setChecked(app->properties.value("settings/download_updates", 0).toBool());
  30. ui->expert_tabs_checkbox_common->setChecked(app->properties.value("settings/expert_mode", 0).toBool());
  31. ui->restrict_download_speed_checkbox_common->setChecked(app->properties.value("settings/limit_download_speed", 0).toBool());
  32. ui->download_restrict_slider->setValue(app->properties.value("settings/download_speed", 64).toInt());
  33. if (app->properties.value("settings/expert_mode", 0).toBool()) {
  34. ui->management_widget->show();
  35. ui->data_protection_checkbox_common->show();
  36. ui->restore_checkbox_common->show();
  37. } else {
  38. ui->management_widget->hide();
  39. ui->data_protection_checkbox_common->hide();
  40. ui->restore_checkbox_common->hide();
  41. }
  42. int locale_index = 0;
  43. QString value = app->properties.value("settings/locale", "English").toString();
  44. if (value == "English")
  45. locale_index = 0;
  46. if (value == "DE")
  47. locale_index = 1;
  48. if (value == "FR")
  49. locale_index = 2;
  50. ui->lotro_patch_language_combobox_common->setCurrentIndex(locale_index);
  51. }
  52. void SettingsWidget::on_download_restrict_slider_valueChanged(int value)
  53. {
  54. if (value >= 1024) {
  55. double new_value = double(value) / 1024;
  56. ui->download_speed_label_common->setText(QString::number(new_value, 'g', 2) + " Мб/с");
  57. } else {
  58. ui->download_speed_label_common->setText(QString::number(value) + " Кб/с");
  59. }
  60. app->properties.setValue("settings/download_speed", value);
  61. app->properties.sync();
  62. }
  63. void SettingsWidget::on_interface_scale_combobox_common_currentIndexChanged(const QString &arg1)
  64. {
  65. int value = arg1.left(arg1.length() - 1).toInt();
  66. app->window.changeFontSizeRecursive(value, &app->window);
  67. app->window.resize(900 * value / 100, 650 * value / 100);
  68. app->properties.setValue("settings/ui_scale", value);
  69. app->properties.sync();
  70. }
  71. void SettingsWidget::on_change_folder_button_clicked()
  72. {
  73. QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
  74. QString template_path = known_paths.size() > 0 ? known_paths[0] : "";
  75. QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
  76. QString path = str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/");
  77. if (!FileSystem::fileExists(path + "/LotroLauncher.exe")) {
  78. QMessageBox error_box("Ошибка!", "Похоже, указана неверная папка с игрой. Не могу найти файл LotroLauncher.exe",
  79. QMessageBox::Critical, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
  80. return;
  81. }
  82. if (!FileSystem::fileExists(path + "/client_local_English.dat")) {
  83. QMessageBox pmbx("Файл данных не найден",
  84. "Файл данных client_local_English.dat не обнаружен в папке с игрой. Запустить лаунчер игры с целью скачать недостающие данные?",
  85. QMessageBox::Warning,
  86. QMessageBox::Yes,
  87. QMessageBox::No,
  88. QMessageBox::NoButton);
  89. if (pmbx.exec() == QMessageBox::Yes) {
  90. // Start LotRO;
  91. return;
  92. } else {
  93. // Set status Файл данных не найден
  94. }
  95. }
  96. app->properties.setValue("settings/lotro_folder", path);
  97. app->properties.sync();
  98. ui->folder_value_common->setText(path);
  99. }
  100. void SettingsWidget::on_data_protection_checkbox_common_stateChanged(int arg1)
  101. {
  102. app->properties.setValue("settings/data_protection", arg1);
  103. app->properties.sync();
  104. }
  105. void SettingsWidget::on_restore_checkbox_common_stateChanged(int arg1)
  106. {
  107. app->properties.setValue("settings/auto_restore", arg1);
  108. app->properties.sync();
  109. }
  110. void SettingsWidget::on_download_updates_checkbox_common_stateChanged(int arg1)
  111. {
  112. app->properties.setValue("settings/download_updates", arg1);
  113. app->properties.sync();
  114. }
  115. void SettingsWidget::on_expert_tabs_checkbox_common_stateChanged(int arg1)
  116. {
  117. app->properties.setValue("settings/expert_mode", arg1);
  118. app->properties.sync();
  119. }
  120. void SettingsWidget::on_restrict_download_speed_checkbox_common_stateChanged(int arg1)
  121. {
  122. app->properties.setValue("settings/limit_download_speed", arg1);
  123. app->properties.sync();
  124. }
  125. void SettingsWidget::on_lotro_patch_language_combobox_common_activated(int index)
  126. {
  127. QString value = "";
  128. if (index == 0)
  129. value = "English";
  130. if (index == 1)
  131. value = "DE";
  132. if (index == 2)
  133. value = "FR";
  134. app->properties.setValue("settings/locale", value);
  135. app->properties.sync();
  136. }