2022-09-13 05:20:37 -07:00
|
|
|
#include "todo.h"
|
|
|
|
#include "ui_todo.h"
|
|
|
|
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
todo::todo(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::todo)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
this->setStyleSheet(readFile("/mnt/onboard/.adds/inkbox/eink.qss"));
|
|
|
|
this->setFont(QFont("u001"));
|
|
|
|
|
|
|
|
ui->closeBtn->setProperty("type", "borderless");
|
|
|
|
ui->newListBtn->setProperty("type", "borderless");
|
2022-09-13 20:03:51 -07:00
|
|
|
ui->deleteBtn->setProperty("type", "borderless");
|
|
|
|
ui->setupBtn->setProperty("type", "borderless");
|
|
|
|
ui->deleteBtn->setStyleSheet("padding: 10px");
|
|
|
|
ui->setupBtn->setStyleSheet("padding: 10px");
|
2022-09-13 05:20:37 -07:00
|
|
|
ui->closeBtn->setIcon(QIcon(":/resources/close.png"));
|
|
|
|
ui->newListBtn->setIcon(QIcon(":/resources/new.png"));
|
2022-09-13 20:03:51 -07:00
|
|
|
ui->deleteBtn->setIcon(QIcon(":/resources/x-circle.png"));
|
|
|
|
ui->setupBtn->setIcon(QIcon(":/resources/arrow-right.png"));
|
2022-09-13 05:20:37 -07:00
|
|
|
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
|
|
|
todo::~todo()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void todo::on_closeBtn_clicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void todo::on_newListBtn_clicked()
|
|
|
|
{
|
|
|
|
global::keyboard::embed = false;
|
|
|
|
virtualkeyboard * virtualKeyboardWidget = new virtualkeyboard(this);
|
|
|
|
virtualKeyboardWidget->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
QObject::connect(virtualKeyboardWidget, &virtualkeyboard::enterBtnPressed, this, &todo::createNewList);
|
|
|
|
virtualKeyboardWidget->show();
|
|
|
|
ui->statusLabel->setText("Enter the list's name");
|
|
|
|
}
|
|
|
|
|
|
|
|
void todo::createNewList(QString listName) {
|
|
|
|
log("Initializing new To-Do list with name '" + listName + "'", className);
|
|
|
|
QJsonDocument document;
|
2022-09-13 20:03:51 -07:00
|
|
|
QJsonArray mainArray;
|
|
|
|
QJsonArray listArray;
|
|
|
|
QJsonObject object;
|
2022-09-13 05:20:37 -07:00
|
|
|
if(QFile::exists(global::localLibrary::todoDatabasePath)) {
|
|
|
|
document = readTodoDatabase();
|
2022-09-13 20:03:51 -07:00
|
|
|
object = document.object();
|
|
|
|
mainArray = object["List"].toArray();
|
2022-09-13 05:20:37 -07:00
|
|
|
}
|
2022-09-13 20:03:51 -07:00
|
|
|
listArray.append(listName);
|
2022-09-13 05:20:37 -07:00
|
|
|
|
2022-09-13 20:03:51 -07:00
|
|
|
mainArray.push_back(listArray);
|
|
|
|
object["List"] = mainArray;
|
2022-09-13 05:20:37 -07:00
|
|
|
|
2022-09-13 20:03:51 -07:00
|
|
|
document.setObject(object);
|
2022-09-13 05:20:37 -07:00
|
|
|
writeTodoDatabase(document);
|
|
|
|
|
|
|
|
ui->statusLabel->setText("Select or create a new list");
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void todo::refreshList() {
|
|
|
|
if(QFile::exists(global::localLibrary::todoDatabasePath)) {
|
|
|
|
ui->listWidget->clear();
|
2022-09-13 20:03:51 -07:00
|
|
|
QJsonArray array = readTodoDatabase().object()["List"].toArray();
|
|
|
|
for(int i = 0; i < array.count(); i++) {
|
|
|
|
QString name = array.at(i).toArray().at(0).toString();
|
2022-09-13 05:20:37 -07:00
|
|
|
if(!name.isEmpty()) {
|
|
|
|
ui->listWidget->addItem(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 20:03:51 -07:00
|
|
|
|
|
|
|
void todo::setupList(QString listName) {
|
|
|
|
log("Setting up list with name '" + listName + "'", className);
|
|
|
|
QJsonArray array = readTodoDatabase().object()["List"].toArray();
|
|
|
|
int index;
|
|
|
|
for(int i = 0; i < array.count(); i++) {
|
|
|
|
QString name = array.at(i).toArray().at(0).toString();
|
|
|
|
log("name is " + name);
|
|
|
|
if(name == listName) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log("List index is " + QString::number(index), className);
|
|
|
|
}
|
|
|
|
|
|
|
|
void todo::on_setupBtn_clicked()
|
|
|
|
{
|
|
|
|
ui->deleteBtn->setEnabled(false);
|
|
|
|
ui->setupBtn->setEnabled(false);
|
|
|
|
setupList(ui->listWidget->currentItem()->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void todo::on_listWidget_itemClicked(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
ui->deleteBtn->setEnabled(true);
|
|
|
|
ui->setupBtn->setEnabled(true);
|
|
|
|
}
|