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

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

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

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

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

Loading…
Cancel
Save