/**
 * Runs in a pooled thread.
 */
void BarcodeScanner::processDecode() {
    qDebug() << "processDecode() is called from " << QThread::currentThread();

    QString code = decoder->decodeBarcodeFromCache();
    qDebug() << "decoding has been finished";

    emit decodingFinished(code);
}
/**
 * Runs in a pooled thread.
 */
void AutoBarcodeScanner::processDecode() {
    qDebug() << "processDecode() is called from " << QThread::currentThread();

    bool scanActive = true;
    QString code;
    QVariantHash result;

    while (scanActive) {
        // timeout timer and deconstructor can abort scan process
        m_scanProcessMutex.lock();
        scanActive = !m_flagScanAbort;
        if (!scanActive) {
            qDebug() << "decoding aborted";
        }
        m_scanProcessMutex.unlock();

        if (scanActive) {
            QDBusMessage m = QDBusMessage::createMethodCall("org.nemomobile.lipstick", "/org/nemomobile/lipstick/screenshot", "org.nemomobile.lipstick", "saveScreenshot");
            m << m_decoder->getCaptureLocation();
            QDBusConnection::sessionBus().call(m);

            QImage screenshot(m_decoder->getCaptureLocation());

            // crop the image - we need only the viewfinder
            QImage copy = screenshot.copy(m_viewFinderRect);
            copy.save(m_decoder->getCaptureLocation());

            result = m_decoder->decodeBarcodeFromCache();
            code = result["content"].toString();

            if (code.isEmpty()) {
                // try for 1D bar code the other orientation
                QTransform transform;
                transform.rotate(90);
                copy = copy.transformed(transform);
                copy.save(m_decoder->getCaptureLocation());

                result = m_decoder->decodeBarcodeFromCache();
                code = result["content"].toString();
            }

            if (!code.isEmpty()) {
                m_timeoutTimer->stop();
                scanActive = false;
                qDebug() << "bar code found";
            }
        }
    }

    if (!result.empty()) {
        QList<QVariant> points = result["points"].toList();
        markLastCaptureImage(points);
    }

    qDebug() << "decoding has been finished, result: " + code;
    emit decodingFinished(code);

    m_scanProcessMutex.lock();
    m_flagScanRunning = false;
    m_timeoutTimer->stop();

    // wake deconstructor or stopScanning method
    qDebug() << "m_scanProcessStopped.wakeAll";
    m_scanProcessStopped.wakeAll();
    m_scanProcessMutex.unlock();
}
Beispiel #3
0
void QAudioDecoderStream::finished()
{
	emit decodingFinished(this);
}