From 5fda126ea9bfcf2f9ca6f1079fd0360a2f8d25b3 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 7 Jul 2024 23:49:00 +0300 Subject: [PATCH] implement response form (code 10) --- src/Entity/Browser/Container/Tab/Page.php | 27 +++- .../Browser/Container/Tab/Page/Content.php | 16 +++ .../Browser/Container/Tab/Page/Response.php | 121 ++++++++++++++++++ .../Container/Tab/Page/Response/Query.php | 43 +++++++ .../Container/Tab/Page/Response/Send.php | 38 ++++++ 5 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 src/Entity/Browser/Container/Tab/Page/Response.php create mode 100644 src/Entity/Browser/Container/Tab/Page/Response/Query.php create mode 100644 src/Entity/Browser/Container/Tab/Page/Response/Send.php diff --git a/src/Entity/Browser/Container/Tab/Page.php b/src/Entity/Browser/Container/Tab/Page.php index 58fca566..fc7990ae 100644 --- a/src/Entity/Browser/Container/Tab/Page.php +++ b/src/Entity/Browser/Container/Tab/Page.php @@ -7,6 +7,7 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response; class Page { @@ -19,6 +20,7 @@ class Page public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title $title; public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar; public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content; + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response; public function __construct( \Yggverse\Yoda\Entity\Browser\Container\Tab $tab @@ -54,6 +56,15 @@ class Page $this->content->gtk ); + // Init response bar + $this->response = new Response( + $this + ); + + $this->gtk->pack_end( + $this->response->gtk + ); + // Render $this->gtk->show_all(); } @@ -64,14 +75,26 @@ class Page $this->content->refresh(); } - public function update( + public function open( + ?string $request = null, bool $history = true ): void { - // @TODO navbar + $this->navbar->request->setValue( + $request + ); $this->content->update( $history ); } + + public function update( + bool $history = true + ): void + { + $this->content->update( + $history + ); + } } \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab/Page/Content.php b/src/Entity/Browser/Container/Tab/Page/Content.php index 7844c55d..b7e1d115 100644 --- a/src/Entity/Browser/Container/Tab/Page/Content.php +++ b/src/Entity/Browser/Container/Tab/Page/Content.php @@ -185,6 +185,22 @@ class Content // Process codes switch ($response->getCode()) { + case 10: // response expected + + $this->page->title->setValue( + $address->getHost(), + sprintf( + 'response expected (code %d)', + intval( + $response->getCode() + ) + ) + ); + + $this->page->response->show(); + + break; + case 20: // ok // Process content type diff --git a/src/Entity/Browser/Container/Tab/Page/Response.php b/src/Entity/Browser/Container/Tab/Page/Response.php new file mode 100644 index 00000000..e4d21538 --- /dev/null +++ b/src/Entity/Browser/Container/Tab/Page/Response.php @@ -0,0 +1,121 @@ +page = $page; + + // Init container + $this->gtk = new \GtkBox( + \GtkOrientation::HORIZONTAL + ); + + $this->gtk->set_margin_top( + $this->_margin + ); + + $this->gtk->set_margin_bottom( + $this->_margin + ); + + $this->gtk->set_margin_start( + $this->_margin + ); + + $this->gtk->set_margin_end( + $this->_margin + ); + + $this->gtk->set_spacing( + $this->_margin + ); + + // Init query field + $this->query = new Query( + $this + ); + + $this->gtk->pack_start( + $this->query->gtk, + true, + true, + 0 + ); + + // Init send button + $this->send = new Send( + $this + ); + + $this->gtk->add( + $this->send->gtk + ); + + // Hide widget by default + $this->hide(); + } + + public function show(): void + { + $this->gtk->show_all(); + } + + public function hide(): void + { + $this->gtk->hide(); + } + + public function refresh() + { + $this->query->refresh(); + $this->send->refresh(); + } + + public function send(): void + { + $address = new Address( + $this->page->navbar->request->getValue() + ); + + $address->setQuery( + urlencode( + trim( + strval( + $this->query->getValue() + ) + ) + ) + ); + + $this->page->open( + $address->get(), + false // disable history recording + ); + + $this->hide(); + } +} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab/Page/Response/Query.php b/src/Entity/Browser/Container/Tab/Page/Response/Query.php new file mode 100644 index 00000000..716be8e5 --- /dev/null +++ b/src/Entity/Browser/Container/Tab/Page/Response/Query.php @@ -0,0 +1,43 @@ +response = $response; + } + + protected function _onActivate( + \GtkEntry $entry + ): void + { + $this->response->send(); + } + + protected function _onKeyRelease( + \GtkEntry $entry, + \GdkEvent $event + ): void + { + $this->response->refresh(); + } + + public function refresh(): void + { + // @TODO + } +} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab/Page/Response/Send.php b/src/Entity/Browser/Container/Tab/Page/Response/Send.php new file mode 100644 index 00000000..5dded6af --- /dev/null +++ b/src/Entity/Browser/Container/Tab/Page/Response/Send.php @@ -0,0 +1,38 @@ +response = $response; + } + + protected function _onCLick( + \GtkButton $entity + ): void + { + $this->response->send(); + } + + public function refresh(): void + { + $this->gtk->set_sensitive( + !empty($this->response->query->getValue()) + ); + } +} \ No newline at end of file