Browse Source

implement separated restore action method

CPP-GTK4
yggverse 4 months ago
parent
commit
817c946270
  1. 89
      src/app/browser/main/tab.cpp
  2. 2
      src/app/browser/main/tab.hpp

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

@ -53,48 +53,7 @@ Tab::Tab( @@ -53,48 +53,7 @@ Tab::Tab(
[this]
{
// Restore session from DB
sqlite3_stmt* statement;
const int PREPARE = ::sqlite3_prepare_v3(
this->db,
R"SQL(
SELECT * FROM `app_browser_main_tab` ORDER BY `number` ASC
)SQL",
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE == SQLITE_OK)
{
while (::sqlite3_step(statement) == SQLITE_ROW)
{
const int PAGE_NUMBER = append();
get_tabPage(
PAGE_NUMBER
)->set_navbar_request_text(
reinterpret_cast<const char*>(
::sqlite3_column_text(
statement,
DB::APP_BROWSER_MAIN_TAB::REQUEST
)
)
);
if (::sqlite3_column_int(statement, DB::APP_BROWSER_MAIN_TAB::CURRENT) == 1)
{
set_current_page(
PAGE_NUMBER
);
}
}
}
sqlite3_finalize(
statement
);
restore();
}
);
@ -107,6 +66,52 @@ Tab::Tab( @@ -107,6 +66,52 @@ Tab::Tab(
);
}
void Tab::restore()
{
sqlite3_stmt* statement;
const int PREPARE = ::sqlite3_prepare_v3(
this->db,
R"SQL(
SELECT * FROM `app_browser_main_tab` ORDER BY `number` ASC
)SQL",
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE == SQLITE_OK)
{
while (::sqlite3_step(statement) == SQLITE_ROW)
{
const int PAGE_NUMBER = append();
get_tabPage(
PAGE_NUMBER
)->set_navbar_request_text(
reinterpret_cast<const char*>(
::sqlite3_column_text(
statement,
DB::APP_BROWSER_MAIN_TAB::REQUEST
)
)
);
if (::sqlite3_column_int(statement, DB::APP_BROWSER_MAIN_TAB::CURRENT) == 1)
{
set_current_page(
PAGE_NUMBER
);
}
}
}
sqlite3_finalize(
statement
);
}
void Tab::save()
{
char * error; // @TODO

2
src/app/browser/main/tab.hpp

@ -94,6 +94,8 @@ namespace app::browser::main @@ -94,6 +94,8 @@ namespace app::browser::main
const int & PAGE_NUMBER
);
void restore();
void save();
void shutdown();

Loading…
Cancel
Save