Ejemplo n.º 1
0
bool WBSDefinition::loadXML(KoXmlElement &element, XMLLoaderObject & ) {
    m_projectCode = element.attribute( "project-code" );
    m_projectSeparator = element.attribute( "project-separator" );
    m_levelsEnabled = (bool)element.attribute( "levels-enabled", "0" ).toInt();
    KoXmlNode n = element.firstChild();
    for ( ; ! n.isNull(); n = n.nextSibling() ) {
        if ( ! n.isElement() ) {
            continue;
        }
        KoXmlElement e = n.toElement();
        if (e.tagName() == "default") {
            m_defaultDef.code = e.attribute( "code", "Number" );
            m_defaultDef.separator = e.attribute( "separator", "." );
        } else if (e.tagName() == "levels") {
            KoXmlNode n = e.firstChild();
            for ( ; ! n.isNull(); n = n.nextSibling() ) {
                if ( ! n.isElement() ) {
                    continue;
                }
                KoXmlElement el = n.toElement();
                CodeDef d;
                d.code = el.attribute( "code" );
                d.separator = el.attribute( "separator" );
                int lvl = el.attribute( "level", "-1" ).toInt();
                if ( lvl >= 0 ) {
                    setLevelsDef( lvl, d );
                } else kError()<<"Invalid levels definition";
            }
        }
    }
    return true;
}
Ejemplo n.º 2
0
bool KoOdfLoadingContext::parseManifest(const KoXmlDocument &manifestDocument)
{
    // First find the manifest:manifest node.
    KoXmlNode  n = manifestDocument.firstChild();
    kDebug(30006) << "Searching for manifest:manifest " << n.toElement().nodeName();
    for (; !n.isNull(); n = n.nextSibling()) {
        if (!n.isElement()) {
            kDebug(30006) << "NOT element";
            continue;
        } else {
            kDebug(30006) << "element";
        }

        kDebug(30006) << "name:" << n.toElement().localName()
                      << "namespace:" << n.toElement().namespaceURI();

        if (n.toElement().localName() == "manifest"
            && n.toElement().namespaceURI() == KoXmlNS::manifest)
        {
            kDebug(30006) << "found manifest:manifest";
            break;
        }
    }
    if (n.isNull()) {
        kDebug(30006) << "Could not find manifest:manifest";
        return false;
    }

    // Now loop through the children of the manifest:manifest and
    // store all the manifest:file-entry elements.
    const KoXmlElement  manifestElement = n.toElement();
    for (n = manifestElement.firstChild(); !n.isNull(); n = n.nextSibling()) {

        if (!n.isElement())
            continue;

        KoXmlElement el = n.toElement();
        if (!(el.localName() == "file-entry" && el.namespaceURI() == KoXmlNS::manifest))
            continue;

        QString fullPath  = el.attributeNS(KoXmlNS::manifest, "full-path", QString());
        QString mediaType = el.attributeNS(KoXmlNS::manifest, "media-type", QString(""));
        QString version   = el.attributeNS(KoXmlNS::manifest, "version", QString());

        // Only if fullPath is valid, should we store this entry.
        // If not, we don't bother to find out exactly what is wrong, we just skip it.
        if (!fullPath.isNull()) {
            d->manifestEntries.insert(fullPath,
                                      new KoOdfManifestEntry(fullPath, mediaType, version));
        }
    }

    return true;
}
Ejemplo n.º 3
0
KisNodeSP KisKraLoader::loadNodes(const KoXmlElement& element, KisImageWSP image, KisNodeSP parent)
{

    KoXmlNode node = element.firstChild();
    KoXmlNode child;

    if (!node.isNull()) {

        if (node.isElement()) {

            if (node.nodeName().toUpper() == LAYERS.toUpper() || node.nodeName().toUpper() == MASKS.toUpper()) {
                for (child = node.lastChild(); !child.isNull(); child = child.previousSibling()) {
                    KisNodeSP node = loadNode(child.toElement(), image, parent);
                    if (node) {
                        image->nextLayerName(); // Make sure the nameserver is current with the number of nodes.
                        image->addNode(node, parent);
                        if (node->inherits("KisLayer") && child.childNodesCount() > 0) {
                            loadNodes(child.toElement(), image, node);
                        }
                    }
                }
            }
        }
    }

    return parent;
}
Ejemplo n.º 4
0
bool KPlatoXmlLoader::load( const KoXmlElement& plan )
{
    kDebug(kplatoXmlDebugArea())<<"plan";
    QString syntaxVersion = plan.attribute( "version" );
    m_loader.setVersion( syntaxVersion );
    if ( syntaxVersion.isEmpty() ) {
        int ret = KMessageBox::warningContinueCancel(
                      0, i18n( "This document has no syntax version.\n"
                               "Opening it in Plan may lose information." ),
                      i18n( "File-Format Error" ), KGuiItem( i18n( "Continue" ) ) );
        if ( ret == KMessageBox::Cancel ) {
            m_message = "USER_CANCELED";
            return false;
        }
        // set to max version and hope for the best
        m_loader.setVersion( KPLATO_MAX_FILE_SYNTAX_VERSION );
    } else if ( syntaxVersion > KPLATO_MAX_FILE_SYNTAX_VERSION ) {
        int ret = KMessageBox::warningContinueCancel(
                      0, i18n( "This document was created with a newer version of KPlato than Plan can load.\n"
                               "Syntax version: %1\n"
                               "Opening it in this version of Plan may lose some information.", syntaxVersion ),
                      i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
        if ( ret == KMessageBox::Cancel ) {
            m_message = "USER_CANCELED";
            return false;
        }
    }
    m_loader.startLoad();
    bool result = false;
    KoXmlNode n = plan.firstChild();
    for ( ; ! n.isNull(); n = n.nextSibling() ) {
        if ( ! n.isElement() ) {
            continue;
        }
        KoXmlElement e = n.toElement();
        if ( e.tagName() == "project" ) {
            m_loader.setProject( m_project );
            result = load( m_project, e, m_loader );
            if ( result ) {
                if ( m_project->id().isEmpty() ) {
                    m_project->setId( m_project->uniqueNodeId() );
                    m_project->registerNodeId( m_project );
                }
            } else {
                m_loader.addMsg( XMLLoaderObject::Errors, "Loading of project failed" );
                kError()<<"Loading of project failed";
                //TODO add some ui here
            }
        }
    }
    m_loader.stopLoad();
    return result;
}
Ejemplo n.º 5
0
bool KraConverter::loadXML(const KoXmlDocument &doc, KoStore *store)
{
    Q_UNUSED(store);

    KoXmlElement root;
    KoXmlNode node;

    if (doc.doctype().name() != "DOC") {
       m_doc->setErrorMessage(i18n("The format is not supported or the file is corrupted"));
        return false;
    }
    root = doc.documentElement();
    int syntaxVersion = root.attribute("syntaxVersion", "3").toInt();
    if (syntaxVersion > 2) {
       m_doc->setErrorMessage(i18n("The file is too new for this version of Krita (%1).", syntaxVersion));
        return false;
    }

    if (!root.hasChildNodes()) {
       m_doc->setErrorMessage(i18n("The file has no layers."));
        return false;
    }

    m_kraLoader = new KisKraLoader(m_doc, syntaxVersion);

    // Legacy from the multi-image .kra file period.
    for (node = root.firstChild(); !node.isNull(); node = node.nextSibling()) {
        if (node.isElement()) {
            if (node.nodeName() == "IMAGE") {
                KoXmlElement elem = node.toElement();
                if (!(m_image = m_kraLoader->loadXML(elem))) {
                    if (m_kraLoader->errorMessages().isEmpty()) {
                        m_doc->setErrorMessage(i18n("Unknown error."));
                    }
                    else {
                        m_doc->setErrorMessage(m_kraLoader->errorMessages().join(".\n"));
                    }
                    return false;
                }
                return true;
            }
            else {
                if (m_kraLoader->errorMessages().isEmpty()) {
                    m_doc->setErrorMessage(i18n("The file does not contain an image."));
                }
                return false;
            }
        }
    }
    return false;
}
Ejemplo n.º 6
0
bool Context::load( const KoXmlDocument &document ) {
    m_document = document; // create a copy, document is deleted under our feet

    // Check if this is the right app
    KoXmlElement elm = m_document.documentElement();
    QString value = elm.attribute( "mime", QString() );
    if ( value.isEmpty() ) {
        errorPlan << "No mime type specified!";
//        setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
        return false;
    } else if ( value != "application/x-vnd.kde.plan" ) {
        if ( value == "application/x-vnd.kde.kplato" ) {
            // accept, since we forgot to change kplato to plan for so long...
        } else {
            errorPlan << "Unknown mime type " << value;
//        setErrorMessage( i18n( "Invalid document. Expected mimetype application/x-vnd.kde.kplato, got %1", value ) );
            return false;
        }
    }
/*    QString m_syntaxVersion = elm.attribute( "version", "0.0" );
    if ( m_syntaxVersion > "0.0" ) {
        int ret = KMessageBox::warningContinueCancel(
                      0, i18n( "This document was created with a newer version of Plan (syntax version: %1)\n"
                               "Opening it in this version of Plan will lose some information.", m_syntaxVersion ),
                      i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
        if ( ret == KMessageBox::Cancel ) {
            setErrorMessage( "USER_CANCELED" );
            return false;
        }
    }
*/
/*
#ifdef KOXML_USE_QDOM
    int numNodes = elm.childNodes().count();
#else
    int numNodes = elm.childNodesCount();
#endif
*/
    KoXmlNode n = elm.firstChild();
    for ( ; ! n.isNull(); n = n.nextSibling() ) {
        if ( ! n.isElement() ) {
            continue;
        }
        KoXmlElement element = n.toElement();
        if ( element.tagName() == "context" ) {
            m_context = element;
            m_contextLoaded = true;
        }
    }
    return true;
}
Ejemplo n.º 7
0
bool KPlatoXmlLoader::loadWorkpackage( const KoXmlElement& plan )
{
    kDebug(kplatoXmlDebugArea());
    bool ok = false;
    if ( m_loader.workVersion() > KPLATOWORK_MAX_FILE_SYNTAX_VERSION ) {
        int ret = KMessageBox::warningContinueCancel(
                0, i18n( "This document was created with a newer version of KPlatoWork (syntax version: %1)\n"
                "Opening it in this version of PlanWork will lose some information.", m_loader.workVersion() ),
                i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
        if ( ret == KMessageBox::Cancel ) {
            m_message = "USER_CANCELED";
            return false;
        }
    }
    m_loader.startLoad();
    Project *proj = new Project();
    Package *package = new Package();
    package->project = proj;
    KoXmlNode n = plan.firstChild();
    for ( ; ! n.isNull(); n = n.nextSibling() ) {
        if ( ! n.isElement() ) {
            continue;
        }
        KoXmlElement e = n.toElement();
        if ( e.tagName() == "project" ) {
            m_loader.setProject( proj );
            ok = load( proj, e, m_loader );
            if ( ! ok ) {
                m_loader.addMsg( XMLLoaderObject::Errors, "Loading of work package failed" );
                //TODO add some ui here
            }
        } else if ( e.tagName() == "workpackage" ) {
            m_timeTag = e.attribute( "time-tag" );
            package->ownerId = e.attribute( "owner-id" );
            package->ownerName = e.attribute( "owner" );
            KoXmlElement elem;
            forEachElement( elem, e ) {
                if ( elem.tagName() != "settings" ) {
                    continue;
                }
                package->settings.usedEffort = (bool)elem.attribute( "used-effort" ).toInt();
                package->settings.progress = (bool)elem.attribute( "progress" ).toInt();
                package->settings.documents = (bool)elem.attribute( "documents" ).toInt();
            }
        }
    }
Ejemplo n.º 8
0
bool KoDocumentInfo::loadOasisAuthorInfo(const KoXmlNode &metaDoc)
{
    KoXmlElement e = KoXml::namedItemNS(metaDoc, KoXmlNS::dc, "creator");
    if (!e.isNull() && !e.text().isEmpty())
        setActiveAuthorInfo("creator", e.text());

    KoXmlNode n = metaDoc.firstChild();
    for (; !n.isNull(); n = n.nextSibling()) {
        if (!n.isElement())
            continue;

        KoXmlElement e = n.toElement();
        if (!(e.namespaceURI() == KoXmlNS::meta &&
                e.localName() == "user-defined" && !e.text().isEmpty()))
            continue;

        QString name = e.attributeNS(KoXmlNS::meta, "name", QString());
        setActiveAuthorInfo(name, e.text());
    }

    return true;
}
Ejemplo n.º 9
0
bool Context::load( const KoXmlDocument &document ) {
    m_document = document; // create a copy, document is deleted under our feet
    
    // Check if this is the right app
    KoXmlElement elm = m_document.documentElement();
    QString value = elm.attribute( "mime", QString() );
    if ( value.isEmpty() ) {
        kError() << "No mime type specified!" << endl;
//        setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
        return false;
    } else if ( value != "application/x-vnd.kde.kplato" ) {
        kError() << "Unknown mime type " << value << endl;
//        setErrorMessage( i18n( "Invalid document. Expected mimetype application/x-vnd.kde.kplato, got %1", value ) );
        return false;
    }
    QString m_syntaxVersion = elm.attribute( "version", "0.0" );
    if ( m_syntaxVersion > "0.0" ) {
/*        int ret = KMessageBox::warningContinueCancel(
                      0, i18n( "This document was created with a newer version of KPlato (syntax version: %1)\n"
                               "Opening it in this version of KPlato will lose some information.", m_syntaxVersion ),
                      i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
        if ( ret == KMessageBox::Cancel ) {
            setErrorMessage( "USER_CANCELED" );
            return false;
        }*/
    }

#ifdef KOXML_USE_QDOM
    int numNodes = elm.childNodes().count();
#else
    int numNodes = elm.childNodesCount();
#endif
    
    KoXmlNode n = elm.firstChild();
    for ( ; ! n.isNull(); n = n.nextSibling() ) {
        if ( ! n.isElement() ) {
            continue;
        }
        KoXmlElement element = n.toElement();
        if ( element.tagName() == "context" ) {
            m_context = element;
            m_contextLoaded = true;
/*            currentView = element.attribute("current-view");
            currentEstimateType = element.attribute("estimate-type").toInt();
            currentSchedule = element.attribute("current-schedule").toLong();
            actionViewExpected = element.attribute("view-expected").toInt();
            actionViewOptimistic = element.attribute("view-optimistic").toInt();
            actionViewPessimistic = element.attribute("view-pessimistic").toInt();
        
            QDomNodeList list = element.childNodes();
            for (int i=0; i<list.count(); ++i) {
                if (list.item(i).isElement()) {
                    QDomElement e = list.item(i).toElement();
                    if (e.tagName() == "gantt-view") {
                        ganttview.ganttviewsize = e.attribute("ganttview-size").toInt();
                        ganttview.taskviewsize = e.attribute("taskview-size").toInt();
                        ganttview.currentNode = e.attribute("current-node");
                        ganttview.showResources = e.attribute("show-resources").toInt();
                        ganttview.showTaskName = e.attribute("show-taskname").toInt();
                        ganttview.showTaskLinks = e.attribute("show-tasklinks").toInt();
                        ganttview.showProgress = e.attribute("show-progress").toInt();
                        ganttview.showPositiveFloat = e.attribute("show-positivefloat").toInt();
                        ganttview.showCriticalTasks = attribute("show-criticaltasks").toInt();
                        ganttview.showCriticalPath = e.attribute("show-criticalpath").toInt();
                        ganttview.showNoInformation = e.attribute("show-noinformation").toInt();
        
                        QDomNodeList list = e.childNodes();
                        for (int i=0; i<list.count(); ++i) {
                            if (list.item(i).isElement()) {
                              QDomElement g = list.item(i).toElement();
                                if (g.tagName() == "closed-nodes") {
                                    QDomNodeList list = g.childNodes();
                                    for (int i=0; i<list.count(); ++i) {
                                        if (list.item(i).isElement()) {
                                            QDomElement ei = list.item(i).toElement();
                                            if (ei.tagName() == "node") {
                                                ganttview.closedNodes.append(ei.attribute("id"));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else if (e.tagName() == "accounts-view") {
                        accountsview.accountsviewsize = e.attribute("accountsview-size").toInt();
                        accountsview.periodviewsize = e.attribute("periodview-size").toInt();
                        accountsview.date = QDate::fromString(e.attribute("date"), Qt::ISODate);
                        accountsview.period = e.attribute("period").toInt();
                        accountsview.cumulative = e.attribute("cumulative").toInt();
        
                        QDomNodeList list = e.childNodes();
                        for (int i=0; i<list.count(); ++i) {
                            if (list.item(i).isElement()) {
                                QDomElement g = list.item(i).toElement();
                                if (g.tagName() == "closed-items") {
                                    QDomNodeList list = g.childNodes();
                                    for (int i=0; i<list.count(); ++i) {
                                        if (list.item(i).isElement()) {
                                            QDomElement ei = list.item(i).toElement();
                                            if (ei.tagName() == "account") {
                                                 accountsview.closedItems.append(ei.attribute("name"));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        kError()<<"Unknown tag: "<<e.tagName()<<endl;
                    }
                }
            }*/
        }
    }
    return true;
}