vnote/vnote.cpp
Le Tan 4d9946bfe1 support creating new notebook
Thanks to [benjsperry](https://github.com/driftyco/ionicons) for the
icons.

Signed-off-by: Le Tan <tamlokveer@gmail.com>
2016-10-17 11:28:37 +08:00

53 lines
1.2 KiB
C++

#include <QSettings>
#include <QDebug>
#include <QJsonObject>
#include <QJsonArray>
#include "vnote.h"
#include "utils/vutils.h"
#include "vconfigmanager.h"
VConfigManager vconfig;
QString VNote::templateHtml;
VNote::VNote() : QObject()
{
vconfig.initialize();
decorateTemplate();
notebooks = vconfig.getNotebooks();
emit notebooksChanged(notebooks);
}
void VNote::decorateTemplate()
{
templateHtml = VUtils::readFileFromDisk(vconfig.getTemplatePath());
templateHtml.replace("CSS_PLACE_HOLDER", vconfig.getTemplateCssUrl());
}
const QVector<VNotebook>& VNote::getNotebooks()
{
return notebooks;
}
void VNote::createNotebook(const QString &name, const QString &path)
{
// Create a directory config file in @path
QJsonObject configJson;
configJson["version"] = "1";
configJson["name"] = name;
configJson["sub_directories"] = QJsonArray();
configJson["files"] = QJsonArray();
if (!vconfig.writeDirectoryConfig(path, configJson)) {
return;
}
// Update notebooks settings
notebooks.prepend(VNotebook(name, path));
vconfig.setNotebooks(notebooks);
// Set current index to the new notebook
vconfig.setCurNotebookIndex(0);
emit notebooksChanged(notebooks);
}