Browse Source

restore previous tab session on browser launch

CPP-GTK4
yggverse 3 months ago
parent
commit
eaa4b78dbd
  1. 3
      src/app/browser/main.cpp
  2. 42
      src/app/browser/main/tab.cpp
  3. 11
      src/app/browser/main/tab.hpp

3
src/app/browser/main.cpp

@ -47,7 +47,10 @@ void Main::refresh()
void Main::tab_append() void Main::tab_append()
{ {
const unsigned char * REQUEST; // @TODO
mainTab->append( mainTab->append(
REQUEST,
true true
); );
}; };

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

@ -46,7 +46,44 @@ Tab::Tab(
SCROLLABLE SCROLLABLE
); );
// Init event listeners // Init events
signal_realize().connect(
[this]
{
// Restore session from DB
sqlite3_stmt* statement;
int prepare = sqlite3_prepare_v3(
this->db,
R"SQL(
SELECT * FROM `app_browser_main_tab`
)SQL",
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (prepare == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
append(
sqlite3_column_text(
statement,
DB::APP_BROWSER_MAIN_TAB::REQUEST
),
true
);
}
}
sqlite3_finalize(
statement
);
}
);
signal_switch_page().connect( signal_switch_page().connect(
[this](Gtk::Widget*, guint) [this](Gtk::Widget*, guint)
{ {
@ -54,8 +91,6 @@ Tab::Tab(
action__refresh->activate(); action__refresh->activate();
} }
); );
// @TODO restore session from DB
} }
void Tab::shutdown() void Tab::shutdown()
@ -133,6 +168,7 @@ void Tab::refresh(
} }
void Tab::append( void Tab::append(
const unsigned char * REQUEST,
const bool & FOCUS const bool & FOCUS
) { ) {
auto tabPage = new tab::Page( auto tabPage = new tab::Page(

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

@ -21,6 +21,16 @@ namespace app::browser::main
// Database // Database
sqlite3 * db; sqlite3 * db;
struct DB
{
enum APP_BROWSER_MAIN_TAB
{
ID,
TIME,
REQUEST,
};
};
// Actions // Actions
Glib::RefPtr<Gio::SimpleAction> action__refresh, Glib::RefPtr<Gio::SimpleAction> action__refresh,
action__tab_close_active, action__tab_close_active,
@ -60,6 +70,7 @@ namespace app::browser::main
); );
void append( void append(
const unsigned char * REQUEST,
const bool & FOCUS const bool & FOCUS
); );

Loading…
Cancel
Save