Browse Source

implement title detection by content type provider

CPP-GTK4
yggverse 6 days 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( @@ -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();
}

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

@ -31,6 +31,12 @@ Content::~Content() @@ -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( @@ -39,6 +45,8 @@ void Content::update(
// Cleanup, free memory
if (contentText != nullptr)
{
title.clear();
remove(
* contentText
);
@ -58,6 +66,8 @@ void Content::update( @@ -58,6 +66,8 @@ void Content::update(
DATA
);
title = contentText->get_title();
append(
* contentText
);

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

@ -22,8 +22,11 @@ namespace app::browser::main::tab::page @@ -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 @@ -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();
};
}

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

@ -14,7 +14,8 @@ Text::Text( @@ -14,7 +14,8 @@ Text::Text(
set_child(
* Gtk::make_managed<text::Gemini>(
TEXT
TEXT,
title
)
);
@ -34,4 +35,10 @@ Text::Text( @@ -34,4 +35,10 @@ Text::Text(
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 @@ -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();
};
}

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

@ -4,19 +4,26 @@ @@ -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
);
}

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

@ -8,10 +8,14 @@ namespace app::browser::main::tab::page::content::text @@ -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
);
};
}

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

@ -52,6 +52,12 @@ Reader::Reader( @@ -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( @@ -152,6 +158,11 @@ Glib::ustring Reader::make(
)
);
if (title.empty())
{
title = header;
}
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 @@ -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();
};
}

Loading…
Cancel
Save