コード例 #1
0
void PanoLastPage::checkFiles()
{
    QString dir = d->mngr->preProcessedMap().begin().key().toString(QUrl::RemoveFilename);
    QUrl panoUrl(dir + panoFileName(d->fileTemplateQLineEdit->text()));
    QUrl ptoUrl(dir + d->fileTemplateQLineEdit->text() + QLatin1String(".pto"));
    QFile panoFile(panoUrl.toString(QUrl::PreferLocalFile));
    QFile ptoFile(ptoUrl.toString(QUrl::PreferLocalFile));

    bool rawsOk = true;

    if (d->savePtoCheckBox->isChecked())
    {
        for (auto& input : d->mngr->preProcessedMap().keys())
        {
            if (input != d->mngr->preProcessedMap()[input].preprocessedUrl)
            {
                QString dir = input.toString(QUrl::RemoveFilename);
                QUrl derawUrl(dir + d->mngr->preProcessedMap()[input].preprocessedUrl.fileName());
                QFile derawFile(derawUrl.toString(QUrl::PreferLocalFile));
                rawsOk &= !derawFile.exists();
            }
        }
    }

    if (panoFile.exists() || (d->savePtoCheckBox->isChecked() && ptoFile.exists()))
    {
        setComplete(false);
        emit completeChanged();
        d->warningLabel->setText(i18n("<qt><p><font color=\"red\"><b>Warning:</b> "
                                      "This file already exists.</font></p></qt>"));
        d->warningLabel->show();
    }
    else if (!rawsOk)
    {
        setComplete(true);
        emit completeChanged();
        d->warningLabel->setText(i18n("<qt><p><font color=\"orange\"><b>Warning:</b> "
                                      "One or more converted raw files already exists (they will be skipped during the copying process).</font></p></qt>"));
        d->warningLabel->show();
    }
    else
    {
        setComplete(true);
        emit completeChanged();
        d->warningLabel->hide();
    }
}
コード例 #2
0
ファイル: copyfilestask.cpp プロジェクト: rickysarraf/digikam
void CopyFilesTask::run()
{
    QFile     panoFile(panoUrl.toLocalFile());
    QFile     finalPanoFile(finalPanoUrl.toLocalFile());

    QFileInfo fi(finalPanoUrl.toLocalFile());
    KUrl      finalPTOUrl(finalPanoUrl);
    finalPTOUrl.setFileName(fi.completeBaseName() + ".pto");

    QFile     ptoFile(ptoUrl.toLocalFile());
    QFile     finalPTOFile(finalPTOUrl.toLocalFile());

    if (!panoFile.exists())
    {
        errString = i18n("Temporary panorama file does not exists.");
        kDebug() << "Temporary panorama file does not exists: " + panoUrl.toLocalFile();
        successFlag = false;
        return;
    }

    if (finalPanoFile.exists())
    {
        errString = i18n("A file named %1 already exists.", finalPanoUrl.fileName());
        kDebug() << "Final panorama file already exists: " + finalPanoUrl.toLocalFile();
        successFlag = false;
        return;
    }

    if (savePTO && !ptoFile.exists())
    {
        errString = i18n("Temporary project file does not exist.");
        kDebug() << "Temporary project file does not exists: " + ptoUrl.toLocalFile();
        successFlag = false;
        return;
    }

    if (savePTO && finalPTOFile.exists())
    {
        errString = i18n("A file named %1 already exists.", finalPTOUrl.fileName());
        kDebug() << "Final project file already exists: " + finalPTOUrl.toLocalFile();
        successFlag = false;
        return;
    }

    kDebug() << "Copying GPS info...";

    // Find first src image which contain geolocation and save it to target pano file. 

    double lat, lng, alt;

    for (ItemUrlsMap::const_iterator i = urlList->constBegin(); i != urlList->constEnd(); ++i)
    {
        kDebug() << i.key();

        KPMetadata metaSrc(i.key().toLocalFile());

        if(metaSrc.getGPSInfo(alt, lat, lng))
        {
            kDebug() << "GPS info found and saved in " << panoUrl;
            KPMetadata metaDst(panoUrl.toLocalFile());
            metaDst.setGPSInfo(alt, lat, lng);
            metaDst.applyChanges();
            break;
        }
    }

    // Restore usual and common metadata from first shot.

    KPMetadata metaSrc(urlList->constBegin().key().toLocalFile());
    KPMetadata metaDst(panoUrl.toLocalFile());
    metaDst.setIptc(metaSrc.getIptc());
    metaDst.setXmp(metaSrc.getXmp());
    metaDst.setXmpTagString("Xmp.tiff.Make",  metaSrc.getExifTagString("Exif.Image.Make"));
    metaDst.setXmpTagString("Xmp.tiff.Model", metaSrc.getExifTagString("Exif.Image.Model"));
    metaDst.setImageDateTime(metaSrc.getImageDateTime(), true);

    QString filesList;

    for (ItemUrlsMap::const_iterator i = urlList->constBegin(); i != urlList->constEnd(); ++i)
        filesList.append(i.key().fileName() + " ; ");

    filesList.truncate(filesList.length()-3);

    metaDst.setXmpTagString("Xmp.kipi.PanoramaInputFiles", filesList, false);
    metaDst.setImageDateTime(QDateTime::currentDateTime());

    // NOTE : See https://developers.google.com/photo-sphere/metadata/ for details
    if (addGPlusMetadata)
    {
        kDebug() << "Adding PhotoSphere metadata...";
        metaDst.registerXmpNameSpace("http://ns.google.com/photos/1.0/panorama/", "GPano");
        metaDst.setXmpTagString("Xmp.GPano.UsePanoramaViewer", "True");
        metaDst.setXmpTagString("Xmp.GPano.StitchingSoftware", "Panorama Kipi Plugin with Hugin");
        metaDst.setXmpTagString("Xmp.GPano.ProjectionType",    "equirectangular");
    }

    metaDst.applyChanges();

    kDebug() << "Copying panorama file...";

    if (!panoFile.copy(finalPanoUrl.toLocalFile()) || !panoFile.remove())
    {
        errString = i18n("Cannot move panorama from %1 to %2.",
                         panoUrl.toLocalFile(),
                         finalPanoUrl.toLocalFile());
        kDebug() << "Cannot move panorama: QFile error = " << panoFile.error();
        successFlag = false;
        return;
    }

    if (savePTO)
    {
        kDebug() << "Copying project file...";

        if (!ptoFile.copy(finalPTOUrl.toLocalFile()))
        {
            errString = i18n("Cannot move project file from %1 to %2.",
                             panoUrl.toLocalFile(),
                             finalPanoUrl.toLocalFile());
            successFlag = false;
            return;
        }

        kDebug() << "Copying converted RAW files...";

        for (ItemUrlsMap::const_iterator i = urlList->constBegin(); i != urlList->constEnd(); ++i)
        {
            if (KPMetadata::isRawFile(i.key()))
            {
                KUrl finalImgUrl(finalPanoUrl);
                finalImgUrl.setFileName(i->preprocessedUrl.fileName());
                QFile imgFile(i->preprocessedUrl.toLocalFile());

                if (!imgFile.copy(finalImgUrl.toLocalFile()))
                {
                    errString = i18n("Cannot copy converted image file from %1 to %2.",
                                     i->preprocessedUrl.toLocalFile(),
                                     finalImgUrl.toLocalFile());
                    successFlag = false;
                    return;
                }
            }
        }
    }

    successFlag = true;
    return;
}