2019-05-30 09:32:28 +02:00
|
|
|
#include <utility>
|
2016-06-28 17:22:16 +02:00
|
|
|
#include "entities/notesubfolder.h"
|
2016-07-03 13:49:34 +02:00
|
|
|
#include "notefolder.h"
|
2016-07-16 12:06:38 +02:00
|
|
|
#include "note.h"
|
2019-03-16 11:03:34 +01:00
|
|
|
#include "tag.h"
|
2016-06-28 17:22:16 +02:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QSqlRecord>
|
|
|
|
#include <QSqlError>
|
2016-06-29 17:55:26 +02:00
|
|
|
#include <QDir>
|
2016-07-02 12:45:16 +02:00
|
|
|
#include <QSettings>
|
|
|
|
#include <utils/misc.h>
|
2016-06-28 17:22:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
NoteSubFolder::NoteSubFolder() {
|
|
|
|
this->id = 0;
|
|
|
|
this->parentId = 0;
|
2016-07-31 18:16:58 +02:00
|
|
|
this->name = "";
|
2016-06-28 17:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int NoteSubFolder::getId() {
|
|
|
|
return this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int NoteSubFolder::getParentId() {
|
|
|
|
return this->parentId;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:55:26 +02:00
|
|
|
NoteSubFolder NoteSubFolder::getParent() {
|
|
|
|
return NoteSubFolder::fetch(parentId);
|
|
|
|
}
|
|
|
|
|
2016-06-28 17:22:16 +02:00
|
|
|
QString NoteSubFolder::getName() {
|
|
|
|
return this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime NoteSubFolder::getFileLastModified() {
|
|
|
|
return this->fileLastModified;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime NoteSubFolder::getModified() {
|
|
|
|
return this->modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoteSubFolder::setName(QString text) {
|
2019-05-30 09:32:28 +02:00
|
|
|
this->name = std::move(text);
|
2016-06-28 17:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoteSubFolder::setParentId(int parentId) {
|
|
|
|
this->parentId = parentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NoteSubFolder::isFetched() {
|
|
|
|
return (this->id > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NoteSubFolder NoteSubFolder::fetch(int id) {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-28 17:22:16 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
NoteSubFolder noteSubFolder;
|
|
|
|
|
|
|
|
query.prepare("SELECT * FROM noteSubFolder WHERE id = :id");
|
|
|
|
query.bindValue(":id", id);
|
|
|
|
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else {
|
|
|
|
if (query.first()) {
|
|
|
|
noteSubFolder = noteSubFolderFromQuery(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return noteSubFolder;
|
|
|
|
}
|
|
|
|
|
2016-07-03 13:49:34 +02:00
|
|
|
NoteSubFolder NoteSubFolder::fetchByNameAndParentId(
|
2019-05-30 09:32:28 +02:00
|
|
|
const QString& name, int parentId) {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-07-03 13:49:34 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
NoteSubFolder noteSubFolder;
|
|
|
|
|
|
|
|
query.prepare("SELECT * FROM noteSubFolder WHERE name = :name "
|
|
|
|
"AND parent_id = :parent_id");
|
|
|
|
query.bindValue(":name", name);
|
|
|
|
query.bindValue(":parent_id", parentId);
|
|
|
|
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else {
|
|
|
|
if (query.first()) {
|
|
|
|
noteSubFolder = noteSubFolderFromQuery(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return noteSubFolder;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:55:26 +02:00
|
|
|
/**
|
|
|
|
* Gets the relative path name of the note sub folder
|
|
|
|
*/
|
2016-07-17 11:39:54 +02:00
|
|
|
QString NoteSubFolder::relativePath(QString separator) {
|
|
|
|
if (separator.isEmpty()) {
|
2016-10-13 16:48:16 +02:00
|
|
|
// be aware that the separator has to be same on all platforms to
|
|
|
|
// work cross platform
|
|
|
|
separator = Utils::Misc::dirSeparator();
|
2016-07-17 11:39:54 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 17:55:26 +02:00
|
|
|
return parentId == 0 ?
|
|
|
|
name :
|
2016-07-17 11:39:54 +02:00
|
|
|
getParent().relativePath(separator) + separator + name;
|
2016-06-29 17:55:26 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 12:06:38 +02:00
|
|
|
/**
|
2016-07-17 09:44:52 +02:00
|
|
|
* Gets the full path of the note sub folder
|
2016-07-16 12:06:38 +02:00
|
|
|
*/
|
|
|
|
QString NoteSubFolder::fullPath() {
|
2018-02-12 16:55:26 +01:00
|
|
|
return Utils::Misc::removeIfEndsWith(
|
2019-09-05 17:41:20 +02:00
|
|
|
Note::getFullFilePathForFile(relativePath()), "/");
|
2016-07-17 09:19:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-17 09:44:52 +02:00
|
|
|
* Gets the full path of the note sub folder as QDir
|
2016-07-17 09:19:55 +02:00
|
|
|
*/
|
|
|
|
QDir NoteSubFolder::dir() {
|
|
|
|
return QDir(fullPath());
|
2016-07-16 12:06:38 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 13:49:34 +02:00
|
|
|
/**
|
|
|
|
* Gets the path data of the note sub folder
|
|
|
|
*/
|
|
|
|
QString NoteSubFolder::pathData() {
|
|
|
|
return parentId == 0 ?
|
|
|
|
name :
|
2016-07-17 08:50:16 +02:00
|
|
|
getParent().pathData() + "\n" + name;
|
2016-07-03 13:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-05 18:34:17 +02:00
|
|
|
* Fetches a note sub folder by its path data
|
2016-07-03 13:49:34 +02:00
|
|
|
*/
|
2016-08-05 18:34:17 +02:00
|
|
|
NoteSubFolder NoteSubFolder::fetchByPathData(QString pathData,
|
2019-05-30 09:32:28 +02:00
|
|
|
const QString& separator) {
|
2016-08-05 18:34:17 +02:00
|
|
|
pathData = Utils::Misc::removeIfStartsWith(pathData, separator);
|
|
|
|
QStringList pathList = pathData.split(separator);
|
2016-07-03 13:49:34 +02:00
|
|
|
NoteSubFolder noteSubFolder;
|
|
|
|
QStringListIterator itr(pathList);
|
|
|
|
|
|
|
|
// loop through all names to fetch the deepest note sub folder
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
QString name = itr.next();
|
|
|
|
noteSubFolder = NoteSubFolder::fetchByNameAndParentId(
|
|
|
|
name, noteSubFolder.getId());
|
|
|
|
if (!noteSubFolder.isFetched()) {
|
|
|
|
return NoteSubFolder();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return noteSubFolder;
|
|
|
|
}
|
|
|
|
|
2016-06-28 17:22:16 +02:00
|
|
|
bool NoteSubFolder::remove() {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-28 17:22:16 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
query.prepare("DELETE FROM noteSubFolder WHERE id = :id");
|
|
|
|
query.bindValue(":id", this->id);
|
|
|
|
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 13:02:08 +02:00
|
|
|
/**
|
2016-07-17 09:44:52 +02:00
|
|
|
* Removes the directory recursively from the file system
|
2016-07-16 13:02:08 +02:00
|
|
|
*/
|
|
|
|
bool NoteSubFolder::removeFromFileSystem() {
|
2016-07-17 09:44:52 +02:00
|
|
|
QDir dir = this->dir();
|
|
|
|
|
2016-07-16 13:02:08 +02:00
|
|
|
if (dir.exists()) {
|
|
|
|
return dir.removeRecursively();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-17 09:44:52 +02:00
|
|
|
/**
|
|
|
|
* Renames the note subfolder in the file system
|
|
|
|
*/
|
2019-05-30 09:32:28 +02:00
|
|
|
bool NoteSubFolder::rename(const QString& newName) {
|
2016-07-17 09:44:52 +02:00
|
|
|
QDir dir = this->dir();
|
|
|
|
|
|
|
|
if (dir.exists() && !newName.isEmpty()) {
|
|
|
|
QString oldPath = fullPath();
|
2019-03-16 11:03:34 +01:00
|
|
|
QString oldRelativePath = relativePath();
|
2016-07-17 09:44:52 +02:00
|
|
|
setName(newName);
|
|
|
|
QString newPath = fullPath();
|
2019-03-16 11:03:34 +01:00
|
|
|
QString newRelativePath = relativePath();
|
|
|
|
|
|
|
|
// rename the note sub folder paths of note tag links
|
|
|
|
// (needs to be done before the folder rename because folder renaming
|
|
|
|
// will cause a reload which would trigger the removal of the tag links)
|
|
|
|
Tag::renameNoteSubFolderPathsOfLinks(oldRelativePath, newRelativePath);
|
2016-07-17 09:44:52 +02:00
|
|
|
|
|
|
|
// rename the note subfolder
|
|
|
|
return dir.rename(oldPath, newPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-30 09:32:28 +02:00
|
|
|
NoteSubFolder NoteSubFolder::noteSubFolderFromQuery(const QSqlQuery& query) {
|
2016-06-28 17:22:16 +02:00
|
|
|
NoteSubFolder noteSubFolder;
|
|
|
|
noteSubFolder.fillFromQuery(query);
|
|
|
|
return noteSubFolder;
|
|
|
|
}
|
|
|
|
|
2019-05-30 09:32:28 +02:00
|
|
|
bool NoteSubFolder::fillFromQuery(const QSqlQuery& query) {
|
2016-06-28 17:22:16 +02:00
|
|
|
id = query.value("id").toInt();
|
|
|
|
parentId = query.value("parent_id").toInt();
|
|
|
|
name = query.value("name").toString();
|
|
|
|
fileLastModified = query.value("file_last_modified").toDateTime();
|
|
|
|
created = query.value("created").toDateTime();
|
|
|
|
modified = query.value("modified").toDateTime();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<NoteSubFolder> NoteSubFolder::fetchAll(int limit) {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-28 17:22:16 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
QList<NoteSubFolder> noteSubFolderList;
|
2016-06-29 17:55:26 +02:00
|
|
|
QString sql = "SELECT * FROM noteSubFolder "
|
|
|
|
"ORDER BY file_last_modified DESC";
|
2016-06-28 17:22:16 +02:00
|
|
|
|
|
|
|
if (limit >= 0) {
|
|
|
|
sql += " LIMIT :limit";
|
|
|
|
}
|
|
|
|
|
|
|
|
query.prepare(sql);
|
|
|
|
|
|
|
|
if (limit >= 0) {
|
|
|
|
query.bindValue(":limit", limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else {
|
|
|
|
for (int r = 0; query.next(); r++) {
|
|
|
|
NoteSubFolder noteSubFolder = noteSubFolderFromQuery(query);
|
|
|
|
noteSubFolderList.append(noteSubFolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return noteSubFolderList;
|
|
|
|
}
|
|
|
|
|
2016-08-18 14:15:47 +02:00
|
|
|
QList<int> NoteSubFolder::fetchAllIds() {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-08-18 14:15:47 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
QList<int> idList;
|
|
|
|
QString sql = "SELECT * FROM noteSubFolder";
|
|
|
|
|
|
|
|
query.prepare(sql);
|
|
|
|
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else {
|
|
|
|
for (int r = 0; query.next(); r++) {
|
|
|
|
NoteSubFolder noteSubFolder = noteSubFolderFromQuery(query);
|
|
|
|
idList.append(noteSubFolder.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return idList;
|
|
|
|
}
|
|
|
|
|
2018-09-16 07:48:18 +02:00
|
|
|
QList<NoteSubFolder> NoteSubFolder::fetchAllByParentId(
|
2019-05-30 09:32:28 +02:00
|
|
|
int parentId, const QString& sortBy) {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-29 17:55:26 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
QList<NoteSubFolder> noteSubFolderList;
|
|
|
|
QString sql = "SELECT * FROM noteSubFolder WHERE parent_id = "
|
2018-09-16 07:48:18 +02:00
|
|
|
":parent_id ORDER BY " + sortBy;
|
2016-06-29 17:55:26 +02:00
|
|
|
|
|
|
|
query.prepare(sql);
|
|
|
|
query.bindValue(":parent_id", parentId);
|
|
|
|
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else {
|
|
|
|
for (int r = 0; query.next(); r++) {
|
|
|
|
NoteSubFolder noteSubFolder = noteSubFolderFromQuery(query);
|
|
|
|
noteSubFolderList.append(noteSubFolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return noteSubFolderList;
|
|
|
|
}
|
|
|
|
|
2017-10-27 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Fetches a list of all ids recursively by a parent id
|
|
|
|
* The parent id is included in the list
|
|
|
|
*
|
|
|
|
* @param parentId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
QList<int> NoteSubFolder::fetchIdsRecursivelyByParentId(int parentId) {
|
|
|
|
QList<int> idList = QList<int>() << parentId;
|
|
|
|
|
|
|
|
Q_FOREACH(NoteSubFolder noteSubFolder, fetchAllByParentId(parentId)) {
|
|
|
|
int id = noteSubFolder.getId();
|
|
|
|
idList << fetchIdsRecursivelyByParentId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return idList;
|
|
|
|
}
|
|
|
|
|
2016-06-28 17:22:16 +02:00
|
|
|
//
|
|
|
|
// inserts or updates a noteSubFolder object in the database
|
|
|
|
//
|
|
|
|
bool NoteSubFolder::store() {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-28 17:22:16 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
// don't store noteSubFolders with empty name
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id > 0) {
|
|
|
|
query.prepare("UPDATE noteSubFolder SET "
|
|
|
|
"parent_id = :parent_id,"
|
|
|
|
"name = :name,"
|
|
|
|
"file_last_modified = :file_last_modified,"
|
|
|
|
"modified = :modified "
|
|
|
|
"WHERE id = :id");
|
|
|
|
query.bindValue(":id", id);
|
|
|
|
} else {
|
|
|
|
query.prepare("INSERT INTO noteSubFolder"
|
|
|
|
"(name, file_last_modified, parent_id,"
|
|
|
|
"modified) "
|
|
|
|
"VALUES (:name, :file_last_modified, :parent_id,"
|
|
|
|
":modified)");
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime modified = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
query.bindValue(":name", name);
|
2016-06-29 17:55:26 +02:00
|
|
|
query.bindValue(":parent_id", parentId);
|
2016-06-28 17:22:16 +02:00
|
|
|
query.bindValue(":file_last_modified", fileLastModified);
|
|
|
|
query.bindValue(":modified", modified);
|
|
|
|
|
|
|
|
// on error
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
return false;
|
|
|
|
} else if (id == 0) { // on insert
|
|
|
|
id = query.lastInsertId().toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
modified = modified;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// deletes all noteSubFolders in the database
|
|
|
|
//
|
|
|
|
bool NoteSubFolder::deleteAll() {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-28 17:22:16 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
// no truncate in sqlite
|
|
|
|
query.prepare("DELETE FROM noteSubFolder");
|
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// checks if the current noteSubFolder still exists in the database
|
|
|
|
//
|
|
|
|
bool NoteSubFolder::exists() {
|
|
|
|
NoteSubFolder noteSubFolder = NoteSubFolder::fetch(this->id);
|
|
|
|
return noteSubFolder.id > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts all notes
|
|
|
|
*/
|
|
|
|
int NoteSubFolder::countAll() {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-06-28 17:22:16 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
query.prepare("SELECT COUNT(*) AS cnt FROM noteSubFolder");
|
|
|
|
|
2016-08-15 18:16:10 +02:00
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else if (query.first()) {
|
|
|
|
return query.value("cnt").toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts all notes of a parent
|
|
|
|
*/
|
|
|
|
int NoteSubFolder::countAllParentId(int parentId) {
|
2019-11-01 10:05:32 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
2016-08-15 18:16:10 +02:00
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
query.prepare("SELECT COUNT(*) AS cnt FROM noteSubFolder "
|
|
|
|
"WHERE parent_id = :parentId ");
|
|
|
|
query.bindValue(":parentId", parentId);
|
|
|
|
|
2016-06-28 17:22:16 +02:00
|
|
|
if (!query.exec()) {
|
|
|
|
qWarning() << __func__ << ": " << query.lastError();
|
|
|
|
} else if (query.first()) {
|
|
|
|
return query.value("cnt").toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-02 16:12:20 +02:00
|
|
|
void NoteSubFolder::setAsActive() {
|
|
|
|
NoteSubFolder::setAsActive(id);
|
|
|
|
}
|
|
|
|
|
2016-07-03 13:49:34 +02:00
|
|
|
/**
|
|
|
|
* Set a note sub folder as active note sub folder for the current note folder
|
|
|
|
*/
|
|
|
|
bool NoteSubFolder::setAsActive(int noteSubFolderId) {
|
|
|
|
NoteFolder noteFolder = NoteFolder::currentNoteFolder();
|
|
|
|
if (!noteFolder.isFetched()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we don't need to check if the note sub folder was really fetched
|
|
|
|
// because we also want to get the root folder
|
|
|
|
NoteSubFolder noteSubFolder = NoteSubFolder::fetch(noteSubFolderId);
|
|
|
|
noteFolder.setActiveNoteSubFolder(noteSubFolder);
|
2016-07-03 14:25:27 +02:00
|
|
|
return noteFolder.store();
|
2016-07-02 16:12:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-02 12:45:16 +02:00
|
|
|
/**
|
|
|
|
* Checks if this note sub folder is the current one
|
|
|
|
*/
|
|
|
|
bool NoteSubFolder::isActive() {
|
2016-07-16 12:06:38 +02:00
|
|
|
return activeNoteSubFolderId() == id;
|
2016-07-02 12:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-03 13:49:34 +02:00
|
|
|
* Returns the id of the current note sub folder of the current note folder
|
2016-07-02 12:45:16 +02:00
|
|
|
*/
|
2016-07-16 12:06:38 +02:00
|
|
|
int NoteSubFolder::activeNoteSubFolderId() {
|
2016-07-03 13:49:34 +02:00
|
|
|
return activeNoteSubFolder().getId();
|
2016-07-02 12:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-03 13:49:34 +02:00
|
|
|
* Returns the current note sub folder of the current note folder
|
2016-07-02 12:45:16 +02:00
|
|
|
*/
|
2016-07-03 13:49:34 +02:00
|
|
|
NoteSubFolder NoteSubFolder::activeNoteSubFolder() {
|
|
|
|
// we don't need to check if the note sub folder was really fetched
|
|
|
|
// because we also want to get the root folder
|
|
|
|
NoteFolder noteFolder = NoteFolder::currentNoteFolder();
|
|
|
|
return noteFolder.getActiveNoteSubFolder();
|
2016-07-02 12:45:16 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 19:06:39 +02:00
|
|
|
/**
|
|
|
|
* Saves the expand status of the item
|
|
|
|
*/
|
|
|
|
void NoteSubFolder::saveTreeWidgetExpandState(bool expanded) {
|
|
|
|
QSettings settings;
|
|
|
|
QString settingsKey = treeWidgetExpandStateSettingsKey();
|
|
|
|
|
|
|
|
// load the settings
|
|
|
|
QStringList pathList = settings.value(settingsKey).toStringList();
|
|
|
|
QString path = relativePath();
|
|
|
|
|
|
|
|
if (!expanded) {
|
|
|
|
// if item is not expanded remove the path from the list
|
|
|
|
pathList.removeAll(path);
|
|
|
|
} else if (!pathList.contains(path)) {
|
|
|
|
// if item is collapsed and not already exists in the list then add it
|
|
|
|
pathList.append(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// store the settings again
|
|
|
|
settings.setValue(settingsKey, pathList);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the expand status of the item
|
|
|
|
*/
|
|
|
|
bool NoteSubFolder::treeWidgetExpandState() {
|
|
|
|
QSettings settings;
|
|
|
|
QString settingsKey = treeWidgetExpandStateSettingsKey();
|
|
|
|
|
|
|
|
// load the settings
|
|
|
|
QStringList pathList = settings.value(settingsKey).toStringList();
|
|
|
|
QString path = relativePath();
|
|
|
|
|
|
|
|
return pathList.contains(path);
|
|
|
|
}
|
|
|
|
|
2017-10-27 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Checks if noteSubfoldersPanelShowNotesRecursively is set
|
|
|
|
*/
|
|
|
|
bool NoteSubFolder::isNoteSubfoldersPanelShowNotesRecursively() {
|
|
|
|
QSettings settings;
|
|
|
|
return settings.value("noteSubfoldersPanelShowNotesRecursively").toBool();
|
|
|
|
}
|
|
|
|
|
2016-07-12 19:06:39 +02:00
|
|
|
/**
|
|
|
|
* Returns the tree widget expand status settings key
|
|
|
|
*/
|
2016-07-14 06:56:50 +02:00
|
|
|
QString NoteSubFolder::treeWidgetExpandStateSettingsKey(int noteFolderId) {
|
|
|
|
if (noteFolderId == 0) {
|
|
|
|
noteFolderId = NoteFolder::currentNoteFolderId();
|
|
|
|
}
|
|
|
|
|
2016-07-12 19:06:39 +02:00
|
|
|
return "MainWindow/noteSubFolderTreeWidgetExpandState-" +
|
2016-07-12 19:15:32 +02:00
|
|
|
QString::number(noteFolderId);
|
2016-07-12 19:06:39 +02:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:35:41 +02:00
|
|
|
/**
|
|
|
|
* @brief NoteSubFolder::depth return the depth of the folder in regard to the note folder
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
int NoteSubFolder::depth() {
|
|
|
|
auto relativePath = this->relativePath("\n");
|
|
|
|
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return relativePath.split("\n").count();
|
|
|
|
}
|
|
|
|
|
2016-06-28 17:22:16 +02:00
|
|
|
QDebug operator<<(QDebug dbg, const NoteSubFolder ¬eSubFolder) {
|
|
|
|
dbg.nospace() << "NoteSubFolder: <id>" << noteSubFolder.id <<
|
|
|
|
" <name>" << noteSubFolder.name <<
|
|
|
|
" <parentId>" << noteSubFolder.parentId;
|
|
|
|
return dbg.space();
|
|
|
|
}
|