Browse Source

draft page session db features

CPP-GTK4
yggverse 2 months ago
parent
commit
e78b7e5487
  1. 10
      src/app/browser/main/tab.cpp
  2. 66
      src/app/browser/main/tab/page.cpp
  3. 21
      src/app/browser/main/tab/page.hpp
  4. 5
      src/app/browser/main/tab/page/navigation.cpp
  5. 5
      src/app/browser/main/tab/page/navigation.hpp

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

@ -71,7 +71,7 @@ int Tab::restore() @@ -71,7 +71,7 @@ int Tab::restore()
sqlite3_stmt* statement;
const int PREPARE_STATUS = ::sqlite3_prepare_v3(
this->db,
db,
R"SQL(
SELECT * FROM `app_browser_main_tab__session` ORDER BY `page_number` ASC
)SQL",
@ -161,7 +161,11 @@ int Tab::save() @@ -161,7 +161,11 @@ int Tab::save()
// Delegate save action to the page component
get_tabPage(
page_number
)->save();
)->save(
::sqlite3_last_insert_rowid(
db
)
);
}
}
@ -198,7 +202,7 @@ int Tab::append( @@ -198,7 +202,7 @@ int Tab::append(
const bool & IS_CURRENT
) {
const auto TAB_PAGE = new tab::Page(
db,
tab::Page::MIME::UNDEFINED,
LABEL_TEXT,
"", // @TODO restore feature

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

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
using namespace app::browser::main::tab;
Page::Page(
sqlite3 * db,
const MIME & MIME,
const Glib::ustring & TITLE,
const Glib::ustring & DESCRIPTION,
@ -22,6 +23,28 @@ Page::Page( @@ -22,6 +23,28 @@ Page::Page(
// Init actions
action__refresh = ACTION__REFRESH;
// Init database
this->db = db;
char * error;
::sqlite3_exec(
db,
R"SQL(
CREATE TABLE IF NOT EXISTS `app_browser_main_tab_page__session`
(
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab__session_id` INTEGER NOT NULL,
`time` INTEGER NOT NULL,
`mime` INTEGER NOT NULL,
`title` VARCHAR(1024) NOT NULL,
`description` VARCHAR(1024) NOT NULL
)
)SQL",
nullptr,
nullptr,
&error
);
// Init components
pageNavigation = Gtk::make_managed<page::Navigation>(
ACTION__REFRESH,
@ -63,9 +86,46 @@ void Page::refresh() @@ -63,9 +86,46 @@ void Page::refresh()
);
}
int Page::save()
{
pageNavigation->save();
int Page::save(
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB__SESSION_ID
) {
char * error; // @TODO
::sqlite3_exec(
db,
Glib::ustring::sprintf(
R"SQL(
INSERT INTO `app_browser_main_tab_page__session` (
`app_browser_main_tab__session_id`,
`time`,
`mime`,
`title`,
`description`
) VALUES (
'%d',
CURRENT_TIMESTAMP,
'%d',
'%d',
'%s',
'%s'
)
)SQL",
DB__APP_BROWSER_MAIN_TAB__SESSION_ID,
mime,
title,
description
).c_str(),
nullptr,
nullptr,
&error
); // @TODO auto-clean old records somewhere
// Delegate save action to child components
pageNavigation->save(
::sqlite3_last_insert_rowid(
db
)
);
return 1; // @TODO SQL
}

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

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/object.h>
#include <sqlite3.h>
namespace app::browser::main::tab
{
@ -45,6 +46,21 @@ namespace app::browser::main::tab @@ -45,6 +46,21 @@ namespace app::browser::main::tab
// Actions
Glib::RefPtr<Gio::SimpleAction> action__refresh;
// Database
sqlite3 * db;
struct DB
{
enum APP_BROWSER_MAIN_TAB_PAGE__DATA
{
ID,
TIME,
MIME,
TITLE,
DESCRIPTION
};
};
// Socket
char buffer[0xfffff]; // 1Mb
@ -58,6 +74,7 @@ namespace app::browser::main::tab @@ -58,6 +74,7 @@ namespace app::browser::main::tab
public:
Page(
sqlite3 * db,
const MIME & MIME,
const Glib::ustring & TITLE,
const Glib::ustring & DESCRIPTION,
@ -70,7 +87,9 @@ namespace app::browser::main::tab @@ -70,7 +87,9 @@ namespace app::browser::main::tab
// Actions
void refresh();
int save();
int save(
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB__SESSION_ID
);
void update(
const MIME & MIME,

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

@ -101,8 +101,9 @@ void Navigation::refresh( @@ -101,8 +101,9 @@ void Navigation::refresh(
);
}
int Navigation::save()
{
int Navigation::save(
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
) {
navigationRequest->save();
return 1; // @TODO SQL

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

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/object.h>
#include <sqlite3.h>
namespace app::browser::main::tab::page
{
@ -45,7 +46,9 @@ namespace app::browser::main::tab::page @@ -45,7 +46,9 @@ namespace app::browser::main::tab::page
const double & PROGRESS_FRACTION
);
int save();
int save(
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB__SESSION_ID
);
void history_add(
const Glib::ustring & REQUEST,

Loading…
Cancel
Save