From 3a9115559690afba784cf0ab3cd0f5f56e25126b Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 6 Sep 2024 05:17:33 +0300 Subject: [PATCH] append progressbar to request entry --- Makefile | 1 - po/POTFILES.in | 1 - src/app/browser/main/tab/page.cpp | 15 ++---- src/app/browser/main/tab/page.hpp | 4 +- src/app/browser/main/tab/page/navigation.cpp | 16 ++++-- src/app/browser/main/tab/page/navigation.hpp | 4 +- .../main/tab/page/navigation/request.cpp | 34 +++++++++++++ .../main/tab/page/navigation/request.hpp | 18 ++++++- src/app/browser/main/tab/page/progress.cpp | 51 ------------------- src/app/browser/main/tab/page/progress.hpp | 27 ---------- 10 files changed, 68 insertions(+), 103 deletions(-) delete mode 100644 src/app/browser/main/tab/page/progress.cpp delete mode 100644 src/app/browser/main/tab/page/progress.hpp diff --git a/Makefile b/Makefile index e0545baa..49696069 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,6 @@ SRCS = src/main.cpp\ src/app/browser/main/tab/page/navigation/history/forward.cpp\ src/app/browser/main/tab/page/navigation/request.cpp\ src/app/browser/main/tab/page/navigation/update.cpp\ - src/app/browser/main/tab/page/progress.cpp\ src/app/browser/main/tab/label.cpp\ src/lib/database.cpp\ src/lib/database/session.cpp diff --git a/po/POTFILES.in b/po/POTFILES.in index 6ce04a21..f91583d3 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -19,7 +19,6 @@ src/app/browser/main/tab/page/navigation/history/back.cpp src/app/browser/main/tab/page/navigation/history/forward.cpp src/app/browser/main/tab/page/navigation/request.cpp src/app/browser/main/tab/page/navigation/update.cpp -src/app/browser/main/tab/page/progress.cpp src/app/browser/main/tab/label.cpp src/lib/database.cpp src/lib/database/session.cpp diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 98f9fec5..b14730c5 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -1,7 +1,6 @@ #include "page.hpp" #include "page/content.hpp" #include "page/navigation.hpp" -#include "page/progress.hpp" using namespace app::browser::main::tab; @@ -24,12 +23,6 @@ Page::Page( * pageNavigation ); - pageProgress = Gtk::make_managed(); - - append( - * pageProgress - ); - pageContent = Gtk::make_managed(); append( @@ -48,16 +41,14 @@ Page::Page( void Page::refresh( const Glib::ustring & TITLE, const Glib::ustring & SUBTITLE, - const double & PROGRESS + const double & PROGRESS_FRACTION ) { title = TITLE; // @TODO copy subtitle = SUBTITLE; - pageProgress->refresh( - PROGRESS + pageNavigation->refresh( + PROGRESS_FRACTION ); - - pageNavigation->refresh(); } void Page::navigation_update( diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index f0812db2..e36c410f 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -20,7 +20,6 @@ namespace app::browser::main::tab { class Content; class Navigation; - class Progress; } class Page : public Gtk::Box @@ -38,7 +37,6 @@ namespace app::browser::main::tab // Components page::Content * pageContent; page::Navigation * pageNavigation; - page::Progress * pageProgress; public: @@ -52,7 +50,7 @@ namespace app::browser::main::tab void refresh( const Glib::ustring & TITLE, const Glib::ustring & SUBTITLE, - const double & PROGRESS + const double & PROGRESS_FRACTION ); void navigation_update( diff --git a/src/app/browser/main/tab/page/navigation.cpp b/src/app/browser/main/tab/page/navigation.cpp index f8a43f98..637634ff 100644 --- a/src/app/browser/main/tab/page/navigation.cpp +++ b/src/app/browser/main/tab/page/navigation.cpp @@ -76,7 +76,7 @@ Navigation::Navigation( "refresh", [this] { - refresh(); + refresh(0); } ); @@ -87,20 +87,26 @@ Navigation::Navigation( } // Actions -void Navigation::refresh() -{ +void Navigation::refresh( + const double & PROGRESS_FRACTION +) { // Toggle base button sensibility navigationBase->set_sensitive( !navigationRequest->get_host().empty() && !navigationRequest->get_path().empty() ); + // Refresh history widget + navigationHistory->refresh(); + // Toggle update button sensibility navigationUpdate->set_sensitive( navigationRequest->get_text_length() > 0 ); - // Refresh history widget - navigationHistory->refresh(); + // Refresh request area (with progressbar) + navigationRequest->refresh( + PROGRESS_FRACTION + ); } void Navigation::history_add( diff --git a/src/app/browser/main/tab/page/navigation.hpp b/src/app/browser/main/tab/page/navigation.hpp index 339cd02e..67a9426b 100644 --- a/src/app/browser/main/tab/page/navigation.hpp +++ b/src/app/browser/main/tab/page/navigation.hpp @@ -37,7 +37,9 @@ namespace app::browser::main::tab::page ); // Actions - void refresh(); + void refresh( + const double & PROGRESS_FRACTION + ); void history_add( const Glib::ustring & REQUEST, diff --git a/src/app/browser/main/tab/page/navigation/request.cpp b/src/app/browser/main/tab/page/navigation/request.cpp index ae37345f..ee4d16d1 100644 --- a/src/app/browser/main/tab/page/navigation/request.cpp +++ b/src/app/browser/main/tab/page/navigation/request.cpp @@ -15,6 +15,10 @@ Request::Request( HEXPAND ); + set_progress_pulse_step( + PROGRESS_PULSE_STEP + ); + if (!TEXT.empty()) { set_text( @@ -48,6 +52,36 @@ Request::Request( ); } +// Actions +void Request::refresh( + const double & PROGRESS_FRACTION +) { + // Update progress + progress_fraction = PROGRESS_FRACTION; + + // Animate progress function + Glib::signal_timeout().connect( + [this]() -> bool + { + double current_progress_fraction = get_progress_fraction(); + + if (current_progress_fraction < progress_fraction) + { + set_progress_fraction( + current_progress_fraction + PROGRESS_PULSE_STEP + ); + + return false; + } + + return true; // 100% of value + + //return current_progress_fraction < 1; // until 100% of value + }, + PROGRESS_ANIMATION_TIME + ); +} + // Getters Glib::ustring Request::get_scheme() { diff --git a/src/app/browser/main/tab/page/navigation/request.hpp b/src/app/browser/main/tab/page/navigation/request.hpp index 827de312..a0846341 100644 --- a/src/app/browser/main/tab/page/navigation/request.hpp +++ b/src/app/browser/main/tab/page/navigation/request.hpp @@ -2,6 +2,7 @@ #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST_HPP #include +#include #include #include #include @@ -10,7 +11,8 @@ namespace app::browser::main::tab::page::navigation { class Request : public Gtk::Entry { - const bool HEXPAND = true; + // Extras + double progress_fraction; Glib::ustring scheme, host, @@ -18,14 +20,26 @@ namespace app::browser::main::tab::page::navigation path, query; + // Defaults + const bool HEXPAND = true; + const double PROGRESS_PULSE_STEP = .1; + const int PROGRESS_ANIMATION_TIME = 10; + + // Private helpers void parse(); public: Request( - const Glib::ustring & VALUE = "" + const Glib::ustring & VALUE = "" // @TODO remove default value + ); + + // Actions + void refresh( + const double & PROGRESS_FRACTION ); + // Getters Glib::ustring get_scheme(); Glib::ustring get_host(); Glib::ustring get_port(); diff --git a/src/app/browser/main/tab/page/progress.cpp b/src/app/browser/main/tab/page/progress.cpp deleted file mode 100644 index fb8bb15d..00000000 --- a/src/app/browser/main/tab/page/progress.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "progress.hpp" - -using namespace app::browser::main::tab::page; - -Progress::Progress() -{ - set_margin_top( - MARGIN - ); - - set_margin_bottom( - MARGIN - ); - - set_pulse_step( - PULSE_STEP - ); - - set_opacity(0); // fixed height, not hide() -} - -// Public actions -void Progress::refresh( - 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 - ); -} diff --git a/src/app/browser/main/tab/page/progress.hpp b/src/app/browser/main/tab/page/progress.hpp deleted file mode 100644 index de8a166d..00000000 --- a/src/app/browser/main/tab/page/progress.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef APP_BROWSER_MAIN_TAB_PAGE_PROGRESS_HPP -#define APP_BROWSER_MAIN_TAB_PAGE_PROGRESS_HPP - -#include -#include - -namespace app::browser::main::tab::page -{ - class Progress : public Gtk::ProgressBar - { - const int MARGIN = 2; - const double PULSE_STEP = .1; - const int ANIMATION_TIME = 10; - - double progress = 0; - - public: - - Progress(); - - void refresh( - double fraction - ); - }; -} - -#endif // APP_BROWSER_MAIN_TAB_PAGE_PROGRESS_HPP \ No newline at end of file