*/ class mpGtkController { /** * The context view object. * * @type mpGtkView * @var mpGtkView $view */ private $view = null; /** * Controller ctor. */ public function __construct() { $this->view = new mpGtkView(); $this->view->button->connect_simple( "clicked", array( $this, "doAddProduct" ) ); } /** * Starts the main gtk loop */ public function run() { Gtk::main(); } /** * Add product action with the hole domain logic. */ public function doAddProduct() { // Get given name $name = $this->view->input->get_text(); // Create a domain Facade $facade = new mpDomainFacade(); try { // Try to add product $facade->addProduct( $name ); // Reset input $this->view->input->set_text( "" ); } catch ( mpDomainException $e ) { $this->showDialog( $e->getTitle(), $e->getMessage() ); } } /** * Shows a simple error dialog. * * @param string $title * @param string $message */ private function showDialog( $title, $message ) { $dialog = new GtkDialog( $title, $this->view ); $dialog->vbox->pack_start( new GtkLabel( $message ), true ); $dialog->show_all(); } } $controller = new mpGtkController(); $controller->run();