Browse Source

update new tab api

CPP-GTK4
yggverse 4 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() @@ -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()

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

@ -8,12 +8,12 @@ Tab::Tab() @@ -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( @@ -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

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

@ -9,6 +9,9 @@ namespace app::browser::main @@ -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 @@ -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 @@ -34,7 +36,7 @@ namespace app::browser::main
void close_all();
void update(
int number
int page_number
);
};
}

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

@ -5,8 +5,9 @@ @@ -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() @@ -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() @@ -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<Gio::AsyncResult> & result)
{
progressbar->set(
@ -175,24 +178,24 @@ void Page::update() @@ -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();

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

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

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

@ -7,8 +7,9 @@ @@ -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() @@ -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() @@ -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( @@ -118,7 +121,7 @@ void Navbar::set_request(
}
// Getters
Glib::ustring Navbar::get_request()
Glib::ustring Navbar::get_request_text()
{
return request->get_text();
}

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

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

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

@ -3,17 +3,27 @@ @@ -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]

6
src/app/browser/main/tab/page/navbar/request.hpp

@ -10,6 +10,8 @@ namespace app::browser::main::tab::page::navbar @@ -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 @@ -20,7 +22,9 @@ namespace app::browser::main::tab::page::navbar
public:
Request();
Request(
const Glib::ustring & text = ""
);
~Request();

Loading…
Cancel
Save