I have a program that (among other things) has a command line interface that allows the user to enter lines that will then be sent over the network. The problem is that I'm not sure how to connect events that are generated deep inside the GUI to the network interface. For example, suppose my hierarchy of GUI classes looks like this:
GUI → MainWindow → CommandLineInterface → EntryField
Each GUI object contains some other GUI objects, and everything is private. Now the entryField object generates the event / signal in which the message was entered. I am currently passing a signal to the class hierarchy, so the CLI class will look something like this:
public:
sig::csignal<void, string> msgEntered;
And in c'tor:
entryField.msgEntered.connect(sigc::mem_fun(this, &CLI::passUp));
The passUp function simply emits a signal again for the owner class (MainWindow) to connect until I can finally do this in the main loop:
gui.msgEntered.connect(sigc::mem_fun(networkInterface, &NetworkInterface::sendMSG));
Now this seems like a real bad decision. Every time I add something to the GUI, I have to connect it through the class hierarchy. I see several ways around this. I could make all objects publicly accessible, which would allow me to simply do this in the main loop:
gui.mainWindow.cli.entryField.msgEntered.connect(sigc::mem_fun(networkInterface, &NetworkInterface::sendMSG));
But this would be contrary to the idea of encapsulation. I could also pass the link to the network interface throughout the GUI, but I would like to leave the GUI code as individual as possible.
Looks like I'm missing something here. Is there a clean way to do this?
. GTK +/gtkmm/LibSig++, , Qt. .