Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(status): use enum as UI property instead of untranslated string
Browse files Browse the repository at this point in the history
Translation of getStatusTitle introduced in 15d72a9, breaking asset path from string.
  • Loading branch information
anthonybilinski committed Apr 24, 2019
1 parent e1876a2 commit 881aa30
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
28 changes: 18 additions & 10 deletions src/model/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,32 @@ namespace Status
return QStringLiteral("");
}

QString getIconPath(Status status, bool event)
QString getAssetSuffix(Status status)
{
const QString eventSuffix = event ? QStringLiteral("_notification") : QString();

switch (status) {
case Status::Online:
return ":/img/status/online" + eventSuffix + ".svg";
return "online";
case Status::Away:
return ":/img/status/away" + eventSuffix + ".svg";
return "away";
case Status::Busy:
return ":/img/status/busy" + eventSuffix + ".svg";
return "busy";
case Status::Offline:
return ":/img/status/offline" + eventSuffix + ".svg";
return "offline";
case Status::Blocked:
return ":/img/status/blocked.svg";
return "blocked";
}
qWarning() << "Status unknown";
assert(false);
return QString{};
return QStringLiteral("");
}

QString getIconPath(Status status, bool event)
{
const QString eventSuffix = event ? QStringLiteral("_notification") : QString();
const QString statusSuffix = getAssetSuffix(status);
if (status == Status::Blocked) {
return ":/img/status/" + statusSuffix + ".svg";
} else {
return ":/img/status/" + statusSuffix + eventSuffix + ".svg";
}
}
} // namespace Status
1 change: 1 addition & 0 deletions src/model/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Status

QString getIconPath(Status status, bool event = false);
QString getTitle(Status status);
QString getAssetSuffix(Status status);
}

#endif // STATUS_H
22 changes: 8 additions & 14 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,9 @@ void Widget::updateIcons()
return;
}

QString status;
if (eventIcon) {
status = QStringLiteral("event");
} else {
status = ui->statusButton->property("status").toString();
if (!status.length()) {
status = QStringLiteral("offline");
}
}
const QString assetSuffix = eventIcon ? "event" :
Status::getAssetSuffix(static_cast<Status::Status>(ui->statusButton->property("status").toInt()));


// Some builds of Qt appear to have a bug in icon loading:
// QIcon::hasThemeIcon is sometimes unaware that the icon returned
Expand Down Expand Up @@ -474,11 +468,11 @@ void Widget::updateIcons()
}

QIcon ico;
if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + status)) {
ico = QIcon::fromTheme("qtox-" + status);
if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + assetSuffix)) {
ico = QIcon::fromTheme("qtox-" + assetSuffix);
} else {
QString color = settings.getLightTrayIcon() ? "light" : "dark";
QString path = ":/img/taskbar/" + color + "/taskbar_" + status + ".svg";
QString path = ":/img/taskbar/" + color + "/taskbar_" + assetSuffix + ".svg";
QSvgRenderer renderer(path);

// Prepare a QImage with desired characteritisc
Expand Down Expand Up @@ -649,7 +643,7 @@ void Widget::onBadProxyCore()

void Widget::onStatusSet(Status::Status status)
{
ui->statusButton->setProperty("status", getTitle(status));
ui->statusButton->setProperty("status", static_cast<int>(status));
ui->statusButton->setIcon(prepareIcon(getIconPath(status), icon_size, icon_size));
updateIcons();
}
Expand Down Expand Up @@ -1968,7 +1962,7 @@ void Widget::onUserAwayCheck()
{
#ifdef QTOX_PLATFORM_EXT
uint32_t autoAwayTime = settings.getAutoAwayTime() * 60 * 1000;
bool online = ui->statusButton->property("status").toString() == "online";
bool online = static_cast<Status::Status>(ui->statusButton->property("status").toInt()) == Status::Status::Online;
bool away = autoAwayTime && Platform::getIdleTime() >= autoAwayTime;

if (online && away) {
Expand Down

0 comments on commit 881aa30

Please sign in to comment.