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;
|
2020-10-17 13:58:09 +00:00
|
|
|
import gtk.Statusbar;
|
2020-10-18 19:41:22 +00:00
|
|
|
import gtk.Toolbar;
|
2020-10-17 11:54:07 +00:00
|
|
|
|
|
|
|
import Connection;
|
|
|
|
import std.socket;
|
|
|
|
|
2020-10-19 07:27:10 +00:00
|
|
|
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;
|
2020-10-18 19:41:22 +00:00
|
|
|
private Toolbar toolbar;
|
2020-10-17 11:54:07 +00:00
|
|
|
public Notebook notebook;
|
|
|
|
|
2020-10-17 13:58:09 +00:00
|
|
|
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++)
|
|
|
|
{
|
2020-10-17 13:58:09 +00:00
|
|
|
// connections ~= new Connection(this, parseAddress("0.0.0.0", 7777));
|
2020-10-17 11:54:07 +00:00
|
|
|
}
|
2020-10-17 13:58:09 +00:00
|
|
|
|
2020-10-19 07:27:10 +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);
|
2020-10-18 19:41:22 +00:00
|
|
|
|
|
|
|
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-17 13:58:09 +00:00
|
|
|
statusBar = new Statusbar();
|
|
|
|
statusBar.add(new Label("Gustav: Bruh"));
|
2020-10-17 18:43:20 +00:00
|
|
|
box.setChildPacking(notebook, true, true, 0, GtkPackType.START);
|
2020-10-17 13:58:09 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2020-10-18 19:41:22 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
ToolButton setAvail = new ToolButton("");
|
|
|
|
setAvail.setLabel("available");
|
|
|
|
setAvail.setIconName("user-available");
|
|
|
|
toolbar.add(setAvail);
|
|
|
|
|
|
|
|
ToolButton setAway = new ToolButton("");
|
|
|
|
setAway.setLabel("away");
|
|
|
|
setAway.setIconName("user-away");
|
|
|
|
toolbar.add(setAway);
|
|
|
|
|
|
|
|
ToolButton setBusy = new ToolButton("");
|
|
|
|
setBusy.setLabel("busy");
|
|
|
|
setBusy.setIconName("user-busy");
|
|
|
|
toolbar.add(setBusy);
|
|
|
|
|
|
|
|
|
2020-10-18 19:44:50 +00:00
|
|
|
setAvail.addOnClicked(&setStatus);
|
|
|
|
setAway.addOnClicked(&setStatus);
|
2020-10-18 19:41:22 +00:00
|
|
|
setBusy.addOnClicked(&setStatus);
|
2020-10-18 19:44:50 +00:00
|
|
|
|
2020-10-18 19:41:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
|
|
|
import gtk.ToolButton;
|
|
|
|
private void setStatus(ToolButton x)
|
|
|
|
{
|
|
|
|
/* Get the current connection */
|
|
|
|
Connection currentConnection = connections[notebook.getCurrentPage()];
|
|
|
|
|
|
|
|
/* Set the status */
|
|
|
|
currentConnection.getClient().setStatus(x.getLabel());
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2020-10-17 13:58:09 +00:00
|
|
|
/* Connect option */
|
|
|
|
MenuItem connectItem = new MenuItem();
|
|
|
|
connectItem.setLabel("Connect");
|
2020-10-17 17:32:31 +00:00
|
|
|
connectItem.addOnActivate(&connectButton);
|
2020-10-17 13:58:09 +00:00
|
|
|
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-17 13:58:09 +00:00
|
|
|
|
|
|
|
|
2020-10-17 11:54:07 +00:00
|
|
|
/* Add all menues */
|
|
|
|
menuBar.add(gustavMenuItem);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2020-10-19 07:27:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|