diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 58491a7e..725bf175 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -47,6 +47,7 @@ #include "gui/Platform.h" #include "gui/widgets/LabeledToolButton.h" +#include "widgets/ServerStatus.h" #include "gui/dialogs/SettingsDialog.h" #include "gui/dialogs/NewInstanceDialog.h" @@ -216,29 +217,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad())); m_statusLeft = new QLabel(tr("No instance selected"), this); - m_statusRight = new QLabel(tr("No status available"), this); - m_statusRefresh = new QToolButton(this); - m_statusRefresh->setCheckable(true); - m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly); - m_statusRefresh->setIcon(QIcon::fromTheme("refresh")); - + m_statusRight = new ServerStatus(this); statusBar()->addPermanentWidget(m_statusLeft, 1); statusBar()->addPermanentWidget(m_statusRight, 0); - statusBar()->addPermanentWidget(m_statusRefresh, 0); - - // Start status checker - { - connect(MMC->statusChecker().get(), &StatusChecker::statusLoaded, this, - &MainWindow::updateStatusUI); - connect(MMC->statusChecker().get(), &StatusChecker::statusLoadingFailed, this, - &MainWindow::updateStatusFailedUI); - - connect(m_statusRefresh, &QAbstractButton::clicked, this, &MainWindow::reloadStatus); - connect(&statusTimer, &QTimer::timeout, this, &MainWindow::reloadStatus); - statusTimer.setSingleShot(true); - - reloadStatus(); - } // Add "manage accounts" button, right align QWidget *spacer = new QWidget(); @@ -620,60 +601,6 @@ void MainWindow::updateNewsLabel() } } -static QString convertStatus(const QString &status) -{ - QString ret = "?"; - - if (status == "green") - ret = "↑"; - else if (status == "yellow") - ret = "-"; - else if (status == "red") - ret = "↓"; - - return "" + ret + ""; -} - -void MainWindow::reloadStatus() -{ - m_statusRefresh->setChecked(true); - MMC->statusChecker()->reloadStatus(); - // updateStatusUI(); -} - -static QString makeStatusString(const QMap statuses) -{ - 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 MainWindow::updateStatusUI() -{ - auto statusChecker = MMC->statusChecker(); - auto statuses = statusChecker->getStatusEntries(); - - QString status = makeStatusString(statuses); - m_statusRefresh->setChecked(false); - - m_statusRight->setText(status); - - statusTimer.start(60 * 1000); -} - -void MainWindow::updateStatusFailedUI() -{ - m_statusRight->setText(makeStatusString(QMap())); - m_statusRefresh->setChecked(false); - - statusTimer.start(60 * 1000); -} - void MainWindow::updateAvailable(QString repo, QString versionName, int versionId) { UpdateDialog dlg; diff --git a/gui/MainWindow.h b/gui/MainWindow.h index d610a87d..ad160da7 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -171,12 +171,6 @@ slots: void updateNewsLabel(); - void updateStatusUI(); - - void updateStatusFailedUI(); - - void reloadStatus(); - /*! * Runs the DownloadUpdateTask and installs updates. */ @@ -207,11 +201,8 @@ private: QLabel *m_statusLeft; QLabel *m_statusRight; - QToolButton *m_statusRefresh; QMenu *accountMenu; QToolButton *accountMenuButton; QAction *manageAccountsAction; - - QTimer statusTimer; }; diff --git a/gui/widgets/ServerStatus.cpp b/gui/widgets/ServerStatus.cpp new file mode 100644 index 00000000..1b1bb6f7 --- /dev/null +++ b/gui/widgets/ServerStatus.cpp @@ -0,0 +1,125 @@ +#include "ServerStatus.h" +#include "logic/status/StatusChecker.h" + +#include "MultiMC.h" + +#include +#include +#include +#include +#include + +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); + m_statusRefresh = new QToolButton(this); + m_statusRefresh->setCheckable(true); + m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_statusRefresh->setIcon(QIcon::fromTheme("refresh")); + // Start status checker + { + connect(MMC->statusChecker().get(), &StatusChecker::statusLoaded, this, + &ServerStatus::updateStatusUI); + connect(MMC->statusChecker().get(), &StatusChecker::statusLoadingFailed, this, + &ServerStatus::updateStatusFailedUI); + + connect(m_statusRefresh, &QAbstractButton::clicked, this, &ServerStatus::reloadStatus); + connect(&statusTimer, &QTimer::timeout, this, &ServerStatus::reloadStatus); + statusTimer.setSingleShot(true); + + reloadStatus(); + } + +} + +ServerStatus::addLine() +{ + auto line = new QFrame(this); + line->setFrameShape(QFrame::VLine); + line->setFrameShadow(QFrame::Sunken); + layout->addWidget(line); +} + +ServerStatus::addStatus(QString name, bool online) +{ + auto label = new QLabel(this); + label->setText(name); + if(online) + label->setPixmap(goodIcon); + else + label->setPixmap(badIcon); + layout->addWidget(label); +} + +ServerStatus::clear() +{ + if(layout) + delete layout; + layout = new QHBoxLayout(this); +} + +void ServerStatus::StatusChanged(QMap statusEntries) +{ + clear(); + int howmany = statusEntries.size(); + int index = 0; + auto iter = statusEntries.begin(); + while (iter != statusEntries.end()) + { + addStatus(); + index++; + } +} + +static QString convertStatus(const QString &status) +{ + QString ret = "?"; + + if (status == "green") + ret = "↑"; + else if (status == "yellow") + ret = "-"; + else if (status == "red") + ret = "↓"; + + return "" + ret + ""; +} + +void ServerStatus::reloadStatus() +{ + m_statusRefresh->setChecked(true); + MMC->statusChecker()->reloadStatus(); + // updateStatusUI(); +} + +static QString makeStatusString(const QMap statuses) +{ + 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); +} + +void ServerStatus::updateStatusFailedUI() +{ + m_statusRefresh->setChecked(false); + StatusChanged(); + statusTimer.start(60 * 1000); +} diff --git a/gui/widgets/ServerStatus.h b/gui/widgets/ServerStatus.h new file mode 100644 index 00000000..a116d3d4 --- /dev/null +++ b/gui/widgets/ServerStatus.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include + +class QToolButton; +class QHBoxLayout; + +class ServerStatus: public QWidget +{ + Q_OBJECT +public: + explicit ServerStatus(QWidget *parent = nullptr, Qt::WindowFlags f = 0); + virtual ~ServerStatus() {}; +public slots: + void updateStatusUI(); + + void updateStatusFailedUI(); + + void reloadStatus(); + void StatusChanged(); + +private: /* methods */ + clear(); + addLine(); + addStatus(QString name, bool online); +private: /* data */ + QHBoxLayout * layout = nullptr; + QToolButton *m_statusRefresh = nullptr; + QPixmap goodIcon; + QPixmap badIcon; + QTimer statusTimer; +}; diff --git a/resources/multimc/16x16/status-bad.png b/resources/multimc/16x16/status-bad.png new file mode 100644 index 00000000..5b3f2051 Binary files /dev/null and b/resources/multimc/16x16/status-bad.png differ diff --git a/resources/multimc/16x16/status-good.png b/resources/multimc/16x16/status-good.png new file mode 100644 index 00000000..5cbdee81 Binary files /dev/null and b/resources/multimc/16x16/status-good.png differ diff --git a/resources/multimc/22x22/status-bad.png b/resources/multimc/22x22/status-bad.png new file mode 100644 index 00000000..2707539e Binary files /dev/null and b/resources/multimc/22x22/status-bad.png differ diff --git a/resources/multimc/22x22/status-good.png b/resources/multimc/22x22/status-good.png new file mode 100644 index 00000000..f55debc3 Binary files /dev/null and b/resources/multimc/22x22/status-good.png differ diff --git a/resources/multimc/24x24/status-bad.png b/resources/multimc/24x24/status-bad.png new file mode 100644 index 00000000..d1547a47 Binary files /dev/null and b/resources/multimc/24x24/status-bad.png differ diff --git a/resources/multimc/24x24/status-good.png b/resources/multimc/24x24/status-good.png new file mode 100644 index 00000000..3545bc4c Binary files /dev/null and b/resources/multimc/24x24/status-good.png differ diff --git a/resources/multimc/32x32/status-bad.png b/resources/multimc/32x32/status-bad.png new file mode 100644 index 00000000..8c2c9d4f Binary files /dev/null and b/resources/multimc/32x32/status-bad.png differ diff --git a/resources/multimc/32x32/status-good.png b/resources/multimc/32x32/status-good.png new file mode 100644 index 00000000..1a805e68 Binary files /dev/null and b/resources/multimc/32x32/status-good.png differ diff --git a/resources/multimc/48x48/status-bad.png b/resources/multimc/48x48/status-bad.png new file mode 100644 index 00000000..41c9cf22 Binary files /dev/null and b/resources/multimc/48x48/status-bad.png differ diff --git a/resources/multimc/48x48/status-good.png b/resources/multimc/48x48/status-good.png new file mode 100644 index 00000000..df7cb59b Binary files /dev/null and b/resources/multimc/48x48/status-good.png differ diff --git a/resources/multimc/64x64/status-bad.png b/resources/multimc/64x64/status-bad.png new file mode 100644 index 00000000..64060ba0 Binary files /dev/null and b/resources/multimc/64x64/status-bad.png differ diff --git a/resources/multimc/64x64/status-good.png b/resources/multimc/64x64/status-good.png new file mode 100644 index 00000000..e862ddcd Binary files /dev/null and b/resources/multimc/64x64/status-good.png differ diff --git a/resources/multimc/multimc.qrc b/resources/multimc/multimc.qrc index d3068ff4..1df22c29 100644 --- a/resources/multimc/multimc.qrc +++ b/resources/multimc/multimc.qrc @@ -87,6 +87,22 @@ 48x48/news.png 64x64/news.png + + 16x16/status-bad.png + 24x24/status-bad.png + 22x22/status-bad.png + 32x32/status-bad.png + 48x48/status-bad.png + 64x64/status-bad.png + + + 16x16/status-good.png + 24x24/status-good.png + 22x22/status-good.png + 32x32/status-good.png + 48x48/status-good.png + 64x64/status-good.png + 16x16/refresh.png 22x22/refresh.png diff --git a/resources/multimc/scalable/status-bad.svg b/resources/multimc/scalable/status-bad.svg new file mode 100644 index 00000000..9f47307e --- /dev/null +++ b/resources/multimc/scalable/status-bad.svg @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/resources/multimc/scalable/status-good.svg b/resources/multimc/scalable/status-good.svg new file mode 100644 index 00000000..0a35c80f --- /dev/null +++ b/resources/multimc/scalable/status-good.svg @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/resources/sources/status-bad.svg b/resources/sources/status-bad.svg deleted file mode 100644 index 54334e06..00000000 --- a/resources/sources/status-bad.svg +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - diff --git a/resources/sources/status-good.svg b/resources/sources/status-good.svg deleted file mode 100644 index 3b311806..00000000 --- a/resources/sources/status-good.svg +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - diff --git a/resources/sources/status-terrible.svg b/resources/sources/status-terrible.svg deleted file mode 100644 index b0de7bfd..00000000 --- a/resources/sources/status-terrible.svg +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - -