gustav/source/gui.d

484 lines
12 KiB
D
Raw Normal View History

2020-10-17 11:54:07 +00:00
module gui;
import core.thread;
import gtk.MainWindow;
import gtk.ListBox;
import gtk.Label;
import gtk.Notebook;
import gdk.Threads : te = threadsEnter, tl = threadsLeave;
import gtk.MenuBar;
import gtk.Box;
import gtk.Menu;
import gtk.MenuItem;
import std.stdio;
import gtk.Statusbar;
import gtk.Toolbar;
2020-10-19 14:23:00 +00:00
import gtk.ToolButton;
2020-10-19 16:01:00 +00:00
import gtk.ScrolledWindow;
2020-10-17 11:54:07 +00:00
import Connection;
import Channel;
2020-10-17 11:54:07 +00:00
import std.socket;
import std.conv;
2020-10-17 11:54:07 +00:00
public class GUI : Thread
{
/* Main window (GUI homepage) */
public MainWindow mainWindow;
private MenuBar menuBar;
private Toolbar toolbar;
2020-10-17 11:54:07 +00:00
public Notebook notebook;
private Statusbar statusBar;
2020-10-17 11:54:07 +00:00
private Connection[] connections;
private ListBox list;
this()
{
super(&worker);
}
private void worker()
{
initializeGUI();
te();
tl();
writeln("brg");
while(true)
{
}
}
private void initializeGUI()
{
initializeMainWindow();
/* Test adding a connection */
for(uint i = 0; i < 5; i++)
{
// connections ~= new Connection(this, parseAddress("0.0.0.0", 7777));
2020-10-17 11:54:07 +00:00
}
connections ~= new Connection(this, parseAddress("0.0.0.0", 7777), ["testGustav"~to!(string)(connections.length), "bruh"]);
2020-10-17 11:54:07 +00:00
}
/**
* Initializes the main home screen window
*/
private void initializeMainWindow()
{
/* Get GTK lock */
te();
/* Create a window */
mainWindow = new MainWindow("unamed");
/**
* Create a Box in vertical layout mode
* and adds it to the window
*
* This lays out components like so:
*
* |component 1|
* |component 2|
*/
Box box = new Box(GtkOrientation.VERTICAL, 1);
/**
* Add needed components
*
* Menubar, tabbed pane switcher, statusbar
*/
menuBar = initializeMenuBar();
box.add(menuBar);
toolbar = getToolbar();
box.add(toolbar);
2020-10-17 11:54:07 +00:00
notebook = new Notebook();
2020-10-18 20:48:21 +00:00
notebook.setScrollable(true);
2020-10-17 11:54:07 +00:00
box.add(notebook);
2020-10-19 12:57:16 +00:00
statusBar = new Statusbar();
statusBar.add(new Label("Gustav: Bruh"));
2020-10-19 12:57:16 +00:00
2020-10-17 18:43:20 +00:00
box.setChildPacking(notebook, true, true, 0, GtkPackType.START);
box.packEnd(statusBar, 0, 0, 0);
2020-10-17 11:54:07 +00:00
//notebook.add(createServerTab());
2020-10-17 18:43:20 +00:00
2020-10-17 11:54:07 +00:00
/* Add the Box to main window */
mainWindow.add(box);
mainWindow.showAll();
/* Unlock GTK lock */
tl();
writeln("unlock gui setup");
}
private Toolbar getToolbar()
{
Toolbar toolbar = new Toolbar();
/* Status selector dropdown */
import gtk.ComboBox;
import gtk.ToolButton;
// Menu menu = new Menu();
// menu.add(new MenuItem(""));
ComboBox statusBox = new ComboBox();
statusBox.setTitle("Status");
/* Set available button */
ToolButton setAvail = new ToolButton("");
setAvail.setLabel("available");
setAvail.setIconName("user-available");
toolbar.add(setAvail);
/* Set away button */
ToolButton setAway = new ToolButton("");
setAway.setLabel("away");
setAway.setIconName("user-away");
toolbar.add(setAway);
/* Set busy button */
ToolButton setBusy = new ToolButton("");
setBusy.setLabel("busy");
setBusy.setIconName("user-busy");
toolbar.add(setBusy);
/* Assign actions */
2020-10-18 19:44:50 +00:00
setAvail.addOnClicked(&setStatus);
setAway.addOnClicked(&setStatus);
setBusy.addOnClicked(&setStatus);
2020-10-19 12:57:16 +00:00
import gtk.SeparatorToolItem;
toolbar.add(new SeparatorToolItem());
/* List channels button */
2020-10-19 16:01:00 +00:00
ToolButton channelListButton = new ToolButton("");
channelListButton.setIconName("emblem-documents");
2020-10-19 12:57:16 +00:00
channelListButton.setTooltipText("List channels");
2020-10-19 14:23:00 +00:00
channelListButton.addOnClicked(&listChannels);
2020-10-19 12:57:16 +00:00
toolbar.add(channelListButton);
// import gtk.ComboBox;
// ComboBox d = new ComboBox();
// import gtk.Button;
// import gtk.Entry;
// import gtk.Switch;
// import gtk.ToolItem;
// ToolItem g = new ToolItem();
// g.add(new Switch());
// toolbar.add(g);
// d.add(new Entry(new Label("1")));
// d.add(new Entry(new Label("2")));
// d.add(new Entry(new Label("3")));
// Entry jj;
// d.add(new Entry("available"));
// d.add(new Entry("away"));
// d.add(new Entry("busy"));
// import gtk.
2020-10-18 19:44:50 +00:00
2020-10-19 12:57:16 +00:00
// import gtk.ToolItem;
// ToolItem h =new ToolItem();
// h.add(d);
// toolbar.add(h);
//toolbar.add(new ToolButton("user-available,""Available"));
// toolbar.add(new ToolButton("Away"));
// toolbar.add(new ToolButton("Busy"));
// toolbar.add(new Label("Away"));
// toolbar.add(new Label("Busy"));
// import gtk.ToolItem;
// ToolItem toolItem = new ToolItem();
// toolItem.add(new Label("Available"));
// statusBox.add()
//toolbar.add(statusBox);
return toolbar;
}
2020-10-19 14:14:28 +00:00
private void about(MenuItem)
2020-10-19 14:09:08 +00:00
{
import gtk.AboutDialog;
AboutDialog about = new AboutDialog();
about.setVersion("21893");
/* TODO: License */
/* TODO: Icon */
/* TODO: Buttons or close */
/* TODO: Set version based on compiler flag */
about.setLogoIconName("user-available");
2020-10-19 14:11:24 +00:00
about.setArtists(["i wonder if I could commision an artwork from her"]);
2020-10-19 14:09:08 +00:00
/* Set all the information */
about.setLicense("LICENSE GOES HERE");
about.setComments("A clean GTK+ graphical DNET client");
about.setWebsite("http://deavmi.assigned.network/docs/dnet/site");
about.setDocumenters(["ss","fdsfsd"]);
about.setAuthors(["Tristan B. Kildaire (Deavmi) - deavmi@disroot.org"]);
/* Show the about dialog */
about.showAll();
}
/**
* List channels
*
* Brings up a window listing channels of the current server
*/
2020-10-19 14:23:00 +00:00
private void listChannels(ToolButton)
2020-10-19 14:09:08 +00:00
{
import gtk.Window;
2020-10-19 14:23:00 +00:00
/* Create the window */
Window win = new Window(GtkWindowType.TOPLEVEL);
/* Create the list of channels */
ListBox channelsList = new ListBox();
2020-10-19 16:01:00 +00:00
win.add(new ScrolledWindow(channelsList));
2020-10-19 14:23:00 +00:00
/* Get the current connection */
Connection currentConnection = connections[notebook.getCurrentPage()];
/* Fetch the channels */
string[] channels = currentConnection.getClient().list();
/* Add each channel */
foreach(string channel; channels)
{
channelsList.add(new Label(channel));
channelsList.showAll();
}
/* TODO: Add handler for clicking label that lets you join the channel */
channelsList.addOnSelectedRowsChanged(&selectChannelNG);
win.showAll();
}
import gtk.ListBoxRow;
private void selectChannelNG(ListBox s)
{
/* Get the current connection */
Connection currentConnection = connections[notebook.getCurrentPage()];
/* Get the name of the channel selected */
string channelSelected = (cast(Label)(s.getSelectedRow().getChild())).getText();
/* Check if we have joined this channel already */
Channel foundChannel = currentConnection.findChannel(channelSelected);
/* If we have joined this channel before */
if(foundChannel)
{
/* TODO: Switch to */
writeln("nope time: "~channelSelected);
}
/* If we haven't joined this channel before */
else
{
/* Join the channel */
currentConnection.getClient().join(channelSelected);
/* Create the Channel object */
Channel newChannel = new Channel(currentConnection.getClient(), channelSelected);
/* Add the channel */
currentConnection.addChannel(newChannel);
/* Set as the `foundChannel` */
foundChannel = newChannel;
/* Get the Widgets container for this channel and add a tab for it */
currentConnection.notebookSwitcher.add(newChannel.getBox());
currentConnection.notebookSwitcher.setTabReorderable(newChannel.getBox(), true);
currentConnection.notebookSwitcher.setTabLabelText(newChannel.getBox(), newChannel.getName());
writeln("hdsjghjsd");
writeln("first time: "~channelSelected);
/* Get the user's list */
newChannel.populateUsersList();
}
/* Switch to the channel's pane */
currentConnection.notebookSwitcher.setCurrentPage(foundChannel.getBox());
currentConnection.box.showAll();
// notebookSwitcher.showAll();
/* TODO: Now add the widget */
// /* Set this as the currently selected channel */
// currentChannel = channelSelected;
// currentChannelLabel.setText(currentChannel);
// // currentChannelLabel.show();
// // box.show();
// /* Fetch a list of members */
// string[] members = client.getMembers(channelSelected);
// /* Display the members */
// users.removeAll();
// foreach(string member; members)
// {
// users.add(new Label(member));
// users.showAll();
// }
// /* Clear the text area */
// textArea.removeAll();
// textArea.showAll();
2020-10-19 14:09:08 +00:00
}
private void setStatus(ToolButton x)
{
/* Get the current connection */
Connection currentConnection = connections[notebook.getCurrentPage()];
/* Set the status */
2020-10-19 12:06:14 +00:00
currentConnection.getClient().setStatus(x.getLabel()~",Hey there");
}
2020-10-17 11:54:07 +00:00
private MenuBar initializeMenuBar()
{
MenuBar menuBar = new MenuBar();
/* Gustav menu */
MenuItem gustavMenuItem = new MenuItem();
gustavMenuItem.setLabel("Gustav");
Menu gustavMenu = new Menu();
gustavMenuItem.setSubmenu(gustavMenu);
/* Connect option */
MenuItem connectItem = new MenuItem();
connectItem.setLabel("Connect");
2020-10-17 17:32:31 +00:00
connectItem.addOnActivate(&connectButton);
gustavMenu.add(connectItem);
/* Exit option */
2020-10-17 11:54:07 +00:00
MenuItem exitItem = new MenuItem();
exitItem.setLabel("Exit");
exitItem.addOnActivate(&exitButton);
gustavMenu.add(exitItem);
2020-10-19 14:14:28 +00:00
/* Help menu */
MenuItem helpMenuItem = new MenuItem();
helpMenuItem.setLabel("Help");
Menu helpMenu = new Menu();
helpMenuItem.setSubmenu(helpMenu);
/* About option */
MenuItem aboutItem = new MenuItem();
aboutItem.setLabel("About");
aboutItem.addOnActivate(&about);
2020-10-19 14:15:01 +00:00
helpMenu.add(aboutItem);
2020-10-19 14:14:28 +00:00
2020-10-17 11:54:07 +00:00
2020-10-17 11:54:07 +00:00
/* Add all menues */
menuBar.add(gustavMenuItem);
2020-10-19 14:14:28 +00:00
menuBar.add(helpMenuItem);
2020-10-17 11:54:07 +00:00
return menuBar;
}
private void exitButton(MenuItem)
{
writeln("bruh");
/* TODO: Implement exit */
// tl();
//te();
shutdownConnections();
// mainWindow.showAll();
// tl();
}
2020-10-17 17:32:31 +00:00
private void connectButton(MenuItem)
{
connections ~= new Connection(this, parseAddress("0.0.0.0", 7777), ["testGustav"~to!(string)(connections.length), "bruh"]);
2020-10-17 17:32:31 +00:00
}
2020-10-17 11:54:07 +00:00
private void shutdownConnections()
{
foreach(Connection connection; connections)
{
/**
* TODO: This is called by signal handler, we need no mutexes for signal handler
* hence it means that connection
*/
connection.shutdown();
Thread.sleep(dur!("seconds")(2));
}
}
private void newServer()
{
}
private Box createServerTab()
{
Box serverTab = new Box(GtkOrientation.HORIZONTAL, 1);
serverTab.add(new Label("hello"));
// serverTab.add();
return serverTab;
}
}