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 */
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., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************/
26
27 #include "sxwim.h"
28 #include <QStringList>
29 #include <QTemporaryDir>
30
31 #ifndef HAVE_XML
32 #error The sxwim plugin requires libxml to build
33 #endif
34
35 #include "prefsmanager.h"
36 #include <prefsfile.h>
37 #include <prefscontext.h>
38 #include <prefstable.h>
39 #include "stylereader.h"
40 #include "contentreader.h"
41 #include "sxwdia.h"
42 #include "third_party/zip/scribus_zip.h"
43
FileFormatName()44 QString FileFormatName()
45 {
46 return QObject::tr("OpenOffice.org Writer Documents");
47 }
48
FileExtensions()49 QStringList FileExtensions()
50 {
51 return QStringList("sxw");
52 }
53
GetText(const QString & filename,const QString & encoding,bool textOnly,gtWriter * writer)54 void GetText(const QString& filename, const QString& encoding, bool textOnly, gtWriter *writer)
55 {
56 SxwIm* sim = new SxwIm(filename, encoding, writer, textOnly);
57 delete sim;
58 }
59
60 /********** Class SxwIm ************************************************************/
61
SxwIm(const QString & fileName,const QString & enc,gtWriter * w,bool textOnly)62 SxwIm::SxwIm(const QString& fileName, const QString& enc, gtWriter* w, bool textOnly)
63 {
64 PrefsContext* prefs = PrefsManager::instance().prefsFile->getPluginContext("SxwIm");
65 bool update = prefs->getBool("update", true);
66 bool prefix = prefs->getBool("prefix", true);
67 bool ask = prefs->getBool("askAgain", true);
68 bool pack = prefs->getBool("pack", true);
69 encoding = enc;
70 writer = w;
71 if (!textOnly)
72 {
73 if (ask)
74 {
75 SxwDialog* sxwdia = new SxwDialog(update, prefix, pack);
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 }
89 }
90 }
91 filename = fileName;
92 writer->setUpdateParagraphStyles(update);
93 ScZipHandler* fun = new ScZipHandler();
94 if (fun->open(fileName))
95 {
96 const QString STYLE = "styles.xml";
97 const QString CONTENT = "content.xml";
98 QTemporaryDir *dir = new QTemporaryDir();
99 QString baseDir = dir->path();
100 fun->extract(STYLE, baseDir, ScZipHandler::SkipPaths);
101 fun->extract(CONTENT, baseDir, ScZipHandler::SkipPaths);
102 stylePath = baseDir + "/" + STYLE;
103 contentPath = baseDir + "/" + CONTENT;
104 if ((!stylePath.isNull()) && (!contentPath.isNull()))
105 {
106 QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
107 docname = docname.left(docname.lastIndexOf("."));
108 StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
109 sreader->parse(stylePath);
110 ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
111 creader->parse(contentPath);
112 delete sreader;
113 delete creader;
114 }
115 delete dir;
116 }
117 delete fun;
118 }
119
~SxwIm()120 SxwIm::~SxwIm()
121 {
122
123 }
124