From ebbc900755b09862be95d29d2a02b8abd1792a3a Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 12 Jun 2019 15:10:41 -0400 Subject: 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() --- src/statusbar.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'src/statusbar.cpp') 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()); +} -- cgit v1.3.1