9 #include "item_conduct.h"
10 #include "item_exclusa.h"
11 #include "item_tank.h"
12 #include "item_pump.h"
13 #include "item_union.h"
15 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
17 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0;
18 Gtk::Button *btn_get=0, *bar_connect=0;
20 txt_target = txt_command = txt_args = 0;
23 rg->get_widget("mnu_file_connect", conect);
24 rg->get_widget("mnu_file_exit", exit);
25 rg->get_widget("mnu_help_about", about);
26 rg->get_widget("mnu_prop", mnu_prop);
27 rg->get_widget_derived("dlgConectar", dlg_conectar);
28 rg->get_widget("btn_get", btn_get);
29 rg->get_widget("txt_view", txt_view);
30 rg->get_widget("txt_target", txt_target);
31 rg->get_widget("txt_command", txt_command);
32 rg->get_widget("txt_args", txt_args);
33 rg->get_widget("bar_connect", bar_connect);
34 rg->get_widget("work_place", work_place);
36 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
37 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
38 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
39 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
40 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
41 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
42 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
47 Principal::~Principal()
52 void Principal::on_dlg_connect_ok()
54 if (conexion == NULL) {
55 std::cout << "Conectando ..." << std::endl;
58 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
61 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
65 // Conecto las señales
66 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
67 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
74 txt_view->get_buffer()->insert_at_cursor("no se puede correr ->run()!!!\n");
77 std::cout << "Ya estas conectado" << std::endl;
82 void Principal::on_mnu_file_exit()
87 void Principal::on_mnu_file_connect()
92 void Principal::on_mnu_help_about()
94 // preparo para leer el archivo ChangeLog
95 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
97 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
98 Glib::RefPtr<Glib::IOChannel> log_io;
100 log_buffer = Gtk::TextBuffer::create();
101 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
102 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
103 log_buffer->insert_at_cursor(line);
107 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
109 catch(const Gnome::Glade::XmlError &ex) {
110 std::cerr << ex.what() << std::endl;
113 Gtk::Window *dlg = 0;
114 Gtk::Button *btn_cerrar = 0;
115 Gtk::TextView *txt_changelog = 0;
116 xml->get_widget("dlgAbout", dlg);
117 xml->get_widget("btn_close", btn_cerrar);
118 xml->get_widget("txt_changelog", txt_changelog);
119 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
120 txt_changelog->set_buffer(log_buffer);
124 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
126 txt_view->get_buffer()->insert_at_cursor("Item : ");
127 txt_view->get_buffer()->insert_at_cursor(i->get_name());
128 txt_view->get_buffer()->insert_at_cursor("\n");
131 void Principal::on_conexion_ok()
133 txt_view->get_buffer()->insert_at_cursor("El server dice que ta' todo ok!\n");
136 void Principal::on_conexion_error(unsigned code)
142 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
143 txt_view->get_buffer()->insert_at_cursor(s);
144 txt_view->get_buffer()->insert_at_cursor("\n");
148 void Principal::on_get_clicked()
150 if (conexion == NULL) {
151 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
155 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
156 command.add_arg( txt_args->get_text() );
157 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
159 conexion->send(command);
162 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
167 void Principal::on_mnu_prop()
169 /* Parseo de ejemplo de un XML desde archivo */
171 document = xmlParseFile("test.xml");
172 if (document == NULL) {
176 /* bien, el archivo se parseo bien! */
177 xmlNodePtr nodo, items;
178 nodo = document->children;
180 if (strcmp((char *)nodo->name, "planta") == 0) {
181 items = nodo->children;
182 while (items != NULL) {
183 if (items->type == XML_ELEMENT_NODE) {
184 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
186 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
188 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
190 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
192 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
194 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
204 printf("NO ES UNA PLANTA\n");
208 printf("Fin parseo!!\n");
211 void Principal::loadBomba(xmlNodePtr nodo)
213 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
214 int orientacion=0, x, y;
216 nodo = nodo->children;
217 while (nodo != NULL) {
218 if (nodo->type == XML_ELEMENT_NODE) {
219 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
220 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
221 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
222 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
223 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
224 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
230 // listo, ya recolecte todos los datos, ahora creo el objeto!
231 ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) );
232 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
233 b->set_position(x,y);
234 work_place->put(*b, x, y);
238 void Principal::loadCodo(xmlNodePtr nodo)
240 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
241 int orientacion=0, x, y;
243 nodo = nodo->children;
244 while (nodo != NULL) {
245 if (nodo->type == XML_ELEMENT_NODE) {
246 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
247 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
248 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
249 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
250 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
251 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
257 // listo, ya recolecte todos los datos, ahora creo el objeto!
258 ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) );
259 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
260 b->set_position(x,y);
261 work_place->put(*b, x, y);
263 // los agrego al hash
264 //mapItems.insert(name, b);
267 void Principal::loadConduct(xmlNodePtr nodo)
269 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
270 int orientacion=0, x, y;
272 nodo = nodo->children;
273 while (nodo != NULL) {
274 if (nodo->type == XML_ELEMENT_NODE) {
275 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
276 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
277 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
278 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
279 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
280 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
286 // listo, ya recolecte todos los datos, ahora creo el objeto!
287 ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) );
288 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
289 b->set_position(x,y);
290 work_place->put(*b, x, y);
294 void Principal::loadExclusa(xmlNodePtr nodo)
296 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
297 int orientacion=0, x, y;
299 nodo = nodo->children;
300 while (nodo != NULL) {
301 if (nodo->type == XML_ELEMENT_NODE) {
302 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
303 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
304 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
305 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
306 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
307 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
313 // listo, ya recolecte todos los datos, ahora creo el objeto!
314 ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) );
315 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
316 b->set_position(x,y);
317 work_place->put(*b, x, y);
321 void Principal::loadTank(xmlNodePtr nodo)
323 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
324 int orientacion=0, x, y;
326 nodo = nodo->children;
327 while (nodo != NULL) {
328 if (nodo->type == XML_ELEMENT_NODE) {
329 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
330 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
331 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
332 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
333 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
334 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
340 // listo, ya recolecte todos los datos, ahora creo el objeto!
341 ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) );
342 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
343 b->set_position(x,y);
344 work_place->put(*b, x, y);
348 void Principal::loadUnion(xmlNodePtr nodo)
350 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
351 int orientacion=0, x, y;
353 nodo = nodo->children;
354 while (nodo != NULL) {
355 if (nodo->type == XML_ELEMENT_NODE) {
356 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
357 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
358 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
359 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
360 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
361 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
367 // listo, ya recolecte todos los datos, ahora creo el objeto!
368 ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) );
369 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
370 b->set_position(x,y);
371 work_place->put(*b, x, y);