Browse Source

implement title detection by content type provider

CPP-GTK4
yggverse 2 months ago
parent
commit
f31dc84fe6
  1. 6
      src/app/browser/main/tab/page.cpp
  2. 10
      src/app/browser/main/tab/page/content.cpp
  3. 9
      src/app/browser/main/tab/page/content.hpp
  4. 9
      src/app/browser/main/tab/page/content/text.cpp
  5. 14
      src/app/browser/main/tab/page/content/text.hpp
  6. 15
      src/app/browser/main/tab/page/content/text/gemini.cpp
  7. 6
      src/app/browser/main/tab/page/content/text/gemini.hpp
  8. 11
      src/app/browser/main/tab/page/content/text/gemini/reader.cpp
  9. 12
      src/app/browser/main/tab/page/content/text/gemini/reader.hpp

6
src/app/browser/main/tab/page.cpp

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

10
src/app/browser/main/tab/page/content.cpp

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

9
src/app/browser/main/tab/page/content.hpp

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

9
src/app/browser/main/tab/page/content/text.cpp

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

14
src/app/browser/main/tab/page/content/text.hpp

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

15
src/app/browser/main/tab/page/content/text/gemini.cpp

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

6
src/app/browser/main/tab/page/content/text/gemini.hpp

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

11
src/app/browser/main/tab/page/content/text/gemini/reader.cpp

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

12
src/app/browser/main/tab/page/content/text/gemini/reader.hpp

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

Loading…
Cancel
Save