diff --git a/shared/shared.pro b/shared/shared.pro index a355c22..a6f1a89 100644 --- a/shared/shared.pro +++ b/shared/shared.pro @@ -60,6 +60,7 @@ SOURCES += sqlitesearch.cpp \ processor.cpp \ sandboxedprocessor.cpp \ sqlitedbservice.cpp \ + tagmanager.cpp \ tagstripperprocessor.cpp \ utils.cpp \ ../submodules/exile.h/exile.c \ @@ -93,6 +94,7 @@ HEADERS += sqlitesearch.h \ savefileresult.h \ searchresult.h \ sqlitedbservice.h \ + tagmanager.h \ tagstripperprocessor.h \ token.h \ common.h \ diff --git a/shared/tagmanager.cpp b/shared/tagmanager.cpp new file mode 100644 index 0000000..437ca85 --- /dev/null +++ b/shared/tagmanager.cpp @@ -0,0 +1,41 @@ +#include "tagmanager.h" + +TagManager::TagManager(SqliteDbService &dbService) +{ + this->dbService = &dbService; +} + +bool TagManager::addTagsToPath(QString path, const QSet &tags) +{ + QVector currentTags = this->dbService->getTagsForPath(path); + for(const QString &tag : tags) + { + currentTags.append(tag.toLower()); + } + + QSet newTags{currentTags.begin(), currentTags.end()}; + return this->dbService->setTags(path, newTags); +} + +bool TagManager::removeTagsForPath(QString path, const QSet &tags) +{ + QVector currentTags = this->dbService->getTagsForPath(path); + for(const QString &tag : tags) + { + currentTags.removeAll(tag); + } + QSet newTags{currentTags.begin(), currentTags.end()}; + return this->dbService->setTags(path, newTags); +} + +bool TagManager::addTagsToPath(QString path, QString tagstring, QChar delim) +{ + auto splitted = tagstring.split(delim); + + return addTagsToPath(path, QSet{splitted.begin(), splitted.end()}); +} + +bool TagManager::addPathsToTag(QString tag, const QVector &paths) +{ + return this->dbService->addTag(tag, paths); +} diff --git a/shared/tagmanager.h b/shared/tagmanager.h new file mode 100644 index 0000000..6c3d0ca --- /dev/null +++ b/shared/tagmanager.h @@ -0,0 +1,26 @@ +#ifndef TAGMANAGER_H +#define TAGMANAGER_H +#include "sqlitedbservice.h" + +class TagManager +{ + private: + SqliteDbService *dbService = nullptr; + bool ensurePathOkay(QString inpath); + + public: + TagManager(SqliteDbService &dbService); + + bool addTagsToPath(QString path, const QSet &tags); + bool addTagsToPath(QString path, QString tagstring, QChar delim); + + bool addPathsToTag(QString tag, const QVector &paths); + bool removeTagsForPath(QString path, const QSet &tags); + + bool deleteTag(QString tag); + + QVector getTags(QString path); + QVector getPaths(QString tag); +}; + +#endif // TAGMANAGER_H