Unverified Commit caa456f0 authored by Linus Jahn's avatar Linus Jahn
Browse files

RosterPage: Add tooltips for presence information and JID

This adds tool tips to the roster. They show the alias/name of the contact,
their full JID (in small), the presence status type (i.e. 'Available', 'Away',
etc.) and the optional presence status message. The font of the status type is
in the apropriate color, so for 'Away' the font is orange.

Closes #77.
parent da5679eb
......@@ -72,7 +72,7 @@ quint8 PresenceCache::getDefaultPresType(QString jid)
}
ContactPresences::ContactPresences(QString jid, QObject* parent)
: jid(jid), defaultPresence(new EntityPresence(gloox::Presence::Unavailable, "Offline")),
: jid(jid), defaultPresence(new EntityPresence(gloox::Presence::Unavailable, "")),
QObject(parent)
{
}
......
......@@ -65,8 +65,10 @@ Kirigami.ScrollablePage {
delegate: RosterListItem {
id: rosterItem
name: model.name ? model.name : model.jid
jid: model.jid
lastMessage: model.lastMessage
presenceType: kaidan.presenceCache.getDefaultPresType(model.jid)
statusMsg: kaidan.presenceCache.getDefaultStatus(model.jid)
unreadMessages: model.unreadMessages
avatarImagePath: kaidan.avatarStorage.getHashOfJid(model.jid) !== "" ?
kaidan.avatarStorage.getAvatarUrl(model.jid) :
......@@ -98,6 +100,8 @@ Kirigami.ScrollablePage {
if (jid === model.jid) {
rosterItem.presenceType = kaidan.presenceCache.
getDefaultPresType(model.jid)
rosterItem.statusMsg = kaidan.presenceCache.
getDefaultStatus(model.jid)
}
}
......
......@@ -35,14 +35,16 @@ import QtGraphicalEffects 1.0
import org.kde.kirigami 2.0 as Kirigami
Kirigami.SwipeListItem {
id: listItem
property string name
property string jid
property string lastMessage
property int unreadMessages
property string avatarImagePath
property int presenceType
property string presenceErrorMsg
property string statusMsg
id: listItem
topPadding: Kirigami.Units.smallSpacing * 1.5
height: Kirigami.Units.gridUnit * 3.5
......@@ -62,6 +64,13 @@ Kirigami.SwipeListItem {
width: height
fillMode: Image.PreserveAspectFit
mipmap: true
Controls.ToolTip {
visible: hovered
delay: Qt.styleHints.mousePressAndHoldInterval
text: generateToolTipText(listItem.name, listItem.jid,
listItem.presenceType, listItem.statusMsg)
}
}
Rectangle {
......@@ -73,16 +82,7 @@ Kirigami.SwipeListItem {
width: Kirigami.Units.gridUnit
height: Kirigami.Units.gridUnit
color: {
presenceType === 0 ? "green" : // available
presenceType === 1 ? "darkgreen" : // chat
presenceType === 2 ? "orange" : // away
presenceType === 3 ? "orange" : // do not disturb
presenceType === 4 ? "orange" : // extended away
presenceType === 7 ? "red" : // error
presenceType === 6 ? "red" : // error
"lightgrey" // unavailable (offline) (5), probe (6), invalid (8)
}
color: presenceTypeToColor(presenceType)
radius: Math.min(width, height) * 0.5
// shadow
layer.enabled: presenceIndicator.visible
......@@ -139,4 +139,49 @@ Kirigami.SwipeListItem {
Layout.preferredWidth: Kirigami.Units.gridUnit * 1.25
}
}
/**
* Returns the colour beloning to the given presence status type
*/
function presenceTypeToColor(type) {
return type === 0 ? "green" : // available
type === 1 ? "darkgreen" : // chat
type === 2 ? "orange" : // away
type === 3 ? "orange" : // do not disturb
type === 4 ? "orange" : // extended away
type === 7 ? "red" : // error
type === 6 ? "red" : // error
"lightgrey" // unavailable (offline) (5), probe (6), invalid (8)
}
/**
* Generates a styled text telling some basic information about the contact,
* is used for a tooltip
*/
function generateToolTipText(name, jid, statusType, statusMsg) {
// header (contact name)
var string = "<h3>" + name + "</h3>"
// in small: JID (only if differs name)
if (name !== jid) {
string += "<h5><i>" + jid + "</i></h5>"
}
// presence status type
string += "<font color='" + presenceTypeToColor(statusType) + "'>"
string += statusType === 0 ? qsTr("Available") :
statusType === 1 ? qsTr("Free for chat") :
statusType === 2 ? qsTr("Away") :
statusType === 3 ? qsTr("Do not disturb") :
statusType === 4 ? qsTr("Away for longer") :
statusType === 5 ? qsTr("Offline") :
statusType === 7 ? qsTr("Error") :
qsTr("Invalid")
string += "</font>"
// presence status message
if (statusMsg !== "") {
string += ": " + statusMsg
}
return string
}
}
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