Browse Source

update new tab api

CPP-GTK4
yggverse 3 months ago
parent
commit
dd68120c10
  1. 6
      src/app/browser/main.cpp
  2. 33
      src/app/browser/main/tab.cpp
  3. 12
      src/app/browser/main/tab.hpp
  4. 29
      src/app/browser/main/tab/page.cpp
  5. 5
      src/app/browser/main/tab/page.hpp
  6. 13
      src/app/browser/main/tab/page/navbar.cpp
  7. 9
      src/app/browser/main/tab/page/navbar.hpp
  8. 16
      src/app/browser/main/tab/page/navbar/request.cpp
  9. 6
      src/app/browser/main/tab/page/navbar/request.hpp

6
src/app/browser/main.cpp

@ -40,11 +40,7 @@ Glib::ustring Main::get_current_tab_label_text()
// Actions // Actions
void Main::tab_append() void Main::tab_append()
{ {
tab->append( tab->append();
nullptr,
true,
true
);
}; };
void Main::tab_update() void Main::tab_update()

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

@ -8,12 +8,12 @@ Tab::Tab()
{ {
// Init widget // Init widget
set_scrollable( set_scrollable(
true SCROLLABLE
); );
// Init events // Init events
signal_switch_page().connect( 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 // Refresh window elements, e.g. tab label to header bar
activate_action( activate_action(
@ -47,49 +47,50 @@ Glib::ustring Tab::get_label_text(
// Actions // Actions
void Tab::append( void Tab::append(
const char * request, const Glib::ustring & page_navbar_request_text,
bool open,
bool focus bool focus
) { ) {
auto label = new tab::Label(); auto label = new tab::Label;
auto page = new tab::Page();
append_page( auto page = new tab::Page(
page_navbar_request_text
);
int page_number = append_page(
* page, * page,
* label * label
); );
set_tab_reorderable( set_tab_reorderable(
* page, * page,
true REORDERABLE
); );
if (focus) if (focus)
{ {
set_current_page( set_current_page(
page_num( page_number
* page
)
); );
} }
}; };
void Tab::close( void Tab::close(
int number int page_number
) { ) {
auto page = get_nth_page( auto page = get_nth_page(
number page_number
); );
auto label = get_tab_label( auto label = get_tab_label(
* page * page
); );
delete page; // @TODO data type
delete label; // delete page;
// delete label;
remove_page( remove_page(
number page_number
); );
// @TODO fix GtkGizmo reported min height, but sizes must be >= 0 // @TODO fix GtkGizmo reported min height, but sizes must be >= 0

12
src/app/browser/main/tab.hpp

@ -9,6 +9,9 @@ namespace app::browser::main
{ {
class Tab : public Gtk::Notebook class Tab : public Gtk::Notebook
{ {
const bool REORDERABLE = true;
const bool SCROLLABLE = true;
public: public:
Tab(); Tab();
@ -20,13 +23,12 @@ namespace app::browser::main
); );
void append( void append(
const char * request, const Glib::ustring & page_navbar_request_text = "",
bool open, bool focus = true
bool focus
); );
void close( void close(
int number int page_number
); );
void close_left(); void close_left();
@ -34,7 +36,7 @@ namespace app::browser::main
void close_all(); void close_all();
void update( void update(
int number int page_number
); );
}; };
} }

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

@ -5,8 +5,9 @@
using namespace app::browser::main::tab; using namespace app::browser::main::tab;
Page::Page() Page::Page(
{ const Glib::ustring & navbar_request_text
) {
// Init container // Init container
set_orientation( set_orientation(
Gtk::Orientation::VERTICAL Gtk::Orientation::VERTICAL
@ -30,7 +31,9 @@ Page::Page()
); );
// Init components // Init components
navbar = new page::Navbar(); navbar = new page::Navbar(
navbar_request_text
);
append( append(
* navbar * navbar
@ -106,11 +109,11 @@ void Page::update()
); );
// Request // 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( socket_connection->get_output_stream()->write_async(
request.data(), navbar_request_text.data(),
request.size(), navbar_request_text.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set( progressbar->set(
@ -175,24 +178,24 @@ void Page::update()
// Scheme not found but host provided, redirect to gemini:// // Scheme not found but host provided, redirect to gemini://
else if (!navbar->get_request_host().empty()) 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()) 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()) if (!navbar->get_request_query().empty())
{ {
request += "?" + navbar->get_request_query(); navbar_request_text += "?" + navbar->get_request_query();
} }
navbar->set_request( navbar->set_request_text(
request navbar_request_text
); );
update(); update();

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

@ -37,7 +37,10 @@ namespace app::browser::main::tab
public: public:
Page(); Page(
const Glib::ustring & navbar_request_text = ""
);
~Page(); ~Page();
void update(); void update();

13
src/app/browser/main/tab/page/navbar.cpp

@ -7,8 +7,9 @@
using namespace app::browser::main::tab::page; using namespace app::browser::main::tab::page;
Navbar::Navbar() Navbar::Navbar(
{ const Glib::ustring & request_text
) {
// Init container // Init container
set_orientation( set_orientation(
Gtk::Orientation::HORIZONTAL Gtk::Orientation::HORIZONTAL
@ -53,7 +54,9 @@ Navbar::Navbar()
* update * update
); );
request = new navbar::Request(); request = new navbar::Request(
request_text
);
append( append(
* request * request
@ -107,7 +110,7 @@ void Navbar::refresh()
} }
// Setters // Setters
void Navbar::set_request( void Navbar::set_request_text(
const Glib::ustring & value const Glib::ustring & value
) { ) {
request->set_text( request->set_text(
@ -118,7 +121,7 @@ void Navbar::set_request(
} }
// Getters // Getters
Glib::ustring Navbar::get_request() Glib::ustring Navbar::get_request_text()
{ {
return request->get_text(); return request->get_text();
} }

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

@ -35,19 +35,22 @@ namespace app::browser::main::tab::page
public: public:
Navbar(); Navbar(
const Glib::ustring & request_text = ""
);
~Navbar(); ~Navbar();
// Actions // Actions
void refresh(); void refresh();
// Setters // Setters
void set_request( void set_request_text(
const Glib::ustring & value const Glib::ustring & value
); );
// Getters // Getters
Glib::ustring get_request(); Glib::ustring get_request_text();
Glib::ustring get_request_scheme(); Glib::ustring get_request_scheme();
Glib::ustring get_request_host(); Glib::ustring get_request_host();

16
src/app/browser/main/tab/page/navbar/request.cpp

@ -3,17 +3,27 @@
using namespace app::browser::main::tab::page::navbar; using namespace app::browser::main::tab::page::navbar;
// Construct // Construct
Request::Request() Request::Request(
{ const Glib::ustring & text
) {
// Init entry // Init entry
set_placeholder_text( set_placeholder_text(
_("URL or search term...") _("URL or search term...")
); );
set_hexpand( set_hexpand(
true HEXPAND
);
if (!text.empty())
{
set_text(
text
); );
parse();
}
// Connect events // Connect events
signal_changed().connect( signal_changed().connect(
[this] [this]

6
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 class Request : public Gtk::Entry
{ {
const bool HEXPAND = true;
Glib::ustring scheme, Glib::ustring scheme,
host, host,
port, port,
@ -20,7 +22,9 @@ namespace app::browser::main::tab::page::navbar
public: public:
Request(); Request(
const Glib::ustring & text = ""
);
~Request(); ~Request();

Loading…
Cancel
Save