Subversion Repositories Scribus

Rev

Rev 17170 | Rev 18913 | Go to most recent revision | 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
*/
411 Franz 7
/***************************************************************************
8
 *   Copyright (C) 2004 by Riku Leino                                      *
1157 tsoots 9
 *   tsoots@gmail.com                                                      *
411 Franz 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.             *
411 Franz 25
 ***************************************************************************/
26
 
27
#include "sxwim.h"
10223 cbradney 28
#include <QStringList>
411 Franz 29
 
11918 jghali 30
#ifndef HAVE_XML
31
#error The sxwim plugin requires libxml to build
32
#endif
411 Franz 33
 
2856 cbradney 34
#include "prefsmanager.h"
415 Franz 35
#include <prefsfile.h>
36
#include <prefscontext.h>
37
#include <prefstable.h>
1578 tsoots 38
#include "fileunzip.h"
411 Franz 39
#include "stylereader.h"
40
#include "contentreader.h"
41
#include "sxwdia.h"
42
 
43
QString FileFormatName()
44
{
874 cbradney 45
    return QObject::tr("OpenOffice.org Writer Documents");
411 Franz 46
}
47
 
48
QStringList FileExtensions()
49
{
50
        return QStringList("sxw");
51
}
52
 
53
void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
54
{
456 fschmid 55
        SxwIm* sim = new SxwIm(filename, encoding, writer, textOnly);
411 Franz 56
        delete sim;
57
}
58
 
59
/********** Class SxwIm ************************************************************/
60
 
456 fschmid 61
SxwIm::SxwIm(QString fileName, QString enc, gtWriter* w, bool textOnly)
411 Franz 62
{
2856 cbradney 63
        PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("SxwIm");
415 Franz 64
        bool update = prefs->getBool("update", true);
65
        bool prefix = prefs->getBool("prefix", true);
66
        bool ask = prefs->getBool("askAgain", true);
1157 tsoots 67
        bool pack = prefs->getBool("pack", true);
456 fschmid 68
        encoding = enc;
411 Franz 69
        if (!textOnly)
70
        {
415 Franz 71
                if (ask)
72
                {
1157 tsoots 73
                        SxwDialog* sxwdia = new SxwDialog(update, prefix, pack);
3970 tsoots 74
                        if (sxwdia->exec()) {
75
                                update = sxwdia->shouldUpdate();
76
                                prefix = sxwdia->usePrefix();
77
                                pack = sxwdia->packStyles();
78
                                prefs->set("update", update);
79
                                prefs->set("prefix", sxwdia->usePrefix());
80
                                prefs->set("askAgain", sxwdia->askAgain());
81
                                prefs->set("pack", sxwdia->packStyles());
82
                                delete sxwdia;
83
                        } else {
84
                                delete sxwdia;
85
                                return;
86
                        }
415 Franz 87
                }
411 Franz 88
        }
89
        filename = fileName;
90
        writer = w;
91
        writer->setUpdateParagraphStyles(update);
1578 tsoots 92
        FileUnzip* fun = new FileUnzip(fileName);
93
        stylePath   = fun->getFile(STYLE);
94
        contentPath = fun->getFile(CONTENT);
8623 subik 95
        // Qt4 NULL -> isNull()
96
        if ((!stylePath.isNull()) && (!contentPath.isNull()))
411 Franz 97
        {
10427 cbradney 98
                QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
99
                docname = docname.left(docname.lastIndexOf("."));
1157 tsoots 100
                StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
411 Franz 101
                sreader->parse(stylePath);
102
                ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
103
                creader->parse(contentPath);
104
                delete sreader;
105
                delete creader;
106
        }
17170 fschmid 107
        delete fun;
411 Franz 108
}
109
 
110
SxwIm::~SxwIm()
111
{
112
 
113
}