settingswidget.cpp 5.6 KB

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