Browse Source

append progressbar to request entry

CPP-GTK4
yggverse 2 months ago
parent
commit
3a91155596
  1. 1
      Makefile
  2. 1
      po/POTFILES.in
  3. 15
      src/app/browser/main/tab/page.cpp
  4. 4
      src/app/browser/main/tab/page.hpp
  5. 16
      src/app/browser/main/tab/page/navigation.cpp
  6. 4
      src/app/browser/main/tab/page/navigation.hpp
  7. 34
      src/app/browser/main/tab/page/navigation/request.cpp
  8. 18
      src/app/browser/main/tab/page/navigation/request.hpp
  9. 51
      src/app/browser/main/tab/page/progress.cpp
  10. 27
      src/app/browser/main/tab/page/progress.hpp

1
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/history/forward.cpp\
src/app/browser/main/tab/page/navigation/request.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/navigation/update.cpp\
src/app/browser/main/tab/page/progress.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

@ -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/history/forward.cpp
src/app/browser/main/tab/page/navigation/request.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/navigation/update.cpp
src/app/browser/main/tab/page/progress.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

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

@ -1,7 +1,6 @@
#include "page.hpp" #include "page.hpp"
#include "page/content.hpp" #include "page/content.hpp"
#include "page/navigation.hpp" #include "page/navigation.hpp"
#include "page/progress.hpp"
using namespace app::browser::main::tab; using namespace app::browser::main::tab;
@ -24,12 +23,6 @@ Page::Page(
* pageNavigation * pageNavigation
); );
pageProgress = Gtk::make_managed<page::Progress>();
append(
* pageProgress
);
pageContent = Gtk::make_managed<page::Content>(); pageContent = Gtk::make_managed<page::Content>();
append( append(
@ -48,16 +41,14 @@ Page::Page(
void Page::refresh( void Page::refresh(
const Glib::ustring & TITLE, const Glib::ustring & TITLE,
const Glib::ustring & SUBTITLE, const Glib::ustring & SUBTITLE,
const double & PROGRESS const double & PROGRESS_FRACTION
) { ) {
title = TITLE; // @TODO copy title = TITLE; // @TODO copy
subtitle = SUBTITLE; subtitle = SUBTITLE;
pageProgress->refresh( pageNavigation->refresh(
PROGRESS PROGRESS_FRACTION
); );
pageNavigation->refresh();
} }
void Page::navigation_update( void Page::navigation_update(

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

@ -20,7 +20,6 @@ namespace app::browser::main::tab
{ {
class Content; class Content;
class Navigation; class Navigation;
class Progress;
} }
class Page : public Gtk::Box class Page : public Gtk::Box
@ -38,7 +37,6 @@ namespace app::browser::main::tab
// Components // Components
page::Content * pageContent; page::Content * pageContent;
page::Navigation * pageNavigation; page::Navigation * pageNavigation;
page::Progress * pageProgress;
public: public:
@ -52,7 +50,7 @@ namespace app::browser::main::tab
void refresh( void refresh(
const Glib::ustring & TITLE, const Glib::ustring & TITLE,
const Glib::ustring & SUBTITLE, const Glib::ustring & SUBTITLE,
const double & PROGRESS const double & PROGRESS_FRACTION
); );
void navigation_update( void navigation_update(

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

@ -76,7 +76,7 @@ Navigation::Navigation(
"refresh", "refresh",
[this] [this]
{ {
refresh(); refresh(0);
} }
); );
@ -87,20 +87,26 @@ Navigation::Navigation(
} }
// Actions // Actions
void Navigation::refresh() void Navigation::refresh(
{ const double & PROGRESS_FRACTION
) {
// Toggle base button sensibility // Toggle base button sensibility
navigationBase->set_sensitive( navigationBase->set_sensitive(
!navigationRequest->get_host().empty() && !navigationRequest->get_path().empty() !navigationRequest->get_host().empty() && !navigationRequest->get_path().empty()
); );
// Refresh history widget
navigationHistory->refresh();
// Toggle update button sensibility // Toggle update button sensibility
navigationUpdate->set_sensitive( navigationUpdate->set_sensitive(
navigationRequest->get_text_length() > 0 navigationRequest->get_text_length() > 0
); );
// Refresh history widget // Refresh request area (with progressbar)
navigationHistory->refresh(); navigationRequest->refresh(
PROGRESS_FRACTION
);
} }
void Navigation::history_add( void Navigation::history_add(

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

@ -37,7 +37,9 @@ namespace app::browser::main::tab::page
); );
// Actions // Actions
void refresh(); void refresh(
const double & PROGRESS_FRACTION
);
void history_add( void history_add(
const Glib::ustring & REQUEST, const Glib::ustring & REQUEST,

34
src/app/browser/main/tab/page/navigation/request.cpp

@ -15,6 +15,10 @@ Request::Request(
HEXPAND HEXPAND
); );
set_progress_pulse_step(
PROGRESS_PULSE_STEP
);
if (!TEXT.empty()) if (!TEXT.empty())
{ {
set_text( 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 // Getters
Glib::ustring Request::get_scheme() Glib::ustring Request::get_scheme()
{ {

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

@ -2,6 +2,7 @@
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST_HPP
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/main.h>
#include <glibmm/regex.h> #include <glibmm/regex.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/entry.h> #include <gtkmm/entry.h>
@ -10,7 +11,8 @@ namespace app::browser::main::tab::page::navigation
{ {
class Request : public Gtk::Entry class Request : public Gtk::Entry
{ {
const bool HEXPAND = true; // Extras
double progress_fraction;
Glib::ustring scheme, Glib::ustring scheme,
host, host,
@ -18,14 +20,26 @@ namespace app::browser::main::tab::page::navigation
path, path,
query; query;
// Defaults
const bool HEXPAND = true;
const double PROGRESS_PULSE_STEP = .1;
const int PROGRESS_ANIMATION_TIME = 10;
// Private helpers
void parse(); void parse();
public: public:
Request( 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_scheme();
Glib::ustring get_host(); Glib::ustring get_host();
Glib::ustring get_port(); Glib::ustring get_port();

51
src/app/browser/main/tab/page/progress.cpp

@ -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
);
}

27
src/app/browser/main/tab/page/progress.hpp

@ -1,27 +0,0 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_PROGRESS_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_PROGRESS_HPP
#include <glibmm/main.h>
#include <gtkmm/progressbar.h>
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
Loading…
Cancel
Save