QString DImgFilterManager::i18nDisplayableName(const QString& filterIdentifier)
{
    QMutexLocker lock(&d->mutex);
    QString name = d->i18nFilterNames.value(filterIdentifier);

    if (!name.isEmpty())
    {
        return name;
    }

    if (DImgBuiltinFilter::isSupported(filterIdentifier))
    {
        return DImgBuiltinFilter::i18nDisplayableName(filterIdentifier);
    }

    name = displayableName(filterIdentifier);

    if (!name.isEmpty())
    {
        QByteArray latin1  = name.toLatin1();
        QString translated = i18n(latin1.constData());

        if (translated != name)
        {
            return translated;
        }

        return name;
    }

    QString digikamNamespace = QLatin1String("digikam:");

    if (filterIdentifier.startsWith(digikamNamespace))
    {
        return filterIdentifier.mid(digikamNamespace.length());
    }

    return filterIdentifier;
}
QString DImgBuiltinFilter::i18nDisplayableName() const
{
    QByteArray latin1 = displayableName().toLatin1();
    return i18n(latin1.data());
}
FilterAction DImgBuiltinFilter::filterAction() const
{
    FilterAction action;

    switch (m_type)
    {
        case NoOperation:
        default:
            return action;

        case Rotate90:
        case Rotate180:
        case Rotate270:
        {
            action = FilterAction("transform:rotate", 1);
            int angle;

            if (m_type == Rotate90)
            {
                angle = 90;
            }
            else if (m_type == Rotate180)
            {
                angle = 180;
            }
            else
            {
                angle = 270;
            }

            action.addParameter("angle", angle);
            break;
        }

        case FlipHorizontally:
        case FlipVertically:
        {
            action = FilterAction("transform:flip", 1);
            action.addParameter("direction", m_type == FlipHorizontally ? "horizontal" : "vertical");
            break;
        }

        case Crop:
        {
            action  = FilterAction("transform:crop", 1);
            QRect r = m_arg.toRect();
            action.addParameter("x",      r.x());
            action.addParameter("y",      r.y());
            action.addParameter("width",  r.width());
            action.addParameter("height", r.height());
            break;
        }

        case Resize:
        {
            action  = FilterAction("transform:resize", 1);
            QSize s = m_arg.toSize();
            action.addParameter("width",  s.width());
            action.addParameter("height", s.height());
            break;
        }

        case ConvertTo8Bit:
        case ConvertTo16Bit:
        {
            action = FilterAction("transform:convertDepth", 1);
            action.addParameter("depth", m_type == ConvertTo8Bit ? 8 : 16);
            break;
        }
    }

    action.setDisplayableName(displayableName());
    return action;
}