add entity namespace

This commit is contained in:
yggverse 2024-04-10 07:08:49 +03:00
parent 7398ed7af2
commit 90c6d615fb
15 changed files with 40 additions and 40 deletions

30
src/Entity/Box/Menu.php Normal file
View file

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Box;
class Menu
{
public \GtkBox $box;
public \Yggverse\Yoda\Entity\Menu\Bar\Main $main;
public function __construct(
string $name = 'boxMenu'
) {
$this->box = new \GtkBox(
\GtkOrientation::VERTICAL
);
$this->box->set_name(
$name
);
$this->main = new \Yggverse\Yoda\Entity\Menu\Bar\Main();
$this->box->add(
$this->main->bar
);
}
}

View file

@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Box;
class Navigation
{
public \GtkBox $box;
public \Yggverse\Yoda\Entity\Entry\Address $address;
public \Yggverse\Yoda\Entity\Button\Home $home;
public \Yggverse\Yoda\Entity\Button\Back $back;
public \Yggverse\Yoda\Entity\Button\Forward $forward;
public \Yggverse\Yoda\Entity\Button\Reload $reload;
public \Yggverse\Yoda\Entity\Button\Go $go;
public object $config;
public function __construct(
string $name = 'boxNavigation'
) {
$this->config = \Yggverse\Yoda\Model\File::getConfig();
$this->box = new \GtkBox(
\GtkOrientation::HORIZONTAL
);
$this->box->set_name(
$name
);
if ($this->config->interface->window->navigation->button->home && $this->config->homepage)
{
$this->home = new \Yggverse\Yoda\Entity\Button\Home();
$this->box->pack_start(
$this->home->button,
false,
false,
8
);
}
if ($this->config->interface->window->navigation->button->back || $this->config->interface->window->navigation->button->forward)
{
$boxBackForward = new \GtkButtonBox(
\GtkOrientation::HORIZONTAL
);
$boxBackForward->set_layout(
\GtkButtonBoxStyle::EXPAND
);
if ($this->config->interface->window->navigation->button->back)
{
$this->back = new \Yggverse\Yoda\Entity\Button\Back();
$boxBackForward->pack_start(
$this->back->button,
false,
true,
0
);
}
if ($this->config->interface->window->navigation->button->forward)
{
$this->forward = new \Yggverse\Yoda\Entity\Button\Forward();
$boxBackForward->pack_end(
$this->forward->button,
false,
true,
0
);
}
$this->box->pack_start(
$boxBackForward,
false,
false,
8
);
}
if ($this->config->interface->window->navigation->button->reload)
{
$this->reload = new \Yggverse\Yoda\Entity\Button\Reload();
$this->box->pack_start(
$this->reload->button,
false,
false,
8
);
}
$this->address = new \Yggverse\Yoda\Entity\Entry\Address(
$this->config->homepage
);
$this->box->pack_start(
$this->address->entry,
true,
true,
8
);
if ($this->config->interface->window->navigation->button->go)
{
$this->go = new \Yggverse\Yoda\Entity\Button\Go();
$this->box->pack_end(
$this->go->button,
false,
false,
8
);
}
}
}

234
src/Entity/Box/Tab.php Normal file
View file

@ -0,0 +1,234 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Box;
class Tab
{
public \GtkBox $box;
public \GtkWindow $window;
public \Yggverse\Yoda\Entity\Box\Menu $menu;
public \Yggverse\Yoda\Entity\Box\Navigation $navigation;
public \Yggverse\Yoda\Entity\Label\Content $content;
public \Yggverse\Yoda\Entity\Label\Tray $tray;
public \Yggverse\Yoda\Model\Memory $memory;
public object $config;
public function __construct(
\GtkWindow $window,
string $name = 'boxTab'
) {
// Init window
$this->window = $window;
// Init config
$this->config = \Yggverse\Yoda\Model\File::getConfig();
// Init memory
$this->memory = new \Yggverse\Yoda\Model\Memory();
// Init container
$this->box = new \GtkBox(
\GtkOrientation::VERTICAL
);
$this->box->set_name(
$name
);
// Init dependencies
$this->menu = new \Yggverse\Yoda\Entity\Box\Menu();
$this->box->pack_start(
$this->menu->box,
false,
true,
0
);
$this->navigation = new \Yggverse\Yoda\Entity\Box\Navigation();
$this->box->pack_start(
$this->navigation->box,
false,
true,
8
);
$this->content = new \Yggverse\Yoda\Entity\Label\Content();
$scroll = new \GtkScrolledWindow();
$scroll->add(
$this->content->label
);
$this->box->pack_start(
$scroll,
true,
true,
10
);
$this->tray = new \Yggverse\Yoda\Entity\Label\Tray();
$this->box->pack_start(
$this->tray->label,
false,
true,
0
);
// Init listeners
$this->navigation->address->entry->connect(
'activate',
function ($entry)
{
$this->navigate(
$entry->get_text()
);
}
);
$this->navigation->go->button->connect(
'released',
function ($entry)
{
$this->navigate(
$this->navigation->address->entry->get_text()
);
}
);
$this->navigation->reload->button->connect(
'released',
function ($entry)
{
$this->navigate(
$this->navigation->address->entry->get_text()
);
}
);
if ($this->config->homepage)
{
$this->navigation->home->button->connect(
'released',
function ($entry)
{
$this->navigation->address->entry->set_text(
$this->config->homepage
);
$this->navigate(
$this->config->homepage
);
}
);
}
// @TODO back, forward buttons
}
// Actions
public function navigate(string $url)
{
$this->tray->label->set_text(
sprintf(
'Open %s...',
urldecode(
$url
)
)
);
$start = microtime(true);
$host = null;
if ($this->config->resolver->enabled)
{
$address = new \Yggverse\Net\Address(
$url
);
$name = $address->getHost();
if (!$host = $this->memory->get($name))
{
$resolve = new \Yggverse\Net\Resolve(
$this->config->resolver->request->record,
$this->config->resolver->request->host,
$this->config->resolver->request->timeout,
$this->config->resolver->result->shuffle
);
$resolved = $resolve->address(
$address
);
if ($resolved)
{
$host = $resolved->getHost();
$this->memory->set(
$name,
$host
);
}
}
}
$request = new \Yggverse\Gemini\Client\Request(
$url,
$host
);
$raw = $request->getResponse();
$end = microtime(true);
$response = new \Yggverse\Gemini\Client\Response(
$raw
);
$this->content->label->set_markup(
$response->getBody()
);
$body = new \Yggverse\Gemini\Gemtext\Body(
$response->getBody()
);
if ($h1 = $body->getH1())
{
$this->window->set_title(
sprintf(
'%s - Yoda',
empty($h1[0]) ? $address->getHost() : $h1[0]
)
);
}
$this->tray->label->set_text(
sprintf(
'%s | %s | %d bytes | %s seconds',
date('c'),
$response->getMeta() ? $response->getMeta() : $response->getCode(),
number_format(
mb_strlen(
$raw
)
),
round(
$end - $start, 2
)
)
);
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Button;
class Back
{
public \GtkButton $button;
public function __construct(
?string $label = 'Back'
) {
$this->button = \GtkButton::new_with_label(
$label
);
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Button;
class Forward
{
public \GtkButton $button;
public function __construct(
?string $label = 'Forward'
) {
$this->button = \GtkButton::new_with_label(
$label
);
}
}

18
src/Entity/Button/Go.php Normal file
View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Button;
class Go
{
public \GtkButton $button;
public function __construct(
?string $label = 'Go'
) {
$this->button = \GtkButton::new_with_label(
$label
);
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Button;
class Home
{
public \GtkButton $button;
public function __construct(
?string $label = 'Home'
) {
$this->button = \GtkButton::new_with_label(
$label
);
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Button;
class Reload
{
public \GtkButton $button;
public function __construct(
?string $label = 'Reload'
) {
$this->button = \GtkButton::new_with_label(
$label
);
}
}

View file

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Entry;
class Address
{
public \GtkEntry $entry;
public function __construct(
?string $text = null,
?string $placeholder = 'URL or any search term...'
) {
$this->entry = new \GtkEntry();
$this->entry->set_text(
$text
);
$this->entry->set_placeholder_text(
$placeholder
);
$this->entry->set_max_length(
1024
);
}
}

View file

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Label;
class Content
{
public \GtkLabel $label;
public function __construct(string $value = '')
{
$this->label = new \GtkLabel(
$value
);
$this->label->set_use_markup(
true
);
$this->label->set_selectable(
true
);
$this->label->set_xalign(
0
);
$this->label->set_yalign(
0
);
}
}

33
src/Entity/Label/Tray.php Normal file
View file

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Label;
class Tray
{
public \GtkLabel $label;
public function __construct(string $value = '')
{
$this->label = new \GtkLabel(
$value
);
$this->label->set_use_markup(
true
);
$this->label->set_selectable(
false
);
$this->label->set_xalign(
0
);
$this->label->set_yalign(
0
);
}
}

View file

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Menu\Bar;
class Main
{
public \GtkMenuBar $bar;
public \Yggverse\Yoda\Entity\Menu\Item\Yoda $yoda;
public function __construct()
{
$this->bar = new \GtkMenuBar();
$this->yoda = new \Yggverse\Yoda\Entity\Menu\Item\Yoda();
$this->bar->append(
$this->yoda->item
);
}
}

View file

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Menu\Item;
class Quit
{
public \GtkMenuItem $item;
public function __construct(string $label = 'Quit')
{
$this->item = \GtkMenuItem::new_with_label(
$label
);
$this->activate();
}
public function activate(): void
{
$this->item->connect(
'activate',
function ()
{
\Gtk::main_quit();
}
);
}
}

View file

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Menu\Item;
class Yoda
{
public \GtkMenuItem $item;
public function __construct(string $label = 'Yoda')
{
$this->item = \GtkMenuItem::new_with_label(
$label
);
$children = new \GtkMenu();
$quit = new \Yggverse\Yoda\Entity\Menu\Item\Quit();
$children->append(
$quit->item
);
$this->item->set_submenu(
$children
);
}
}