summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorSky <git@bunnies.cc>2014-01-12 18:28:42 +0000
committerSky <git@bunnies.cc>2014-01-12 18:28:42 +0000
commita774b3d24816aa0010e1d5f67b20acb99e7181ac (patch)
tree384c51d242898d3b7a145ed987bcfb8c54c040ba /gui
parent498520446fcd10003226822f5ada9c2fe90e8c63 (diff)
downloadMultiMC-a774b3d24816aa0010e1d5f67b20acb99e7181ac.tar
MultiMC-a774b3d24816aa0010e1d5f67b20acb99e7181ac.tar.gz
MultiMC-a774b3d24816aa0010e1d5f67b20acb99e7181ac.tar.lz
MultiMC-a774b3d24816aa0010e1d5f67b20acb99e7181ac.tar.xz
MultiMC-a774b3d24816aa0010e1d5f67b20acb99e7181ac.zip
Show Mojang service statuses in status bar
Diffstat (limited to 'gui')
-rw-r--r--gui/MainWindow.cpp79
-rw-r--r--gui/MainWindow.h11
2 files changed, 90 insertions, 0 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index dba15e98..cc6d4abb 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -77,6 +77,8 @@
#include "logic/news/NewsChecker.h"
+#include "logic/status/StatusChecker.h"
+
#include "logic/net/URLConstants.h"
#include "logic/BaseInstance.h"
@@ -199,7 +201,27 @@ 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->setToolButtonStyle(Qt::ToolButtonIconOnly);
+ m_statusRefresh->setIcon(
+ QPixmap(":/icons/toolbar/refresh").scaled(16, 16, Qt::KeepAspectRatio));
+
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();
@@ -498,6 +520,63 @@ void MainWindow::updateNewsLabel()
}
}
+static QString convertStatus(const QString &status)
+{
+ if(status == "green") return "↑";
+ else if(status == "yellow") return "-";
+ else if(status == "red") return "↓";
+ else return "?";
+}
+
+void MainWindow::reloadStatus()
+{
+ MMC->statusChecker()->reloadStatus();
+ updateStatusUI();
+}
+
+static QString makeStatusString(const QMap<QString, QString> 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);
+ if(statusChecker->isLoadingStatus())
+ {
+ m_statusRefresh->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ m_statusRefresh->setText(tr("Loading..."));
+ }
+ else
+ {
+ m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly);
+ m_statusRefresh->setText(tr(""));
+ }
+
+ m_statusRight->setText(status);
+
+ statusTimer.start(60 * 1000);
+}
+
+void MainWindow::updateStatusFailedUI()
+{
+ m_statusRight->setText(makeStatusString(QMap<QString, QString>()));
+ m_statusRefresh->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ m_statusRefresh->setText(tr("Failed."));
+
+ 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 12d76da4..eb478776 100644
--- a/gui/MainWindow.h
+++ b/gui/MainWindow.h
@@ -17,6 +17,7 @@
#include <QMainWindow>
#include <QProcess>
+#include <QTimer>
#include "logic/lists/InstanceList.h"
#include "logic/BaseInstance.h"
@@ -168,6 +169,12 @@ slots:
void repopulateAccountsMenu();
void updateNewsLabel();
+
+ void updateStatusUI();
+
+ void updateStatusFailedUI();
+
+ void reloadStatus();
/*!
* Runs the DownloadUpdateTask and installs updates.
@@ -198,8 +205,12 @@ private:
Task *m_versionLoadTask;
QLabel *m_statusLeft;
+ QLabel *m_statusRight;
+ QToolButton *m_statusRefresh;
QMenu *accountMenu;
QToolButton *accountMenuButton;
QAction *manageAccountsAction;
+
+ QTimer statusTimer;
};