statuswidget.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "statuswidget.h"
  2. #include "ui_statuswidget.h"
  3. #include "widgets/mainwindow.h"
  4. #include "models/patchdownloader.h"
  5. #include "models/lotrodatmanager.h"
  6. #include <QDesktopServices>
  7. #include <QUrl>
  8. #include <QDebug>
  9. #include <QMessageBox>
  10. StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
  11. QWidget(parent), lotro_manager(lotro_dat_manager),
  12. ui(new Ui::StatusWidget)
  13. {
  14. ui->setupUi(this);
  15. connect(ui->announcements_list, &NewsListWidget::newsUpdated, this, &StatusWidget::invokeUpdateFontSize);
  16. connect(ui->server_status_flag, &StatusFlagWidget::flagIdChanged, this, &StatusWidget::changeCentralWidget);
  17. ui->status_widget->hide();
  18. patch_updater = patch_downloader;
  19. connect(patch_updater, &PatchDownloader::downloadStarted, this, &StatusWidget::onPatchDownloaderStarted, Qt::QueuedConnection);
  20. connect(patch_updater, &PatchDownloader::progressChanged, this, &StatusWidget::onPatchDownloaderProgressChanged, Qt::QueuedConnection);
  21. connect(patch_updater, &PatchDownloader::downloadCompleted, this, &StatusWidget::onPatchDownloaderFinished, Qt::QueuedConnection);
  22. ui->bottom_widget->hide();
  23. }
  24. StatusWidget::~StatusWidget()
  25. {
  26. delete ui;
  27. }
  28. void StatusWidget::onPatchDownloaderStarted()
  29. {
  30. qDebug() << "Status widget received DownloadStarted signal!";
  31. ui->bottom_widget->show();
  32. ui->process_label->setText("Загрузка обновлений патчей...");
  33. ui->progressBar->setValue(0);
  34. }
  35. void StatusWidget::onPatchDownloaderFinished()
  36. {
  37. ui->process_label->setText("Загрузка обновлений патчей завершена...");
  38. ui->progressBar->setValue(100);
  39. ui->bottom_widget->hide();
  40. }
  41. void StatusWidget::onPatchDownloaderProgressChanged(quint64 bytesDownloaded, quint64 bytesTotal, QString download_speed_formatted, QString elapsed_time_formatted)
  42. {
  43. ui->bottom_widget->show();
  44. ui->process_label->setText("Загрузка " + download_speed_formatted + ". Загружено "
  45. + Downloader::getSizeFormatted(bytesDownloaded) + " из " + Downloader::getSizeFormatted(bytesTotal)
  46. + " (" + QString::number(bytesDownloaded * 100 / bytesTotal) + "%) ");
  47. //+ "\nОставшееся время: " + elapsed_time_formatted);
  48. ui->progressBar->setValue(bytesDownloaded * 100 / bytesTotal + 5);
  49. }
  50. void StatusWidget::changeCentralWidget()
  51. {
  52. if (ui->announcements_widget->isHidden()) {
  53. ui->announcements_widget->show();
  54. ui->status_widget->hide();
  55. } else {
  56. ui->announcements_widget->hide();
  57. ui->status_widget->show();
  58. }
  59. }
  60. void StatusWidget::invokeUpdateFontSize()
  61. {
  62. MainWindow* window = qobject_cast<MainWindow*>(parentWidget()->parentWidget()->parentWidget());
  63. window->changeFontSizeRecursive(100, this);
  64. }
  65. void StatusWidget::on_site_link_button_clicked()
  66. {
  67. QDesktopServices::openUrl(QUrl("http://translate.lotros.ru/"));
  68. }
  69. void StatusWidget::on_forum_link_button_clicked()
  70. {
  71. QDesktopServices::openUrl(QUrl("http://lotros.ru/"));
  72. }
  73. void StatusWidget::on_guides_link_button_clicked()
  74. {
  75. QDesktopServices::openUrl(QUrl("http://translate.lotros.ru/guides"));
  76. }
  77. void StatusWidget::on_addons_link_button_clicked()
  78. {
  79. QDesktopServices::openUrl(QUrl("http://translate.lotros.ru/mathoms"));
  80. }
  81. void StatusWidget::on_bugreport_link_button_clicked()
  82. {
  83. QDesktopServices::openUrl(QUrl("http://translate.lotros.ru/bugs/add"));
  84. }
  85. void StatusWidget::on_donate_link_button_clicked()
  86. {
  87. QDesktopServices::openUrl(QUrl("http://translate.lotros.ru/donate"));
  88. }
  89. void StatusWidget::on_game_button_clicked()
  90. {
  91. MainWindow* window = qobject_cast<MainWindow*>(parentWidget()->parentWidget()->parentWidget());
  92. window->showChooseVersionDialog();
  93. }