diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-05-17 16:23:48 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-05-17 16:23:48 +0200 |
commit | 8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02 (patch) | |
tree | ad53f17dde79b5c23534c7b0e869852f94a66d84 /gui/widgets/ServerStatus.cpp | |
parent | 927217c7f06017db23b232f055dd5343e39d871f (diff) | |
download | MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar.gz MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar.lz MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar.xz MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.zip |
Finish status pills.
Diffstat (limited to 'gui/widgets/ServerStatus.cpp')
-rw-r--r-- | gui/widgets/ServerStatus.cpp | 150 |
1 files changed, 70 insertions, 80 deletions
diff --git a/gui/widgets/ServerStatus.cpp b/gui/widgets/ServerStatus.cpp index 1b1bb6f7..e540a301 100644 --- a/gui/widgets/ServerStatus.cpp +++ b/gui/widgets/ServerStatus.cpp @@ -1,4 +1,6 @@ #include "ServerStatus.h" +#include "LineSeparator.h" +#include "IconLabel.h" #include "logic/status/StatusChecker.h" #include "MultiMC.h" @@ -8,118 +10,106 @@ #include <QLabel> #include <QMap> #include <QToolButton> +#include <QAction> -ServerStatus::ServerStatus(QWidget *parent, Qt::WindowFlags f) - :QWidget(parent, f) +ServerStatus::ServerStatus(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { - clear(); - goodIcon = QPixmap(":/icons/multimc/48x48/status-good.png"); - goodIcon.setDevicePixelRatio(2.0); - badIcon = QPixmap(":/icons/multimc/48x48/status-bad.png"); - badIcon.setDevicePixelRatio(2.0); - addStatus(tr("No status available"), false); + layout = new QHBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + goodIcon = QIcon::fromTheme("status-good"); + badIcon = QIcon::fromTheme("status-bad"); + + addStatus("minecraft.net", tr("Web")); + addLine(); + addStatus("account.mojang.com", tr("Account")); + addLine(); + addStatus("skins.minecraft.net", tr("Skins")); + addLine(); + addStatus("authserver.mojang.com", tr("Auth")); + addLine(); + addStatus("sessionserver.mojang.com", tr("Session")); + m_statusRefresh = new QToolButton(this); m_statusRefresh->setCheckable(true); m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly); m_statusRefresh->setIcon(QIcon::fromTheme("refresh")); + layout->addWidget(m_statusRefresh); + + setLayout(layout); + // Start status checker { - connect(MMC->statusChecker().get(), &StatusChecker::statusLoaded, this, - &ServerStatus::updateStatusUI); - connect(MMC->statusChecker().get(), &StatusChecker::statusLoadingFailed, this, - &ServerStatus::updateStatusFailedUI); - + auto reloader = MMC->statusChecker().get(); + connect(reloader, &StatusChecker::statusChanged, this, &ServerStatus::StatusChanged); + connect(reloader, &StatusChecker::statusLoading, this, &ServerStatus::StatusReloading); connect(m_statusRefresh, &QAbstractButton::clicked, this, &ServerStatus::reloadStatus); - connect(&statusTimer, &QTimer::timeout, this, &ServerStatus::reloadStatus); - statusTimer.setSingleShot(true); - + MMC->statusChecker()->startTimer(60000); reloadStatus(); } - } -ServerStatus::addLine() +ServerStatus::~ServerStatus() { - auto line = new QFrame(this); - line->setFrameShape(QFrame::VLine); - line->setFrameShadow(QFrame::Sunken); - layout->addWidget(line); } -ServerStatus::addStatus(QString name, bool online) +void ServerStatus::reloadStatus() { - auto label = new QLabel(this); - label->setText(name); - if(online) - label->setPixmap(goodIcon); - else - label->setPixmap(badIcon); - layout->addWidget(label); + MMC->statusChecker()->reloadStatus(); } -ServerStatus::clear() +void ServerStatus::addLine() { - if(layout) - delete layout; - layout = new QHBoxLayout(this); + layout->addWidget(new LineSeparator(this)); } -void ServerStatus::StatusChanged(QMap<QString, QString> statusEntries) +void ServerStatus::addStatus(QString key, QString name) { - clear(); - int howmany = statusEntries.size(); - int index = 0; - auto iter = statusEntries.begin(); - while (iter != statusEntries.end()) { - addStatus(); - index++; + auto label = new IconLabel(this, badIcon, QSize(16, 16)); + label->setToolTip(key); + serverLabels[key] = label; + layout->addWidget(label); + } + { + auto label = new QLabel(this); + label->setText(name); + label->setToolTip(key); + layout->addWidget(label); } } -static QString convertStatus(const QString &status) -{ - QString ret = "?"; - - if (status == "green") - ret = "↑"; - else if (status == "yellow") - ret = "-"; - else if (status == "red") - ret = "↓"; - - return "<span style=\"font-size:11pt; font-weight:600;\">" + ret + "</span>"; -} - -void ServerStatus::reloadStatus() +void ServerStatus::setStatus(QString key, bool value) { - m_statusRefresh->setChecked(true); - MMC->statusChecker()->reloadStatus(); - // updateStatusUI(); + if (!serverLabels.contains(key)) + return; + IconLabel *label = serverLabels[key]; + label->setIcon(value ? goodIcon : badIcon); } -static QString makeStatusString(const QMap<QString, QString> statuses) +void ServerStatus::StatusChanged(const QMap<QString, QString> statusEntries) { - QString status = ""; - status += "Web: " + convertStatus(statuses["minecraft.net"]); - status += " Account: " + convertStatus(statuses["account.mojang.com"]); - status += " Skins: " + convertStatus(statuses["skins.minecraft.net"]); - status += " Auth: " + convertStatus(statuses["authserver.mojang.com"]); - status += " Session: " + convertStatus(statuses["sessionserver.mojang.com"]); - - return status; -} - -void ServerStatus::updateStatusUI() -{ - m_statusRefresh->setChecked(false); - MMC->statusChecker()->getStatusEntries(); - statusTimer.start(60 * 1000); + auto convertStatus = [&](QString status)->bool + { + if (status == "green") + return true; + else if (status == "yellow") + return false; + else if (status == "red") + return false; + return false; + } + ; + auto iter = statusEntries.begin(); + while (iter != statusEntries.end()) + { + QString key = iter.key(); + bool value = convertStatus(iter.value()); + setStatus(key, value); + iter++; + } } -void ServerStatus::updateStatusFailedUI() +void ServerStatus::StatusReloading(bool is_reloading) { - m_statusRefresh->setChecked(false); - StatusChanged(); - statusTimer.start(60 * 1000); + m_statusRefresh->setChecked(is_reloading); } |