25#include <gui_utils/avahi_dispatcher.h>
26#include <gui_utils/connection_dispatcher.h>
27#include <gui_utils/logview.h>
28#include <gui_utils/service_chooser_dialog.h>
29#include <netcomm/dns-sd/avahi_thread.h>
30#include <netcomm/fawkes/client.h>
31#include <netinet/in.h>
47 const Glib::RefPtr<Gtk::Builder> &builder)
50 builder->get_widget(
"vbox_main", vbox_main);
51 builder->get_widget(
"lab_no_connection", lab_no_connection);
52 builder->get_widget(
"tb_connection", tb_connection);
53 builder->get_widget(
"tb_exit", tb_exit);
54 builder->get_widget(
"tb_clear", tb_clear);
56 vbox_main->pack_end(ntb_logviewers);
60 sigc::retype_return<void>(sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_service_added)));
62 sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_service_removed));
65 avahi_thread->
start();
66 avahi_thread->
watch_service(
"_fawkes._tcp", avahi_dispatcher);
68 tb_connection->signal_clicked().connect(
69 sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_connection_clicked));
70 tb_exit->signal_clicked().connect(sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_exit_clicked));
71 tb_clear->signal_clicked().connect(sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_clear_clicked));
79 delete avahi_dispatcher;
85NetLogGuiGtkWindow::on_connection_clicked()
92 Glib::ustring name, hostname;
93 std::list<std::string> txt;
94 unsigned short int port = 1910;
95 struct sockaddr_in saddr;
96 socklen_t saddr_size =
sizeof(
struct sockaddr_in);
97 ssd.get_selected_service(name, hostname, port);
98 ssd.get_raw_address((
struct sockaddr *)&saddr, saddr_size);
104 (
struct sockaddr *)&saddr,
107 page = on_service_added(service);
111 Gtk::ScrolledWindow *scrolled =
112 dynamic_cast<Gtk::ScrolledWindow *
>(ntb_logviewers.get_nth_page(page));
113 LogView *logview =
dynamic_cast<LogView *
>(scrolled->get_child());
117 Glib::ustring message = *(e.
begin());
118 Gtk::MessageDialog md(*
this,
124 md.set_title(
"Connection failed");
127 ntb_logviewers.remove_page(page);
133NetLogGuiGtkWindow::on_exit_clicked()
139NetLogGuiGtkWindow::on_clear_clicked()
141 int page = ntb_logviewers.get_current_page();
143 Gtk::ScrolledWindow *scrolled =
144 dynamic_cast<Gtk::ScrolledWindow *
>(ntb_logviewers.get_nth_page(page));
153 if (ntb_logviewers.get_n_pages() == 0) {
154 lab_no_connection->hide();
158 ntb_logviewers.show();
161 Gtk::HBox * hbox = Gtk::manage(
new Gtk::HBox(
false, 4));
162 Gtk::Button *button = Gtk::manage(
new Gtk::Button());
163 Gtk::Image * image = Gtk::manage(
new Gtk::Image(Gtk::Stock::CONNECT, Gtk::ICON_SIZE_BUTTON));
165 button->set_relief(Gtk::RELIEF_NONE);
166 Gtk::Label *label = Gtk::manage(
new Gtk::Label());
167 label->set_markup(Glib::ustring(
"<b>") + service->
host() +
"</b>\n" + service->
addr_string());
168 label->set_line_wrap();
169 Gtk::Label * invisible = Gtk::manage(
new Gtk::Label(
170 Glib::ustring(service->
name()) +
"::" + service->
type() +
"::" + service->
domain()));
171 Gtk::ScrolledWindow *scrolled = Gtk::manage(
new Gtk::ScrolledWindow());
172 scrolled->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
176 hbox->pack_start(*button);
177 hbox->pack_start(*label);
178 hbox->pack_start(*invisible);
180 button->signal_clicked().connect(
181 sigc::bind(sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_connbut_clicked), image, logview));
183 sigc::bind(sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_connected), image));
185 sigc::bind(sigc::mem_fun(*
this, &NetLogGuiGtkWindow::on_disconnected), image));
194 int rv = ntb_logviewers.append_page(*logview, *hbox);
202 bool removed =
false;
206 for (
int i = 0; !removed && (i < ntb_logviewers.get_n_pages()); ++i) {
207 Gtk::Widget *child = ntb_logviewers.get_nth_page(i);
208 Gtk::Widget *tab_label = ntb_logviewers.get_tab_label(*child);
209 Gtk::HBox * hbox =
dynamic_cast<Gtk::HBox *
>(tab_label);
212 std::vector<Gtk::Widget *> children = hbox->get_children();
213 Gtk::Widget * w = children[2];
215 Gtk::Label *label =
dynamic_cast<Gtk::Label *
>(w);
218 Glib::ustring(service->
name()) +
"::" + service->
type() +
"::" + service->
domain();
219 if (label->get_text() == s) {
220 ntb_logviewers.remove_page(i);
229 if (ntb_logviewers.get_n_pages() == 0) {
230 ntb_logviewers.hide();
234 lab_no_connection->show();
239NetLogGuiGtkWindow::on_connbut_clicked(Gtk::Image *image,
fawkes::LogView *logview)
248 Glib::ustring message = *(e.
begin());
249 Gtk::MessageDialog md(*
this,
255 md.set_title(
"Connection failed");
262NetLogGuiGtkWindow::on_connected(Gtk::Image *image)
264 image->set(Gtk::Stock::DISCONNECT, Gtk::ICON_SIZE_BUTTON);
268NetLogGuiGtkWindow::on_disconnected(Gtk::Image *image)
270 image->set(Gtk::Stock::CONNECT, Gtk::ICON_SIZE_BUTTON);
~NetLogGuiGtkWindow()
Destructor.
NetLogGuiGtkWindow(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
sigc::signal< void, NetworkService * > signal_service_removed()
Get "service remove" signal.
sigc::signal< void, NetworkService * > signal_service_added()
Get "service added" signal.
void watch_service(const char *service_type, ServiceBrowseHandler *h)
Add a result handler.
sigc::signal< void > signal_connected()
Get "connected" signal.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
Base class for exceptions in Fawkes.
iterator begin() noexcept
Get iterator for messages.
Simple Fawkes network client.
void connect()
Connect to remote.
void disconnect()
Disconnect socket.
bool connected() const noexcept
Check if connection is alive.
void clear()
Clear all records.
ConnectionDispatcher * get_connection_dispatcher() const
Get ConnectionDispatcher instance that is used internally.
FawkesNetworkClient * get_client()
Get the used FawkesNetworkClient.
Representation of a service announced or found via service discovery (i.e.
std::string addr_string() const
Get IP address of entry as string.
const char * type() const
Get type of service.
unsigned short int port() const
Get port of service.
const char * name() const
Get name of service.
const char * host() const
Get host of service.
const char * domain() const
Get domain of service.
void start(bool wait=true)
Call this method to start the thread.
void join()
Join the thread.
void cancel()
Cancel a thread.
Fawkes library namespace.