rename tab elements namespace

This commit is contained in:
yggverse 2024-08-15 18:52:11 +03:00
parent 4e733d8997
commit 2986a475c1
29 changed files with 181 additions and 181 deletions

View file

@ -0,0 +1,16 @@
#include "content.hpp"
using namespace app::browser::main::tab::page;
Content::Content()
{
set_orientation(
Gtk::Orientation::VERTICAL
);
set_homogeneous(
true
);
}
Content::~Content() = default;

View file

@ -0,0 +1,18 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#include <gtkmm/box.h>
namespace app::browser::main::tab::page
{
class Content : public Gtk::Box
{
public:
Content();
~Content();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP

View file

@ -0,0 +1,106 @@
#include "navbar.hpp"
#include "navbar/base.hpp"
#include "navbar/bookmark.hpp"
#include "navbar/history.hpp"
#include "navbar/request.hpp"
#include "navbar/update.hpp"
using namespace app::browser::main::tab::page;
Navbar::Navbar()
{
// Init container
set_orientation(
Gtk::Orientation::HORIZONTAL
);
set_spacing(
SPACING
);
set_margin_top(
MARGIN
);
set_margin_start(
MARGIN
);
set_margin_end(
MARGIN
);
set_margin_bottom(
MARGIN
);
// Init components
base = new navbar::Base();
append(
* base
);
history = new navbar::History();
append(
* history
);
update = new navbar::Update();
append(
* update
);
request = new navbar::Request();
append(
* request
);
bookmark = new navbar::Bookmark();
append(
* bookmark
);
// Init actions group
action_group = Gio::SimpleActionGroup::create();
// Define group actions
action_group->add_action(
"refresh",
sigc::mem_fun(
* this,
& Navbar::refresh
)
);
insert_action_group(
"navbar",
action_group
);
}
Navbar::~Navbar() = default;
// Actions
void Navbar::refresh()
{
// Toggle base button sensibility
base->set_sensitive(
!empty(request->get_host()) && !empty(request->get_path())
);
// Toggle update button sensibility
update->set_sensitive(
(bool) request->get_text_length()
);
}
// Getters
Glib::ustring Navbar::get_request_value()
{
return request->get_text();
}

View file

@ -0,0 +1,52 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HPP
#include <giomm/simpleactiongroup.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <sigc++/functors/mem_fun.h>
namespace app::browser::main::tab::page
{
namespace navbar
{
class Base;
class Bookmark;
class History;
class Update;
class Request;
}
class Navbar : public Gtk::Box
{
private:
// Actions
Glib::RefPtr<Gio::SimpleActionGroup> action_group;
// Components
navbar::Base * base;
navbar::Bookmark * bookmark;
navbar::History * history;
navbar::Request * request;
navbar::Update * update;
// Defaults
const int SPACING = 8;
const int MARGIN = 8;
public:
Navbar();
~Navbar();
// Actions
void refresh();
// Getters
Glib::ustring get_request_value();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HPP

View file

@ -0,0 +1,20 @@
#include "base.hpp"
using namespace app::browser::main::tab::page::navbar;
Base::Base()
{
set_action_name(
"tab.base"
);
set_icon_name(
"go-home-symbolic"
);
set_tooltip_text(
_("Base")
);
}
Base::~Base() = default;

View file

@ -0,0 +1,19 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_BASE_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_BASE_HPP
#include <glibmm/i18n.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navbar
{
class Base : public Gtk::Button
{
public:
Base();
~Base();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_BASE_HPP

View file

@ -0,0 +1,20 @@
#include "bookmark.hpp"
using namespace app::browser::main::tab::page::navbar;
Bookmark::Bookmark()
{
set_action_name(
"tab.bookmark"
);
set_icon_name(
"starred-symbolic" // | non-starred-symbolic
);
set_tooltip_text(
_("Toggle bookmark")
);
}
Bookmark::~Bookmark() = default;

View file

@ -0,0 +1,19 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_BOOKMARK_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_BOOKMARK_HPP
#include <glibmm/i18n.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navbar
{
class Bookmark : public Gtk::Button
{
public:
Bookmark();
~Bookmark();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_BOOKMARK_HPP

View file

@ -0,0 +1,26 @@
#include "history.hpp"
#include "history/back.hpp"
#include "history/forward.hpp"
using namespace app::browser::main::tab::page::navbar;
History::History()
{
add_css_class(
"linked" // merge children elements
);
back = new history::Back();
append(
* back
);
forward = new history::Forward();
append(
* forward
);
}
History::~History() = default;

View file

@ -0,0 +1,30 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_HPP
#include <glibmm/i18n.h>
#include <gtkmm/box.h>
namespace app::browser::main::tab::page::navbar
{
namespace history
{
class Back;
class Forward;
}
class History : public Gtk::Box
{
private:
history::Back * back;
history::Forward * forward;
public:
History();
~History();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_HPP

View file

@ -0,0 +1,20 @@
#include "back.hpp"
using namespace app::browser::main::tab::page::navbar::history;
Back::Back()
{
set_action_name(
"tab.back"
);
set_icon_name(
"go-previous-symbolic"
);
set_tooltip_text(
_("Back")
);
}
Back::~Back() = default;

View file

@ -0,0 +1,19 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_BACK_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_BACK_HPP
#include <glibmm/i18n.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navbar::history
{
class Back : public Gtk::Button
{
public:
Back();
~Back();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_BACK_HPP

View file

@ -0,0 +1,20 @@
#include "forward.hpp"
using namespace app::browser::main::tab::page::navbar::history;
Forward::Forward()
{
set_action_name(
"tab.forward"
);
set_icon_name(
"go-next-symbolic"
);
set_tooltip_text(
_("Forward")
);
}
Forward::~Forward() = default;

View file

@ -0,0 +1,19 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_FORWARD_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_FORWARD_HPP
#include <glibmm/i18n.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navbar::history
{
class Forward : public Gtk::Button
{
public:
Forward();
~Forward();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_HISTORY_FORWARD_HPP

View file

@ -0,0 +1,94 @@
#include "request.hpp"
using namespace app::browser::main::tab::page::navbar;
using namespace std;
// Construct
Request::Request()
{
// Init entry
set_placeholder_text(
_("URL or search term...")
);
set_hexpand(
true
);
// Connect events
signal_changed().connect(
[this]
{
parse();
activate_action(
"navbar.refresh"
);
}
);
signal_activate().connect(
[this]
{
parse();
activate_action(
"page.update"
);
}
);
}
Request::~Request() = default;
// Getters
string Request::get_scheme()
{
return scheme;
}
string Request::get_host()
{
return host;
}
string Request::get_path()
{
return path;
}
string Request::get_query()
{
return path;
}
int Request::get_port()
{
return stoi(
port
);
}
// Private helpers
void Request::parse()
{
string subject = get_text();
smatch results;
static const regex pattern( // @TODO user:password@#fragment?
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex"
);
regex_search(
subject,
results,
pattern
);
scheme = results[2];
host = results[3];
port = results[5];
path = results[6];
query = results[8];
}

View file

@ -0,0 +1,39 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP
#include <glibmm/i18n.h>
#include <gtkmm/entry.h>
#include <regex>
#include <string>
namespace app::browser::main::tab::page::navbar
{
class Request : public Gtk::Entry
{
private:
std::string scheme,
host,
port,
path,
query;
void parse();
public:
Request();
~Request();
std::string get_scheme();
std::string get_host();
std::string get_path();
std::string get_query();
int get_port();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP

View file

@ -0,0 +1,20 @@
#include "update.hpp"
using namespace app::browser::main::tab::page::navbar;
Update::Update()
{
set_action_name(
"page.update"
);
set_icon_name(
"view-refresh-symbolic"
);
set_tooltip_text(
_("Update")
);
}
Update::~Update() = default;

View file

@ -0,0 +1,19 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_UPDATE_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_UPDATE_HPP
#include <glibmm/i18n.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navbar
{
class Update : public Gtk::Button
{
public:
Update();
~Update();
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_UPDATE_HPP