From dd68120c100d26e06bb5de9cec0c7ef4ef3065c6 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 26 Aug 2024 22:29:09 +0300 Subject: [PATCH] update new tab api --- src/app/browser/main.cpp | 6 +--- src/app/browser/main/tab.cpp | 33 ++++++++++--------- src/app/browser/main/tab.hpp | 12 ++++--- src/app/browser/main/tab/page.cpp | 29 ++++++++-------- src/app/browser/main/tab/page.hpp | 5 ++- src/app/browser/main/tab/page/navbar.cpp | 13 +++++--- src/app/browser/main/tab/page/navbar.hpp | 9 +++-- .../browser/main/tab/page/navbar/request.cpp | 16 +++++++-- .../browser/main/tab/page/navbar/request.hpp | 6 +++- 9 files changed, 77 insertions(+), 52 deletions(-) diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index 40b562c7..b66c2b56 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -40,11 +40,7 @@ Glib::ustring Main::get_current_tab_label_text() // Actions void Main::tab_append() { - tab->append( - nullptr, - true, - true - ); + tab->append(); }; void Main::tab_update() diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 429b8c16..fec1a278 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -8,12 +8,12 @@ Tab::Tab() { // Init widget set_scrollable( - true + SCROLLABLE ); // Init events signal_switch_page().connect( - [this](Gtk::Widget * page, guint page_num) + [this](Gtk::Widget * page, guint page_number) { // Refresh window elements, e.g. tab label to header bar activate_action( @@ -47,49 +47,50 @@ Glib::ustring Tab::get_label_text( // Actions void Tab::append( - const char * request, - bool open, + const Glib::ustring & page_navbar_request_text, bool focus ) { - auto label = new tab::Label(); - auto page = new tab::Page(); + auto label = new tab::Label; - append_page( + auto page = new tab::Page( + page_navbar_request_text + ); + + int page_number = append_page( * page, * label ); set_tab_reorderable( * page, - true + REORDERABLE ); if (focus) { set_current_page( - page_num( - * page - ) + page_number ); } }; void Tab::close( - int number + int page_number ) { auto page = get_nth_page( - number + page_number ); auto label = get_tab_label( * page ); - delete page; - delete label; + // @TODO data type + // delete page; + // delete label; remove_page( - number + page_number ); // @TODO fix GtkGizmo reported min height, but sizes must be >= 0 diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index cf13b4f0..ec708d58 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -9,6 +9,9 @@ namespace app::browser::main { class Tab : public Gtk::Notebook { + const bool REORDERABLE = true; + const bool SCROLLABLE = true; + public: Tab(); @@ -20,13 +23,12 @@ namespace app::browser::main ); void append( - const char * request, - bool open, - bool focus + const Glib::ustring & page_navbar_request_text = "", + bool focus = true ); void close( - int number + int page_number ); void close_left(); @@ -34,7 +36,7 @@ namespace app::browser::main void close_all(); void update( - int number + int page_number ); }; } diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 81c71831..4384b4e6 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -5,8 +5,9 @@ using namespace app::browser::main::tab; -Page::Page() -{ +Page::Page( + const Glib::ustring & navbar_request_text +) { // Init container set_orientation( Gtk::Orientation::VERTICAL @@ -30,7 +31,9 @@ Page::Page() ); // Init components - navbar = new page::Navbar(); + navbar = new page::Navbar( + navbar_request_text + ); append( * navbar @@ -106,11 +109,11 @@ void Page::update() ); // Request - const Glib::ustring request = navbar->get_request() + "\r\n"; + const Glib::ustring navbar_request_text = navbar->get_request_text() + "\r\n"; socket_connection->get_output_stream()->write_async( - request.data(), - request.size(), + navbar_request_text.data(), + navbar_request_text.size(), [this](const Glib::RefPtr & result) { progressbar->set( @@ -175,24 +178,24 @@ void Page::update() // Scheme not found but host provided, redirect to gemini:// else if (!navbar->get_request_host().empty()) { - Glib::ustring request = "gemini://"; + Glib::ustring navbar_request_text = "gemini://"; - request += navbar->get_request_host(); // @TODO validate + navbar_request_text += navbar->get_request_host(); // @TODO validate if (!navbar->get_request_port().empty()) { - request += navbar->get_request_port(); + navbar_request_text += navbar->get_request_port(); } - request += navbar->get_request_path(); + navbar_request_text += navbar->get_request_path(); if (!navbar->get_request_query().empty()) { - request += "?" + navbar->get_request_query(); + navbar_request_text += "?" + navbar->get_request_query(); } - navbar->set_request( - request + navbar->set_request_text( + navbar_request_text ); update(); diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 94fd0a9e..ad3d18f2 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -37,7 +37,10 @@ namespace app::browser::main::tab public: - Page(); + Page( + const Glib::ustring & navbar_request_text = "" + ); + ~Page(); void update(); diff --git a/src/app/browser/main/tab/page/navbar.cpp b/src/app/browser/main/tab/page/navbar.cpp index 5c60a0f9..66584eb4 100644 --- a/src/app/browser/main/tab/page/navbar.cpp +++ b/src/app/browser/main/tab/page/navbar.cpp @@ -7,8 +7,9 @@ using namespace app::browser::main::tab::page; -Navbar::Navbar() -{ +Navbar::Navbar( + const Glib::ustring & request_text +) { // Init container set_orientation( Gtk::Orientation::HORIZONTAL @@ -53,7 +54,9 @@ Navbar::Navbar() * update ); - request = new navbar::Request(); + request = new navbar::Request( + request_text + ); append( * request @@ -107,7 +110,7 @@ void Navbar::refresh() } // Setters -void Navbar::set_request( +void Navbar::set_request_text( const Glib::ustring & value ) { request->set_text( @@ -118,7 +121,7 @@ void Navbar::set_request( } // Getters -Glib::ustring Navbar::get_request() +Glib::ustring Navbar::get_request_text() { return request->get_text(); } diff --git a/src/app/browser/main/tab/page/navbar.hpp b/src/app/browser/main/tab/page/navbar.hpp index 16153724..1b717d4f 100644 --- a/src/app/browser/main/tab/page/navbar.hpp +++ b/src/app/browser/main/tab/page/navbar.hpp @@ -35,19 +35,22 @@ namespace app::browser::main::tab::page public: - Navbar(); + Navbar( + const Glib::ustring & request_text = "" + ); + ~Navbar(); // Actions void refresh(); // Setters - void set_request( + void set_request_text( const Glib::ustring & value ); // Getters - Glib::ustring get_request(); + Glib::ustring get_request_text(); Glib::ustring get_request_scheme(); Glib::ustring get_request_host(); diff --git a/src/app/browser/main/tab/page/navbar/request.cpp b/src/app/browser/main/tab/page/navbar/request.cpp index cfdf22e9..49d61efb 100644 --- a/src/app/browser/main/tab/page/navbar/request.cpp +++ b/src/app/browser/main/tab/page/navbar/request.cpp @@ -3,17 +3,27 @@ using namespace app::browser::main::tab::page::navbar; // Construct -Request::Request() -{ +Request::Request( + const Glib::ustring & text +) { // Init entry set_placeholder_text( _("URL or search term...") ); set_hexpand( - true + HEXPAND ); + if (!text.empty()) + { + set_text( + text + ); + + parse(); + } + // Connect events signal_changed().connect( [this] diff --git a/src/app/browser/main/tab/page/navbar/request.hpp b/src/app/browser/main/tab/page/navbar/request.hpp index cfc1a6fa..f30c3a8c 100644 --- a/src/app/browser/main/tab/page/navbar/request.hpp +++ b/src/app/browser/main/tab/page/navbar/request.hpp @@ -10,6 +10,8 @@ namespace app::browser::main::tab::page::navbar { class Request : public Gtk::Entry { + const bool HEXPAND = true; + Glib::ustring scheme, host, port, @@ -20,7 +22,9 @@ namespace app::browser::main::tab::page::navbar public: - Request(); + Request( + const Glib::ustring & text = "" + ); ~Request();