From 6167b4e2c0d5bb091f61eee563b2d9e001788a17 Mon Sep 17 00:00:00 2001 From: altffour <56314286+realaltffour@users.noreply.github.com> Date: Sat, 14 Dec 2019 09:08:14 +0300 Subject: [PATCH] Add settings.ui --- settingsWin.cpp | 0 settingsWin.h | 0 src/lib/category.h | 8 ++++---- src/lib/contract.h | 4 ++-- src/lib/db.h | 8 ++++++-- src/main.cpp | 2 +- src/mainwindow.cpp | 2 +- src/mainwindow.h | 2 ++ src/settingsWin.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/settingsWin.h | 34 ++++++++++++++++++++++++++++++++++ 10 files changed, 87 insertions(+), 10 deletions(-) delete mode 100644 settingsWin.cpp delete mode 100644 settingsWin.h create mode 100644 src/settingsWin.cpp create mode 100644 src/settingsWin.h diff --git a/settingsWin.cpp b/settingsWin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/settingsWin.h b/settingsWin.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/category.h b/src/lib/category.h index 4177788..09425e0 100644 --- a/src/lib/category.h +++ b/src/lib/category.h @@ -29,7 +29,7 @@ struct Category { } }; -auto category_removeContract(Category &category, Contract &item) -> void { +static auto category_removeContract(Category &category, Contract &item) -> void { // Search for the item to remove. for (int i = 0; i < category._contracts.size(); i++) { if (category._contracts[i] == item) { @@ -40,7 +40,7 @@ auto category_removeContract(Category &category, Contract &item) -> void { throw std::runtime_error("Contract to remove does not exist."); } -auto category_addContract(Category &category, Contract item) -> void { +static auto category_addContract(Category &category, Contract item) -> void { // Check if the item is not already in Category. for (auto i : category._contracts) { if (i == item) { @@ -52,7 +52,7 @@ auto category_addContract(Category &category, Contract item) -> void { category._contracts.push_back(item); } -auto category_moveContract(Category &src, Category &dest, Contract &item) -> void { +static auto category_moveContract(Category &src, Category &dest, Contract &item) -> void { // Check if the item is in dest. for (auto i : dest._contracts) { if (i == item) { @@ -75,7 +75,7 @@ auto category_moveContract(Category &src, Category &dest, Contract &item) -> voi dest._contracts.push_back(local); } -auto category_getContract(Category &category, std::string _name) -> Contract& { +static auto category_getContract(Category &category, std::string _name) -> Contract& { for (int i = 0; i < category._contracts.size(); i++) if (category._contracts[i]._name == _name) return category._contracts[i]; diff --git a/src/lib/contract.h b/src/lib/contract.h index e6c7834..21916db 100644 --- a/src/lib/contract.h +++ b/src/lib/contract.h @@ -39,11 +39,11 @@ struct Contract { } }; -auto contract_getExpiry(const Contract &contract) -> QDate { +static auto contract_getExpiry(const Contract &contract) -> QDate { return (QDate::fromString(QString::fromStdString(contract._expiry), DATE_FORMAT)); } -auto contract_setExpiry(Contract &contract, QDate date) -> void { +static auto contract_setExpiry(Contract &contract, QDate date) -> void { contract._expiry = date.toString(DATE_FORMAT).toUtf8().constData(); } diff --git a/src/lib/db.h b/src/lib/db.h index ffeb57a..8a609e5 100644 --- a/src/lib/db.h +++ b/src/lib/db.h @@ -13,15 +13,19 @@ struct DB { std::vector _categories; Category _deactivatedCategory; std::string _notifier_email = ""; + bool _notify_by_email = true; + bool _notify_by_notify = true; template void serialize(Archive & ar, const unsigned int version) { ar & _categories; ar & _notifier_email; + ar & _notify_by_email; + ar & _notify_by_notify; } }; -auto db_addCategory(DB db, Category item) -> void { +static auto db_addCategory(DB db, Category item) -> void { // Check if category is already present. for (auto i : db._categories) { if (i == item) { @@ -33,7 +37,7 @@ auto db_addCategory(DB db, Category item) -> void { db._categories.push_back(item); } -auto db_removeCategory(DB db, Category &item) -> void { +static auto db_removeCategory(DB db, Category &item) -> void { // Search for the item to remove. for (int i = 0; i < db._categories.size(); i++) { if (db._categories[i] == item) { diff --git a/src/main.cpp b/src/main.cpp index ef2ee0a..b847fac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { db._notifier_email = "ayhamaboualfadl@gmail.com"; export_db_as_db(db, "db.db"); - notify_check(db, true, true); + notify_check(db, false, true); QApplication a(argc, argv); MainWindow w; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 61bac95..30da1ea 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,6 +45,6 @@ void MainWindow::on_closeBtn_clicked() { } void MainWindow::on_settingsBtn_clicked() { - settingsWin* win = new settingsWin(this); + settingsWindow* win = new settingsWindow(&_db, this); win->show(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index a02a4b1..03ce81c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,6 +31,8 @@ private slots: private: void checkDB(); // Does checks and notifies. bool closing = false; + + DB _db; }; #endif // MAINWINDOW_H diff --git a/src/settingsWin.cpp b/src/settingsWin.cpp new file mode 100644 index 0000000..e741974 --- /dev/null +++ b/src/settingsWin.cpp @@ -0,0 +1,37 @@ +#include "settingsWin.h" + +settingsWindow::settingsWindow(DB *db,QWidget *parent) + : QMainWindow(parent), _db(db) { + setupUi(this); + this->emailBox->setText(QString::fromStdString(db->_notifier_email)); + if (db->_notify_by_email) + this->notifyByEmail->setCheckState(Qt::Checked); + else + this->notifyByEmail->setCheckState(Qt::Unchecked); + if (db->_notify_by_notify) + this->notifyByNotify->setCheckState(Qt::Checked); + else + this->notifyByNotify->setCheckState(Qt::Unchecked); +} + +settingsWindow::~settingsWindow() { +} + +auto settingsWindow::on_closeBtn_clicked() -> void { + this->close(); +} +auto settingsWindow::on_helpBtn_clicked() -> void { + // TODO: Make help +} +auto settingsWindow::on_applyBtn_clicked() -> void { + // Save the data. + std::string email = this->emailBox->text().toUtf8().constData(); + _db->_notifier_email = email; + + if (this->notifyByEmail->checkState() == Qt::Checked) + _db->_notify_by_email = true; + else _db->_notify_by_email = false; + if (this->notifyByNotify->checkState() == Qt::Checked) + _db->_notify_by_notify = true; + else _db->_notify_by_notify = false; +} diff --git a/src/settingsWin.h b/src/settingsWin.h new file mode 100644 index 0000000..7f1b00e --- /dev/null +++ b/src/settingsWin.h @@ -0,0 +1,34 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include +#include +#include +#include +#include +#include +#include "ui_settings.h" +#include "lib/db.h" + +namespace Ui { + class settingsWin; +} + +class settingsWindow : public QMainWindow, private Ui::settingsWin { + Q_OBJECT + +public: + explicit settingsWindow(DB *db, QWidget *parent = nullptr); + ~settingsWindow(); + +private slots: + void on_closeBtn_clicked(); + void on_helpBtn_clicked(); + void on_applyBtn_clicked(); + +private: + DB* _db; +}; + +#endif // MAINWINDOW_H