mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
delegate specific database operations to widgets, use SQLiteCpp wrapper
This commit is contained in:
parent
35f4741a1c
commit
f98b0e55e9
6
Makefile
6
Makefile
@ -5,7 +5,7 @@ LDFLAGS = `pkg-config --libs gio-2.0 glibmm-2.68 gtkmm-4.0 pangomm-2.48 sqlite3`
|
||||
|
||||
# Define target executable and source files
|
||||
TARGET = bin/Yoda
|
||||
SRCS = src/main.cpp\
|
||||
SRCS = src/app.cpp\
|
||||
src/app/browser.cpp\
|
||||
src/app/browser/header.cpp\
|
||||
src/app/browser/header/main.cpp\
|
||||
@ -27,9 +27,7 @@ SRCS = src/main.cpp\
|
||||
src/app/browser/main/tab/page/navigation/history/forward.cpp\
|
||||
src/app/browser/main/tab/page/navigation/request.cpp\
|
||||
src/app/browser/main/tab/page/navigation/update.cpp\
|
||||
src/app/browser/main/tab/label.cpp\
|
||||
src/lib/database.cpp\
|
||||
src/lib/database/session.cpp
|
||||
src/app/browser/main/tab/label.cpp
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
|
@ -16,7 +16,8 @@ apt install git\
|
||||
libglibmm-2.68-dev\
|
||||
libgtkmm-4.0-dev\
|
||||
libpangomm-2.48-dev\
|
||||
libsqlite3-dev
|
||||
libsqlite3-dev\
|
||||
libsqlitecpp-dev
|
||||
```
|
||||
|
||||
* `git clone https://github.com/YGGverse/Yoda.git`
|
||||
@ -67,4 +68,5 @@ pkg-config --cflags --libs gio-2.0\
|
||||
|
||||
* [GTK](https://gtk.org) - free and open-source cross-platform widget toolkit
|
||||
* [gtkmm](https://gtkmm.org) - official C++ interface for GTK
|
||||
* [SQLite](https://sqlite.org) - profile database
|
||||
* [SQLite](https://sqlite.org) - profile database
|
||||
* [SQLiteCpp](https://github.com/SRombauts/SQLiteCpp) - SQLite3 C++ wrapper
|
@ -1,3 +1,4 @@
|
||||
src/app.cpp
|
||||
src/app/browser.cpp
|
||||
src/app/browser/header.cpp
|
||||
src/app/browser/header/main.cpp
|
||||
@ -21,7 +22,4 @@ src/app/browser/main/tab/page/navigation/history/back.cpp
|
||||
src/app/browser/main/tab/page/navigation/history/forward.cpp
|
||||
src/app/browser/main/tab/page/navigation/request.cpp
|
||||
src/app/browser/main/tab/page/navigation/update.cpp
|
||||
src/app/browser/main/tab/label.cpp
|
||||
src/lib/database.cpp
|
||||
src/lib/database/session.cpp
|
||||
src/main.cpp
|
||||
src/app/browser/main/tab/label.cpp
|
40
src/app.cpp
Normal file
40
src/app.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "app.hpp"
|
||||
#include "app/browser.hpp"
|
||||
|
||||
int main(
|
||||
int argc,
|
||||
char * argv[]
|
||||
) {
|
||||
// Init database
|
||||
SQLite::Database db(
|
||||
"database.sqlite3",
|
||||
SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE
|
||||
);
|
||||
|
||||
// Init application
|
||||
auto app = Gtk::Application::create(
|
||||
"io.github.yggverse.Yoda"
|
||||
);
|
||||
|
||||
// Init actions
|
||||
app->add_action(
|
||||
"quit",
|
||||
[app]
|
||||
{
|
||||
app->quit();
|
||||
}
|
||||
);
|
||||
|
||||
app->set_accel_for_action(
|
||||
"app.quit",
|
||||
"<Primary>q"
|
||||
);
|
||||
|
||||
// Launch browser component
|
||||
return app->make_window_and_run<app::Browser>(
|
||||
argc,
|
||||
argv,
|
||||
db,
|
||||
app
|
||||
);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#include <glibmm/refptr.h>
|
||||
#include <gtkmm/application.h>
|
||||
#include <SQLiteCpp/SQLiteCpp.h>
|
||||
|
||||
int main(
|
||||
int argc,
|
@ -5,8 +5,8 @@
|
||||
using namespace app;
|
||||
|
||||
Browser::Browser(
|
||||
SQLite::Database & db,
|
||||
const Glib::RefPtr<Gtk::Application> & APP
|
||||
//const std::shared_ptr<lib::Database> & db
|
||||
) {
|
||||
// Init window actions
|
||||
const auto ACTION__REFRESH = add_action(
|
||||
@ -177,6 +177,7 @@ Browser::Browser(
|
||||
);
|
||||
|
||||
browserMain = Gtk::make_managed<browser::Main>(
|
||||
db,
|
||||
ACTION__REFRESH,
|
||||
ACTION__MAIN_TAB_CLOSE_ACTIVE,
|
||||
ACTION__MAIN_TAB_CLOSE_ALL,
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <gtkmm/application.h>
|
||||
#include <gtkmm/applicationwindow.h>
|
||||
#include <gtkmm/object.h>
|
||||
#include <SQLiteCpp/SQLiteCpp.h>
|
||||
|
||||
namespace lib
|
||||
{
|
||||
@ -34,8 +35,8 @@ namespace app
|
||||
public:
|
||||
|
||||
Browser(
|
||||
SQLite::Database & db,
|
||||
const Glib::RefPtr<Gtk::Application> & APP
|
||||
//const std::shared_ptr<lib::Database> & db
|
||||
);
|
||||
};
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
using namespace app::browser;
|
||||
|
||||
Main::Main(
|
||||
SQLite::Database & db,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE_ACTIVE,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE_ALL,
|
||||
@ -22,6 +23,7 @@ Main::Main(
|
||||
|
||||
// Init components
|
||||
mainTab = Gtk::make_managed<main::Tab>(
|
||||
db,
|
||||
ACTION__REFRESH,
|
||||
ACTION__MAIN_TAB_CLOSE_ACTIVE,
|
||||
ACTION__MAIN_TAB_CLOSE_ALL,
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <glibmm/ustring.h>
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/object.h>
|
||||
#include <SQLiteCpp/SQLiteCpp.h>
|
||||
|
||||
namespace app::browser
|
||||
{
|
||||
@ -26,6 +27,7 @@ namespace app::browser
|
||||
public:
|
||||
|
||||
Main(
|
||||
SQLite::Database & db,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE_ACTIVE,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE_ALL,
|
||||
|
@ -5,6 +5,7 @@
|
||||
using namespace app::browser::main;
|
||||
|
||||
Tab::Tab(
|
||||
SQLite::Database & db,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_CLOSE_ACTIVE,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE_ALL,
|
||||
@ -12,6 +13,18 @@ Tab::Tab(
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_UPDATE
|
||||
) {
|
||||
// Init database
|
||||
db.exec(
|
||||
R"SQL(
|
||||
CREATE TABLE IF NOT EXISTS `app_browser_tab`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`time` INTEGER NOT NULL,
|
||||
`request` VARCHAR(1024)
|
||||
)
|
||||
)SQL"
|
||||
);
|
||||
|
||||
// Init actions
|
||||
action__refresh = ACTION__REFRESH;
|
||||
action__tab_close_active = ACTION__TAB_CLOSE_ACTIVE;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <glibmm/refptr.h>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <gtkmm/notebook.h>
|
||||
#include <SQLiteCpp/SQLiteCpp.h>
|
||||
|
||||
namespace app::browser::main
|
||||
{
|
||||
@ -41,6 +42,7 @@ namespace app::browser::main
|
||||
public:
|
||||
|
||||
Tab(
|
||||
SQLite::Database & db,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_CLOSE_ACTIVE,
|
||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE_ALL,
|
||||
|
@ -1,17 +0,0 @@
|
||||
#include "database.hpp"
|
||||
#include "database/session.hpp"
|
||||
|
||||
using namespace lib;
|
||||
|
||||
Database::Database(
|
||||
const char * filename
|
||||
) {
|
||||
status = sqlite3_open(
|
||||
filename,
|
||||
&connection
|
||||
);
|
||||
|
||||
session = new database::Session(
|
||||
connection
|
||||
);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef LIB_DATABASE_HPP
|
||||
#define LIB_DATABASE_HPP
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
namespace lib
|
||||
{
|
||||
namespace database
|
||||
{
|
||||
class Session;
|
||||
}
|
||||
|
||||
class Database
|
||||
{
|
||||
int status;
|
||||
|
||||
char * error;
|
||||
|
||||
sqlite3 * connection;
|
||||
|
||||
public:
|
||||
|
||||
database::Session * session;
|
||||
|
||||
Database(
|
||||
const char * filename
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LIB_DATABASE_HPP
|
@ -1,22 +0,0 @@
|
||||
#include "session.hpp"
|
||||
|
||||
using namespace lib::database;
|
||||
|
||||
Session::Session(
|
||||
sqlite3 * connection
|
||||
) {
|
||||
status = sqlite3_exec(
|
||||
connection,
|
||||
R"SQL(
|
||||
CREATE TABLE IF NOT EXISTS `session`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`time` INTEGER NOT NULL,
|
||||
`request` VARCHAR(1024)
|
||||
)
|
||||
)SQL",
|
||||
nullptr,
|
||||
nullptr,
|
||||
&error
|
||||
);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#ifndef LIB_DATABASE_SESSION_HPP
|
||||
#define LIB_DATABASE_SESSION_HPP
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
namespace lib::database
|
||||
{
|
||||
class Session
|
||||
{
|
||||
int status;
|
||||
|
||||
char * error;
|
||||
|
||||
sqlite3 * connection;
|
||||
|
||||
public:
|
||||
|
||||
Session(
|
||||
sqlite3 * connection
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LIB_DATABASE_SESSION_HPP
|
41
src/main.cpp
41
src/main.cpp
@ -1,41 +0,0 @@
|
||||
#include "main.hpp"
|
||||
#include "app/browser.hpp"
|
||||
#include "lib/database.hpp"
|
||||
|
||||
int main(
|
||||
int argc,
|
||||
char * argv[]
|
||||
) {
|
||||
// Init profile database
|
||||
const std::shared_ptr<lib::Database> DB( // @TODO
|
||||
new lib::Database(
|
||||
"database.sqlite3"
|
||||
)
|
||||
);
|
||||
|
||||
// Init app
|
||||
const Glib::RefPtr<Gtk::Application> APP = Gtk::Application::create(
|
||||
"io.github.yggverse.Yoda"
|
||||
);
|
||||
|
||||
APP->add_action(
|
||||
"quit",
|
||||
[APP]
|
||||
{
|
||||
APP->quit();
|
||||
}
|
||||
);
|
||||
|
||||
APP->set_accel_for_action(
|
||||
"app.quit",
|
||||
"<Primary>q"
|
||||
);
|
||||
|
||||
// Launch browser component
|
||||
return APP->make_window_and_run<app::Browser>(
|
||||
argc,
|
||||
argv,
|
||||
APP
|
||||
// DB
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user