summaryrefslogtreecommitdiff
path: root/src/statusbar.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-06-12 15:10:41 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-06-12 15:47:36 -0400
commitebbc900755b09862be95d29d2a02b8abd1792a3a (patch)
tree0b49cd9669e62cf04c6489d341a53eb0679d120d /src/statusbar.cpp
parent853c95b921f4fc3beb8daf71d79b44aa1ab06c92 (diff)
added a few helper classes for user accounts and stats
moved the api label to the status bar refactored a bunch of copy/pasted code in NexusInterface to use shouldThrottle() and throttledWarning()
Diffstat (limited to 'src/statusbar.cpp')
-rw-r--r--src/statusbar.cpp53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/statusbar.cpp b/src/statusbar.cpp
index 7370662a..6af10c56 100644
--- a/src/statusbar.cpp
+++ b/src/statusbar.cpp
@@ -1,23 +1,26 @@
#include "statusbar.h"
+#include "nexusinterface.h"
+#include "settings.h"
StatusBar::StatusBar(QStatusBar* bar)
- : m_bar(bar), m_nexusAPI(new QLabel), m_progress(new QProgressBar)
+ : m_bar(bar), m_api(new QLabel), m_progress(new QProgressBar)
{
m_progress->setTextVisible(true);
m_progress->setRange(0, 100);
- m_progress->setValue(0);
- m_progress->setVisible(false);
- m_bar->addPermanentWidget(m_nexusAPI);
+ m_bar->addPermanentWidget(m_api);
m_bar->addPermanentWidget(m_progress);
+ m_api->setObjectName("apistats");
+ m_api->setStyleSheet("QLabel{ padding-left: 0.1em; padding-right: 0.1em; }");
+
m_bar->clearMessage();
+ setProgress(-1);
+ updateAPI({}, {});
}
void StatusBar::setProgress(int percent)
{
- qDebug().nospace() << "progress: " << percent;
-
if (percent < 0 || percent >= 100) {
m_progress->setVisible(false);
} else if (!m_progress->isVisible()) {
@@ -25,3 +28,41 @@ void StatusBar::setProgress(int percent)
m_progress->setValue(percent);
}
}
+
+void StatusBar::updateAPI(const APIStats& stats, const APIUserAccount& user)
+{
+ m_api->setText(
+ QString("API: Q: %1 | D: %2 | H: %3")
+ .arg(stats.requestsQueued)
+ .arg(user.limits().remainingDailyRequests)
+ .arg(user.limits().remainingHourlyRequests));
+
+ QColor textColor;
+ QColor backgroundColor;
+
+ if (user.type() == APIUserAccountTypes::None) {
+ backgroundColor = Qt::transparent;
+ } else if (user.remainingRequests() > 300) {
+ textColor = "white";
+ backgroundColor = Qt::darkGreen;
+ } else if (user.remainingRequests() < 150) {
+ textColor = "white";
+ backgroundColor = Qt::darkRed;
+ } else {
+ textColor = "black";
+ backgroundColor = Qt::darkYellow;
+ }
+
+ QPalette palette = m_api->palette();
+
+ palette.setColor(QPalette::WindowText, textColor);
+ palette.setColor(QPalette::Background, backgroundColor);
+
+ m_api->setPalette(palette);
+ m_api->setAutoFillBackground(true);
+}
+
+void StatusBar::checkSettings(const Settings& settings)
+{
+ m_api->setVisible(!settings.hideAPICounter());
+}