Add settings.ui
This commit is contained in:
parent
846a5c35bb
commit
6167b4e2c0
|
@ -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];
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,15 +13,19 @@ struct DB {
|
|||
std::vector<Category> _categories;
|
||||
Category _deactivatedCategory;
|
||||
std::string _notifier_email = "";
|
||||
bool _notify_by_email = true;
|
||||
bool _notify_by_notify = true;
|
||||
|
||||
template<typename Archive>
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ private slots:
|
|||
private:
|
||||
void checkDB(); // Does checks and notifies.
|
||||
bool closing = false;
|
||||
|
||||
DB _db;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QString>
|
||||
#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
|
Loading…
Reference in New Issue