void MetadataIOCoordinator::afterImportHandler(const QVector<Models::ArtworkMetadata*> &itemsToRead, bool ignoreBackups) {
        Models::SettingsModel *settingsModel = m_CommandManager->getSettingsModel();
        const QHash<QString, ImportDataResult> &importResult = m_ReadingWorker->getImportResult();
        const QVector<QPair<int, int> > &rangesToUpdate = m_ReadingWorker->getRangesToUpdate();

        if (!ignoreBackups && settingsModel->getSaveBackups()) {
            LOG_DEBUG << "Restoring the backups...";
            int size = itemsToRead.size();
            for (int i = 0; i < size; ++i) {
                Models::ArtworkMetadata *metadata = itemsToRead.at(i);
                const QString &filepath = metadata->getFilepath();

                if (importResult.contains(filepath)) {
                    const ImportDataResult &importResultItem = importResult.value(filepath);
                    MetadataSavingCopy copy(importResultItem.BackupDict);
                    copy.saveToMetadata(metadata);
                }
            }
        } else {
            LOG_DEBUG << "Skipped restoring the backups";
        }

        if (!getHasErrors()) {
            m_CommandManager->addToLibrary(itemsToRead);
        }

        m_CommandManager->updateArtworks(rangesToUpdate);
        m_CommandManager->submitForSpellCheck(itemsToRead);
        m_CommandManager->submitForWarningsCheck(itemsToRead);
    }
Example #2
0
    void MetadataIOCoordinator::readingFinishedHandler(bool ignoreBackups) {
        Q_ASSERT(m_CanProcessResults);
        m_CanProcessResults = false;

        const QHash<QString, ImportDataResult> &importResult = m_ReadingWorker->getImportResult();
        const QVector<Models::ArtworkMetadata*> &itemsToRead = m_ReadingWorker->getArtworksToImport();

        qDebug() << "Setting imported metadata...";
        int size = itemsToRead.size();
        for (int i = 0; i < size; ++i) {
            Models::ArtworkMetadata *metadata = itemsToRead.at(i);
            const QString &filepath = metadata->getFilepath();

            if (importResult.contains(filepath)) {
                const ImportDataResult &importResultItem = importResult.value(filepath);
                metadata->initialize(importResultItem.Title,
                                     importResultItem.Description,
                                     importResultItem.Keywords);
                metadata->setSize(importResultItem.Size);
            }
        }

        afterImportHandler(itemsToRead, ignoreBackups);

        qDebug() << "Metadata import finished";
        emit metadataReadingFinished();
    }
Example #3
0
void FilteredModelTests::filterDescriptionTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    Models::SettingsModel settingsModel;
    settingsModel.setSearchUsingAnd(false);
    commandManagerMock.InjectDependency(&settingsModel);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);

        if (i % 2) {
            metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");
        } else {
            metadata->initialize("", "", QStringList());
        }
    }

    filteredItemsModel.setSearchTerm("desc");
    QCOMPARE(filteredItemsModel.getItemsCount(), 5);

    filteredItemsModel.setSearchTerm("!desc");
    QCOMPARE(filteredItemsModel.getItemsCount(), 0);

    filteredItemsModel.setSearchTerm("description");
    QCOMPARE(filteredItemsModel.getItemsCount(), 5);

    // strict match does not work for description/title
    filteredItemsModel.setSearchTerm("!description");
    QCOMPARE(filteredItemsModel.getItemsCount(), 0);
}
Example #4
0
void FilteredModelTests::filterTitleAndKeywordsTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    Models::SettingsModel settingsModel;
    settingsModel.setSearchUsingAnd(false);
    commandManagerMock.InjectDependency(&settingsModel);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);

        if (i % 2 == 0) {
            metadata->initialize("title", "description", QStringList() << "keyword1" << "mess1");
        } else {
            metadata->initialize("title", "description", QStringList() << "keyword2" << "mess2");
        }
    }

    filteredItemsModel.setSearchTerm("keyword1 tit");
    QCOMPARE(filteredItemsModel.getItemsCount(), 10);

    filteredItemsModel.setSearchTerm("!keyword tit");
    QCOMPARE(filteredItemsModel.getItemsCount(), 10);

    settingsModel.setSearchUsingAnd(true);

    filteredItemsModel.setSearchTerm("!keyword tit");
    QCOMPARE(filteredItemsModel.getItemsCount(), 0);

    filteredItemsModel.setSearchTerm("!keyword2 title");
    QCOMPARE(filteredItemsModel.getItemsCount(), 5);
}
    void MetadataIOCoordinator::readingFinishedHandler(bool ignoreBackups) {
        Q_ASSERT(m_CanProcessResults);
        m_CanProcessResults = false;

        const QHash<QString, ImportDataResult> &importResult = m_ReadingWorker->getImportResult();
        const QVector<Models::ArtworkMetadata*> &itemsToRead = m_ReadingWorker->getItemsToRead();

        LOG_DEBUG  << "Setting imported metadata...";
        int size = itemsToRead.size();
        for (int i = 0; i < size; ++i) {
            Models::ArtworkMetadata *metadata = itemsToRead.at(i);
            const QString &filepath = metadata->getFilepath();

            if (importResult.contains(filepath)) {
                const ImportDataResult &importResultItem = importResult.value(filepath);
                metadata->initialize(importResultItem.Title,
                                     importResultItem.Description,
                                     importResultItem.Keywords);

                Models::ImageArtwork *image = dynamic_cast<Models::ImageArtwork*>(metadata);
                if (image != NULL) {
                    image->setImageSize(importResultItem.ImageSize);
                    image->setDateTimeOriginal(importResultItem.DateTimeOriginal);
                }

                metadata->setFileSize(importResultItem.FileSize);
            }
        }

        afterImportHandler(itemsToRead, ignoreBackups);

        LOG_DEBUG << "Metadata import finished";
        emit metadataReadingFinished();
    }
Example #6
0
    void Exiv2ReadingWorker::process() {
        LOG_DEBUG << "Worker #" << m_WorkerIndex << "started";

        bool anyError = false;

        int size = m_ItemsToRead.size();
        for (int i = 0; i < size; ++i) {
            if (m_Stopped) { break; }

            Models::ArtworkMetadata *artwork = m_ItemsToRead.at(i);
            const QString &filepath = artwork->getFilepath();
            ImportDataResult importResult;

            try {
                if (readMetadata(artwork, importResult)) {
                    Q_ASSERT(!m_ImportResult.contains(filepath));
                    m_ImportResult.insert(filepath, importResult);
                }
            }
            catch(Exiv2::Error &error) {
                anyError = true;
                LOG_WARNING << "Worker" << m_WorkerIndex << "Exiv2 error:" << error.what();
            }
            catch(...) {
                anyError = true;
                LOG_WARNING << "Worker" << m_WorkerIndex << "Reading error for item" << filepath;
            }
        }

        LOG_INFO << "Worker #" << m_WorkerIndex << "finished";

        emit finished(anyError);
    }
Example #7
0
void FilteredModelTests::clearEmptyKeywordsTest() {
    DECLARE_MODELS_AND_GENERATE(1);
    Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(0);
    metadata->clearKeywords();

    commandManagerMock.resetAnyCommandProcessed();
    filteredItemsModel.clearKeywords(0);
    QVERIFY(!commandManagerMock.anyCommandProcessed());
}
Example #8
0
void FilteredModelTests::removeMetadataMarksAsModifiedTest() {
    DECLARE_MODELS_AND_GENERATE(1);

    Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(0);

    QVERIFY(!metadata->isModified());

    metadata->setIsSelected(true);
    filteredItemsModel.removeMetadataInSelected();

    QVERIFY(metadata->isModified());
}
Example #9
0
void Commands::CommandManager::submitForSpellCheck(const QVector<Models::ArtworkMetadata *> &items) const {
    if ((m_SettingsModel != NULL) &&
        m_SettingsModel->getUseSpellCheck() &&
        (m_SpellCheckerService != NULL) &&
        !items.isEmpty()) {
        QVector<Common::BasicKeywordsModel *> itemsToSubmit;
        int count = items.length();
        itemsToSubmit.reserve(count);

        for (int i = 0; i < count; ++i) {
            Models::ArtworkMetadata *metadata = items.at(i);
            itemsToSubmit << metadata->getBasicModel();
        }

        this->submitForSpellCheck(itemsToSubmit);
    }
}
Example #10
0
void ReplaceTests::caseSensitiveTest() {
    const int itemsToGenerate = 10;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    QString replaceFrom = "rePLace";
    QString replaceTo = "Replaced";
    QString initString = "ReplaceMe";
    QString finalString = "ReplacedMe";

    auto flags = Common::SearchFlags::Description |
            Common::SearchFlags::Title |
            Common::SearchFlags::Keywords;

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize(initString, initString, QStringList() << initString);
    }

    auto artWorksInfo = filteredItemsModel.getSearchablePreviewOriginalItems(replaceFrom, flags);
    std::shared_ptr<Commands::FindAndReplaceCommand> replaceCommand(
                new Commands::FindAndReplaceCommand(artWorksInfo, replaceFrom, replaceTo, flags));
    auto result = commandManagerMock.processCommand(replaceCommand);

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        QCOMPARE(metadata->getDescription(), finalString);
        QCOMPARE(metadata->getTitle(), finalString);
        QCOMPARE(metadata->getKeywords()[0], finalString);
        QVERIFY(metadata->isModified());
    }
}
Example #11
0
void FilteredModelTests::setSelectedForZippingTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    Models::ZipArchiver zipArchiver;
    commandManagerMock.InjectDependency(&zipArchiver);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");

        if (i % 2) {
            metadata->setIsSelected(true);
        }
    }

    filteredItemsModel.setSelectedForZipping();

    const QVector<Models::ArtworkMetadata*> &artworks = zipArchiver.getArtworkList();
    QCOMPARE(artworks.length(), 5);
}
Example #12
0
void FilteredModelTests::removeMetadataDeletesMetadataTest() {
    DECLARE_MODELS_AND_GENERATE(10);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");
        metadata->setIsSelected(true);
    }

    filteredItemsModel.removeMetadataInSelected();

    for (int i = 0; i < 10; ++i) {
        Mocks::ArtworkMetadataMock *metadata = artItemsModelMock.getMockArtwork(i);
        QVERIFY(metadata->isDescriptionEmpty());
        QVERIFY(metadata->isTitleEmpty());
        QVERIFY(metadata->areKeywordsEmpty());
        QVERIFY(metadata->isModified());
    }
}
Example #13
0
std::shared_ptr<Commands::ICommandResult> Commands::PasteKeywordsCommand::execute(const ICommandManager *commandManagerInterface) const {
    LOG_INFO << "Pasting" << m_KeywordsList.length() << "keywords to" << m_MetadataElements.size() << "item(s)";

    CommandManager *commandManager = (CommandManager*)commandManagerInterface;

    QVector<int> indicesToUpdate;
    std::vector<UndoRedo::ArtworkMetadataBackup> artworksBackups;
    QVector<Models::ArtworkMetadata*> itemsToSave;
    size_t size = m_MetadataElements.size();
    indicesToUpdate.reserve((int)size);
    artworksBackups.reserve(size);
    itemsToSave.reserve((int)size);

    for (size_t i = 0; i < size; ++i) {
        const Models::MetadataElement &element = m_MetadataElements.at(i);
        Models::ArtworkMetadata *metadata = element.getOrigin();

        indicesToUpdate.append(element.getOriginalIndex());
        artworksBackups.emplace_back(metadata);

        metadata->appendKeywords(m_KeywordsList);
        itemsToSave.append(metadata);
    }

    if (size > 0) {
        commandManager->submitForSpellCheck(itemsToSave);
        commandManager->submitForWarningsCheck(itemsToSave);
        commandManager->saveArtworksBackups(itemsToSave);

        std::unique_ptr<UndoRedo::IHistoryItem> modifyArtworksItem(new UndoRedo::ModifyArtworksHistoryItem(artworksBackups, indicesToUpdate,
                                                                                                           UndoRedo::PasteModificationType));
        commandManager->recordHistoryItem(modifyArtworksItem);
    } else {
        LOG_WARNING << "Pasted zero real words!";
    }

    std::shared_ptr<PasteKeywordsCommandResult> result(new PasteKeywordsCommandResult(indicesToUpdate));
    return result;
}
Example #14
0
    bool WarningsModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
        Q_UNUSED(sourceParent);

        QAbstractItemModel *sourceItemModel = sourceModel();
        Models::ArtItemsModel *artItemsModel = dynamic_cast<Models::ArtItemsModel *>(sourceItemModel);
        Q_ASSERT(artItemsModel != NULL);
        Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(sourceRow);

        bool rowIsOk = false;

        if (metadata != NULL) {
            Common::WarningFlags warningsFlags = metadata->getWarningsFlags();
            bool anyWarnings = warningsFlags != Common::WarningFlags::None;

            rowIsOk = anyWarnings;

            if (m_ShowOnlySelected) {
                rowIsOk = metadata->isSelected() && anyWarnings;
            }
        }

        return rowIsOk;
    }
    void MetadataIOCoordinator::continueWithoutReading() {
        LOG_DEBUG << "Setting technical data";

        const QHash<QString, ImportDataResult> &importResult = m_ReadingWorker->getImportResult();
        const QVector<Models::ArtworkMetadata*> &itemsToRead = m_ReadingWorker->getItemsToRead();

        int size = itemsToRead.size();
        for (int i = 0; i < size; ++i) {
            Models::ArtworkMetadata *metadata = itemsToRead.at(i);
            const QString &filepath = metadata->getFilepath();

            if (importResult.contains(filepath)) {
                const ImportDataResult &importResultItem = importResult.value(filepath);

                Models::ImageArtwork *image = dynamic_cast<Models::ImageArtwork*>(metadata);
                if (image != NULL) {
                    image->setImageSize(importResultItem.ImageSize);
                    image->setDateTimeOriginal(importResultItem.DateTimeOriginal);
                }

                metadata->setFileSize(importResultItem.FileSize);
            }
        }
    }
Example #16
0
void ReplaceTests::replaceKeywordsTest() {
    const int itemsToGenerate = 10;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    QString replaceFrom = "keywordOld";
    QString replaceTo = "keywordNew";
    QString replaceToLower = replaceTo.toLower();

    auto flags = Common::SearchFlags::CaseSensitive |
                Common::SearchFlags::Description |
                Common::SearchFlags::Title |
                Common::SearchFlags::Keywords;

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize(QString("title"), QString("description"),
                             QStringList() << replaceToLower << "dummyKey" << replaceFrom);
    }

    auto artWorksInfo = filteredItemsModel.getSearchablePreviewOriginalItems(replaceFrom, flags);
    std::shared_ptr<Commands::FindAndReplaceCommand> replaceCommand(
                new Commands::FindAndReplaceCommand(artWorksInfo, replaceFrom, replaceTo, flags));
    auto result = commandManagerMock.processCommand(replaceCommand);

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        QCOMPARE(metadata->getDescription(), QString("description"));
        QCOMPARE(metadata->getTitle(), QString("title"));

        QStringList test = metadata->getKeywords();
        QStringList gold;

        gold << replaceToLower << "dummyKey";
        qSort(gold.begin(), gold.end());
        qSort(test.begin(), test.end());

        QCOMPARE(gold, test);
        QVERIFY(metadata->isModified());
    }
}
int SpellingProducesWarningsTest::doTest() {
    Models::ArtItemsModel *artItemsModel = m_CommandManager->getArtItemsModel();
    QList<QUrl> files;
    files << getImagePathForTest("images-for-tests/vector/026.jpg");

    int addedCount = artItemsModel->addLocalArtworks(files);

    VERIFY(addedCount == files.length(), "Failed to add file");

    MetadataIO::MetadataIOCoordinator *ioCoordinator = m_CommandManager->getMetadataIOCoordinator();
    SignalWaiter waiter;
    QObject::connect(ioCoordinator, SIGNAL(metadataReadingFinished()), &waiter, SIGNAL(finished()));

    ioCoordinator->continueReading(true);

    if (!waiter.wait(20)) {
        VERIFY(false, "Timeout exceeded for reading metadata.");
    }

    VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while reading");

    Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(0);

    sleepWait(3, [metadata]() {
        return !Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle) &&
                !Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription) &&
                !Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords);
    });

    VERIFY(!Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle), "Error for reading title");
    VERIFY(!Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription), "Error for reading description");
    VERIFY(!Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords), "Error for reading keywords");

    QString wrongWord = "abbreviatioe";
    metadata->setDescription(metadata->getDescription() + ' ' + wrongWord);
    metadata->setTitle(metadata->getTitle() + ' ' + wrongWord);
    metadata->appendKeyword("correct part " + wrongWord);
    metadata->setIsSelected(true);

    Models::FilteredArtItemsProxyModel *filteredModel = m_CommandManager->getFilteredArtItemsModel();
    SpellCheck::SpellCheckerService *spellCheckService = m_CommandManager->getSpellCheckerService();

    SignalWaiter spellingWaiter;
    QObject::connect(spellCheckService, SIGNAL(spellCheckQueueIsEmpty()), &spellingWaiter, SIGNAL(finished()));

    filteredModel->spellCheckSelected();

    if (!spellingWaiter.wait(5)) {
        VERIFY(false, "Timeout for waiting for first spellcheck results");
    }

    LOG_INFO << "Spellchecking finished. Waiting for warnings...";

    sleepWait(5, [=]() {
        return Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle) &&
                Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription) &&
                Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords);
    });

    auto *keywordsModel = metadata->getBasicModel();

    VERIFY(keywordsModel->hasDescriptionSpellError(), "Description spell error not detected");
    VERIFY(keywordsModel->hasTitleSpellError(), "Title spell error not detected");
    VERIFY(keywordsModel->hasKeywordsSpellError(), "Keywords spell error not detected");

    VERIFY(Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle),
           "Warning was not produced for title spelling error");
    VERIFY(Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription),
           "Warning was not produced for description spelling error");
    VERIFY(Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords),
           "Warning was not produced for keywords spelling error");

    return 0;
}
int AddToUserDictionaryTest::doTest() {
    Models::ArtItemsModel *artItemsModel = m_CommandManager->getArtItemsModel();

    QList<QUrl> files;
    files << getImagePathForTest("images-for-tests/pixmap/seagull.jpg");

    int addedCount = artItemsModel->addLocalArtworks(files);

    VERIFY(addedCount == files.length(), "Failed to add file");

    MetadataIO::MetadataIOCoordinator *ioCoordinator = m_CommandManager->getMetadataIOCoordinator();
    SignalWaiter waiter;
    QObject::connect(ioCoordinator, SIGNAL(metadataReadingFinished()), &waiter, SIGNAL(finished()));

    ioCoordinator->continueReading(true);

    if (!waiter.wait(20)) {
        VERIFY(false, "Timeout exceeded for reading metadata.");
    }

    VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while reading");

    Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(0);

    // wait for after-add spellchecking
    QThread::sleep(1);

    auto *basicKeywordsModel = metadata->getBasicModel();

    QString wrongWord = "abbreviatioe";
    metadata->setDescription(metadata->getDescription() + ' ' + wrongWord);
    metadata->setTitle(metadata->getTitle() + ' ' + wrongWord);
    metadata->appendKeyword("correct part " + wrongWord);
    metadata->setIsSelected(true);

    Models::FilteredArtItemsProxyModel *filteredModel = m_CommandManager->getFilteredArtItemsModel();
    SpellCheck::SpellCheckerService *spellCheckService = m_CommandManager->getSpellCheckerService();
    QObject::connect(spellCheckService, SIGNAL(spellCheckQueueIsEmpty()), &waiter, SIGNAL(finished()));

    filteredModel->spellCheckSelected();

    if (!waiter.wait(5)) {
        VERIFY(false, "Timeout for waiting for spellcheck results");
    }

    // wait for finding suggestions
    QThread::sleep(1);

    VERIFY(basicKeywordsModel->hasDescriptionSpellError(), "Description spell error not detected");
    VERIFY(basicKeywordsModel->hasTitleSpellError(), "Title spell error not detected");
    VERIFY(basicKeywordsModel->hasKeywordsSpellError(), "Keywords spell error not detected");

    spellCheckService->addWordToUserDictionary(wrongWord);

    SignalWaiter spellingWaiter;
    QObject::connect(spellCheckService, SIGNAL(spellCheckQueueIsEmpty()), &spellingWaiter, SIGNAL(finished()));

    QCoreApplication::processEvents(QEventLoop::AllEvents);

    // wait add user word to finish
    if (!spellingWaiter.wait(5)) {
        VERIFY(false, "Timeout for waiting for spellcheck results");
    }

    sleepWait(5, [=]() {
        return !basicKeywordsModel->hasDescriptionSpellError() &&
                !basicKeywordsModel->hasTitleSpellError() &&
                !basicKeywordsModel->hasKeywordsSpellError();
    });

    int userDictWords = spellCheckService->getUserDictWordsNumber();
    LOG_DEBUG << "User dict words count:" << userDictWords;

    VERIFY(userDictWords == 1, "Wrong number of words in user dictionary");
    VERIFY(!basicKeywordsModel->hasDescriptionSpellError(), "After adding word. Description spell error is still present");
    VERIFY(!basicKeywordsModel->hasTitleSpellError(), "After adding word. Title spell error is still present");
    VERIFY(!basicKeywordsModel->hasKeywordsSpellError(), "After adding word. Keywords spell error is still present");

    return 0;
}
Example #19
0
int SpellCheckUndoTest::doTest() {
    Models::ArtItemsModel *artItemsModel = m_CommandManager->getArtItemsModel();
    QList<QUrl> files;
    files << getImagePathForTest("images-for-tests/vector/026.jpg");

    int addedCount = artItemsModel->addLocalArtworks(files);

    VERIFY(addedCount == files.length(), "Failed to add file");

    MetadataIO::MetadataIOCoordinator *ioCoordinator = m_CommandManager->getMetadataIOCoordinator();
    SignalWaiter waiter;
    QObject::connect(ioCoordinator, SIGNAL(metadataReadingFinished()), &waiter, SIGNAL(finished()));

    ioCoordinator->continueReading(true);

    if (!waiter.wait(20)) {
        VERIFY(false, "Timeout exceeded for reading metadata.");
    }

    VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while reading");

    Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(0);

    QString wrongWord = "abbreviatioe";
    metadata->setDescription(metadata->getDescription() + ' ' + wrongWord);
    metadata->setTitle(metadata->getTitle() + ' ' + wrongWord);
    metadata->appendKeyword("correct part " + wrongWord);
    metadata->setIsSelected(true);

    // wait for after-add spellchecking
    QThread::sleep(1);

    Models::FilteredArtItemsProxyModel *filteredModel = m_CommandManager->getFilteredArtItemsModel();
    SpellCheck::SpellCheckerService *spellCheckService = m_CommandManager->getSpellCheckerService();
    QObject::connect(spellCheckService, SIGNAL(spellCheckQueueIsEmpty()), &waiter, SIGNAL(finished()));

    filteredModel->spellCheckSelected();

    if (!waiter.wait(5)) {
        VERIFY(false, "Timeout for waiting for first spellcheck results");
    }

    // wait for finding suggestions
    QThread::sleep(1);
    Common::BasicKeywordsModel *basicKeywordsModel = metadata->getKeywordsModel();

    VERIFY(basicKeywordsModel->hasDescriptionSpellError(), "Description spell error not detected");
    VERIFY(basicKeywordsModel->hasTitleSpellError(), "Title spell error not detected");
    VERIFY(basicKeywordsModel->hasKeywordsSpellError(), "Keywords spell error not detected");

    filteredModel->clearKeywords(0);
    QThread::sleep(1);

    VERIFY(!basicKeywordsModel->hasKeywordsSpellError(), "Keywords spell error not cleared");

    UndoRedo::UndoRedoManager *undoRedoManager = m_CommandManager->getUndoRedoManager();
    undoRedoManager->undoLastAction();

    if (!waiter.wait(5)) {
        VERIFY(false, "Timeout for waiting for second spellcheck results");
    }

    // wait for finding suggestions
    QThread::sleep(1);

    VERIFY(basicKeywordsModel->hasDescriptionSpellError(), "Description spell error not detected on the second time");
    VERIFY(basicKeywordsModel->hasTitleSpellError(), "Title spell error not detected on the second time");
    VERIFY(basicKeywordsModel->hasKeywordsSpellError(), "Keywords spell error not detected on the second time");

    return 0;
}
Example #20
0
int ClearMetadataTest::doTest() {
    Models::ArtItemsModel *artItemsModel = m_CommandManager->getArtItemsModel();
    QList<QUrl> files;
    files << getImagePathForTest("images-for-tests/pixmap/seagull-for-clear.jpg");

    int addedCount = artItemsModel->addLocalArtworks(files);

    VERIFY(addedCount == files.length(), "Failed to add file");

    MetadataIO::MetadataIOCoordinator *ioCoordinator = m_CommandManager->getMetadataIOCoordinator();
    SignalWaiter waiter;
    QObject::connect(ioCoordinator, SIGNAL(metadataReadingFinished()), &waiter, SIGNAL(finished()));

    ioCoordinator->continueReading(true);

    if (!waiter.wait(20)) {
        VERIFY(false, "Timeout exceeded for reading metadata.");
    }

    VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while reading");

    Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(0);
    const QStringList &keywords = metadata->getKeywords();

    QStringList expectedKeywords = QString("picture,seagull,bird").split(',');

    VERIFY(expectedKeywords == keywords, "Keywords are not the same!");
    VERIFY(metadata->getDescription() == "Seagull description", "Description is not the same!");
    VERIFY(metadata->getTitle() == "Seagull title", "Title is not the same!");

    Models::FilteredArtItemsProxyModel *filteredModel = m_CommandManager->getFilteredArtItemsModel();
    metadata->setIsSelected(true);

    filteredModel->removeMetadataInSelected();

    bool doOverwrite = true, dontSaveBackups = false;
    QObject::connect(ioCoordinator, SIGNAL(metadataWritingFinished()), &waiter, SIGNAL(finished()));

    artItemsModel->saveSelectedArtworks(QVector<int>() << 0, doOverwrite, dontSaveBackups);

    if (!waiter.wait(20)) {
        VERIFY(false, "Timeout exceeded for writing metadata.");
    }

    VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while writing");

    filteredModel->removeSelectedArtworks();
    addedCount = artItemsModel->addLocalArtworks(files);

    VERIFY(addedCount == files.length(), "Failed to add file after removal");

    ioCoordinator->continueReading(true);

    if (!waiter.wait(20)) {
        VERIFY(false, "Timeout exceeded for reading metadata.");
    }

    VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while reading");

    metadata = artItemsModel->getArtwork(0);

    VERIFY(metadata->getBasicModel()->isDescriptionEmpty(), "Description was not empty");
    VERIFY(metadata->getBasicModel()->isTitleEmpty(), "Title was not empty");
    VERIFY(metadata->getBasicModel()->areKeywordsEmpty(), "Keywords were not empty");

    return 0;
}