Browse Source

implement base button action

CPP-GTK4
yggverse 2 months ago
parent
commit
893a9d92e1
  1. 1
      src/app/browser/main/tab/page.cpp
  2. 5
      src/app/browser/main/tab/page/navigation.cpp
  3. 9
      src/app/browser/main/tab/page/navigation.hpp
  4. 29
      src/app/browser/main/tab/page/navigation/base.cpp
  5. 18
      src/app/browser/main/tab/page/navigation/base.hpp

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

@ -62,6 +62,7 @@ Page::Page( @@ -62,6 +62,7 @@ Page::Page(
this->db,
ACTION__HISTORY_BACK,
ACTION__HISTORY_FORWARD,
ACTION__OPEN_LINK_VARIANT,
ACTION__RELOAD,
ACTION__UPDATE
);

5
src/app/browser/main/tab/page/navigation.cpp

@ -11,6 +11,7 @@ Navigation::Navigation( @@ -11,6 +11,7 @@ Navigation::Navigation(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__OPEN_LINK_VARIANT,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__RELOAD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE
) {
@ -45,7 +46,9 @@ Navigation::Navigation( @@ -45,7 +46,9 @@ Navigation::Navigation(
);
// Init components
navigationBase = Gtk::make_managed<navigation::Base>();
navigationBase = Gtk::make_managed<navigation::Base>(
ACTION__OPEN_LINK_VARIANT
);
append(
* navigationBase

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

@ -82,10 +82,11 @@ namespace app::browser::main::tab::page @@ -82,10 +82,11 @@ namespace app::browser::main::tab::page
Navigation(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_RELOAD
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__OPEN_LINK_VARIANT,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__RELOAD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE
);
// Actions

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

@ -2,8 +2,13 @@ @@ -2,8 +2,13 @@
using namespace app::browser::main::tab::page::navigation;
Base::Base()
{
Base::Base(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__OPEN_LINK_VARIANT
) {
// Init shared actions
action__open_link_variant = ACTION__OPEN_LINK_VARIANT;
// Init widget
set_icon_name(
"go-home-symbolic"
);
@ -16,13 +21,29 @@ Base::Base() @@ -16,13 +21,29 @@ Base::Base()
false
);
// @TODO add action
// Init events
signal_clicked().connect(
[this]
{
// Currently, there is
action__open_link_variant->activate_variant(
Glib::Variant<Glib::ustring>::create(
Glib::ustring::sprintf(
"%s://%s/",
g_uri_get_scheme(uri), // @TODO NULL validate?
g_uri_get_host(uri)
) // at this moment, there is no G_URI_HIDE_*HOST option for g_uri_to_string_partial,
// build address manually using sprintf @TODO
)
);
}
);
}
void Base::update(
const Glib::ustring & URI
) {
GUri * uri = g_uri_parse(
uri = g_uri_parse(
URI.c_str(),
G_URI_FLAGS_NONE,
NULL // @TODO GError *

18
src/app/browser/main/tab/page/navigation/base.hpp

@ -1,17 +1,33 @@ @@ -1,17 +1,33 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BASE_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BASE_HPP
#include <giomm/simpleaction.h>
#include <glib.h>
#include <glibmm/i18n.h>
#include <glibmm/ustring.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navigation
{
class Base : public Gtk::Button
{
/*
* Internal members
*/
Glib::RefPtr<Gio::SimpleAction> action__open_link_variant;
GUri * uri;
/*
* Base class API
*/
public:
Base();
Base(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__OPEN_LINK_VARIANT
);
// Actions
void update(
const Glib::ustring & URI
);

Loading…
Cancel
Save