| 9 | #define TypeRole Qt::UserRole+2 |
| 10 | #define TagNodeRole Qt::UserRole+3 |
| 11 | LabelModel::LabelModel(QObject *parent) : QAbstractItemModel(parent), root(nullptr) |
| 12 | { |
| 13 | QObject::connect(AnimeWorker::instance(), &AnimeWorker::renameEpTag, this, [=](const QString &oldAnimeName, const QString &newAnimeName){ |
| 14 | for(auto &animes : epPathAnimes) |
| 15 | { |
| 16 | if(animes.contains(oldAnimeName)) |
| 17 | { |
| 18 | animes.remove(oldAnimeName); |
| 19 | animes.insert(newAnimeName); |
| 20 | } |
| 21 | } |
| 22 | }); |
| 23 | QObject::connect(AnimeWorker::instance(), &AnimeWorker::addTimeTag, this, [=](const QString &tag){ |
| 24 | if(tag.isEmpty() || !root) return; |
| 25 | insertNodeIndex(root->subNodes->value(C_TIME), tag.left(7), 1, TagNode::TAG_TIME, '-'); |
| 26 | }); |
| 27 | |
| 28 | QObject::connect(AnimeWorker::instance(), &AnimeWorker::addScriptTag, this, [=](const QString &scriptId){ |
| 29 | if(scriptId.isEmpty() || !root) return; |
| 30 | QString scriptName(scriptId); |
| 31 | auto script = GlobalObjects::scriptManager->getScript(scriptId); |
| 32 | if(script) scriptName = script->name(); |
| 33 | TagNode *node = insertNodeIndex(root->subNodes->value(C_SCRIPT), scriptName, 1, TagNode::TAG_SCRIPT); |
| 34 | node->tagFilter = scriptId; |
| 35 | }); |
| 36 | |
| 37 | QObject::connect(AnimeWorker::instance(), &AnimeWorker::removeTimeTag, this, [=](const QString &tag){ |
| 38 | if(tag.isEmpty() || !root) return; |
| 39 | removeNodeIndex(root->subNodes->value(C_TIME), tag.left(7), false, '-'); |
| 40 | }); |
| 41 | |
| 42 | QObject::connect(AnimeWorker::instance(), &AnimeWorker::removeScriptTag, this, [=](const QString &scriptId){ |
| 43 | if(scriptId.isEmpty() || !root) return; |
| 44 | QString scriptName(scriptId); |
| 45 | auto script = GlobalObjects::scriptManager->getScript(scriptId); |
| 46 | if(script) scriptName = script->name(); |
| 47 | removeNodeIndex(root->subNodes->value(C_SCRIPT), scriptName, false, TagNode::TAG_SCRIPT); |
| 48 | }); |
| 49 | QObject::connect(AnimeWorker::instance(), &AnimeWorker::epAdded, this, [=](const QString &animeName, const EpInfo &ep){ |
| 50 | QString filePath = ep.localFile.mid(0, ep.localFile.lastIndexOf('/')); |
| 51 | if(filePath.isEmpty() || !root) return; |
| 52 | if(epPathAnimes.contains(filePath) && epPathAnimes[filePath].contains(animeName)) return; |
| 53 | epPathAnimes[filePath].insert(animeName); |
| 54 | insertNodeIndex(root->subNodes->value(C_FILE), filePath, 1, TagNode::TAG_FILE); |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | LabelModel::~LabelModel() |
| 59 | { |