Example #1
0
void MetadataTask::run()
{
    if(d->cancel)
    {
        return;
    }

    if (d->direction == MetadataSynchronizer::WriteFromDatabaseToFile)
    {
        MetadataHub fileHub;

        // read in from database
        fileHub.load(d->item);

        // write out to file DMetadata
        if(d->tagsOnly)
        {
            fileHub.writeTags(d->item.filePath());
        }
        else
        {
            fileHub.write(d->item.filePath(), MetadataHub::WRITE_ALL, true);
        }
    }
    else // MetadataSynchronizer::ReadFromFileToDatabase
    {
        CollectionScanner scanner;
        scanner.scanFile(d->item, CollectionScanner::Rescan);
    }

    emit signalFinished(QImage());
    emit signalDone();
}
Example #2
0
void ImageDescEditTab::slotReadFromFileMetadataToDatabase()
{
    initProgressIndicator();

    emit signalProgressMessageChanged(i18n("Reading metadata from files. Please wait..."));

    d->ignoreImageAttributesWatch = true;
    int i                         = 0;

    ScanController::instance()->suspendCollectionScan();

    CollectionScanner scanner;

    foreach(const ImageInfo& info, d->currInfos)
    {
        scanner.scanFile(info, CollectionScanner::Rescan);

        emit signalProgressValueChanged(i++/(float)d->currInfos.count());

        qApp->processEvents();
    }

    ScanController::instance()->resumeCollectionScan();
    d->ignoreImageAttributesWatch = false;

    emit signalProgressFinished();

    // reload everything
    setInfos(d->currInfos);
}
Example #3
0
void ScanController::scanFileDirectly(const QString& filePath)
{
    suspendCollectionScan();

    CollectionScanner scanner;
    scanner.recordHints(d->itemHints);
    scanner.recordHints(d->itemChangeHints);
    scanner.scanFile(filePath);

    resumeCollectionScan();
}
Example #4
0
void ScanController::scanFileDirectlyCopyAttributes(const QString& filePath, qlonglong parentVersion)
{
    suspendCollectionScan();

    CollectionScanner scanner;
    scanner.recordHints(d->itemHints);
    scanner.recordHints(d->itemChangeHints);
    qlonglong id = scanner.scanFile(filePath);
    ImageInfo dest(id), source(parentVersion);
    scanner.copyFileProperties(source, dest);

    resumeCollectionScan();
}
Example #5
0
void ScanController::run()
{
    while (d->running)
    {
        bool doInit = false, doScan = false, doPartialScan = false, doUpdateUniqueHash = false;
        QString task;
        {
            QMutexLocker lock(&d->mutex);

            if (d->needsInitialization)
            {
                d->needsInitialization = false;
                doInit                 = true;
            }
            else if (d->needsCompleteScan)
            {
                d->needsCompleteScan = false;
                doScan               = true;
            }
            else if (d->needsUpdateUniqueHash)
            {
                d->needsUpdateUniqueHash = false;
                doUpdateUniqueHash       = true;
            }
            else if (!d->scanTasks.isEmpty() && !d->scanSuspended)
            {
                doPartialScan = true;
                task          = d->scanTasks.takeFirst();
            }
            else
            {
                d->idle = true;
                d->condVar.wait(&d->mutex);
                d->idle = false;
            }
        }

        if (doInit)
        {
            d->continueInitialization = true;
            // pass "this" as InitializationObserver
            bool success = DatabaseAccess::checkReadyForUse(this);

            // If d->advice has not been adjusted to a value indicating failure, do this here
            if (!success && d->advice == Success)
            {
                d->advice = ContinueWithoutDatabase;
            }

            emit databaseInitialized(success);
        }
        else if (doScan)
        {
            CollectionScanner scanner;
            connectCollectionScanner(&scanner);
            scanner.setNeedFileCount(d->needTotalFiles);
            scanner.recordHints(d->albumHints);
            scanner.recordHints(d->itemHints);
            scanner.recordHints(d->itemChangeHints);
            SimpleCollectionScannerObserver observer(&d->continueScan);
            scanner.setObserver(&observer);
            scanner.completeScan();
            emit completeScanDone();
        }
        else if (doPartialScan)
        {
            CollectionScanner scanner;
            scanner.recordHints(d->albumHints);
            scanner.recordHints(d->itemHints);
            scanner.recordHints(d->itemChangeHints);
            //connectCollectionScanner(&scanner);
            SimpleCollectionScannerObserver observer(&d->continuePartialScan);
            scanner.setObserver(&observer);
            scanner.partialScan(task);
        }
        else if (doUpdateUniqueHash)
        {
            DatabaseAccess access;
            SchemaUpdater updater(access.db(), access.backend(), access.parameters());
            updater.setDatabaseAccess(&access);
            updater.setObserver(this);
            updater.updateUniqueHash();
            emit completeScanDone();
        }
    }
}