From ac48d440bd03ac7c289ff162bd6ec2742aa7b55b Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 25 Oct 2020 23:35:55 +0200 Subject: [PATCH] Copied over code for user lusts entry into UserNode --- source/UserNode.d | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/source/UserNode.d b/source/UserNode.d index e4b4df6..ead144f 100644 --- a/source/UserNode.d +++ b/source/UserNode.d @@ -1,7 +1,14 @@ module UserNode; import Connection; +import libdnet.dclient; import gtk.Box; +import gtk.Button; +import gtk.Image; +import gtk.Label; +import gtk.Tooltip; +import gtk.Widget; +import std.string; public final class UserNode { @@ -22,9 +29,96 @@ public final class UserNode { box = new Box(GtkOrientation.HORIZONTAL, 1); + /* Layout [Button (Prescence Icon)] - Label */ + Button userButton = new Button(); + Image userButtonImg = new Image("user-available", GtkIconSize.BUTTON); + userButton.setImage(userButtonImg); + + /* Create a label */ + Label userLabel = new Label(username); + + /* Enable the tooltip */ + userLabel.setHasTooltip(true); + + /* Set the handler to run on hover */ + userLabel.addOnQueryTooltip(&userLabelHoverHandler); + /* TODO: Implement me */ } + /** + * Event handler to be run when you hover over a user's + * username in the Users sidebar list which will show + * the status as text (and in an icon format), the user's + * username and also their status message + */ + private bool userLabelHoverHandler(int, int, bool, Tooltip tooltip, Widget userLabel) + { + /* Get the client */ + DClient client = connection.getClient(); + + /* The username hovered over */ + string userHover = (cast(Label)userLabel).getText(); + + /* The final tooltip */ + string toolTipText = ""~userHover~""; + + /* Check if there is a `precensce` message */ + if(client.isProperty(userHover, "pres")) + { + /* Fetch the precensce */ + string prescence = client.getProperty(userHover, "pres"); + + /* Set the icon */ + tooltip.setIconFromIconName(statusToGtkIcon(prescence), GtkIconSize.DIALOG); + + /* Append the precesnee to the tooltip text */ + toolTipText ~= "\n"~prescence; + } + + /* Check if there is a `status` message */ + if(client.isProperty(userHover, "status")) + { + /* Next is status message */ + string status = client.getProperty(userHover, "status"); + + /* Append the status to the tooltip text */ + toolTipText ~= "\n"~status~""; + } + + /* Set the tooltip text */ + tooltip.setMarkup(toolTipText); + + /* TODO: Point of return value? */ + return 1; + } + + private static string statusToGtkIcon(string status) + { + /* The GTK icon */ + string gtkIcon = "image-missing"; + + if(cmp(status, "available") == 0) + { + gtkIcon = "user-available"; + } + else if(cmp(status, "away") == 0) + { + gtkIcon = "user-away"; + } + else if(cmp(status, "busy") == 0) + { + gtkIcon = "user-busy"; + } + /* TODO: This doesn't make sense */ + else if(cmp(status, "offline") == 0) + { + gtkIcon = "user-offline"; + } + + return gtkIcon; + } + public Box getBox() { return box;