void DocumentStructureTest::multipleDocumentContents()
{
    QString odt = QString(FILES_DATA_DIR) + "/DocumentStructure/multipleDocumentContents.odt";
    QVERIFY(QFile(odt).exists());
    KoDocumentInfo *documentInfo = loadDocumentInfo(odt);
    QVERIFY(documentInfo);
    QCOMPARE(documentInfo->authorInfo("creator"), QString("Majid Ali Khan"));

    // Should probably test if the document loads fine, but then the test would then depend
    // on kotext. See libs/kotext/opendocument/tests/TestLoading.cpp::documentFromOdt.
    delete documentInfo;
}
static KoDocumentInfo *loadDocumentInfo(const QString &odt)
{
    KoStore *store = KoStore::createStore(odt, KoStore::Read, "", KoStore::Zip);
    KoOdfReadStore odfReadStore(store);
    KoXmlDocument metaDoc;
    KoDocumentInfo *documentInfo = new KoDocumentInfo;
    QString error;
    if (!odfReadStore.loadAndParse("meta.xml", metaDoc, error)) {
	delete store;
        delete documentInfo;
        return 0;
    }
    if (!documentInfo->loadOasis(metaDoc)) {
	delete store;
        delete documentInfo;
        return 0;
    }
    delete store;
    return documentInfo;
}
示例#3
0
void KPrWebPresentation::init()
{

    KoDocumentInfo * info = doc->documentInfo();
    KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
    if ( !authorPage )
        kdWarning() << "Author information not found in documentInfo !" << endl;
    else
    {
        author = authorPage->fullName();
        email = authorPage->email();
    }

    title = i18n("Slideshow");
    kdDebug(33001) << "KPrWebPresentation::init : " << doc->getPageNums() << " pages." << endl;
    for ( unsigned int i = 0; i < doc->getPageNums(); i++ )
    {
        if ( doc->isSlideSelected( i ) )
        {
            SlideInfo info;
            info.pageNumber = i;
            info.slideTitle = doc->pageList().at(i)->pageTitle();
            slideInfos.append( info );
        }
    }
    if ( slideInfos.isEmpty() )
        kdWarning() << "No slides selected!" << endl;
    backColor = Qt::white;
    textColor = Qt::black;
    titleColor = Qt::red;

    path = KGlobalSettings::documentPath() + "www";

    zoom = 100;

    timeBetweenSlides = 0;

    m_encoding = QTextCodec::codecForLocale()->name();
}
void DocumentStructureTest::rootAttributes()
{
    QString odt = QString(FILES_DATA_DIR) + "/DocumentStructure/rootAttributes.odt";
    QVERIFY(QFile(odt).exists());
    KoDocumentInfo *documentInfo = loadDocumentInfo(odt);
    QVERIFY(documentInfo);

    QCOMPARE(documentInfo->aboutInfo("creation-date"), QString("2005-12-13T11:59:58"));
    QCOMPARE(documentInfo->aboutInfo("initial-creator"), QString("Majid Ali Khan"));
    QCOMPARE(documentInfo->aboutInfo("date"), QString("2005-12-13T11:59:58"));
    QCOMPARE(documentInfo->aboutInfo("language"), QString("en-US"));
    QCOMPARE(documentInfo->aboutInfo("editing-cycles"), QString("1"));
    QEXPECT_FAIL("", "Not supported", Continue);
    QCOMPARE(documentInfo->aboutInfo("editing-duration"), QString("PT19S"));

    QCOMPARE(documentInfo->authorInfo("creator"), QString("Majid Ali Khan"));
    delete documentInfo;
}
void DocumentStructureTest::predefinedMetaData()
{
    QString odt = QString(FILES_DATA_DIR) + "/DocumentStructure/predefined.odt";
    QVERIFY(QFile(odt).exists());
    KoDocumentInfo *documentInfo = loadDocumentInfo(odt);
    QVERIFY(documentInfo);
    QString keyword = documentInfo->aboutInfo("keyword");
    QStringList keywords = keyword.split(", ");
    QVERIFY(keywords.count() == 3);
    QCOMPARE(keywords[0], QString("First keyword"));
    QCOMPARE(keywords[1], QString("Second keyword"));
    QCOMPARE(keywords[2], QString("Third keyword"));

    // this is not really the point of this test, but I wrote this already. So...
    QCOMPARE(documentInfo->aboutInfo("title"), QString("Meta Test Document"));
    QCOMPARE(documentInfo->aboutInfo("description"), QString("A test document to test meta elements"));
    QCOMPARE(documentInfo->aboutInfo("subject"), QString("Subject of the document"));
    QCOMPARE(documentInfo->aboutInfo("creation-date"), QString("2005-12-19T12:50:56"));
    QCOMPARE(documentInfo->aboutInfo("initial-creator"), QString("Majid Khan"));
    QCOMPARE(documentInfo->aboutInfo("date"), QString("2005-12-19T12:50:56"));

    QCOMPARE(documentInfo->authorInfo("creator"), QString("Majid Khan"));
    delete documentInfo;
}
示例#6
0
KoFilter::ConversionStatus Odp2Kpr::convert( const QByteArray& from, const QByteArray& to )
{
    if ( to != "application/x-kpresenter"
         || from != "application/vnd.oasis.opendocument.presentation" )
        return KoFilter::NotImplemented;

    KoStoreDevice* inpdev = m_chain->storageFile( "content.xml", KoStore::Read );
    if ( !inpdev )
    {
        kError(31000) << "Unable to open input stream";
        return KoFilter::StorageCreationError;
    }

    // Parse presentation content.xml
    QXmlInputSource source( inpdev );
    QXmlSimpleReader reader;
    KoOdfReadStore::setupXmlReader( reader, true /*namespaceProcessing*/ );
    QString errorMsg;
    int errorLine, errorColumn;
    bool ok = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn );
    if ( !ok )
    {
        kError(31000) << "Parsing error! Aborting!" << endl
                      << " In line: " << errorLine << ", column: " << errorColumn << endl
                      << " Error message: " << errorMsg;
        return KoFilter::ParsingError;
    }

    QDomElement docElem = doc.documentElement();
    QDomElement realBody( KoDom::namedItemNS( docElem, KoXmlNS::office, "body" ) );
    if ( realBody.isNull() )
    {
        kError(31000) << "No office:body found!";
        //setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) );
        return KoFilter::WrongFormat;
    }

    QDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "presentation" );
    if ( body.isNull() )
    {
        kError(32001) << "No office:text found!";
        return KoFilter::WrongFormat;
    }

    //now we can transform it.

    //Parse meta.xml directly
    inpdev = m_chain->storageFile( "meta.xml", KoStore::Read );

    KoXmlDocument metaDoc;
    QString errorMessage;
    KoDocumentInfo info;
    if ( KoOdfReadStore::loadAndParse( inpdev, metaDoc, errorMessage, "meta.xml" /*just for debug message*/ ) ) {
         info.loadOasis( metaDoc );
    }

    // Write output file
    KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write );
    if(!out) {
        kError(30502) << "Unable to open output file!";
        return KoFilter::StorageCreationError;
    }
    QByteArray cstring = outdoc.toByteArray(); // utf-8 already
    out->write( cstring.data(), cstring.length() );
    out->close();

    //Write documentinfo.xml
    out = m_chain->storageFile( "documentinfo.xml", KoStore::Write );
    if(!out) {
        kError(30502) << "Unable to open output file!";
        return KoFilter::StorageCreationError;
    }
    QDomDocument doc = info.save();
    QByteArray s = doc.toByteArray(); // this is already Utf8!
    out->write( cstring.data(), cstring.length() );
    out->close();
    return KoFilter::OK;
}
示例#7
0
QString HeaderFooter::completeHeading(const QString &_data, int _page, const QString &_sheet) const
{
    QString page(QString::number(_page));
    QString pages(QString::number(m_pSheet->print()->pageCount()));

    QString pathFileName(m_pSheet->doc()->url().path());
    if (pathFileName.isNull())
        pathFileName = "";

    QString fileName(m_pSheet->doc()->url().fileName());
    if (fileName.isNull())
        fileName = "";

    QString t(QTime::currentTime().toString());
    QString d(QDate::currentDate().toString());
    QString ta;
    if (!_sheet.isEmpty())
        ta = _sheet;

    KoDocumentInfo* info = m_pSheet->doc()->documentInfo();
    QString full_name;
    QString email_addr;
    QString organization;
    QString tmp;
    if (!info)
        kWarning() << "Author information not found in Document Info !";
    else {
        full_name = info->authorInfo("creator");
        email_addr = info->authorInfo("email");
        organization = info->authorInfo("company");
    }

    char hostname[80];
    struct passwd *p;

    p = getpwuid(getuid());
    gethostname(hostname, sizeof(hostname));

    if (full_name.isEmpty())
        full_name = p->pw_gecos;

    if (email_addr.isEmpty())
        email_addr = QString("%1@%2").arg(p->pw_name).arg(hostname);

    tmp = _data;
    int pos = 0;
    while ((pos = tmp.indexOf("<page>", pos)) != -1)
        tmp.replace(pos, 6, page);
    pos = 0;
    while ((pos = tmp.indexOf("<pages>", pos)) != -1)
        tmp.replace(pos, 7, pages);
    pos = 0;
    while ((pos = tmp.indexOf("<file>", pos)) != -1)
        tmp.replace(pos, 6, pathFileName);
    pos = 0;
    while ((pos = tmp.indexOf("<name>", pos)) != -1)
        tmp.replace(pos, 6, fileName);
    pos = 0;
    while ((pos = tmp.indexOf("<time>", pos)) != -1)
        tmp.replace(pos, 6, t);
    pos = 0;
    while ((pos = tmp.indexOf("<date>", pos)) != -1)
        tmp.replace(pos, 6, d);
    pos = 0;
    while ((pos = tmp.indexOf("<author>", pos)) != -1)
        tmp.replace(pos, 8, full_name);
    pos = 0;
    while ((pos = tmp.indexOf("<email>", pos)) != -1)
        tmp.replace(pos, 7, email_addr);
    pos = 0;
    while ((pos = tmp.indexOf("<org>", pos)) != -1)
        tmp.replace(pos, 5, organization);
    pos = 0;
    while ((pos = tmp.indexOf("<sheet>", pos)) != -1)
        tmp.replace(pos, 7, ta);

    return tmp;
}