Browse Source

implement response form (code 10)

PHP-GTK3
yggverse 4 months ago
parent
commit
5fda126ea9
  1. 27
      src/Entity/Browser/Container/Tab/Page.php
  2. 16
      src/Entity/Browser/Container/Tab/Page/Content.php
  3. 121
      src/Entity/Browser/Container/Tab/Page/Response.php
  4. 43
      src/Entity/Browser/Container/Tab/Page/Response/Query.php
  5. 38
      src/Entity/Browser/Container/Tab/Page/Response/Send.php

27
src/Entity/Browser/Container/Tab/Page.php

@ -7,6 +7,7 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab; @@ -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 @@ -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 @@ -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,12 +75,24 @@ class Page @@ -64,12 +75,24 @@ 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
);

16
src/Entity/Browser/Container/Tab/Page/Content.php

@ -185,6 +185,22 @@ class Content @@ -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

121
src/Entity/Browser/Container/Tab/Page/Response.php

@ -0,0 +1,121 @@ @@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Query;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Send;
use \Yggverse\Net\Address;
class Response
{
public \GtkBox $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
// Requirements
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Query $query;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Send $send;
// Defaults
private int $_margin = 8;
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page
) {
// Init dependencies
$this->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();
}
}

43
src/Entity/Browser/Container/Tab/Page/Response/Query.php

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response;
class Query extends \Yggverse\Yoda\Abstract\Entity\Entry
{
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response;
// Defaults
protected string $_placeholder = 'Enter response...';
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response
) {
// Use parent features
parent::__construct();
// Init dependency
$this->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
}
}

38
src/Entity/Browser/Container/Tab/Page/Response/Send.php

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response;
class Send extends \Yggverse\Yoda\Abstract\Entity\Button
{
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response;
// Defaults
protected string $_label = 'Send';
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response
) {
// Use parent features
parent::__construct();
// Init dependency
$this->response = $response;
}
protected function _onCLick(
\GtkButton $entity
): void
{
$this->response->send();
}
public function refresh(): void
{
$this->gtk->set_sensitive(
!empty($this->response->query->getValue())
);
}
}
Loading…
Cancel
Save