Browse Source

implement clean method

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

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

@ -109,67 +109,104 @@ int Tab::restore()
return PREPARE_STATUS; return PREPARE_STATUS;
} }
int Tab::save() void Tab::clean()
{ {
char * error; // @TODO char * error; // @TODO
sqlite3_stmt * statement;
// Delete previous tab session const int PREPARE_STATUS = ::sqlite3_prepare_v3(
const int EXEC_STATUS = ::sqlite3_exec(
db, db,
R"SQL( R"SQL(
DELETE FROM `app_browser_main_tab__session` SELECT * FROM `app_browser_main_tab__session`
)SQL", )SQL",
nullptr, -1,
nullptr, SQLITE_PREPARE_NORMALIZE,
&error &statement,
nullptr
); );
if (EXEC_STATUS == SQLITE_OK) if (PREPARE_STATUS == SQLITE_OK)
{ {
// Save current tab session while (::sqlite3_step(statement) == SQLITE_ROW)
for (int page_number = 0; page_number < get_n_pages(); page_number++)
{ {
const auto TAB_LABEL = get_tabLabel( const int APP_BROWSER_MAIN_TAB__SESSION_ID = ::sqlite3_column_int(
page_number statement,
DB::APP_BROWSER_MAIN_TAB__SESSION::ID
); );
// @TODO Delegate cleanup to the child components
// Delete record
::sqlite3_exec( ::sqlite3_exec(
db, db,
Glib::ustring::sprintf( Glib::ustring::sprintf(
R"SQL( R"SQL(
INSERT INTO `app_browser_main_tab__session` ( DELETE FROM `app_browser_main_tab__session` WHERE `id` = %d
`time`,
`page_number`,
`is_current`,
`label_text`
) VALUES (
CURRENT_TIMESTAMP,
'%d',
'%d',
'%s'
)
)SQL", )SQL",
page_number, APP_BROWSER_MAIN_TAB__SESSION_ID
page_number == get_current_page() ? 1 : 0,
TAB_LABEL->get_text()
).c_str(), ).c_str(),
nullptr, nullptr,
nullptr, nullptr,
&error &error
); );
// Delegate save action to the page component
get_tabPage(
page_number
)->save(
::sqlite3_last_insert_rowid(
db
)
);
} }
} }
return EXEC_STATUS; ::sqlite3_finalize(
statement
);
close_all();
}
void Tab::save()
{
char * error; // @TODO
// Delete previous data
clean();
// Save current tab session
for (int page_number = 0; page_number < get_n_pages(); page_number++)
{
const auto TAB_LABEL = get_tabLabel(
page_number
);
::sqlite3_exec(
db,
Glib::ustring::sprintf(
R"SQL(
INSERT INTO `app_browser_main_tab__session` (
`time`,
`page_number`,
`is_current`,
`label_text`
) VALUES (
CURRENT_TIMESTAMP,
'%d',
'%d',
'%s'
)
)SQL",
page_number,
page_number == get_current_page() ? 1 : 0,
TAB_LABEL->get_text()
).c_str(),
nullptr,
nullptr,
&error
);
// Delegate save action to the page component
get_tabPage(
page_number
)->save(
::sqlite3_last_insert_rowid(
db
)
);
}
} }
// Actions // Actions

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

@ -99,7 +99,9 @@ namespace app::browser::main
int restore(); int restore();
int save(); void clean();
void save();
// Getters // Getters
Glib::ustring get_page_title( Glib::ustring get_page_title(

Loading…
Cancel
Save