Commit 6231493f authored by LNJ's avatar LNJ 💬

QmlUtils: Add AvailabilityType utilities for name, icon and color

Co-authored-by: Robert Maerkisch's avatarRobert Maerkisch <zatroxde@protonmail.ch>
parent aa22d59f
......@@ -48,6 +48,75 @@ QmlUtils::QmlUtils(QObject *parent)
{
}
QString QmlUtils::presenceTypeToIcon(Enums::AvailabilityTypes type)
{
switch (type) {
case AvailabilityTypes::PresOnline:
return "im-user-online";
case AvailabilityTypes::PresChat:
return "im-user-online";
case AvailabilityTypes::PresAway:
return "im-user-away";
case AvailabilityTypes::PresDND:
return "im-kick-user";
case AvailabilityTypes::PresXA:
return "im-user-away";
case AvailabilityTypes::PresUnavailable:
return "im-user-offline";
case AvailabilityTypes::PresError:
return "im-ban-kick-user";
case AvailabilityTypes::PresInvisible:
return "im-invisible-user";
}
Q_UNREACHABLE();
}
QString QmlUtils::presenceTypeToText(AvailabilityTypes type)
{
switch (type) {
case AvailabilityTypes::PresOnline:
return tr("Available");
case AvailabilityTypes::PresChat:
return tr("Free for chat");
case AvailabilityTypes::PresAway:
return tr("Away");
case AvailabilityTypes::PresDND:
return tr("Do not disturb");
case AvailabilityTypes::PresXA:
return tr("Away for longer");
case AvailabilityTypes::PresUnavailable:
return tr("Offline");
case AvailabilityTypes::PresError:
return tr("Error");
case AvailabilityTypes::PresInvisible:
return tr("Invisible");
}
Q_UNREACHABLE();
}
QColor QmlUtils::presenceTypeToColor(AvailabilityTypes type)
{
switch (type) {
case AvailabilityTypes::PresOnline:
return {"green"};
case AvailabilityTypes::PresChat:
return {"darkgreen"};
case AvailabilityTypes::PresAway:
return {"orange"};
case AvailabilityTypes::PresDND:
return QColor::fromRgb(218, 68, 83);
case AvailabilityTypes::PresXA:
return {"orange"};
case AvailabilityTypes::PresError:
return {"red"};
case AvailabilityTypes::PresUnavailable:
return {"silver"};
case AvailabilityTypes::PresInvisible:
return {"grey"};
}
Q_UNREACHABLE();
}
QString QmlUtils::getResourcePath(const QString &name) const
{
// We generally prefer to first search for files in application resources
......
......@@ -33,6 +33,9 @@
#include <QObject>
#include "Globals.h"
#include "Enums.h"
using namespace Enums;
/**
* @brief C++ utitlities to be used in QML
......@@ -47,6 +50,21 @@ class QmlUtils : public QObject
public:
QmlUtils(QObject *parent = nullptr);
/**
* Returns the icon belonging to the given presence status type
*/
Q_INVOKABLE static QString presenceTypeToIcon(Enums::AvailabilityTypes type);
/**
* Returns the text belonging to the given presence status type
*/
Q_INVOKABLE static QString presenceTypeToText(Enums::AvailabilityTypes type);
/**
* Returns the color belonging to the given presence status type
*/
Q_INVOKABLE static QColor presenceTypeToColor(Enums::AvailabilityTypes type);
public slots:
/**
* Returns a URL to a given resource file name
......
......@@ -62,7 +62,7 @@ Kirigami.SwipeListItem {
width: Kirigami.Units.gridUnit * 0.3
height: parent.height
color: presenceTypeToColor(presenceType)
color: kaidan.utils.presenceTypeToColor(presenceType)
}
// left: avatar
......@@ -156,19 +156,6 @@ Kirigami.SwipeListItem {
}
}
/**
* Returns the color belonging to the given presence status type
*/
function presenceTypeToColor(type) {
return type === Enums.PresOnline ? "green" :
type === Enums.PresChat ? "darkgreen" :
type === Enums.PresAway ? "orange" :
type === Enums.PresDND ? "orange" :
type === Enums.PresXA ? "orange" :
type === Enums.PresError ? "red" :
"silver" // unavailable (offline)
}
/**
* Generates a styled text telling some basic information about the contact,
* is used for a tooltip
......@@ -182,15 +169,8 @@ Kirigami.SwipeListItem {
}
// presence status type
string += "<font color='" + presenceTypeToColor(statusType) + "'>"
string += statusType === Enums.PresOnline ? qsTr("Available") :
statusType === Enums.PresChat ? qsTr("Free for chat") :
statusType === Enums.PresAway ? qsTr("Away") :
statusType === Enums.PresDND ? qsTr("Do not disturb") :
statusType === Enums.PresXA ? qsTr("Away for longer") :
statusType === Enums.PresUnavailable ? qsTr("Offline") :
statusType === Enums.PresError ? qsTr("Error") :
"Invalid" // should never be displayed
string += "<font color='" + kaidan.utils.presenceTypeToColor(statusType) + "'>"
string += kaidan.utils.presenceTypeToText(statusType)
string += "</font>"
// presence status message
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment