shared: Begin TagManager
This commit is contained in:
rodzic
a3cfb7ade1
commit
f324da0369
@ -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
41
shared/tagmanager.cpp
Normal 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
26
shared/tagmanager.h
Normal 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
|
Ładowanie…
Reference in New Issue
Block a user