diff options
author | Louie S <louie@example.com> | 2024-02-19 15:58:23 -0500 |
---|---|---|
committer | Louie S <louie@example.com> | 2024-02-19 15:58:23 -0500 |
commit | a276acd4e0c8031fdef41f11a4fa2285b671207d (patch) | |
tree | e28ba115c97257184e67f9a6787a81671e2aa437 | |
parent | 8145f61fc830c8a3eaf7a9455756b861efb17683 (diff) |
Set config creation
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/assignmentList.cpp | 24 | ||||
-rw-r--r-- | src/assignmentList.h | 7 | ||||
-rw-r--r-- | src/assignmentList.ui (renamed from src/main.ui) | 0 | ||||
-rw-r--r-- | src/backend/db_sqlite.h | 53 | ||||
-rw-r--r-- | src/settings.cpp | 14 | ||||
-rw-r--r-- | src/settings.h | 8 |
7 files changed, 105 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8874654..9d83e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,9 +35,11 @@ set(project_sources "src/add_group_form.ui" "src/assignmentList.cpp" "src/assignmentList.h" + "src/assignmentList.ui" "src/main.cpp" - "src/main.ui" "src/preferences_dialog.ui" + "src/settings.cpp" + "src/settings.h" ) add_executable(assignment-list diff --git a/src/assignmentList.cpp b/src/assignmentList.cpp index c8da5c3..91c4716 100644 --- a/src/assignmentList.cpp +++ b/src/assignmentList.cpp @@ -1,25 +1,43 @@ #include <QAction> #include <QApplication> +#include <QCoreApplication> #include <QDate> #include <QFile> #include <QMessageBox> #include <QObject> +#include <QStandardPaths> #include <QUiLoader> #include <QDebug> +#include <QSettings> #include "assignmentList.h" +#include "settings.h" AssignmentList::AssignmentList() { + // set QSettings information + QCoreApplication::setOrganizationName("assignment-list-qt"); // TODO grab this from a config.h type file + QCoreApplication::setApplicationName("assignment-list-qt"); // TODO grab this from a config.h type file + + // ensure QSettings location exists + this->initializeSettings(); + // load uic - QFile file("/home/louie/Development/projects/assignment-list-qt/src/main.ui"); - file.open(QIODevice::ReadOnly); - QUiLoader loader; ui.setupUi(this); this->initializeUI(); } +void AssignmentList::initializeSettings() { + QSettings settings; + QFile path = settings.fileName(); + + if(!path.exists()) { + qDebug() << "Creating Config"; + Settings::createConfig(); + } +} + void AssignmentList::initializeUI() { // create menu connections QObject::connect(ui.actionPreferences, &QAction::triggered, this, &AssignmentList::preferences); diff --git a/src/assignmentList.h b/src/assignmentList.h index 8171d73..5df18e9 100644 --- a/src/assignmentList.h +++ b/src/assignmentList.h @@ -2,17 +2,22 @@ #define ASSIGNMENTLIST_H #include <QMainWindow> -#include "ui_main.h" +#include <QSettings> + +#include "ui_assignmentList.h" class AssignmentList : public QMainWindow { Q_OBJECT public: + QSettings configuration; + AssignmentList(); private: Ui::MainWindow ui; + void initializeSettings(); void initializeUI(); void setupDB(); void displayWidgets(); diff --git a/src/main.ui b/src/assignmentList.ui index bc3c0fb..bc3c0fb 100644 --- a/src/main.ui +++ b/src/assignmentList.ui diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h new file mode 100644 index 0000000..5c55fef --- /dev/null +++ b/src/backend/db_sqlite.h @@ -0,0 +1,53 @@ +#ifndef BACKEND_DB_SQLITE_H +#define BACKEND_DB_SQLITE_H + +#include <QStringList> + +class BackendDB { + public: + void init(); + void load(); + void insertGroup(int new_group); // param datatype TBD + void insertEntry(int new_entry); // param datatype TBD + void insertRule(int new_rule); // param datatype TBD + void updateGroup(int group); // param datatype TBD + void updateEntry(int entry); // param datatype TBD + void updateRule(int rule); // param datatype TBD + void removeGroup(int group); // param datatype TBD + void removeEntry(int entry); // param datatype TBD + void removeRule(int rule); // param datatype TBD + void cleanHidden(); + + private: + const QStringList create_table_queries = { + "CREATE TABLE groups (" + "id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL," + "name VARCHAR(255) NOT NULL," + "column TINYINT(1) DEFAULT FALSE," + "link VARCHAR(255) NOT NULL," + "hidden TINYINT(1) DEFAULT FALSE" + ")", + "CREATE TABLE entries (" + "id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL," + "parent_id REFERENCES groups (id)," + "description VARCHAR(255) NOT NULL," + "due_date TEXT DEFAULT NULL," + "alt_due_date VARCHAR(255) DEFAULT NULL," + "link VARCHAR(255) DEFAULT NULL," + "color VARCHAR(255) DEFAULT NULL," + "highlight VARCHAR(255) DEFAULT NULL," + "done TINYINT(1) DEFAULT FALSE," + "hidden TINYINT(1) DEFAULT FALSE" + ")", + "CREATE TABLE rules (" + "id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL," + "entry_id REFERENCES entries (id)," + "before_after TINYINT(1) DEFAULT TRUE," + "date TEXT NOT NULL," + "color VARCHAR(255) DEFAULT NULL," + "highlight VARCHAR(255) DEFAULT NULL" + ")" + }; +}; + +#endif diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..4fe67d1 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,14 @@ +#include <QDir> +#include <QSettings> +#include <QStandardPaths> + +#include "settings.h" + +void Settings::createConfig() { + QSettings settings; + QDir local_data_dir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); + + settings.beginGroup("paths"); + settings.setValue("db_path", local_data_dir.filePath("data.db")); + settings.endGroup(); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..bec3c22 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,8 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +namespace Settings { + void createConfig(); +}; + +#endif |