Browse Source

create update method, change refresh logic

CPP-GTK4
yggverse 2 months ago
parent
commit
eb902bdd99
  1. 7
      src/app/browser/main/tab.cpp
  2. 57
      src/app/browser/main/tab/page.cpp
  3. 44
      src/app/browser/main/tab/page.hpp

7
src/app/browser/main/tab.cpp

@ -184,12 +184,7 @@ void Tab::refresh(
TAB_PAGE->get_title() TAB_PAGE->get_title()
); );
TAB_PAGE->refresh( TAB_PAGE->refresh();
tab::Page::MIME::UNDEFINED,
TAB_PAGE->get_title(),
TAB_PAGE->get_description(),
0 // @TODO
);
action__tab_close_active->set_enabled( action__tab_close_active->set_enabled(
get_n_pages() > 0 get_n_pages() > 0

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

@ -10,6 +10,9 @@ Page::Page(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD, const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_UPDATE const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_UPDATE
) { ) {
// Init actions
action__refresh = ACTION__REFRESH;
// Init components // Init components
pageNavigation = Gtk::make_managed<page::Navigation>( pageNavigation = Gtk::make_managed<page::Navigation>(
ACTION__REFRESH, ACTION__REFRESH,
@ -33,30 +36,42 @@ Page::Page(
Gtk::Orientation::VERTICAL Gtk::Orientation::VERTICAL
); );
refresh( // Connect events
MIME::UNDEFINED, signal_realize().connect(
_("New page"), [this]
"", {
0 update(
MIME::UNDEFINED,
_("New page"),
"",
0
);
}
); );
} }
// Actions // Actions
void Page::refresh( void Page::refresh()
{
pageNavigation->refresh(
progress_fraction
);
}
void Page::update(
const MIME & MIME, const MIME & MIME,
const Glib::ustring & TITLE, const Glib::ustring & TITLE,
const Glib::ustring & DESCRIPTION, const Glib::ustring & DESCRIPTION,
const double & PROGRESS_FRACTION const double & PROGRESS_FRACTION
) { ) {
// Refresh page data // Refresh page data
mime = MIME; mime = MIME;
title = TITLE; title = TITLE;
description = DESCRIPTION; description = DESCRIPTION;
progress_fraction = PROGRESS_FRACTION;
// Refresh components // Refresh parent window
pageNavigation->refresh( action__refresh->activate();
PROGRESS_FRACTION
);
} }
void Page::navigation_update( void Page::navigation_update(
@ -72,7 +87,7 @@ void Page::navigation_update(
} }
// Update page extras // Update page extras
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Update"), _("Update"),
Glib::ustring::sprintf( Glib::ustring::sprintf(
@ -109,7 +124,7 @@ void Page::navigation_update(
pageNavigation->get_request_text(), 1965, pageNavigation->get_request_text(), 1965,
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Connect"), _("Connect"),
Glib::ustring::sprintf( Glib::ustring::sprintf(
@ -128,7 +143,7 @@ void Page::navigation_update(
catch (const Glib::Error & EXCEPTION) catch (const Glib::Error & EXCEPTION)
{ {
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Oops"), _("Oops"),
EXCEPTION.what(), EXCEPTION.what(),
@ -146,7 +161,7 @@ void Page::navigation_update(
request.size(), request.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Request"), _("Request"),
Glib::ustring::sprintf( Glib::ustring::sprintf(
@ -163,7 +178,7 @@ void Page::navigation_update(
sizeof(buffer) - 1, sizeof(buffer) - 1,
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Reading"), _("Reading"),
Glib::ustring::sprintf( Glib::ustring::sprintf(
@ -186,7 +201,7 @@ void Page::navigation_update(
// Route by mime type or path extension // Route by mime type or path extension
if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavigation->get_request_path(), ".gmi")) if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavigation->get_request_path(), ".gmi"))
{ {
refresh( update(
MIME::TEXT_GEMINI, MIME::TEXT_GEMINI,
pageNavigation->get_request_host(), // @TODO title pageNavigation->get_request_host(), // @TODO title
pageNavigation->get_request_path().empty() ? pageNavigation->get_request_host() pageNavigation->get_request_path().empty() ? pageNavigation->get_request_host()
@ -202,7 +217,7 @@ void Page::navigation_update(
else else
{ {
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Oops"), _("Oops"),
_("MIME type not supported"), _("MIME type not supported"),
@ -217,7 +232,7 @@ void Page::navigation_update(
else else
{ {
refresh( update(
MIME::UNDEFINED, MIME::UNDEFINED,
_("Oops"), _("Oops"),
Glib::ustring::sprintf( Glib::ustring::sprintf(

44
src/app/browser/main/tab/page.hpp

@ -25,30 +25,32 @@ namespace app::browser::main::tab
class Page : public Gtk::Box class Page : public Gtk::Box
{ {
public: // Extras
enum class MIME
enum class MIME {
{ TEXT_PLAIN,
TEXT_PLAIN, TEXT_GEMINI,
TEXT_GEMINI, UNDEFINED
UNDEFINED };
};
private: // Data
MIME mime;
Glib::ustring title;
Glib::ustring description;
double progress_fraction;
MIME mime; // Actions
Glib::ustring title; Glib::RefPtr<Gio::SimpleAction> action__refresh;
Glib::ustring description;
// Socket // Socket
char buffer[0xfffff]; // 1Mb char buffer[0xfffff]; // 1Mb
Glib::RefPtr<Gio::SocketClient> GioSocketClient; Glib::RefPtr<Gio::SocketClient> GioSocketClient;
Glib::RefPtr<Gio::SocketConnection> GioSocketConnection; Glib::RefPtr<Gio::SocketConnection> GioSocketConnection;
// Components // Components
page::Content * pageContent; page::Content * pageContent;
page::Navigation * pageNavigation; page::Navigation * pageNavigation;
public: public:
@ -60,7 +62,9 @@ namespace app::browser::main::tab
); );
// Actions // Actions
void refresh( void refresh();
void update(
const MIME & MIME, const MIME & MIME,
const Glib::ustring & TITLE, const Glib::ustring & TITLE,
const Glib::ustring & DESCRIPTION, const Glib::ustring & DESCRIPTION,

Loading…
Cancel
Save