00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gtkStatsMainWindow.h"
00020 #include "gtkStats.h"
00021 #include "gtkStatsServer.h"
00022
00023 #include <string_utils.h>
00024
00025 #include <signal.h>
00026
00027 static bool user_interrupted = false;
00028
00029
00030
00031 static void signal_handler(int) {
00032 user_interrupted = true;
00033 }
00034
00035
00036
00037
00038
00039
00040 GtkStatsMainWindow::
00041 GtkStatsMainWindow(int port) : _port(port) {
00042 nassertv(GtkStats::_main_window == (GtkStatsMainWindow *)NULL);
00043 GtkStats::_main_window = this;
00044
00045
00046
00047 signal(SIGINT, &signal_handler);
00048
00049 _server = new GtkStatsServer;
00050 if (!_server->listen(_port)) {
00051 nout << "Unable to open port.\n";
00052 exit(1);
00053 }
00054
00055 layout_window();
00056 setup();
00057
00058 Gtk::Main::timeout.
00059 connect(slot(this, &GtkStatsMainWindow::idle_callback), 200);
00060 }
00061
00062
00063
00064
00065
00066
00067 GtkStatsMainWindow::
00068 ~GtkStatsMainWindow() {
00069 nassertv(GtkStats::_main_window == this);
00070 GtkStats::_main_window = NULL;
00071 }
00072
00073
00074
00075
00076
00077
00078 bool GtkStatsMainWindow::
00079 destruct() {
00080 if (BasicGtkWindow::destruct()) {
00081 nassertr(_server != (GtkStatsServer *)NULL, false);
00082 delete _server;
00083 GtkStats::quit();
00084 }
00085 return false;
00086 }
00087
00088
00089
00090
00091
00092
00093 void GtkStatsMainWindow::
00094 layout_window() {
00095 set_title("Gtk Stats");
00096
00097 Gtk::VBox *box1 = new Gtk::VBox;
00098 box1->show();
00099 box1->set_border_width(8);
00100 add(*manage(box1));
00101
00102 Gtk::Label *listening =
00103 new Gtk::Label("Listening on port " + format_string(_port));
00104 listening->show();
00105 box1->pack_start(*manage(listening), true, false, 8);
00106
00107 Gtk::HBox *box2 = new Gtk::HBox;
00108 box2->show();
00109 box1->pack_start(*manage(box2), false, false, 0);
00110
00111 Gtk::Button *close = new Gtk::Button("Close");
00112 close->set_usize(80, 30);
00113 close->show();
00114 box2->pack_start(*manage(close), true, false, 0);
00115 close->clicked.connect(slot(this, &GtkStatsMainWindow::close_clicked));
00116 }
00117
00118
00119
00120
00121
00122
00123 void GtkStatsMainWindow::
00124 close_clicked() {
00125 destruct();
00126 }
00127
00128
00129
00130
00131
00132
00133 gint GtkStatsMainWindow::
00134 idle_callback() {
00135 if (user_interrupted) {
00136 destruct();
00137 return false;
00138 }
00139 _server->poll();
00140 return true;
00141 }