Exemplo n.º 1
0
void Picdok::searchInComment(const bool searchForEmpty, const QString searchString)
{
    // Walk forwards through directory from current position.
    WaitPtr(true);
    int ix = ui->cmbPicFile->currentIndex() + 1;
    int rows = ui->cmbPicFile->count();
    QString nfile;
    QString nComm;
    QString nOrtn;
    QString nDtTm;
    bool exitHere = false;
    QString exitMessage;
    while (ix < rows)
    {
        nfile = curDir + ui->cmbPicFile->itemText(ix);
        if (!getExifData(nfile, nComm, nOrtn, nDtTm))
        {
            if (!noWarnNoExif)
            {
//              Think about this section of code.
//                WaitPtr(false);
//               QMessageBox::critical(this, ERROR_TITLE, tr("EXIF data not obtained for ") + nfile);
            }
        }
        if (searchForEmpty)
        {
            if (nComm.trimmed() == "") exitHere = true;    // We have found a file without UserComment.
        }
        else
        {
           if (nComm.trimmed().contains(searchString, Qt::CaseInsensitive))
            {
                exitHere = true;    // We have found a file with the search string.
            }
        }
        if (exitHere)
        {
            ui->cmbPicFile->setCurrentIndex(ix);
            setFocusOnCommentIfEmpty();
            WaitPtr(false);
            return;
        }
        ix++;
        nComm = "";
    }
    WaitPtr(false);
    if (searchForEmpty)
    {
        exitMessage = tr("All remaining pictures have user comment data.");
    }
    else
    {
        exitMessage = tr("Search string not found");
    }
    QMessageBox::information(this, tr("Information"), exitMessage);
}
QString ImageImporter::replaceStrings(const QString& src, const QFileInfo* fileinfo, QRegExp regexp )
{
    QString retval = src;

    //general replacement for keys of the form $qdt-XXX where XXX is one of the generic QDateTime
    // format strings
    QStringList qdt;
    qdt << "dddd" << "ddd" << "dd" << "d"
        << "MMMM" << "MMM" << "MM" << "M"
        << "yyyy" << "yy"
        << "hh" << "h" << "mm" << "m"
        << "ss" << "s" << "zzz" << "z"
        << "AP" << "ap";

    QStringList dateTimeVars;
    QStringList dateTimeRepl;

    dateTimeVars << "year" << "month" << "day" << "hour" << "min" << "sec";
    dateTimeRepl << "yyyy" << "MM"    << "dd"  << "hh"   << "mm"  << "ss" ;

    for (QStringList::iterator it = qdt.begin(); it != qdt.end(); ++it) {
        dateTimeVars << QString("$qdt-%1").arg(*it);
        dateTimeRepl << QString(*it);
    }

    if (fileinfo == 0L) {
        QDateTime dt = QDateTime::currentDateTime();
        if (dt.isValid()) {
            retval = retval.replace("$year" , dt.toString("yyyy"));
            retval = retval.replace("$month", dt.toString("MM"));
            retval = retval.replace("$day"  , dt.toString("dd"));
            retval = retval.replace("$hour" , dt.toString("hh"));
            retval = retval.replace("$min"  , dt.toString("mm"));
            retval = retval.replace("$sec"  , dt.toString("ss"));

            for (QStringList::iterator it = qdt.begin(); it != qdt.end(); ++it) {
                retval = retval.replace(QString("$qdt-%1").arg(*it) , dt.toString(*it));
            }
        }

        retval = retval.replace("$ext"  , "[ext]");
        retval = retval.replace("$model"  , "[model]");
        retval = retval.replace("$make"  , "[make]");

        retval = retval.replace("$0"  , "[orig-filename]");
        for (int i = 1; i < 10; ++i) {
            retval = retval.replace(QString("$%1").arg(i)    , QString("[capture-%1]").arg(i));
        }


    } else {

        //replace the captures ...
        if (regexp.exactMatch(fileinfo->fileName())) {
            for (int i = 0; i <= regexp.numCaptures(); ++i) {
                retval = retval.replace(QString("$%1").arg(i)    , regexp.cap(i));
            }
        }

        // we begin with model, as it is a nice way to find out, if exif data is available
        // model
        QString model = getExifData(fileinfo->absFilePath(), EXIF_TAG_MODEL);

        // I assume: No exifdata available if model is not set
        if (model.isEmpty()) {
            return "";
        }
        retval = retval.replace("$model"  , model);

            // make
        QString make = getExifData(fileinfo->absFilePath(), EXIF_TAG_MAKE);
        retval = retval.replace("$make"  , make);

            // dateTime original
        QDateTime dt = QDateTime::fromString(getExifData(fileinfo->absFilePath(), EXIF_TAG_DATE_TIME_ORIGINAL)
                                             .replace(":", "-"), Qt::ISODate);
        if (dt.isValid()) {
            retval = retval.replace("$year" , dt.toString("yyyy"));
            retval = retval.replace("$month", dt.toString("MM"));
            retval = retval.replace("$day"  , dt.toString("dd"));
            retval = retval.replace("$hour" , dt.toString("hh"));
            retval = retval.replace("$min"  , dt.toString("mm"));
            retval = retval.replace("$sec"  , dt.toString("ss"));

            for (QStringList::iterator it = qdt.begin(); it != qdt.end(); ++it) {
                retval = retval.replace(QString("$qdt-%1").arg(*it) , dt.toString(*it));
            }
        }

        // extension
        int pos = fileinfo->fileName().findRev('.') + 1;
        if (pos > 0) {
            retval = retval.replace("$ext"  , fileinfo->fileName().mid(pos));
        }
    }

    //remove all unreplaced $variables
    if (retval.contains("$") ) {
        ///@todo remove all $variables that could not be replaced
    }

    //finally remove multiple slashes
    while (retval.contains("//")) {
        retval = retval.replace("//", "/");
    }

    return retval;
}