settingswidget.cpp 5.7 KB

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