Subversion Repositories Scribus

Rev

Rev 17170 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1579 tsoots 7
/***************************************************************************
8
 *   Copyright (C) 2004 by Riku Leino                                      *
9
 *   tsoots@gmail.com                                                      *
10
 *                                                                         *
11
 *   This program is free software; you can redistribute it and/or modify  *
12
 *   it under the terms of the GNU General Public License as published by  *
13
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 *   (at your option) any later version.                                   *
15
 *                                                                         *
16
 *   This program is distributed in the hope that it will be useful,       *
17
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
 *   GNU General Public License for more details.                          *
20
 *                                                                         *
21
 *   You should have received a copy of the GNU General Public License     *
22
 *   along with this program; if not, write to the                         *
23
 *   Free Software Foundation, Inc.,                                       *
18122 mrdocs 24
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
1579 tsoots 25
 ***************************************************************************/
26
 
27
#include "odtim.h"
10778 craig 28
 
29
#ifndef HAVE_XML
30
#error The odtim plugin requires libxml to build
31
#endif
32
 
10223 cbradney 33
#include <QStringList>
1579 tsoots 34
 
2986 craig 35
#include <scribusstructs.h>
2856 cbradney 36
#include "prefsmanager.h"
1579 tsoots 37
#include <prefsfile.h>
38
#include <prefscontext.h>
39
#include <prefstable.h>
40
#include "fileunzip.h"
41
#include "stylereader.h"
42
#include "contentreader.h"
43
#include "odtdia.h"
44
 
45
QString FileFormatName()
46
{
47
    return QObject::tr("OpenDocument Text Documents");
48
}
49
 
50
QStringList FileExtensions()
51
{
52
        return QStringList("odt");
53
}
54
 
55
void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
56
{
57
        OdtIm* sim = new OdtIm(filename, encoding, writer, textOnly);
58
        delete sim;
59
}
60
 
61
/********** Class OdtIm ************************************************************/
62
 
63
OdtIm::OdtIm(QString fileName, QString enc, gtWriter* w, bool textOnly)
64
{
2856 cbradney 65
        PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("OdtIm");
1579 tsoots 66
        bool update = prefs->getBool("update", true);
67
        bool prefix = prefs->getBool("prefix", true);
68
        bool ask = prefs->getBool("askAgain", true);
69
        bool pack = prefs->getBool("pack", true);
70
        encoding = enc;
71
        if (!textOnly)
72
        {
73
                if (ask)
74
                {
75
                        OdtDialog* sxwdia = new OdtDialog(update, prefix, pack);
3970 tsoots 76
                        if (sxwdia->exec()) {
77
                                update = sxwdia->shouldUpdate();
78
                                prefix = sxwdia->usePrefix();
79
                                pack = sxwdia->packStyles();
80
                                prefs->set("update", update);
81
                                prefs->set("prefix", sxwdia->usePrefix());
82
                                prefs->set("askAgain", sxwdia->askAgain());
83
                                prefs->set("pack", sxwdia->packStyles());
84
                                delete sxwdia;
85
                        } else {
86
                                delete sxwdia;
87
                                return;
88
                        }
1579 tsoots 89
                }
90
        }
91
        filename = fileName;
92
        writer = w;
93
        writer->setUpdateParagraphStyles(update);
94
        FileUnzip* fun = new FileUnzip(fileName);
95
        stylePath   = fun->getFile(STYLE);
96
        contentPath = fun->getFile(CONTENT);
8622 subik 97
        // Qt4 NULL -> isNull()
98
        if ((!stylePath.isNull()) && (!contentPath.isNull()))
1579 tsoots 99
        {
10427 cbradney 100
                QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
101
                docname = docname.left(docname.lastIndexOf("."));
1579 tsoots 102
                StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
103
                sreader->parse(stylePath);
104
                ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
105
                creader->parse(contentPath);
106
                delete sreader;
107
                delete creader;
108
        }
17170 fschmid 109
        delete fun;
1579 tsoots 110
}
111
 
112
OdtIm::~OdtIm()
113
{
114
 
115
}