File: KoDocumentInfoPropsPage.cpp

package info (click to toggle)
calligra 1%3A3.1.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 308,444 kB
  • sloc: cpp: 644,218; xml: 27,515; python: 6,058; perl: 2,724; yacc: 1,817; ansic: 1,310; sh: 1,247; lex: 1,107; ruby: 1,018; makefile: 34
file content (102 lines) | stat: -rw-r--r-- 3,050 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* This file is part of the KDE project
   Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
   Copyright (C) 2004, 2010 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "KoDocumentInfoPropsPage.h"

#include <QIcon>

#include "KoOdfReadStore.h"
#include "KoStore.h"
#include "KoDocumentInfo.h"
#include "KoDocumentInfoDlg.h"
#include <QUrl>
#include <WidgetsDebug.h>

class KoDocumentInfoPropsPage::KoDocumentInfoPropsPagePrivate
{
public:
    KoDocumentInfo *m_info;
    KoDocumentInfoDlg *m_dlg;
    QUrl m_url;
    KoStore *m_src;
    KoStore *m_dst;
};

KoDocumentInfoPropsPage::KoDocumentInfoPropsPage(KPropertiesDialog *props,
        const QVariantList &)
        : KPropertiesDialogPlugin(props)
        , d(new KoDocumentInfoPropsPagePrivate)
{
    d->m_info = new KoDocumentInfo(this);
    d->m_url = props->item().url();
    d->m_dlg = 0;

    if (!d->m_url.isLocalFile())
        return;

    d->m_dst = 0;

    d->m_src = KoStore::createStore(d->m_url.toLocalFile(), KoStore::Read);

    if (d->m_src->bad()) {
        return; // the store will be deleted in the dtor
    }

    // OASIS/OOo file format?
    if (d->m_src->hasFile("meta.xml")) {
        KoXmlDocument metaDoc;
        KoOdfReadStore oasisStore(d->m_src);
        QString lastErrorMessage;
        if (oasisStore.loadAndParse("meta.xml", metaDoc, lastErrorMessage)) {
            d->m_info->loadOasis(metaDoc);
        }
    }
    // Old calligra file format?
    else if (d->m_src->hasFile("documentinfo.xml")) {
        if (d->m_src->open("documentinfo.xml")) {
            KoXmlDocument doc;
            if (doc.setContent(d->m_src->device()))
                d->m_info->load(doc);
        }
    }

    d->m_dlg = new KoDocumentInfoDlg(props, d->m_info);
    d->m_dlg->setReadOnly(true);
    // "Steal" the pages from the document info dialog
    Q_FOREACH(KPageWidgetItem* page, d->m_dlg->pages()) {
        KPageWidgetItem* myPage = new KPageWidgetItem(page->widget(), page->header());
        myPage->setIcon(page->icon());
        props->addPage(myPage);
    }
}

KoDocumentInfoPropsPage::~KoDocumentInfoPropsPage()
{
    delete d->m_info;
    delete d->m_src;
    delete d->m_dst;
    delete d->m_dlg;
    delete d;
}

void KoDocumentInfoPropsPage::applyChanges()
{
    // Unused in Calligra
}