shared: Begin TagManager

This commit is contained in:
Albert S. 2023-04-10 18:24:58 +02:00
parent a3cfb7ade1
commit f324da0369
3 changed files with 69 additions and 0 deletions

View File

@ -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 \

41
shared/tagmanager.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "tagmanager.h"
TagManager::TagManager(SqliteDbService &dbService)
{
this->dbService = &dbService;
}
bool TagManager::addTagsToPath(QString path, const QSet<QString> &tags)
{
QVector<QString> currentTags = this->dbService->getTagsForPath(path);
for(const QString &tag : tags)
{
currentTags.append(tag.toLower());
}
QSet<QString> newTags{currentTags.begin(), currentTags.end()};
return this->dbService->setTags(path, newTags);
}
bool TagManager::removeTagsForPath(QString path, const QSet<QString> &tags)
{
QVector<QString> currentTags = this->dbService->getTagsForPath(path);
for(const QString &tag : tags)
{
currentTags.removeAll(tag);
}
QSet<QString> 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<QString>{splitted.begin(), splitted.end()});
}
bool TagManager::addPathsToTag(QString tag, const QVector<QString> &paths)
{
return this->dbService->addTag(tag, paths);
}

26
shared/tagmanager.h Normal file
View File

@ -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<QString> &tags);
bool addTagsToPath(QString path, QString tagstring, QChar delim);
bool addPathsToTag(QString tag, const QVector<QString> &paths);
bool removeTagsForPath(QString path, const QSet<QString> &tags);
bool deleteTag(QString tag);
QVector<QString> getTags(QString path);
QVector<QString> getPaths(QString tag);
};
#endif // TAGMANAGER_H