123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #include "serverstatuswidget.h"
- #include "ui_serverstatuswidget.h"
- #include <QDebug>
- #include "constants.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);
- }
- ServerStatusWidget::~ServerStatusWidget()
- {
- delete ui;
- }
- void ServerStatusWidget::setupUpdater(QUrl status_url, QUrl tech_works_message_url)
- {
- status_downloader.targetBytearray = &status_data;
- status_downloader.setUrl(status_url);
- tech_work_message_downloader.targetBytearray = &tech_work_message_data;
- tech_work_message_downloader.setUrl(tech_works_message_url);
- update_timer.setInterval(1000 * 60); // 1 minute;
- update_timer.start();
- // Perform update on startup
- status_downloader.start();
- }
- void ServerStatusWidget::updateFontsSizes()
- {
- foreach (QString server_name, servers_list) {
- QLabel* label = ui->servers_list->findChild<QLabel*>(server_name.toLower());
- if (!label) {
- qDebug() << "Error! Cannot find server widget " << server_name;
- continue;
- }
- label->setFont(trajan_9pt);
- }
- }
- void ServerStatusWidget::resizeEvent(QResizeEvent *event)
- {
- updateFontsSizes();
- }
- void ServerStatusWidget::leaveEvent(QEvent *event)
- {
- event->ignore();
- emit showNoTooltip();
- }
- void ServerStatusWidget::enterEvent(QEvent *event)
- {
- event->ignore();
- emit showServersTooltip();
- }
- 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<QLabel*>(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<QWidget*>(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()) {
- QString result;
- if (!servers_disabled) {
- result = "ИГРОВЫЕ СЕРВЕРЫ LOTRO РАБОТАЮТ В ШТАТНОМ РЕЖИМЕ";
- } else {
- result = "<p style =\"color:#ff0000\">СЕРВЕРЫ ИГРЫ ОТКЛЮЧЕНЫ</p>";
- }
- emit updateServersTooltip(result);
- 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 = "<span style =\"font-family:Trajan Pro 3\">" + list[0] + "</span>";
- QString time_end = "<span style =\"font-family:Trajan Pro 3\">" + list[1] + "</span>";
- QString day = "<span style =\"font-family:Trajan Pro 3\">" + list[2] + "</span>";
- QString month = QString(" " + list[3]).toUpper();
- QString result;
- if (!servers_disabled) {
- result = "<p style=\"color:#ffff7f\">ПЛАНИРУЕТСЯ ОТКЛЮЧЕНИЕ СЕРВЕРОВ ИГРЫ " + day + month + " С " + time_beginning + " ДО " + time_end+ " (МСК).</p>";
- } else {
- result = "<p style=\"color:#ff0000\">СЕРВЕРЫ ИГРЫ ОТКЛЮЧЕНЫ<br>ВРЕМЯ ПРОФ.РАБОТ: " + day + month + " С " + time_beginning + " ДО " + time_end + " (МСК).</p>";
- }
- tech_work_message_data = "";
- emit updateServersTooltip(result);
- }
|