Browse Source

implement progressbar

CPP-GTK4
yggverse 3 months ago
parent
commit
46e004966e
  1. 1
      Makefile
  2. 1
      po/POTFILES.in
  3. 32
      src/app/browser/main/tab/page.cpp
  4. 6
      src/app/browser/main/tab/page.hpp
  5. 53
      src/app/browser/main/tab/page/progressbar.cpp
  6. 28
      src/app/browser/main/tab/page/progressbar.hpp

1
Makefile

@ -24,6 +24,7 @@ SRCS = src/main.cpp\
src/app/browser/main/tab/page/navbar/history/forward.cpp\ src/app/browser/main/tab/page/navbar/history/forward.cpp\
src/app/browser/main/tab/page/navbar/request.cpp\ src/app/browser/main/tab/page/navbar/request.cpp\
src/app/browser/main/tab/page/navbar/update.cpp\ src/app/browser/main/tab/page/navbar/update.cpp\
src/app/browser/main/tab/page/progressbar.cpp\
src/app/browser/main/tab/label.cpp\ src/app/browser/main/tab/label.cpp\
src/lib/database.cpp\ src/lib/database.cpp\
src/lib/database/session.cpp src/lib/database/session.cpp

1
po/POTFILES.in

@ -16,6 +16,7 @@ src/app/browser/main/tab/page/navbar/history/back.cpp
src/app/browser/main/tab/page/navbar/history/forward.cpp src/app/browser/main/tab/page/navbar/history/forward.cpp
src/app/browser/main/tab/page/navbar/request.cpp src/app/browser/main/tab/page/navbar/request.cpp
src/app/browser/main/tab/page/navbar/update.cpp src/app/browser/main/tab/page/navbar/update.cpp
src/app/browser/main/tab/page/progressbar.cpp
src/app/browser/main/tab/label.cpp src/app/browser/main/tab/label.cpp
src/lib/database.cpp src/lib/database.cpp
src/lib/database/session.cpp src/lib/database/session.cpp

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

@ -1,6 +1,7 @@
#include "page.hpp" #include "page.hpp"
#include "page/navbar.hpp"
#include "page/content.hpp" #include "page/content.hpp"
#include "page/navbar.hpp"
#include "page/progressbar.hpp"
using namespace app::browser::main::tab; using namespace app::browser::main::tab;
@ -39,6 +40,12 @@ Page::Page()
// because of insert_action_group + append here @TODO // because of insert_action_group + append here @TODO
navbar->refresh(); navbar->refresh();
progressbar = new page::Progressbar();
append(
* progressbar
);
content = new page::Content(); content = new page::Content();
append( append(
@ -50,10 +57,17 @@ Page::~Page()
{ {
delete navbar; delete navbar;
delete content; delete content;
delete progressbar;
} }
void Page::update() void Page::update()
{ {
// Reset progress
progressbar->set(
0
);
// Connect scheme driver
if ("file" == navbar->get_request_scheme()) if ("file" == navbar->get_request_scheme())
{ {
// @TODO // @TODO
@ -83,6 +97,10 @@ void Page::update()
), ),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set(
.25
);
socket_connection = socket_client->connect_to_host_finish( socket_connection = socket_client->connect_to_host_finish(
result result
); );
@ -95,12 +113,20 @@ void Page::update()
request.size(), request.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set(
.5
);
// Response // Response
socket_connection->get_input_stream()->read_async( // | read_all_async socket_connection->get_input_stream()->read_async( // | read_all_async
buffer, buffer,
sizeof(buffer) - 1, sizeof(buffer) - 1,
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set(
.75
);
// Parse meta // Parse meta
auto meta = Glib::Regex::split_simple( auto meta = Glib::Regex::split_simple(
R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex", R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex",
@ -134,6 +160,10 @@ void Page::update()
} }
socket_connection->close(); socket_connection->close();
progressbar->set(
1
);
} }
); );
} }

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

@ -18,8 +18,9 @@ namespace app::browser::main::tab
{ {
namespace page namespace page
{ {
class Navbar;
class Content; class Content;
class Navbar;
class Progressbar;
} }
class Page : public Gtk::Box class Page : public Gtk::Box
@ -30,8 +31,9 @@ namespace app::browser::main::tab
Glib::RefPtr<Gio::SocketClient> socket_client; Glib::RefPtr<Gio::SocketClient> socket_client;
Glib::RefPtr<Gio::SocketConnection> socket_connection; Glib::RefPtr<Gio::SocketConnection> socket_connection;
page::Navbar * navbar;
page::Content * content; page::Content * content;
page::Navbar * navbar;
page::Progressbar * progressbar;
public: public:

53
src/app/browser/main/tab/page/progressbar.cpp

@ -0,0 +1,53 @@
#include "progressbar.hpp"
using namespace app::browser::main::tab::page;
Progressbar::Progressbar()
{
set_margin_top(
MARGIN
);
set_margin_bottom(
MARGIN
);
set_pulse_step(
PULSE_STEP
);
set_opacity(0);
}
Progressbar::~Progressbar() = default;
// Public actions
void Progressbar::set(
double fraction
) {
// Toggle transparency
set_opacity(
fraction < 1 ? 1 : 0
);
// Reset initial progress
progress = fraction;
// Animate progress function
Glib::signal_timeout().connect(
[this]() -> bool
{
double current = get_fraction();
if (current < progress)
{
set_fraction(
current + PULSE_STEP
);
}
return current < 1;
},
ANIMATION_TIME
);
}

28
src/app/browser/main/tab/page/progressbar.hpp

@ -0,0 +1,28 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_PROGRESSBAR_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_PROGRESSBAR_HPP
#include <glibmm/main.h>
#include <gtkmm/progressbar.h>
namespace app::browser::main::tab::page
{
class Progressbar : public Gtk::ProgressBar
{
const int MARGIN = 2;
const double PULSE_STEP = .1;
const int ANIMATION_TIME = 10;
double progress = 0;
public:
Progressbar();
~Progressbar();
void set(
double fraction
);
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_PROGRESSBAR_HPP
Loading…
Cancel
Save