|
@@ -8,16 +8,15 @@ ServerStatusWidget::ServerStatusWidget(QWidget *parent) :
|
|
|
QWidget(parent),
|
|
|
ui(new Ui::ServerStatusWidget)
|
|
|
{
|
|
|
- ui->setupUi(this);
|
|
|
+ servers_disabled = false;
|
|
|
+ setMouseTracking(true);
|
|
|
|
|
|
- downloader.targetBytearray = &downloaded_data;
|
|
|
- downloader.setUrl(QUrl("http://translate.lotros.ru/servers.txt"));
|
|
|
+ ui->setupUi(this);
|
|
|
+ connect(&update_timer, &QTimer::timeout, &status_downloader, &Downloader::start);
|
|
|
|
|
|
- connect(&update_timer, &QTimer::timeout, &downloader, &Downloader::start);
|
|
|
- connect(&downloader, &Downloader::downloadFinished, this, &ServerStatusWidget::updateStatus, Qt::QueuedConnection);
|
|
|
- downloader.start();
|
|
|
- update_timer.setInterval(1000 * 60); // 1 minute;
|
|
|
- update_timer.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()
|
|
@@ -25,27 +24,30 @@ ServerStatusWidget::~ServerStatusWidget()
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
-void ServerStatusWidget::updateFontsSizes()
|
|
|
+void ServerStatusWidget::setupUpdater(QUrl status_url, QUrl tech_works_message_url)
|
|
|
{
|
|
|
- QFont font9pt = QFont(ui->anor->font());
|
|
|
- font9pt.setPixelSize(pixels_in_9_pt);
|
|
|
- QStringList servers_list = {"Anor",
|
|
|
- "Arkenstone",
|
|
|
- "Belegaer",
|
|
|
- "Brandywine",
|
|
|
- "Bullroarer",
|
|
|
- "Crickhollow",
|
|
|
- "Evernight",
|
|
|
- "Gladden",
|
|
|
- "Gwaihir",
|
|
|
- "Ithil",
|
|
|
- "Landroval",
|
|
|
- "Laurelin",
|
|
|
- "Sirannon"};
|
|
|
+ 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());
|
|
|
- label->setFont(font9pt);
|
|
|
+ if (!label) {
|
|
|
+ qDebug() << "Error! Cannot find server widget " << server_name;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ label->setFont(trajan_9pt);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -54,9 +56,38 @@ 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()
|
|
|
{
|
|
|
- QStringList servers = QString(downloaded_data).split("|||");
|
|
|
+ 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());
|
|
@@ -67,5 +98,42 @@ void ServerStatusWidget::updateStatus()
|
|
|
else
|
|
|
widget->setStyleSheet(closed_color);
|
|
|
}
|
|
|
- downloaded_data = "";
|
|
|
+ status_data = "";
|
|
|
+ tech_work_message_downloader.start();
|
|
|
+}
|
|
|
+
|
|
|
+void ServerStatusWidget::updateTechWorksMessage()
|
|
|
+{
|
|
|
+ if (tech_work_message_data.isEmpty()) {
|
|
|
+ QString result;
|
|
|
+ if (!servers_disabled) {
|
|
|
+ result = "<p style=\"color:#00aa00\">Сервера игры работают в штатном режиме.</p>";
|
|
|
+ } 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 = list[0];
|
|
|
+ QString time_end = list[1];
|
|
|
+ QString day = list[2];
|
|
|
+ QString month = " " + list[3];
|
|
|
+
|
|
|
+ QString result;
|
|
|
+ if (!servers_disabled) {
|
|
|
+ result = "<p style=\"color:#ffff7f\">Запланирована профилактика игровых серверов " + day + month + " с " + time_beginning + " до " + time_end+ " (МСК).</p>";
|
|
|
+ } else {
|
|
|
+ result = "<p style=\"color:#ff0000\">Сервера игры отключены. Ориентировочное время проф. работ: " + day + month + " с " + time_beginning + " до " + time_end + " (МСК).</p>";
|
|
|
+ }
|
|
|
+
|
|
|
+ tech_work_message_data = "";
|
|
|
+ emit updateServersTooltip(result);
|
|
|
}
|