Exemplo n.º 1
0
/**
  * Returns the attribute list for the given plugin if found, an empty list else.
  */
const QList<QString> Filter::getAttributes(QString plugin) {
    for (QVector<PluginInterface *>::iterator i = m_plugins.begin(); i != m_plugins.end(); i++) {
        PluginInterface *fiP = *i;
        if (fiP->getName() == plugin)
            return fiP->getAttributeNames();
    }

    return QList<QString>();
}
Exemplo n.º 2
0
bool Filter::checkAndSaveFile(QString path) {
    bool saved = false;

    // does the file rely under the watched directory?
    if (!path.startsWith(m_dir))
        return saved;


    // if any plugin accepts the file, then save its ref
    // in the db
    for (int i = 0; !saved && i < m_plugins.count(); i++) {
        m_plugins[i]->loadAttributes(path);
        saved |= m_plugins[i]->checkFile(path);
    }

    // save file if retained
    if (saved) {
        QString fileId = m_db.addFile(m_filterId, path); // add file to db

        // signal
        newFile(m_virtualDirectoryPath, path);

        // save file attributes
        for (int i = 0; i < m_plugins.count(); i++) {
            PluginInterface *fP = m_plugins[i];
            fP->loadAttributes(path); // attributes are loaded only if not done in the above checkFile iteration, we don't reload attrs if same file...
            QList<QString>attributes = fP->getAttributeNames();
            for (QList<QString>::iterator j = attributes.begin(); j != attributes.end(); j++) {
                    QString  attrName = (*j);
                    QVariant attrObjValue = fP->getAttributeValue(attrName);
                    QString attrValue = attrObjValue.isValid() ? attrObjValue.toString() : "<null>";
                    m_db.addFileAttribute(fileId, attrName, attrValue);
            }
        }
    }

    return saved;
}