MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / setAPI

Method setAPI

src/statusbar.cpp:82–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82void StatusBar::setAPI(const APIStats& stats, const APIUserAccount& user)
83{
84 QString text;
85 QString textColor;
86 QString backgroundColor;
87
88 if (user.type() == APIUserAccountTypes::None) {
89 text = "API: not logged in";
90 textColor = "";
91 backgroundColor = "";
92 } else {
93 text = QString("API: Queued: %1 | Daily: %2 | Hourly: %3")
94 .arg(stats.requestsQueued)
95 .arg(user.limits().remainingDailyRequests)
96 .arg(user.limits().remainingHourlyRequests);
97
98 if (user.remainingRequests() > 500) {
99 textColor = "white";
100 backgroundColor = "darkgreen";
101 } else if (user.remainingRequests() > 200) {
102 textColor = "black";
103 backgroundColor = "rgb(226, 192, 0)"; // yellow
104 } else {
105 textColor = "white";
106 backgroundColor = "darkred";
107 }
108 }
109
110 m_api->setText(text);
111
112 QString ss(R"(
113 QLabel
114 {
115 padding-left: 0.1em;
116 padding-right: 0.1em;
117 padding-top: 0;
118 padding-bottom: 0;)");
119
120 if (!textColor.isEmpty()) {
121 ss += QString("\ncolor: %1;").arg(textColor);
122 }
123
124 if (!backgroundColor.isEmpty()) {
125 ss += QString("\nbackground-color: %2;").arg(backgroundColor);
126 }
127
128 ss += "\n}";
129
130 m_api->setStyleSheet(ss);
131 m_api->setAutoFillBackground(true);
132}
133
134void StatusBar::setUpdateAvailable(bool b)
135{

Callers 1

MainWindowMethod · 0.80

Calls 5

QStringClass · 0.85
remainingRequestsMethod · 0.80
typeMethod · 0.45
setTextMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected