implement title detection by content type provider

This commit is contained in:
yggverse 2024-09-14 09:33:25 +03:00
parent 5e88040bf0
commit f31dc84fe6
9 changed files with 83 additions and 9 deletions

View File

@ -316,6 +316,12 @@ void Page::navigation_reload(
buffer
);
// Update title on detected by document provider
if (!pageContent->get_title().empty())
{
title = pageContent->get_title();
}
action__update->activate();
}

View File

@ -31,6 +31,12 @@ Content::~Content()
delete contentText;
}
// Getters
Glib::ustring Content::get_title()
{
return title;
}
// Setters
void Content::update(
const MIME & MIME,
@ -39,6 +45,8 @@ void Content::update(
// Cleanup, free memory
if (contentText != nullptr)
{
title.clear();
remove(
* contentText
);
@ -58,6 +66,8 @@ void Content::update(
DATA
);
title = contentText->get_title();
append(
* contentText
);

View File

@ -22,8 +22,11 @@ namespace app::browser::main::tab::page
// Components
content::Text * contentText;
// Extra features
Glib::ustring title;
/*
* Class API
* Content class API
*/
public:
@ -36,10 +39,14 @@ namespace app::browser::main::tab::page
Content();
~Content();
// Actions
void update(
const MIME & MIME,
const Glib::ustring & DATA
);
// Getters
Glib::ustring get_title();
};
}

View File

@ -14,7 +14,8 @@ Text::Text(
set_child(
* Gtk::make_managed<text::Gemini>(
TEXT
TEXT,
title
)
);
@ -34,4 +35,10 @@ Text::Text(
throw _("Invalid text type enum"); // @TODO
}
}
// Getters
Glib::ustring Text::get_title()
{
return title;
}

View File

@ -9,18 +9,32 @@ namespace app::browser::main::tab::page::content
{
class Text : public Gtk::ScrolledWindow
{
/*
* Private members
*/
Glib::ustring title;
public:
/*
* Extra features
*/
enum Type
{
GEMINI,
PLAIN
};
/*
* Text class API
*/
Text(
const Type & TYPE,
const Glib::ustring & TEXT
);
// Getters
Glib::ustring get_title();
};
}

View File

@ -4,19 +4,26 @@
using namespace app::browser::main::tab::page::content::text;
Gemini::Gemini(
const Glib::ustring & GEMTEXT
const Glib::ustring & GEMTEXT,
Glib::ustring & title
) : Gtk::Viewport( // add scrolled window features to childs
NULL,
NULL
) {
// Init components
auto geminiReader = Gtk::make_managed<gemini::Reader>(
GEMTEXT
);
// Grab title
title = geminiReader->get_title();
// Init widget
set_scroll_to_focus(
false
);
set_child(
* Gtk::make_managed<gemini::Reader>(
GEMTEXT
)
* geminiReader
);
}

View File

@ -8,10 +8,14 @@ namespace app::browser::main::tab::page::content::text
{
class Gemini : public Gtk::Viewport
{
/*
* Gemini class API
*/
public:
Gemini(
const Glib::ustring & GEMTEXT
const Glib::ustring & GEMTEXT,
Glib::ustring & title
);
};
}

View File

@ -52,6 +52,12 @@ Reader::Reader(
);
}
// Getters
Glib::ustring Reader::get_title()
{
return title;
}
// Match tools
bool Reader::Line::Match::header(
const Glib::ustring & GEMTEXT,
@ -152,6 +158,11 @@ Glib::ustring Reader::make(
)
);
if (title.empty())
{
title = header;
}
continue;
}

View File

@ -62,18 +62,26 @@ namespace app::browser::main::tab::page::content::text::gemini
);
};
static Glib::ustring make(
Glib::ustring make(
const Glib::ustring & GEMTEXT
);
/*
* Gemini class API
* Private members
*/
Glib::ustring title;
/*
* Reader class API
*/
public:
Reader(
const Glib::ustring & GEMTEXT
);
// Getters
Glib::ustring get_title();
};
}