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;
}
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;
}
Exemplo n.º 4
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;
}