#include "serverstatuswidget.h" #include "ui_serverstatuswidget.h" #include #include "constants.h" #include "models/settings.h" ServerStatusWidget::ServerStatusWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ServerStatusWidget) { servers_disabled = false; setMouseTracking(true); ui->setupUi(this); connect(&update_timer, &QTimer::timeout, &status_downloader, &Downloader::start); connect(&status_downloader, &Downloader::downloadFinished, this, &ServerStatusWidget::updateStatus); // updateStatus will start tech_work_message_downloader connect(&tech_work_message_downloader, &Downloader::downloadFinished, this, &ServerStatusWidget::updateTechWorksMessage); status_downloader.targetBytearray = &status_data; status_downloader.setUrl(Settings::getValue("Network/game_servers_status").toUrl()); tech_work_message_downloader.targetBytearray = &tech_work_message_data; tech_work_message_downloader.setUrl(Settings::getValue("Network/game_servers_message").toUrl()); update_timer.setInterval(1000 * 60); // 1 minute; update_timer.start(); // Perform update on startup status_downloader.start(); } ServerStatusWidget::~ServerStatusWidget() { delete ui; } void ServerStatusWidget::updateFontsSizes() { foreach (QString server_name, servers_list) { QLabel* label = ui->servers_list->findChild(server_name.toLower()); if (!label) { qDebug() << "Error! Cannot find server widget " << server_name; continue; } label->setFont(trajan_9pt); } } void ServerStatusWidget::resizeEvent(QResizeEvent*) { updateFontsSizes(); } void ServerStatusWidget::leaveEvent(QEvent *event) { event->ignore(); emit showNoTooltip(); } void ServerStatusWidget::enterEvent(QEvent *event) { event->ignore(); emit showServersTooltip(server_status_tooltip_); } void ServerStatusWidget::updateServerStatus() { status_downloader.start(); } void ServerStatusWidget::updateStatus() { if (QString(status_data).contains("profilaktika")) { servers_disabled = true; qDebug() << "All servers are closed!"; foreach (QString server_name, servers_list) { QLabel* label = ui->servers_list->findChild(server_name.toLower()); if (!label) { qDebug() << "Error! Cannot find server widget " << server_name; continue; } label->setStyleSheet(closed_color); } status_data = ""; tech_work_message_downloader.start(); return; } servers_disabled = false; QStringList servers = QString(status_data).split("|||"); foreach (QString server, servers) { QStringList data = server.split(":::"); QWidget* widget = findChild(QString(data[0]).toLower()); if (!widget) continue; if (data.size() > 1 && data[1] == "on") widget->setStyleSheet(open_color); else widget->setStyleSheet(closed_color); } status_data = ""; tech_work_message_downloader.start(); } void ServerStatusWidget::updateTechWorksMessage() { if (tech_work_message_data.isEmpty()) { if (!servers_disabled) { server_status_tooltip_ = "Серверы игры работают в штатном режиме."; } else { server_status_tooltip_ = "

Серверы игры отключены.

"; } tech_work_message_data = ""; return; } QStringList list = QString(tech_work_message_data).split(":::"); if (list.size() < 4) { tech_work_message_data = ""; return; } QString time_beginning = "" + list[0] + ""; QString time_end = "" + list[1] + ""; QString day = "" + list[2] + ""; QString month = QString(" " + list[3]).toUpper(); if (!servers_disabled) { server_status_tooltip_ = "

Планируется отключение серверов игры " + day + month + " с " + time_beginning + " до " + time_end+ " (мск).

"; } else { server_status_tooltip_ = "

Серверы игры отключены на профилактику
Время проф. работ: " + day + month + " с " + time_beginning + " до " + time_end + " (мск).

"; } tech_work_message_data = ""; }