Browse Source

use dynamic_cast, make const uppercase

CPP-GTK4
yggverse 3 months ago
parent
commit
687b623354
  1. 97
      src/app/browser/main/tab.cpp

97
src/app/browser/main/tab.cpp

@ -53,7 +53,7 @@ Tab::Tab(
// Restore session from DB // Restore session from DB
sqlite3_stmt* statement; sqlite3_stmt* statement;
int prepare = sqlite3_prepare_v3( const int PREPARE = ::sqlite3_prepare_v3(
this->db, this->db,
R"SQL( R"SQL(
SELECT * FROM `app_browser_main_tab` SELECT * FROM `app_browser_main_tab`
@ -64,12 +64,12 @@ Tab::Tab(
nullptr nullptr
); );
if (prepare == SQLITE_OK) if (PREPARE == SQLITE_OK)
{ {
while (sqlite3_step(statement) == SQLITE_ROW) while (sqlite3_step(statement) == SQLITE_ROW)
{ {
append( append(
sqlite3_column_text( ::sqlite3_column_text(
statement, statement,
DB::APP_BROWSER_MAIN_TAB::REQUEST DB::APP_BROWSER_MAIN_TAB::REQUEST
), ),
@ -142,19 +142,19 @@ void Tab::shutdown()
void Tab::refresh( void Tab::refresh(
const int & PAGE_NUMBER const int & PAGE_NUMBER
) { ) {
auto tabPage = get_tabPage( const auto TAB_PAGE = get_tabPage(
PAGE_NUMBER PAGE_NUMBER
); );
get_tabLabel( get_tabLabel(
PAGE_NUMBER PAGE_NUMBER
)->set_label( )->set_label(
tabPage->get_title() TAB_PAGE->get_title()
); );
tabPage->refresh( TAB_PAGE->refresh(
tabPage->get_title(), TAB_PAGE->get_title(),
tabPage->get_subtitle(), TAB_PAGE->get_subtitle(),
0 // @TODO 0 // @TODO
); );
@ -171,31 +171,31 @@ void Tab::append(
const unsigned char * REQUEST, const unsigned char * REQUEST,
const bool & FOCUS const bool & FOCUS
) { ) {
auto tabPage = new tab::Page( const auto TAB_PAGE = new tab::Page(
action__refresh, action__refresh,
action__tab_page_navigation_history_back, action__tab_page_navigation_history_back,
action__tab_page_navigation_history_forward, action__tab_page_navigation_history_forward,
action__tab_page_navigation_update action__tab_page_navigation_update
); );
auto tabLabel = new tab::Label( const auto TAB_LABEL = new tab::Label(
action__tab_close_active action__tab_close_active
); );
int page_number = append_page( const int PAGE_NUMBER = append_page(
* tabPage, * TAB_PAGE,
* tabLabel * TAB_LABEL
); );
set_tab_reorderable( set_tab_reorderable(
* tabPage, * TAB_PAGE,
REORDERABLE REORDERABLE
); );
if (FOCUS) if (FOCUS)
{ {
set_current_page( set_current_page(
page_number PAGE_NUMBER
); );
} }
}; };
@ -258,51 +258,78 @@ void Tab::page_navigation_history_forward(
Glib::ustring Tab::get_page_title( Glib::ustring Tab::get_page_title(
const int & PAGE_NUMBER const int & PAGE_NUMBER
) { ) {
return get_tabPage(PAGE_NUMBER)->get_title(); return get_tabPage(
PAGE_NUMBER
)->get_title();
}; };
Glib::ustring Tab::get_page_subtitle( Glib::ustring Tab::get_page_subtitle(
const int & PAGE_NUMBER const int & PAGE_NUMBER
) { ) {
return get_tabPage(PAGE_NUMBER)->get_subtitle(); return get_tabPage(
PAGE_NUMBER
)->get_subtitle();
}; };
// Private helpers // Private helpers
tab::Label * Tab::get_tabLabel( tab::Label * Tab::get_tabLabel(
const int & PAGE_NUMBER const int & PAGE_NUMBER
) { ) {
auto pageWidget = get_nth_page( // Get page pointer to find label widget
const auto PAGE = get_nth_page(
PAGE_NUMBER PAGE_NUMBER
); );
if (pageWidget == nullptr) if (PAGE == nullptr)
{ {
throw _("Tab page not found!"); // @TODO throw _("Page not found!"); // @TODO
} }
auto labelWidget = get_tab_label( // Get label widget by page pointer
* pageWidget const auto LABEL = get_tab_label(
* PAGE
); );
if (labelWidget == nullptr) if (LABEL == nullptr)
{ {
throw _("Tab label not found!"); // @TODO throw _("Label not found!"); // @TODO
} }
// Downcast
const auto TAB_LABEL = dynamic_cast<tab::Label*>(
LABEL
);
return (tab::Label *) labelWidget; if (TAB_LABEL == nullptr)
{
throw _("Tab label not found!"); // @TODO
}
return TAB_LABEL;
} }
tab::Page * Tab::get_tabPage( tab::Page * Tab::get_tabPage(
const int & PAGE_NUMBER const int & PAGE_NUMBER
) { ) {
auto pageWidget = get_nth_page( // Get page widget
const auto PAGE = get_nth_page(
PAGE_NUMBER PAGE_NUMBER
); );
if (pageWidget == nullptr) if (PAGE == nullptr)
{ {
throw _("Tab page not found!"); // @TODO throw _("Page not found!"); // @TODO
} }
// Downcast
const auto TAB_PAGE = dynamic_cast<tab::Page*>(
PAGE
);
if (TAB_PAGE == nullptr)
{
throw _("Tab page not found!"); // @TODO
}
return (tab::Page *) pageWidget; return TAB_PAGE;
} }
Loading…
Cancel
Save