9 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
11 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0;
12 Gtk::Button *btn_get=0, *bar_connect=0;
14 txt_target = txt_command = txt_args = 0;
17 rg->get_widget("mnu_file_connect", conect);
18 rg->get_widget("mnu_file_exit", exit);
19 rg->get_widget("mnu_help_about", about);
20 rg->get_widget("mnu_prop", mnu_prop);
21 rg->get_widget_derived("dlgConectar", dlg_conectar);
22 rg->get_widget("btn_get", btn_get);
23 rg->get_widget("txt_view", txt_view);
24 rg->get_widget("txt_target", txt_target);
25 rg->get_widget("txt_command", txt_command);
26 rg->get_widget("txt_args", txt_args);
27 rg->get_widget("bar_connect", bar_connect);
28 rg->get_widget("work_place", work_place);
30 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
31 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
32 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
33 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
34 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
35 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
36 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
41 Principal::~Principal()
46 void Principal::on_dlg_connect_ok()
48 if (conexion == NULL) {
49 std::cout << "Conectando ..." << std::endl;
52 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
55 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
59 // Conecto las señales
60 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
61 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
68 txt_view->get_buffer()->insert_at_cursor("no se puede correr ->run()!!!\n");
71 std::cout << "Ya estas conectado" << std::endl;
76 void Principal::on_mnu_file_exit()
81 void Principal::on_mnu_file_connect()
86 void Principal::on_mnu_help_about()
88 // preparo para leer el archivo ChangeLog
89 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
91 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
92 Glib::RefPtr<Glib::IOChannel> log_io;
94 log_buffer = Gtk::TextBuffer::create();
95 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
96 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
97 log_buffer->insert_at_cursor(line);
101 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
103 catch(const Gnome::Glade::XmlError &ex) {
104 std::cerr << ex.what() << std::endl;
107 Gtk::Window *dlg = 0;
108 Gtk::Button *btn_cerrar = 0;
109 Gtk::TextView *txt_changelog = 0;
110 xml->get_widget("dlgAbout", dlg);
111 xml->get_widget("btn_close", btn_cerrar);
112 xml->get_widget("txt_changelog", txt_changelog);
113 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
114 txt_changelog->set_buffer(log_buffer);
118 void Principal::on_conexion_ok()
120 txt_view->get_buffer()->insert_at_cursor("El server dice que ta' todo ok!\n");
123 void Principal::on_conexion_error(unsigned code)
129 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
130 txt_view->get_buffer()->insert_at_cursor(s);
131 txt_view->get_buffer()->insert_at_cursor("\n");
135 void Principal::on_get_clicked()
137 if (conexion == NULL) {
138 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
142 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
143 command.add_arg( txt_args->get_text() );
144 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
146 conexion->send(command);
149 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
154 void Principal::on_mnu_prop()
156 /* Parseo de ejemplo de un XML desde archivo */
158 document = xmlParseFile("test.xml");
159 if (document == NULL) {
160 printf("Error al parsear test.xml\n");
164 /* bien, el archivo se parseo bien! */
165 xmlNodePtr nodo, items;
166 nodo = document->children;
168 if (strcmp((char *)nodo->name, "planta") == 0) {
169 items = nodo->children;
170 while (items != NULL) {
171 if (items->type == XML_ELEMENT_NODE) {
172 if (strcmp((char *)items->name, "bomba")==0) {
174 } else if (strcmp((char *)items->name, "codo")==0) {
181 printf("NO ES UNA PLANTA\n");
185 printf("Fin parseo!!\n");
188 void Principal::loadBomba(xmlNodePtr nodo)
190 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
191 int orientacion=0, x, y;
193 nodo = nodo->children;
194 while (nodo != NULL) {
195 if (nodo->type == XML_ELEMENT_NODE) {
196 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
197 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
198 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
199 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
200 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
201 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
207 // listo, ya recolecte todos los datos, ahora creo el objeto!
208 Bomba *b = Gtk::manage( new Bomba(name, orientacion) );
209 b->set_position(x,y);
210 work_place->put(*b, x, y);
214 void Principal::loadCodo(xmlNodePtr nodo)
216 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
217 int orientacion=0, x, y;
219 nodo = nodo->children;
220 while (nodo != NULL) {
221 if (nodo->type == XML_ELEMENT_NODE) {
222 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
223 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
224 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
225 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
226 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
227 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
233 // listo, ya recolecte todos los datos, ahora creo el objeto!
234 Codo *b = Gtk::manage( new Codo(name, orientacion) );
235 b->set_position(x,y);
236 work_place->put(*b, x, y);