8 #include "plaqui/server/string.h"
10 #include "item_conduct.h"
11 #include "item_exclusa.h"
12 #include "item_tank.h"
13 #include "item_pump.h"
14 #include "item_union.h"
15 #include "item_drain.h"
17 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
19 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect;
20 Gtk::Button *btn_get=0, *bar_connect=0;
22 txt_target = txt_command = txt_args = 0;
24 lbl_nombre = lbl_color = lbl_flujo = 0;
26 rg->get_widget("lbl_nombre", lbl_nombre);
27 rg->get_widget("mnu_file_connect", conect);
28 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
29 rg->get_widget("mnu_file_exit", exit);
30 rg->get_widget("mnu_help_about", about);
31 rg->get_widget("mnu_prop", mnu_prop);
32 rg->get_widget_derived("dlgConectar", dlg_conectar);
33 rg->get_widget("btn_get", btn_get);
34 rg->get_widget("txt_view", txt_view);
35 rg->get_widget("txt_target", txt_target);
36 rg->get_widget("txt_command", txt_command);
37 rg->get_widget("txt_args", txt_args);
38 rg->get_widget("bar_connect", bar_connect);
39 rg->get_widget("work_place", work_place);
40 rg->get_widget("ico_conected", ico_conected);
42 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
43 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
44 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
45 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
46 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
47 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
48 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
49 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
54 Principal::~Principal()
59 void Principal::on_dlg_connect_ok()
61 if (conexion == NULL) {
64 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
67 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
73 // Conecto las señales
74 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
75 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
76 conexion->signal_connected().connect( SigC::slot(*this, &Principal::on_conexion_connected) );
77 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
83 txt_view->get_buffer()->insert_at_cursor("no se puede correr conexion->run()!!!\n");
86 txt_view->get_buffer()->insert_at_cursor("YA ESTAS CONECTADO\n");
91 void Principal::on_mnu_file_exit()
96 void Principal::on_mnu_file_disconnect()
98 if (conexion == NULL) return;
100 PlaQui::Server::Command c("connection", "stop");
101 c.add_arg(conexion->get_host());
102 c.add_arg(conexion->get_port());
106 void Principal::on_mnu_file_connect()
108 dlg_conectar->show();
111 void Principal::on_mnu_help_about()
113 // preparo para leer el archivo ChangeLog
114 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
116 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
117 Glib::RefPtr<Glib::IOChannel> log_io;
119 log_buffer = Gtk::TextBuffer::create();
120 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
121 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
122 log_buffer->insert_at_cursor(line);
126 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
128 catch(const Gnome::Glade::XmlError &ex) {
129 std::cerr << ex.what() << std::endl;
132 Gtk::Window *dlg = 0;
133 Gtk::Button *btn_cerrar = 0;
134 Gtk::TextView *txt_changelog = 0;
135 xml->get_widget("dlgAbout", dlg);
136 xml->get_widget("btn_close", btn_cerrar);
137 xml->get_widget("txt_changelog", txt_changelog);
138 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
139 txt_changelog->set_buffer(log_buffer);
143 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
145 lbl_nombre->set_text(i->get_name());
146 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
147 txt_view->get_buffer()->insert_at_cursor(i->get_name());
148 txt_view->get_buffer()->insert_at_cursor("\n");
151 void Principal::on_conexion_connected()
153 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
154 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
157 void Principal::on_conexion_finished()
159 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
160 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
164 void Principal::on_conexion_ok(const std::string &body)
166 std::cout << body << std::endl;
167 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
168 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
169 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
172 void Principal::on_conexion_error(unsigned code)
178 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
179 txt_view->get_buffer()->insert_at_cursor(s);
180 txt_view->get_buffer()->insert_at_cursor("\n");
184 void Principal::on_get_clicked()
186 if (conexion == NULL) {
187 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
192 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
193 command.add_arg( txt_args->get_text() );
194 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
196 conexion->send(command);
199 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
204 void Principal::on_mnu_prop()
206 /* Parseo de ejemplo de un XML desde archivo */
208 document = xmlParseFile("test.xml");
209 if (document == NULL) {
213 /* bien, el archivo se parseo bien! */
214 xmlNodePtr nodo, items;
215 nodo = document->children;
217 if (strcmp((char *)nodo->name, "planta") == 0) {
218 items = nodo->children;
219 while (items != NULL) {
220 if (items->type == XML_ELEMENT_NODE) {
221 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
223 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
225 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
227 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
229 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
231 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
233 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
243 void Principal::loadBomba(xmlNodePtr nodo)
245 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
246 int orientacion=0, x, y;
248 nodo = nodo->children;
249 while (nodo != NULL) {
250 if (nodo->type == XML_ELEMENT_NODE) {
251 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
252 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
253 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
254 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
255 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
256 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
262 // listo, ya recolecte todos los datos, ahora creo el objeto!
263 ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) );
264 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
265 b->set_position(x,y);
266 work_place->put(*b, x, y);
268 // los agrego al hash
272 void Principal::loadCodo(xmlNodePtr nodo)
274 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
275 int orientacion=0, x, y;
277 nodo = nodo->children;
278 while (nodo != NULL) {
279 if (nodo->type == XML_ELEMENT_NODE) {
280 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
281 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
282 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
283 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
284 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
285 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
291 // listo, ya recolecte todos los datos, ahora creo el objeto!
292 ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) );
293 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
294 b->set_position(x,y);
295 work_place->put(*b, x, y);
297 // los agrego al hash
301 void Principal::loadConduct(xmlNodePtr nodo)
303 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
304 int orientacion=0, x, y;
306 nodo = nodo->children;
307 while (nodo != NULL) {
308 if (nodo->type == XML_ELEMENT_NODE) {
309 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
310 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
311 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
312 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
313 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
314 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
320 // listo, ya recolecte todos los datos, ahora creo el objeto!
321 ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) );
322 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
323 b->set_position(x,y);
324 work_place->put(*b, x, y);
326 // los agrego al hash
330 void Principal::loadExclusa(xmlNodePtr nodo)
332 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
333 int orientacion=0, x, y;
335 nodo = nodo->children;
336 while (nodo != NULL) {
337 if (nodo->type == XML_ELEMENT_NODE) {
338 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
339 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
340 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
341 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
342 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
343 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
349 // listo, ya recolecte todos los datos, ahora creo el objeto!
350 ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) );
351 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
352 b->set_position(x,y);
353 work_place->put(*b, x, y);
355 // los agrego al hash
359 void Principal::loadTank(xmlNodePtr nodo)
361 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
362 int orientacion=0, x, y;
364 nodo = nodo->children;
365 while (nodo != NULL) {
366 if (nodo->type == XML_ELEMENT_NODE) {
367 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
368 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
369 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
370 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
371 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
372 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
378 // listo, ya recolecte todos los datos, ahora creo el objeto!
379 ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) );
380 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
381 b->set_position(x,y);
382 work_place->put(*b, x, y);
384 // los agrego al hash
388 void Principal::loadUnion(xmlNodePtr nodo)
390 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
391 int orientacion=0, x, y;
393 nodo = nodo->children;
394 while (nodo != NULL) {
395 if (nodo->type == XML_ELEMENT_NODE) {
396 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
397 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
398 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
399 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
400 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
401 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
407 // listo, ya recolecte todos los datos, ahora creo el objeto!
408 ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) );
409 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
410 b->set_position(x,y);
411 work_place->put(*b, x, y);
413 // los agrego al hash
417 void Principal::loadDrain(xmlNodePtr nodo)
419 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
420 int orientacion=0, x, y;
422 nodo = nodo->children;
423 while (nodo != NULL) {
424 if (nodo->type == XML_ELEMENT_NODE) {
425 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
426 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
427 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
428 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
429 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
430 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
436 // listo, ya recolecte todos los datos, ahora creo el objeto!
437 ViewDrain *b = Gtk::manage( new ViewDrain(name, orientacion) );
438 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
439 b->set_position(x,y);
440 work_place->put(*b, x, y);
442 // los agrego al hash