mirror of https://github.com/deavminet/gustav.git
Compare commits
No commits in common. "master" and "v0.0.50" have entirely different histories.
5
dub.json
5
dub.json
|
@ -4,9 +4,8 @@
|
|||
],
|
||||
"copyright": "Copyright © 2020, Tristan B. Kildaire",
|
||||
"dependencies": {
|
||||
"gogga": "0.0.2",
|
||||
"gtk-d": "3.9.0",
|
||||
"libdnet": "0.2.3"
|
||||
"gtk-d": "~>3.9.0",
|
||||
"libdnet": "~>0.1.13"
|
||||
},
|
||||
"description": "GTK graphical DNET client",
|
||||
"license": "GPL v3",
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
"fileVersion": 1,
|
||||
"versions": {
|
||||
"bformat": "1.0.8",
|
||||
"gogga": "0.0.2",
|
||||
"gtk-d": "3.9.0",
|
||||
"libdnet": "0.2.3",
|
||||
"libdnet": "0.1.13",
|
||||
"tristanable": "0.1.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
* along with the input box state
|
||||
*/
|
||||
|
||||
module areas.Channel;
|
||||
|
||||
import gtk.Box;
|
||||
import gtk.ListBox;
|
||||
import gtk.Label;
|
||||
import gtk.TextView;
|
||||
import libdnet.client;
|
||||
import libdnet.dclient;
|
||||
import gtk.Label;
|
||||
import std.string;
|
||||
import gtk.Button;
|
||||
|
@ -22,16 +20,12 @@ import gtk.Widget;
|
|||
import gtk.ScrolledWindow;
|
||||
import gtk.Button;
|
||||
import gtk.Entry;
|
||||
import UserNode;
|
||||
|
||||
import pango.PgAttributeList;
|
||||
import pango.PgAttribute;
|
||||
import Connection;
|
||||
|
||||
import gogga;
|
||||
import areas.MessageArea;
|
||||
|
||||
public final class Channel : MessageArea
|
||||
public final class Channel
|
||||
{
|
||||
private DClient client;
|
||||
private Connection connection;
|
||||
|
@ -41,6 +35,11 @@ public final class Channel : MessageArea
|
|||
*/
|
||||
private string channelName;
|
||||
|
||||
/**
|
||||
* The container for this Channel
|
||||
*/
|
||||
private Box box;
|
||||
|
||||
/**
|
||||
* UI components
|
||||
*
|
||||
|
@ -95,24 +94,10 @@ public final class Channel : MessageArea
|
|||
ScrolledWindow scrollTextChats = new ScrolledWindow(textArea);
|
||||
textBox.add(scrollTextChats);
|
||||
|
||||
|
||||
/* The Box for the whole |attach button| text field| send button| */
|
||||
Box textInputBox = new Box(GtkOrientation.HORIZONTAL, 1);
|
||||
|
||||
import gtk.Image;
|
||||
|
||||
/* The attachment button */
|
||||
Button attachFileButton = new Button("Upload");
|
||||
Image attachFileButtonIcon = new Image("user-available", GtkIconSize.BUTTON); /* TODO: Fix icon now showing */
|
||||
attachFileButton.setImage(attachFileButtonIcon);
|
||||
attachFileButton.addOnClicked(&uploadFileDialog);
|
||||
textInputBox.add(attachFileButton);
|
||||
|
||||
/* The text input */
|
||||
textInput = new Entry();
|
||||
textInput.addOnActivate(&sendMessageEnter);
|
||||
textInput.addOnChanged(&textChangd);
|
||||
|
||||
Box textInputBox = new Box(GtkOrientation.HORIZONTAL, 1);
|
||||
textInputBox.packStart(textInput,1,1,0);
|
||||
|
||||
|
||||
|
@ -122,6 +107,14 @@ public final class Channel : MessageArea
|
|||
textInputBox.add(sendButton);
|
||||
textBox.add(textInputBox);
|
||||
|
||||
|
||||
// import gtk.TextView;
|
||||
// TextView f = new TextView();
|
||||
// textBox.add(f);
|
||||
|
||||
|
||||
|
||||
|
||||
box.add(textBox);
|
||||
box.packEnd(userBox,0,0,0);
|
||||
|
||||
|
@ -130,23 +123,6 @@ public final class Channel : MessageArea
|
|||
|
||||
}
|
||||
|
||||
private void uploadFileDialog(Button e)
|
||||
{
|
||||
import gtk.FileChooserDialog; /* TODO: Set parent */
|
||||
FileChooserDialog fileChooser = new FileChooserDialog("Send file to "~channelName, null, FileChooserAction.OPEN);
|
||||
fileChooser.run();
|
||||
gprintln("Selected file: "~fileChooser.getFilename());
|
||||
}
|
||||
|
||||
import gtk.EditableIF;
|
||||
private void textChangd(EditableIF)
|
||||
{
|
||||
/* If the text box just became empty stop ssending typing notifications */
|
||||
/* Send typing stats */
|
||||
// client.sendIsTyping(channelName, true);
|
||||
/* TODO: Client implement wiht different tag? */
|
||||
}
|
||||
|
||||
private void sendMessageEnter(Entry)
|
||||
{
|
||||
/* Retrieve the message */
|
||||
|
@ -181,12 +157,33 @@ public final class Channel : MessageArea
|
|||
box.showAll();
|
||||
}
|
||||
|
||||
public Box getBox()
|
||||
{
|
||||
return box;
|
||||
}
|
||||
|
||||
public string getName()
|
||||
{
|
||||
return channelName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a Label with the tooltip event such
|
||||
* that it will run that handler on hover
|
||||
*/
|
||||
private Label getUserLabel(string username)
|
||||
{
|
||||
/* Create a label */
|
||||
Label userLabel = new Label(username);
|
||||
|
||||
/* Enable the tooltip */
|
||||
userLabel.setHasTooltip(true);
|
||||
|
||||
/* Set the handler to run on hover */
|
||||
userLabel.addOnQueryTooltip(&userLabelHoverHandler);
|
||||
|
||||
return userLabel;
|
||||
}
|
||||
|
||||
|
||||
private Box getUserListItem(string username)
|
||||
|
@ -212,8 +209,49 @@ public final class Channel : MessageArea
|
|||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
/* The username hovered over */
|
||||
string userHover = (cast(Label)userLabel).getText();
|
||||
|
||||
/* The final tooltip */
|
||||
string toolTipText = "<b>"~userHover~"</b>";
|
||||
|
||||
/* 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<i>"~status~"</i>";
|
||||
}
|
||||
|
||||
/* Set the tooltip text */
|
||||
tooltip.setMarkup(toolTipText);
|
||||
|
||||
/* TODO: Point of return value? */
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void populateUsersList()
|
||||
{
|
||||
|
@ -221,19 +259,47 @@ public final class Channel : MessageArea
|
|||
|
||||
foreach(string member; memberList)
|
||||
{
|
||||
/* Create the user entry in the list */
|
||||
UserNode userNode = new UserNode(connection, member);
|
||||
users.add(userNode.getBox());
|
||||
|
||||
/* Add the user to the tracking list */
|
||||
Label bruh = getUserLabel(member);
|
||||
users.add(bruh);
|
||||
usersString~=member;
|
||||
|
||||
|
||||
/* TODO: Testing code, remove */
|
||||
import UserNode;
|
||||
UserNode testNode = new UserNode(connection, member);
|
||||
users.add(testNode.getBox());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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 void channelJoin(string username)
|
||||
{
|
||||
/* The label to add */
|
||||
|
@ -247,11 +313,9 @@ public final class Channel : MessageArea
|
|||
/* Add join message to message log */
|
||||
textArea.add(joinLabel);
|
||||
|
||||
/* Create the user entry in the list */
|
||||
UserNode userNode = new UserNode(connection, username);
|
||||
users.add(userNode.getBox());
|
||||
/* Add user to user list */
|
||||
users.add(getUserLabel(username));
|
||||
|
||||
/* Add the user to the tracking list */
|
||||
usersString~=username;
|
||||
}
|
||||
|
||||
|
@ -288,10 +352,15 @@ public final class Channel : MessageArea
|
|||
|
||||
foreach(string currentUser; usersString)
|
||||
{
|
||||
/* Create the user entry in the list */
|
||||
UserNode userNode = new UserNode(connection, currentUser);
|
||||
users.add(userNode.getBox());
|
||||
users.add(getUserLabel(currentUser));
|
||||
}
|
||||
|
||||
/* Remove user from user list */
|
||||
/* TODO: Do this better */
|
||||
// foreach(Label label; users.get)
|
||||
// users.add(new Label(username));
|
||||
// users.showAll();
|
||||
// box.showAll();+
|
||||
}
|
||||
|
||||
public void sendMessage(string message)
|
|
@ -5,14 +5,12 @@ import gui;
|
|||
import gdk.Threads : te = threadsEnter, tl = threadsLeave;
|
||||
import gtk.Box;
|
||||
import std.stdio;
|
||||
import libdnet.client;
|
||||
import libdnet.dclient;
|
||||
import std.socket;
|
||||
import gtk.ListBox;
|
||||
import gtk.Label;
|
||||
|
||||
import areas.Channel;
|
||||
import areas.MessageArea;
|
||||
import areas.User;
|
||||
import Channel;
|
||||
import std.string;
|
||||
|
||||
import core.sync.mutex;
|
||||
|
@ -21,15 +19,13 @@ import gtk.Notebook;
|
|||
|
||||
import std.conv;
|
||||
|
||||
import gogga;
|
||||
|
||||
|
||||
|
||||
public final class Connection : Thread
|
||||
{
|
||||
private GUI gui;
|
||||
private Box box;
|
||||
private ListBox channels;
|
||||
private ListBox users;
|
||||
private ListBox textArea;
|
||||
|
||||
private DClient client;
|
||||
private Address address;
|
||||
|
@ -45,9 +41,9 @@ public final class Connection : Thread
|
|||
* All joined Channel-s in this Connection
|
||||
*/
|
||||
private Notebook notebookSwitcher;
|
||||
private MessageArea[] areas; /*TODO: Technically locking by GTK would make this not needed */
|
||||
private Channel[] chans; /*TODO: Technically locking by GTK would make this not needed */
|
||||
private Mutex chansLock;
|
||||
private MessageArea focusedArea;
|
||||
private Channel focusedChan;
|
||||
|
||||
|
||||
// public void setPrescence(string pres)
|
||||
|
@ -126,8 +122,7 @@ public final class Connection : Thread
|
|||
{
|
||||
/* Receive a notification */
|
||||
byte[] notificationData = client.awaitNotification();
|
||||
gprintln("A new notification has arrived");
|
||||
gprintln("Notification data: "~to!(string)(notificationData));
|
||||
writeln(notificationData);
|
||||
|
||||
te();
|
||||
// import std.conv;
|
||||
|
@ -156,100 +151,45 @@ public final class Connection : Thread
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Processes an incoming notification
|
||||
* accordingly
|
||||
*/
|
||||
private void process(byte[] data)
|
||||
{
|
||||
/* Get the notification type */
|
||||
/* TODO: Implement me */
|
||||
|
||||
/* TODO: Check notification type */
|
||||
ubyte notificationType = data[0];
|
||||
gprintln("NotificationType: "~to!(string)(notificationType));
|
||||
|
||||
/* For normal message (to channel or user) */
|
||||
if(notificationType == 0)
|
||||
{
|
||||
/* TODO: Handle private messages */
|
||||
/* TODO: Decode using tristanable */
|
||||
writeln("new message");
|
||||
writeln(data);
|
||||
|
||||
/* Decode is a test for assuming channel message received */
|
||||
data = data[1..data.length];
|
||||
gprintln("Channel/User Notification: "~to!(string)(data));
|
||||
|
||||
|
||||
/* Decode the [usernameLength, username] */
|
||||
ubyte usernameLength = data[1];
|
||||
writeln(usernameLength);
|
||||
string username = cast(string)data[2..2+usernameLength];
|
||||
writeln(username);
|
||||
|
||||
/* Decode the [channelLength, channel] */
|
||||
ubyte channelLength = data[2+usernameLength];
|
||||
writeln(channelLength);
|
||||
string channel = cast(string)data[2+usernameLength+1..2+usernameLength+1+channelLength];
|
||||
writeln(channel);
|
||||
|
||||
/* If this is a new message channel notification */
|
||||
if(data[0] == 0)
|
||||
{
|
||||
gprintln("New channel message received", DebugType.WARNING);
|
||||
|
||||
/* Decode the [usernameLength, username] */
|
||||
ubyte usernameLength = data[1];
|
||||
gprintln("ChannelMessage: (Username length): "~to!(string)(usernameLength));
|
||||
string username = cast(string)data[2..2+usernameLength];
|
||||
gprintln("ChannelMessage: (Username): "~username);
|
||||
findChannel(channel).receiveMessage(username, cast(string)data[2+usernameLength+1+channelLength..data.length]);
|
||||
|
||||
/* Decode the [channelLength, channel] */
|
||||
ubyte channelLength = data[2+usernameLength];
|
||||
gprintln("ChannelMessage: (Channel length): "~to!(string)(channelLength));
|
||||
string channel = cast(string)data[2+usernameLength+1..2+usernameLength+1+channelLength];
|
||||
gprintln("ChannelMessage: (Channel): "~channel);
|
||||
|
||||
findChannel(channel).receiveMessage(username, cast(string)data[2+usernameLength+1+channelLength..data.length]);
|
||||
}
|
||||
/* If this is a new direct message notification */
|
||||
else if(data[0] == 1)
|
||||
{
|
||||
gprintln("New direct message received", DebugType.WARNING);
|
||||
|
||||
/* Decode the [usernameLength, username] (username here is recipient's) */
|
||||
ubyte recipientLength = data[1];
|
||||
gprintln("DirectMessage: (Recipient length): "~to!(string)(recipientLength));
|
||||
string recipient = cast(string)data[2..2+recipientLength];
|
||||
gprintln("DirectMessage: (Recipient): "~recipient);
|
||||
|
||||
/* Decode the [usernameLength, username] (username here is sender's) */
|
||||
ubyte sendersLength = data[2+recipientLength];
|
||||
gprintln("DirectMessage: (Sender length): "~to!(string)(sendersLength));
|
||||
string sender = cast(string)data[2+recipientLength+1..2+recipientLength+1+sendersLength];
|
||||
gprintln("DirectMessage: (Sender): "~sender);
|
||||
|
||||
|
||||
|
||||
/* The message is the remainder */
|
||||
string message = cast(string)data[2+recipientLength+1+sendersLength..data.length];
|
||||
gprintln("DirectMessage: (Message): "~message);
|
||||
|
||||
/**
|
||||
* TODO: DIfferes from channels, channels we never get delivered those we have no tab for as we haven't joined them
|
||||
* and because server side knows we haven't joined iot we don't receive the notifivcaiton, eher however, there is no
|
||||
* user tab possibly yet, so we will need to add it our selves */
|
||||
User userArea = findUser(sender);
|
||||
|
||||
if(userArea)
|
||||
{
|
||||
userArea.receiveMessage(sender, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add a new UserArea which will generate a new tab for us */
|
||||
addDirectMessage_unsafe(sender);
|
||||
|
||||
/* The above statement adds an entry for us, now let's find the added UserArea */
|
||||
userArea = findUser(sender);
|
||||
|
||||
/* Now let's add the direct message */
|
||||
userArea.receiveMessage(sender, message);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Handle this */
|
||||
gprintln("FOk");
|
||||
}
|
||||
|
||||
writeln("hdsfhdk");
|
||||
}
|
||||
/* Channel notification (ntype=1) */
|
||||
else if(notificationType == 1)
|
||||
|
@ -300,124 +240,6 @@ public final class Connection : Thread
|
|||
}
|
||||
|
||||
|
||||
private void addUserDM(User newUser)
|
||||
{
|
||||
/* TODO: However this we need to mutex for the areas as we could recieve a new message by watcher which adds for us */
|
||||
chansLock.lock();
|
||||
areas ~= newUser;
|
||||
chansLock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new tab for a new direct message
|
||||
*
|
||||
* (To be called by a handler, which auto-mutexes)
|
||||
*
|
||||
* 1. Will add a new area
|
||||
* 2. Will add a new tab to the notebook switcher
|
||||
* 3. Will switch the current tab to said tab
|
||||
*/
|
||||
public void addDirectMessage_unsafe(string username)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/* TODO: Get box over here etc. */
|
||||
|
||||
gprintln("Henlo begi");
|
||||
|
||||
/* Check if we have joined this user already */
|
||||
User foundUser = findUser(username);
|
||||
|
||||
gprintln("Henlo");
|
||||
|
||||
/* If we have joined this user before */
|
||||
if(foundUser)
|
||||
{
|
||||
/* TODO: Switch to */
|
||||
writeln("nope time: "~username);
|
||||
|
||||
|
||||
}
|
||||
/* If we haven't joined this user before */
|
||||
else
|
||||
{
|
||||
/* Create the new User area */
|
||||
User newUser = new User(this, username);
|
||||
|
||||
/* Add the user */
|
||||
addUserDM(newUser);
|
||||
|
||||
/* Set as the `foundChannel` */
|
||||
foundUser = newUser;
|
||||
|
||||
/* Get the Widgets container for this channel and add a tab for it */
|
||||
notebookSwitcher.add(newUser.getBox());
|
||||
notebookSwitcher.setTabReorderable(newUser.getBox(), true);
|
||||
notebookSwitcher.setTabLabelText(newUser.getBox(), newUser.getUsername());
|
||||
|
||||
writeln("hdsjghjsd");
|
||||
|
||||
writeln("first time: "~username);
|
||||
|
||||
// /* Get the user's list */
|
||||
// newChannel.populateUsersList();
|
||||
}
|
||||
|
||||
/* Render recursively all children of the container and then the container itself */
|
||||
box.showAll();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to find the User object you are looking for
|
||||
*/
|
||||
public User findUser(string username)
|
||||
{
|
||||
User result;
|
||||
|
||||
chansLock.lock();
|
||||
|
||||
/**
|
||||
* Loop through each MessageArea and only inspect those
|
||||
* whose type is `Channel`
|
||||
*/
|
||||
foreach(MessageArea area; areas)
|
||||
{
|
||||
|
||||
/* Make sure the object is of type `Channel` */
|
||||
if(typeid(area) == typeid(User))
|
||||
{
|
||||
/* Down-cast */
|
||||
User user = cast(User)area;
|
||||
|
||||
/* Find the matching channel */
|
||||
if(cmp(user.getUsername(), username) == 0)
|
||||
{
|
||||
result = user;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import std.stdio;
|
||||
writeln("\""~username~"\"");
|
||||
|
||||
|
||||
chansLock.unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void joinChannel(string channelName)
|
||||
{
|
||||
/* Check if we have joined this channel already */
|
||||
|
@ -494,34 +316,18 @@ public final class Connection : Thread
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find the Channel object you are looking for
|
||||
*/
|
||||
public Channel findChannel(string channelName)
|
||||
{
|
||||
Channel result;
|
||||
|
||||
chansLock.lock();
|
||||
|
||||
/**
|
||||
* Loop through each MessageArea and only inspect those
|
||||
* whose type is `Channel`
|
||||
*/
|
||||
foreach(MessageArea area; areas)
|
||||
foreach(Channel channel; chans)
|
||||
{
|
||||
|
||||
/* Make sure the object is of type `Channel` */
|
||||
if(typeid(area) == typeid(Channel))
|
||||
if(cmp(channel.getName(), channelName) == 0)
|
||||
{
|
||||
/* Down-cast */
|
||||
Channel channel = cast(Channel)area;
|
||||
|
||||
/* Find the matching channel */
|
||||
if(cmp(channel.getName(), channelName) == 0)
|
||||
{
|
||||
result = channel;
|
||||
break;
|
||||
}
|
||||
result = channel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,7 +354,7 @@ public final class Connection : Thread
|
|||
{
|
||||
/* Add the channel to the `chans` tracking list */
|
||||
chansLock.lock();
|
||||
areas ~= newChannel;
|
||||
chans ~= newChannel;
|
||||
chansLock.unlock();
|
||||
|
||||
/* Add the channel to the channels list (sidebar) */
|
||||
|
|
|
@ -9,7 +9,6 @@ import gtk.Window;
|
|||
import gtk.Label;
|
||||
import gtk.Image;
|
||||
import std.conv;
|
||||
import gtk.Box;
|
||||
|
||||
public final class ProfileWindow
|
||||
{
|
||||
|
@ -26,41 +25,16 @@ public final class ProfileWindow
|
|||
|
||||
private void showWindow()
|
||||
{
|
||||
/* Create the window with the username as the title */
|
||||
Window profileWindow = new Window(username);
|
||||
|
||||
/* Create a Box for contents */
|
||||
Box profileBox = new Box(GtkOrientation.VERTICAL, 1);
|
||||
|
||||
|
||||
/* Create a Image for the profile picture */
|
||||
Image profileImage = new Image("/home/deavmi/Downloads/logo.png");
|
||||
profileBox.add(profileImage);
|
||||
// profileImage.
|
||||
|
||||
/* Create the username label */
|
||||
Label usernameTitle = new Label("");
|
||||
usernameTitle.setMarkup("<span size=\"20000\">"~username~"</span>");
|
||||
profileBox.add(usernameTitle);
|
||||
|
||||
|
||||
/* Display all props (keys) */
|
||||
Image profileImage = new Image("/home/deavmi/Downloads/5207740.jpg");
|
||||
//profileWindow.add(profileImage);
|
||||
|
||||
string[] props = connection.getClient().getProperties(username);
|
||||
profileBox.add(new Label(to!(string)(props)));
|
||||
profileWindow.add(new Label(to!(string)(props)));
|
||||
|
||||
/* Display all props (values) */
|
||||
string[] propValues;
|
||||
foreach(string property; props)
|
||||
{
|
||||
propValues ~= connection.getClient().getProperty(username, property);
|
||||
}
|
||||
profileBox.add(new Label(to!(string)(propValues)));
|
||||
|
||||
|
||||
|
||||
profileWindow.add(profileBox);
|
||||
profileWindow.showAll();
|
||||
// profileWindow.unmaximize();
|
||||
// profileWindow.setAttachedTo()
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
module UserNode;
|
||||
|
||||
import Connection;
|
||||
import libdnet.client;
|
||||
import libdnet.dclient;
|
||||
import gtk.Box;
|
||||
import gtk.Button;
|
||||
import gtk.Image;
|
||||
|
@ -9,7 +9,6 @@ import gtk.Label;
|
|||
import gtk.Tooltip;
|
||||
import gtk.Widget;
|
||||
import std.string;
|
||||
import ProfileWIndow;
|
||||
|
||||
public final class UserNode
|
||||
{
|
||||
|
@ -26,24 +25,14 @@ public final class UserNode
|
|||
initBox();
|
||||
}
|
||||
|
||||
private void userButtonClick(Button)
|
||||
{
|
||||
/* Create a new ProfileWindow */
|
||||
ProfileWindow profileWindow = new ProfileWindow(connection, username);
|
||||
}
|
||||
|
||||
private void initBox()
|
||||
{
|
||||
/* Create a new Box */
|
||||
box = new Box(GtkOrientation.HORIZONTAL, 10);
|
||||
|
||||
/* Layout [Button (Prescence Icon)] - Label <username> - [Button (Reply Icon)]*/
|
||||
/* Layout [Button (Prescence Icon)] - Label <username> */
|
||||
Button userButton = new Button();
|
||||
Image userButtonImg = new Image("user-available", GtkIconSize.BUTTON);
|
||||
userButton.setImage(userButtonImg);
|
||||
|
||||
/* Set the handler for on click */
|
||||
userButton.addOnClicked(&userButtonClick);
|
||||
|
||||
/* Create a label */
|
||||
Label userLabel = new Label(username);
|
||||
|
@ -59,30 +48,8 @@ public final class UserNode
|
|||
/* Add both components */
|
||||
box.add(userButton);
|
||||
box.add(userLabel);
|
||||
|
||||
|
||||
/* Add the direct message button */
|
||||
Button messageButton = new Button();
|
||||
Image messageButtonImg = new Image("mail-forward", GtkIconSize.BUTTON);
|
||||
messageButton.setImage(messageButtonImg);
|
||||
|
||||
/* Set the handler for on click */
|
||||
messageButton.addOnClicked(&newDirectMessage);
|
||||
|
||||
box.add(messageButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the handler for when the "direct message" button is clicked
|
||||
*
|
||||
* It will call `addDirectMessage_unsafe` with the username specified
|
||||
*/
|
||||
private void newDirectMessage(Button)
|
||||
{
|
||||
connection.addDirectMessage_unsafe(username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Event handler to be run when you hover over a user's
|
||||
* username in the Users sidebar list which will show
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* MessageArea
|
||||
*
|
||||
* Represents the binding of a text entry, send button, user list (sometimes)
|
||||
* and message log - basically the place where you message a channel or someone
|
||||
*
|
||||
* The sub-classes are "Direct Message" and "Channel"
|
||||
*/
|
||||
|
||||
module areas.MessageArea;
|
||||
|
||||
import gtk.Box;
|
||||
|
||||
public class MessageArea
|
||||
{
|
||||
/* TODO: Implement me */
|
||||
|
||||
/* The area's Box (where everything is contained) */
|
||||
protected Box box;
|
||||
|
||||
public Box getBox()
|
||||
{
|
||||
return box;
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
module areas.User;
|
||||
|
||||
import areas.MessageArea;
|
||||
|
||||
import gtk.Box;
|
||||
import gtk.ListBox;
|
||||
import gtk.Label;
|
||||
import gtk.TextView;
|
||||
import libdnet.client;
|
||||
import gtk.Label;
|
||||
import std.string;
|
||||
import gtk.Button;
|
||||
import gtk.Tooltip;
|
||||
import gtk.Widget;
|
||||
import gtk.ScrolledWindow;
|
||||
import gtk.Button;
|
||||
import gtk.Entry;
|
||||
import UserNode;
|
||||
|
||||
import pango.PgAttributeList;
|
||||
import pango.PgAttribute;
|
||||
import Connection;
|
||||
|
||||
import gogga;
|
||||
|
||||
public final class User : MessageArea
|
||||
{
|
||||
private DClient client;
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Username
|
||||
*/
|
||||
private string username;
|
||||
|
||||
/**
|
||||
* UI components
|
||||
*
|
||||
*/
|
||||
// private ListBox users;
|
||||
private ListBox textArea;
|
||||
private Entry textInput;
|
||||
|
||||
|
||||
/* TODO: No mutexes should be needed (same precaution) as the GTK lock provides safety */
|
||||
// private string[] usersString;
|
||||
|
||||
this(Connection connection, string username)
|
||||
{
|
||||
this.client = connection.getClient();
|
||||
this.connection = connection;
|
||||
this.username = username;
|
||||
|
||||
initializeBox();
|
||||
}
|
||||
|
||||
public string getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
private void initializeBox()
|
||||
{
|
||||
box = new Box(GtkOrientation.HORIZONTAL, 1);
|
||||
|
||||
// box.add(new Label("poes"));
|
||||
/* The text box */
|
||||
Box textBox = new Box(GtkOrientation.VERTICAL, 1);
|
||||
|
||||
/* Channel title */
|
||||
Label channelTitleLabel = new Label(username);
|
||||
channelTitleLabel.setMarkup("<span size=\"large\"><b>"~username~"</b></span>");
|
||||
textBox.add(channelTitleLabel);
|
||||
|
||||
/* The messages box */
|
||||
textArea = new ListBox();
|
||||
ScrolledWindow scrollTextChats = new ScrolledWindow(textArea);
|
||||
textBox.add(scrollTextChats);
|
||||
|
||||
|
||||
/* The Box for the whole |attach button| text field| send button| */
|
||||
Box textInputBox = new Box(GtkOrientation.HORIZONTAL, 1);
|
||||
|
||||
import gtk.Image;
|
||||
|
||||
/* The attachment button */
|
||||
Button attachFileButton = new Button("Upload");
|
||||
Image attachFileButtonIcon = new Image("user-available", GtkIconSize.BUTTON); /* TODO: Fix icon now showing */
|
||||
attachFileButton.setImage(attachFileButtonIcon);
|
||||
attachFileButton.addOnClicked(&uploadFileDialog);
|
||||
textInputBox.add(attachFileButton);
|
||||
|
||||
/* The text input */
|
||||
textInput = new Entry();
|
||||
textInput.addOnActivate(&sendMessageEnter);
|
||||
textInput.addOnChanged(&textChangd);
|
||||
|
||||
textInputBox.packStart(textInput,1,1,0);
|
||||
|
||||
|
||||
/* The send button */
|
||||
Button sendButton = new Button("Send");
|
||||
sendButton.addOnClicked(&sendMessageBtn);
|
||||
textInputBox.add(sendButton);
|
||||
textBox.add(textInputBox);
|
||||
|
||||
box.add(textBox);
|
||||
// box.packEnd(userBox,0,0,0);
|
||||
|
||||
textBox.setChildPacking(scrollTextChats, true, true, 0, GtkPackType.START);
|
||||
box.setChildPacking(textBox, true, true, 0, GtkPackType.START);
|
||||
|
||||
}
|
||||
|
||||
|
||||
import gtk.EditableIF;
|
||||
private void textChangd(EditableIF)
|
||||
{
|
||||
/* If the text box just became empty stop ssending typing notifications */
|
||||
/* Send typing stats */
|
||||
// client.sendIsTyping(channelName, true);
|
||||
/* TODO: Client implement wiht different tag? */
|
||||
}
|
||||
|
||||
private void sendMessageEnter(Entry)
|
||||
{
|
||||
/* Retrieve the message */
|
||||
string message = textInput.getBuffer().getText();
|
||||
|
||||
/* TODO: Add the message to our log (as it won't be delivered to us) */
|
||||
sendMessage(message);
|
||||
|
||||
/* Send the message */
|
||||
client.sendMessage(1, username, message);
|
||||
|
||||
/* Clear the text box */
|
||||
textInput.getBuffer().setText("",0);
|
||||
|
||||
box.showAll();
|
||||
}
|
||||
|
||||
private void sendMessageBtn(Button)
|
||||
{
|
||||
/* Retrieve the message */
|
||||
string message = textInput.getBuffer().getText();
|
||||
|
||||
/* TODO: Add the message to our log (as it won't be delivered to us) */
|
||||
sendMessage(message);
|
||||
|
||||
/* Send the message */
|
||||
client.sendMessage(1, username, message);
|
||||
|
||||
/* Clear the text box */
|
||||
textInput.getBuffer().setText("",0);
|
||||
|
||||
box.showAll();
|
||||
}
|
||||
|
||||
public void sendMessage(string message)
|
||||
{
|
||||
/* TOOD: Pass in connection perhaps */
|
||||
string username = "Yourself";
|
||||
|
||||
/* Create the MessageBox */
|
||||
Box messageBox = new Box(GtkOrientation.VERTICAL, 1);
|
||||
|
||||
/* Create and add the username */
|
||||
Label usernameLabel = new Label("");
|
||||
usernameLabel.setMarkup("<b>"~username~"</b>");
|
||||
usernameLabel.setHalign(GtkAlign.END);
|
||||
messageBox.add(usernameLabel);
|
||||
|
||||
/* Create and add the message */
|
||||
Label messageLabel = new Label(message);
|
||||
messageLabel.setHalign(GtkAlign.END);
|
||||
messageLabel.setSelectable(true);
|
||||
messageBox.add(messageLabel);
|
||||
|
||||
/* Add the message to the log */
|
||||
textArea.add(messageBox);
|
||||
}
|
||||
|
||||
public void receiveMessage(string username, string message)
|
||||
{
|
||||
/* Create the MessageBox */
|
||||
Box messageBox = new Box(GtkOrientation.VERTICAL, 1);
|
||||
|
||||
/* Create and add the username */
|
||||
Label usernameLabel = new Label("");
|
||||
usernameLabel.setMarkup("<b>"~username~"</b>");
|
||||
usernameLabel.setHalign(GtkAlign.START);
|
||||
messageBox.add(usernameLabel);
|
||||
|
||||
/* Create and add the message */
|
||||
Label messageLabel = new Label(message);
|
||||
messageLabel.setHalign(GtkAlign.START);
|
||||
messageLabel.setSelectable(true);
|
||||
messageBox.add(messageLabel);
|
||||
|
||||
// import gtk.Image;
|
||||
// Image d = new Image("/home/deavmi/Downloads/5207740.jpg");
|
||||
// messageBox.add(d);
|
||||
|
||||
/* Add the message to the log */
|
||||
textArea.add(messageBox);
|
||||
}
|
||||
|
||||
private void uploadFileDialog(Button e)
|
||||
{
|
||||
import gtk.FileChooserDialog; /* TODO: Set parent */
|
||||
FileChooserDialog fileChooser = new FileChooserDialog("Send file to "~username, null, FileChooserAction.OPEN);
|
||||
fileChooser.run();
|
||||
gprintln("Selected file: "~fileChooser.getFilename());
|
||||
}
|
||||
}
|
81
source/gui.d
81
source/gui.d
|
@ -21,7 +21,7 @@ import gtk.SearchEntry;
|
|||
import gtk.Image;
|
||||
|
||||
import Connection;
|
||||
import areas.Channel;
|
||||
import Channel;
|
||||
import std.socket;
|
||||
|
||||
import std.conv;
|
||||
|
@ -253,16 +253,6 @@ public class GUI : Thread
|
|||
channelListButton.addOnClicked(&listChannels);
|
||||
toolbar.add(channelListButton);
|
||||
|
||||
/* TODO: Join channel button */
|
||||
ToolButton joinChannelButton = new ToolButton("");
|
||||
joinChannelButton.setIconName("document-new");
|
||||
joinChannelButton.setTooltipText("Join channel");
|
||||
toolbar.add(joinChannelButton);
|
||||
|
||||
|
||||
/* TODO: Leave channel button */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -288,18 +278,6 @@ public class GUI : Thread
|
|||
import std.string;
|
||||
private void setStatusMessage(Entry f)
|
||||
{
|
||||
/* If there are no connections */
|
||||
if(!connections.length)
|
||||
{
|
||||
import gtk.MessageDialog;
|
||||
MessageDialog errorDialog = new MessageDialog(mainWindow, GtkDialogFlags.MODAL, GtkMessageType.ERROR, GtkButtonsType.CLOSE, false, "Cannot set status\n\nYou are not connected to a server");
|
||||
errorDialog.setIconName("user-available");
|
||||
// errorDialog.set
|
||||
errorDialog.run();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Get the current connection */
|
||||
Connection currentConnection = connections[notebook.getCurrentPage()];
|
||||
|
||||
|
@ -420,34 +398,6 @@ public class GUI : Thread
|
|||
}
|
||||
|
||||
|
||||
private class JoinButtonCustom : Button
|
||||
{
|
||||
private Entry channelInputBox;
|
||||
|
||||
this(Entry channelInputBox)
|
||||
{
|
||||
/* Set the button's text to "Join" */
|
||||
super("Join");
|
||||
|
||||
/* Set the handler for the button */
|
||||
addOnClicked(&handler);
|
||||
|
||||
this.channelInputBox = channelInputBox;
|
||||
}
|
||||
|
||||
private void handler(Button)
|
||||
{
|
||||
/* Get the current connection */
|
||||
Connection currentConnection = connections[notebook.getCurrentPage()];
|
||||
|
||||
/* Get the name of the channel selected */
|
||||
string channelSelected = channelInputBox.getText();
|
||||
|
||||
/* Join the channel on this connection */
|
||||
currentConnection.joinChannel(channelSelected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List channels
|
||||
*
|
||||
|
@ -464,29 +414,6 @@ public class GUI : Thread
|
|||
ListBox channelsList = new ListBox();
|
||||
win.add(new ScrolledWindow(channelsList));
|
||||
|
||||
|
||||
|
||||
|
||||
/* TODO: Temporary, REMOVE AFTWR TESTING (ADDED ON 27th of JAN 2021) */
|
||||
Box box = new Box(GtkOrientation.HORIZONTAL, 1);
|
||||
Entry customChannelEntry = new Entry();
|
||||
box.packStart(customChannelEntry, 1, 1, 1);
|
||||
box.add(new JoinButtonCustom(customChannelEntry));
|
||||
channelsList.add(box);
|
||||
|
||||
/* If there are no available connections */
|
||||
if(!connections.length)
|
||||
{
|
||||
import gtk.MessageDialog;
|
||||
MessageDialog errorDialog = new MessageDialog(mainWindow, GtkDialogFlags.MODAL, GtkMessageType.ERROR, GtkButtonsType.CLOSE, false, "Cannot list channels\n\nYou are not connected to a server");
|
||||
errorDialog.setIconName("user-available");
|
||||
// errorDialog.set
|
||||
errorDialog.run();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Get the current connection */
|
||||
Connection currentConnection = connections[notebook.getCurrentPage()];
|
||||
|
||||
|
@ -528,10 +455,6 @@ public class GUI : Thread
|
|||
win.showAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run when you select the 'Join' button next tio an already existing
|
||||
* channel in the channels list
|
||||
*/
|
||||
private void selectChannel(Button s)
|
||||
{
|
||||
/* Get the current connection */
|
||||
|
@ -566,7 +489,7 @@ public class GUI : Thread
|
|||
else
|
||||
{
|
||||
import gtk.MessageDialog;
|
||||
MessageDialog errorDialog = new MessageDialog(mainWindow, GtkDialogFlags.MODAL, GtkMessageType.ERROR, GtkButtonsType.CLOSE, false, "Cannot set prescence\n\nYou are not connected to a server");
|
||||
MessageDialog errorDialog = new MessageDialog(mainWindow, GtkDialogFlags.MODAL, GtkMessageType.ERROR, GtkButtonsType.CLOSE, false, "Cannot list channels\n\nYou are not connected to a server");
|
||||
errorDialog.setIconName("user-available");
|
||||
// errorDialog.set
|
||||
errorDialog.run();
|
||||
|
|
Loading…
Reference in New Issue