24 #include <core/exception.h>
25 #include <core/exceptions/software.h>
26 #include <netcomm/fawkes/client.h>
27 #include <netcomm/utils/resolver.h>
28 #include <gui_utils/service_chooser_dialog.h>
29 #include <gui_utils/service_model.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <arpa/inet.h>
36 #include <netinet/in.h>
56 ServiceChooserDialog::ServiceChooserDialog(Gtk::Window &parent,
59 : Gtk::Dialog(title, parent, true),
60 __parent(parent), __expander(
"Manual entry")
78 : Gtk::Dialog(title, parent, true),
79 __parent(parent), __expander(
"Manual entry")
90 delete __service_model;
95 ServiceChooserDialog::ctor()
97 set_default_size(360, 240);
102 __scrollwin.add(__treeview);
103 __scrollwin.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
105 __expander.add(__entry);
107 __entry.set_activates_default(
true);
109 char * fawkes_ip = getenv(
"FAWKES_IP");
110 if (fawkes_ip) __entry.set_text(fawkes_ip);
111 else __entry.set_text(
"localhost");
113 Gtk::Box *vbox = get_vbox();
114 vbox->pack_start(__scrollwin);
115 vbox->pack_end(__expander, Gtk::PACK_SHRINK);
119 add_button(Gtk::Stock::CANCEL, 0);
120 add_button(Gtk::Stock::OK, 1);
122 set_default_response(1);
124 __treeview.signal_row_activated().connect(sigc::bind(sigc::hide<0>(sigc::hide<0>(sigc::mem_fun(*
this, &ServiceChooserDialog::response))), 1));
126 #ifdef GLIBMM_PROPERTIES_ENABLED
143 Glib::ustring &hostname,
144 Glib::ustring &ipaddr,
145 unsigned short int &port)
147 Glib::RefPtr<Gtk::TreeSelection> treesel = __treeview.get_selection();
148 if (__expander.get_expanded() && !__treeview.has_focus()) {
149 if ( __entry.get_text_length() > 0 ) {
150 char *tmpvalue = strdup(__entry.get_text().c_str());
152 if ( strchr(tmpvalue,
':') != NULL ) {
154 hostname = strtok_r(tmpvalue,
":", &save_ptr);
155 char *tmpport = strtok_r(NULL,
"", &save_ptr);
157 int port_num = atoi(tmpport);
158 if ( (port_num < 0) || (port_num > 0xFFFF) ) {
177 Gtk::TreeModel::iterator iter = treesel->get_selected();
179 Gtk::TreeModel::Row row = *iter;
199 if ( addr_size <
sizeof(
struct sockaddr_in) ) {
200 throw Exception(
"Size of addrlen too small, only %u bytes, but required %zu\n",
201 addr_size,
sizeof(
struct sockaddr_in));
203 Glib::ustring name, hostname, ipaddr;
204 unsigned short int port;
207 if (inet_pton(AF_INET, ipaddr.c_str(), &(((
struct sockaddr_in *)addr)->sin_addr)) <= 0) {
209 struct sockaddr_in *saddr;
212 memcpy(addr, saddr, std::min(saddr_len, addr_size));
214 throw Exception(
"Could not lookup hostname '%s' and it is not a valid IP address",
229 if (__expander.get_expanded()) {
230 __entry.grab_focus();
232 __treeview.grab_focus();
253 Glib::ustring hostname;
254 Glib::ustring ipaddr;
255 unsigned short int port;
257 if ( port == 0 ) port = 1910;
259 __client->
connect(hostname.c_str(), ipaddr.c_str(), port);
261 Glib::ustring message = *(e.
begin());
262 Gtk::MessageDialog md(__parent, message,
false,
263 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
265 md.set_title(
"Connection failed");