From 7451d6d78f441644083b0b35f9e6e3261d119469 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 14 Apr 2024 22:15:04 +0300 Subject: [PATCH] save page title to the database history --- src/Entity/Tab/History.php | 21 +++++++++++--- src/Entity/Tab/Page.php | 59 +++++++++++++++++++------------------- src/Model/Database.php | 19 ++++++------ 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/Entity/Tab/History.php b/src/Entity/Tab/History.php index 9cb2e309..a677d7f7 100644 --- a/src/Entity/Tab/History.php +++ b/src/Entity/Tab/History.php @@ -161,7 +161,7 @@ class History $this->treeview->append_column( new \GtkTreeViewColumn( - 'URL', + 'Time', new \GtkCellRendererText(), 'text', 0 @@ -170,15 +170,27 @@ class History $this->treeview->append_column( new \GtkTreeViewColumn( - 'Time', + 'Title', new \GtkCellRendererText(), 'text', 1 ) ); + $this->treeview->append_column( + new \GtkTreeViewColumn( + 'URL', + new \GtkCellRendererText(), + 'text', + 2 + ) + ); + + + // Init list storage $this->list = new \GtkListStore( + \GObject::TYPE_STRING, \GObject::TYPE_STRING, \GObject::TYPE_STRING ); @@ -259,11 +271,12 @@ class History { $this->list->append( [ - $record->url, date( $this->config->time->format, $record->time - ) + ), + $record->title, + $record->url ] ); } diff --git a/src/Entity/Tab/Page.php b/src/Entity/Tab/Page.php index 4b61a25d..8015a6fb 100644 --- a/src/Entity/Tab/Page.php +++ b/src/Entity/Tab/Page.php @@ -46,10 +46,10 @@ class Page $this->history = new \Yggverse\Yoda\Model\History; // Run database cleaner - if ($this->config->history->timeout) + if ($this->config->database->history->timeout) { $this->app->database->cleanHistory( - $this->config->history->timeout + $this->config->database->history->timeout ); } @@ -366,42 +366,17 @@ class Page $url ); - // Ignore history record on same URL given - if ($url == $this->history->getCurrent()) - { - $history = false; - } - - // Ignore history record on same URL stored in DB - if ($result = $this->app->database->getHistory('', 0, 1)) - { - if ($url == $result[0]->url) - { - $history = false; - } - } - // Update address field by requested $this->address->set_text( $url ); - if ($history) + // Update history in memory pool + if ($history && $this->config->memory->history->enabled && $url != $this->history->getCurrent()) { - // Update history in memory pool $this->history->add( $url ); - - // Update history in the database - if ($this->config->history->enabled) - { - $this->app->database->addHistory( - $url - ); - - $this->app->history->refresh(); - } } // Update home button sensibility on match requested @@ -450,7 +425,8 @@ class Page private function _openGemini( string $url, int $code = 0, - int $redirects = 0 + int $redirects = 0, + bool $history = true ): void { // Init base URL @@ -625,6 +601,29 @@ class Page $this->config->footer->status->open->complete ) ); + + // Update history database + if ($history && $this->config->database->history->enabled) + { + // Ignore history record on same URL stored + if ($result = $this->app->database->getHistory('', 0, 1)) + { + if ($url == $result[0]->url) + { + $history = false; + } + } + + if ($history) + { + $this->app->database->addHistory( + $url, + $title + ); + + $this->app->history->refresh(); + } + } } private function _openYoda( diff --git a/src/Model/Database.php b/src/Model/Database.php index d2c4efac..a8392a1d 100644 --- a/src/Model/Database.php +++ b/src/Model/Database.php @@ -37,9 +37,10 @@ class Database $this->_database->query(' CREATE TABLE IF NOT EXISTS "history" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - "time" INTEGER NOT NULL, - "url" VARCHAR(1024) NOT NULL + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "time" INTEGER NOT NULL, + "url" VARCHAR(1024) NOT NULL, + "title" VARCHAR(255) ) '); } @@ -56,17 +57,19 @@ class Database } public function addHistory( - string $url + string $url, + ?string $title = null ): int { $query = $this->_database->prepare( - 'INSERT INTO `history` (`time`, `url`) VALUES (:time, :url)' + 'INSERT INTO `history` (`time`, `url`, `title`) VALUES (:time, :url, :title)' ); $query->execute( [ - ':time' => time(), - ':url' => $url + ':time' => time(), + ':url' => $url, + ':title' => $title ] ); @@ -81,7 +84,7 @@ class Database { $query = $this->_database->prepare( sprintf( - 'SELECT * FROM `history` WHERE `url` LIKE :search ORDER BY `id` DESC LIMIT %d,%d', + 'SELECT * FROM `history` WHERE `url` LIKE :search OR `title` LIKE :search ORDER BY `id` DESC LIMIT %d,%d', $start, $limit )