1 module gui; 2 3 import core.thread; 4 import gtk.MainWindow; 5 import gtk.ListBox; 6 import gtk.Label; 7 import gtk.Notebook; 8 import gdk.Threads : te = threadsEnter, tl = threadsLeave; 9 import gtk.MenuBar; 10 import gtk.Box; 11 import gtk.Menu; 12 import gtk.MenuItem; 13 import std.stdio; 14 15 import Connection; 16 import std.socket; 17 18 public class GUI : Thread 19 { 20 /* Main window (GUI homepage) */ 21 public MainWindow mainWindow; 22 private MenuBar menuBar; 23 public Notebook notebook; 24 25 26 private Connection[] connections; 27 28 private ListBox list; 29 30 31 this() 32 { 33 super(&worker); 34 } 35 36 private void worker() 37 { 38 initializeGUI(); 39 te(); 40 41 tl(); 42 writeln("brg"); 43 while(true) 44 { 45 46 } 47 } 48 49 private void initializeGUI() 50 { 51 initializeMainWindow(); 52 53 /* Test adding a connection */ 54 for(uint i = 0; i < 5; i++) 55 { 56 connections ~= new Connection(this, parseAddress("0.0.0.0", 7777)); 57 } 58 59 60 } 61 62 /** 63 * Initializes the main home screen window 64 */ 65 private void initializeMainWindow() 66 { 67 /* Get GTK lock */ 68 te(); 69 70 /* Create a window */ 71 mainWindow = new MainWindow("unamed"); 72 73 /** 74 * Create a Box in vertical layout mode 75 * and adds it to the window 76 * 77 * This lays out components like so: 78 * 79 * |component 1| 80 * |component 2| 81 */ 82 Box box = new Box(GtkOrientation.VERTICAL, 1); 83 84 /** 85 * Add needed components 86 * 87 * Menubar, tabbed pane switcher, statusbar 88 */ 89 menuBar = initializeMenuBar(); 90 box.add(menuBar); 91 notebook = new Notebook(); 92 box.add(notebook); 93 //notebook.add(createServerTab()); 94 95 96 97 98 /* Add the Box to main window */ 99 mainWindow.add(box); 100 101 mainWindow.showAll(); 102 103 /* Unlock GTK lock */ 104 tl(); 105 106 writeln("unlock gui setup"); 107 } 108 109 private MenuBar initializeMenuBar() 110 { 111 MenuBar menuBar = new MenuBar(); 112 113 /* Gustav menu */ 114 MenuItem gustavMenuItem = new MenuItem(); 115 gustavMenuItem.setLabel("Gustav"); 116 Menu gustavMenu = new Menu(); 117 gustavMenuItem.setSubmenu(gustavMenu); 118 119 MenuItem exitItem = new MenuItem(); 120 exitItem.setLabel("Exit"); 121 exitItem.addOnActivate(&exitButton); 122 gustavMenu.add(exitItem); 123 124 125 126 /* Add all menues */ 127 menuBar.add(gustavMenuItem); 128 129 return menuBar; 130 } 131 132 private void exitButton(MenuItem) 133 { 134 writeln("bruh"); 135 136 /* TODO: Implement exit */ 137 138 139 // tl(); 140 //te(); 141 142 143 shutdownConnections(); 144 145 146 // mainWindow.showAll(); 147 148 // tl(); 149 } 150 151 private void shutdownConnections() 152 { 153 foreach(Connection connection; connections) 154 { 155 /** 156 * TODO: This is called by signal handler, we need no mutexes for signal handler 157 * hence it means that connection 158 */ 159 connection.shutdown(); 160 Thread.sleep(dur!("seconds")(2)); 161 } 162 } 163 164 private void newServer() 165 { 166 167 } 168 169 private Box createServerTab() 170 { 171 Box serverTab = new Box(GtkOrientation.HORIZONTAL, 1); 172 173 serverTab.add(new Label("hello")); 174 175 // serverTab.add(); 176 177 return serverTab; 178 } 179 }