|
|
@ -5,9 +5,16 @@ |
|
|
|
using namespace app::browser::main::tab::page::navigation; |
|
|
|
using namespace app::browser::main::tab::page::navigation; |
|
|
|
|
|
|
|
|
|
|
|
History::History( |
|
|
|
History::History( |
|
|
|
|
|
|
|
sqlite3 * db, |
|
|
|
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK, |
|
|
|
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK, |
|
|
|
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD |
|
|
|
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
// Init database
|
|
|
|
|
|
|
|
DB::SESSION::init( |
|
|
|
|
|
|
|
this->db = db |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init widget
|
|
|
|
add_css_class( |
|
|
|
add_css_class( |
|
|
|
"linked" // merge children elements
|
|
|
|
"linked" // merge children elements
|
|
|
|
); |
|
|
|
); |
|
|
@ -30,6 +37,106 @@ History::History( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
void History::add( |
|
|
|
|
|
|
|
const Glib::ustring & REQUEST, |
|
|
|
|
|
|
|
const bool & UPDATE_MEMORY_INDEX |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
memory.push_back( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
REQUEST, |
|
|
|
|
|
|
|
std::time( |
|
|
|
|
|
|
|
nullptr |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (UPDATE_MEMORY_INDEX) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
index = memory.size() - 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int History::restore( |
|
|
|
|
|
|
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
sqlite3_stmt* statement; // @TODO move to the DB model namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int PREPARE_STATUS = sqlite3_prepare_v3( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
Glib::ustring::sprintf( |
|
|
|
|
|
|
|
R"SQL( |
|
|
|
|
|
|
|
SELECT * FROM `app_browser_main_tab_page_navigation_history__session` |
|
|
|
|
|
|
|
WHERE `app_browser_main_tab_page_navigation__session__id` = %d |
|
|
|
|
|
|
|
ORDER BY `id` DESC LIMIT 1 |
|
|
|
|
|
|
|
)SQL", |
|
|
|
|
|
|
|
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID |
|
|
|
|
|
|
|
).c_str(), |
|
|
|
|
|
|
|
-1, |
|
|
|
|
|
|
|
SQLITE_PREPARE_NORMALIZE, |
|
|
|
|
|
|
|
&statement, |
|
|
|
|
|
|
|
nullptr |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (PREPARE_STATUS == SQLITE_OK) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Use latest record as order
|
|
|
|
|
|
|
|
while (sqlite3_step(statement) == SQLITE_ROW) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
|
|
|
|
memory.clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restore
|
|
|
|
|
|
|
|
memory.push_back( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
reinterpret_cast<const char*>( |
|
|
|
|
|
|
|
sqlite3_column_text( |
|
|
|
|
|
|
|
statement, |
|
|
|
|
|
|
|
DB::SESSION::REQUEST |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
sqlite3_column_int( |
|
|
|
|
|
|
|
statement, |
|
|
|
|
|
|
|
DB::SESSION::TIME |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sqlite3_column_int(statement, DB::SESSION::IS_CURRENT) == 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
index = memory.size() - 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restore children components here (on available)
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sqlite3_finalize( |
|
|
|
|
|
|
|
statement |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void History::save( |
|
|
|
|
|
|
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
// Delete previous records for session
|
|
|
|
|
|
|
|
DB::SESSION::clean( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add new records
|
|
|
|
|
|
|
|
for (const auto & VALUE : memory) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DB::SESSION::add( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID, |
|
|
|
|
|
|
|
VALUE.time, |
|
|
|
|
|
|
|
VALUE.request, |
|
|
|
|
|
|
|
-1 == index // @TODO
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void History::update() |
|
|
|
void History::update() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Memory match; |
|
|
|
Memory match; |
|
|
@ -49,26 +156,6 @@ void History::update() |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void History::add( |
|
|
|
|
|
|
|
const Glib::ustring & REQUEST, |
|
|
|
|
|
|
|
const bool & UPDATE_MEMORY_INDEX |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
memory.push_back( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
REQUEST, |
|
|
|
|
|
|
|
std::time( |
|
|
|
|
|
|
|
nullptr |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (UPDATE_MEMORY_INDEX) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
index = memory.size() - 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool History::try_back( |
|
|
|
bool History::try_back( |
|
|
|
Memory & match, |
|
|
|
Memory & match, |
|
|
|
const bool & UPDATE_MEMORY_INDEX |
|
|
|
const bool & UPDATE_MEMORY_INDEX |
|
|
@ -115,4 +202,123 @@ bool History::try_forward( |
|
|
|
{ |
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Database model
|
|
|
|
|
|
|
|
int History::DB::SESSION::init( |
|
|
|
|
|
|
|
sqlite3 * db |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
char * error; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sqlite3_exec( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
R"SQL( |
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `app_browser_main_tab_page_navigation_history__session` |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab_page_navigation__session__id` INTEGER NOT NULL, |
|
|
|
|
|
|
|
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, |
|
|
|
|
|
|
|
`request` VARCHAR (1024) NOT NULL, |
|
|
|
|
|
|
|
`is_current` INTEGER NOT NULL |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
)SQL", |
|
|
|
|
|
|
|
nullptr, |
|
|
|
|
|
|
|
nullptr, |
|
|
|
|
|
|
|
&error |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int History::DB::SESSION::clean( |
|
|
|
|
|
|
|
sqlite3 * db, |
|
|
|
|
|
|
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
char * error; // @TODO
|
|
|
|
|
|
|
|
sqlite3_stmt * statement; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int PREPARE_STATUS = sqlite3_prepare_v3( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
Glib::ustring::sprintf( |
|
|
|
|
|
|
|
R"SQL( |
|
|
|
|
|
|
|
SELECT * FROM `app_browser_main_tab_page_navigation_history__session` |
|
|
|
|
|
|
|
WHERE `app_browser_main_tab_page_navigation__session__id` = %d |
|
|
|
|
|
|
|
)SQL", |
|
|
|
|
|
|
|
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID |
|
|
|
|
|
|
|
).c_str(), |
|
|
|
|
|
|
|
-1, |
|
|
|
|
|
|
|
SQLITE_PREPARE_NORMALIZE, |
|
|
|
|
|
|
|
&statement, |
|
|
|
|
|
|
|
nullptr |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (PREPARE_STATUS == SQLITE_OK) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
while (sqlite3_step(statement) == SQLITE_ROW) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Delete record
|
|
|
|
|
|
|
|
const int EXEC_STATUS = sqlite3_exec( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
Glib::ustring::sprintf( |
|
|
|
|
|
|
|
R"SQL( |
|
|
|
|
|
|
|
DELETE FROM `app_browser_main_tab_page_navigation_history__session` WHERE `id` = %d |
|
|
|
|
|
|
|
)SQL", |
|
|
|
|
|
|
|
sqlite3_column_int64( |
|
|
|
|
|
|
|
statement, |
|
|
|
|
|
|
|
DB::SESSION::ID |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
).c_str(), |
|
|
|
|
|
|
|
nullptr, |
|
|
|
|
|
|
|
nullptr, |
|
|
|
|
|
|
|
&error |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delegate children dependencies cleanup
|
|
|
|
|
|
|
|
if (EXEC_STATUS == SQLITE_OK) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// nothing here.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sqlite3_finalize( |
|
|
|
|
|
|
|
statement |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlite3_int64 History::DB::SESSION::add( |
|
|
|
|
|
|
|
sqlite3 * db, |
|
|
|
|
|
|
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID, |
|
|
|
|
|
|
|
const int & TIME, |
|
|
|
|
|
|
|
const Glib::ustring & REQUEST, |
|
|
|
|
|
|
|
const bool & IS_CURRENT |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
char * error; // @TODO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlite3_exec( |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
Glib::ustring::sprintf( |
|
|
|
|
|
|
|
R"SQL( |
|
|
|
|
|
|
|
INSERT INTO `app_browser_main_tab_page_navigation_history__session` ( |
|
|
|
|
|
|
|
`app_browser_main_tab_page_navigation__session__id`, |
|
|
|
|
|
|
|
`time`, |
|
|
|
|
|
|
|
`request`, |
|
|
|
|
|
|
|
`is_current` |
|
|
|
|
|
|
|
) VALUES ( |
|
|
|
|
|
|
|
'%d', |
|
|
|
|
|
|
|
'%d', |
|
|
|
|
|
|
|
'%s', |
|
|
|
|
|
|
|
'%d' |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
)SQL", |
|
|
|
|
|
|
|
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID, |
|
|
|
|
|
|
|
TIME, |
|
|
|
|
|
|
|
REQUEST, |
|
|
|
|
|
|
|
IS_CURRENT |
|
|
|
|
|
|
|
).c_str(), |
|
|
|
|
|
|
|
nullptr, |
|
|
|
|
|
|
|
nullptr, |
|
|
|
|
|
|
|
&error |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sqlite3_last_insert_rowid( |
|
|
|
|
|
|
|
db |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |