mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(status): use enum as UI property instead of untranslated string
Translation of getStatusTitle introduced in 15d72a9610
, breaking asset path from string.
This commit is contained in:
parent
e1876a2691
commit
881aa3083a
|
@ -47,24 +47,32 @@ namespace Status
|
||||||
return QStringLiteral("");
|
return QStringLiteral("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getAssetSuffix(Status status)
|
||||||
|
{
|
||||||
|
switch (status) {
|
||||||
|
case Status::Online:
|
||||||
|
return "online";
|
||||||
|
case Status::Away:
|
||||||
|
return "away";
|
||||||
|
case Status::Busy:
|
||||||
|
return "busy";
|
||||||
|
case Status::Offline:
|
||||||
|
return "offline";
|
||||||
|
case Status::Blocked:
|
||||||
|
return "blocked";
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
return QStringLiteral("");
|
||||||
|
}
|
||||||
|
|
||||||
QString getIconPath(Status status, bool event)
|
QString getIconPath(Status status, bool event)
|
||||||
{
|
{
|
||||||
const QString eventSuffix = event ? QStringLiteral("_notification") : QString();
|
const QString eventSuffix = event ? QStringLiteral("_notification") : QString();
|
||||||
|
const QString statusSuffix = getAssetSuffix(status);
|
||||||
switch (status) {
|
if (status == Status::Blocked) {
|
||||||
case Status::Online:
|
return ":/img/status/" + statusSuffix + ".svg";
|
||||||
return ":/img/status/online" + eventSuffix + ".svg";
|
} else {
|
||||||
case Status::Away:
|
return ":/img/status/" + statusSuffix + eventSuffix + ".svg";
|
||||||
return ":/img/status/away" + eventSuffix + ".svg";
|
|
||||||
case Status::Busy:
|
|
||||||
return ":/img/status/busy" + eventSuffix + ".svg";
|
|
||||||
case Status::Offline:
|
|
||||||
return ":/img/status/offline" + eventSuffix + ".svg";
|
|
||||||
case Status::Blocked:
|
|
||||||
return ":/img/status/blocked.svg";
|
|
||||||
}
|
}
|
||||||
qWarning() << "Status unknown";
|
|
||||||
assert(false);
|
|
||||||
return QString{};
|
|
||||||
}
|
}
|
||||||
} // namespace Status
|
} // namespace Status
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace Status
|
||||||
|
|
||||||
QString getIconPath(Status status, bool event = false);
|
QString getIconPath(Status status, bool event = false);
|
||||||
QString getTitle(Status status);
|
QString getTitle(Status status);
|
||||||
|
QString getAssetSuffix(Status status);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // STATUS_H
|
#endif // STATUS_H
|
||||||
|
|
|
@ -437,15 +437,9 @@ void Widget::updateIcons()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString status;
|
const QString assetSuffix = eventIcon ? "event" :
|
||||||
if (eventIcon) {
|
Status::getAssetSuffix(static_cast<Status::Status>(ui->statusButton->property("status").toInt()));
|
||||||
status = QStringLiteral("event");
|
|
||||||
} else {
|
|
||||||
status = ui->statusButton->property("status").toString();
|
|
||||||
if (!status.length()) {
|
|
||||||
status = QStringLiteral("offline");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some builds of Qt appear to have a bug in icon loading:
|
// Some builds of Qt appear to have a bug in icon loading:
|
||||||
// QIcon::hasThemeIcon is sometimes unaware that the icon returned
|
// QIcon::hasThemeIcon is sometimes unaware that the icon returned
|
||||||
|
@ -474,11 +468,11 @@ void Widget::updateIcons()
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon ico;
|
QIcon ico;
|
||||||
if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + status)) {
|
if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + assetSuffix)) {
|
||||||
ico = QIcon::fromTheme("qtox-" + status);
|
ico = QIcon::fromTheme("qtox-" + assetSuffix);
|
||||||
} else {
|
} else {
|
||||||
QString color = settings.getLightTrayIcon() ? "light" : "dark";
|
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);
|
QSvgRenderer renderer(path);
|
||||||
|
|
||||||
// Prepare a QImage with desired characteritisc
|
// Prepare a QImage with desired characteritisc
|
||||||
|
@ -649,7 +643,7 @@ void Widget::onBadProxyCore()
|
||||||
|
|
||||||
void Widget::onStatusSet(Status::Status status)
|
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));
|
ui->statusButton->setIcon(prepareIcon(getIconPath(status), icon_size, icon_size));
|
||||||
updateIcons();
|
updateIcons();
|
||||||
}
|
}
|
||||||
|
@ -1968,7 +1962,7 @@ void Widget::onUserAwayCheck()
|
||||||
{
|
{
|
||||||
#ifdef QTOX_PLATFORM_EXT
|
#ifdef QTOX_PLATFORM_EXT
|
||||||
uint32_t autoAwayTime = settings.getAutoAwayTime() * 60 * 1000;
|
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;
|
bool away = autoAwayTime && Platform::getIdleTime() >= autoAwayTime;
|
||||||
|
|
||||||
if (online && away) {
|
if (online && away) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user