-
Notifications
You must be signed in to change notification settings - Fork 0
/
notesmodel.cpp
42 lines (34 loc) · 1007 Bytes
/
notesmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "notesmodel.h"
#include <QStandardPaths>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QUuid>
NotesModel::NotesModel(QObject *parent) : QObject(parent)
{
QString config_location = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + '/';
storage_location = config_location + "Notix/";
QDir dir;
if (!dir.exists(storage_location)) dir.mkdir(storage_location);
}
void NotesModel::text_changed(const QString& uuid, const QString& new_text)
{
QFile file(storage_location + uuid);
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.write(new_text.toLocal8Bit());
}
QString NotesModel::generate_id()
{
return QUuid::createUuid().toString();
}
QStringList NotesModel::get_all_note_names()
{
QDir dir(storage_location);
return dir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);;
}
QString NotesModel::load_note(const QString& uuid)
{
QFile file(storage_location + uuid);
file.open(QIODevice::ReadOnly | QIODevice::Text);
return file.readAll();
}