r18913 by fschmid - Removed old FileUnzip class and replaced its uses with the new ScZipHandler class
scribus-commit
scribus-commit at lists.scribus.net
Sat Mar 15 09:50:50 UTC 2014
Author: fschmid
Date: Sat Mar 15 09:50:50 2014
New Revision: 18913
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18913
Log:
Removed old FileUnzip class and replaced its uses with the new ScZipHandler class
Modified:
trunk/Scribus/scribus/CMakeLists.txt
trunk/Scribus/scribus/fileunzip.cpp
trunk/Scribus/scribus/fileunzip.h
trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp
trunk/Scribus/scribus/plugins/gettext/sxwim/sxwim.cpp
trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
trunk/Scribus/scribus/plugins/import/idml/importidml.h
trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.h
trunk/Scribus/scribus/third_party/zip/scribus_zip.cpp
trunk/Scribus/scribus/third_party/zip/scribus_zip.h
trunk/Scribus/scribus/ui/prefs_spelling.cpp
trunk/Scribus/scribus/unzip.c
trunk/Scribus/scribus/unzip.h
Modified: trunk/Scribus/scribus/CMakeLists.txt
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/CMakeLists.txt
==============================================================================
--- trunk/Scribus/scribus/CMakeLists.txt (original)
+++ trunk/Scribus/scribus/CMakeLists.txt Sat Mar 15 09:50:50 2014
@@ -557,7 +557,6 @@
exif.cpp
fileloader.cpp
filesearch.cpp
- fileunzip.cpp
filewatcher.cpp
ui/fontcombo.cpp
fontlistmodel.cpp
@@ -702,7 +701,6 @@
undostack.cpp
undostate.cpp
units.cpp
- unzip.c
updatemanager.cpp
upgradechecker.cpp
urllauncher.cpp
Modified: trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp (original)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp Sat Mar 15 09:50:50 2014
@@ -31,16 +31,17 @@
#endif
#include <QStringList>
+#include <QTemporaryDir>
#include <scribusstructs.h>
#include "prefsmanager.h"
#include <prefsfile.h>
#include <prefscontext.h>
#include <prefstable.h>
-#include "fileunzip.h"
#include "stylereader.h"
#include "contentreader.h"
#include "odtdia.h"
+#include "third_party/zip/scribus_zip.h"
QString FileFormatName()
{
@@ -91,20 +92,27 @@
filename = fileName;
writer = w;
writer->setUpdateParagraphStyles(update);
- FileUnzip* fun = new FileUnzip(fileName);
- stylePath = fun->getFile(STYLE);
- contentPath = fun->getFile(CONTENT);
- // Qt4 NULL -> isNull()
- if ((!stylePath.isNull()) && (!contentPath.isNull()))
+ ScZipHandler* fun = new ScZipHandler();
+ if (fun->open(fileName))
{
- QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
- docname = docname.left(docname.lastIndexOf("."));
- StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
- sreader->parse(stylePath);
- ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
- creader->parse(contentPath);
- delete sreader;
- delete creader;
+ QTemporaryDir *dir = new QTemporaryDir();
+ QString baseDir = dir->path();
+ fun->extract(STYLE, baseDir);
+ fun->extract(CONTENT, baseDir);
+ stylePath = baseDir + "/" + STYLE;
+ contentPath = baseDir + "/" + CONTENT;
+ if ((!stylePath.isNull()) && (!contentPath.isNull()))
+ {
+ QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
+ docname = docname.left(docname.lastIndexOf("."));
+ StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
+ sreader->parse(stylePath);
+ ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
+ creader->parse(contentPath);
+ delete sreader;
+ delete creader;
+ }
+ delete dir;
}
delete fun;
}
Modified: trunk/Scribus/scribus/plugins/gettext/sxwim/sxwim.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/plugins/gettext/sxwim/sxwim.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/sxwim/sxwim.cpp (original)
+++ trunk/Scribus/scribus/plugins/gettext/sxwim/sxwim.cpp Sat Mar 15 09:50:50 2014
@@ -26,6 +26,7 @@
#include "sxwim.h"
#include <QStringList>
+#include <QTemporaryDir>
#ifndef HAVE_XML
#error The sxwim plugin requires libxml to build
@@ -35,10 +36,10 @@
#include <prefsfile.h>
#include <prefscontext.h>
#include <prefstable.h>
-#include "fileunzip.h"
#include "stylereader.h"
#include "contentreader.h"
#include "sxwdia.h"
+#include "third_party/zip/scribus_zip.h"
QString FileFormatName()
{
@@ -89,20 +90,27 @@
filename = fileName;
writer = w;
writer->setUpdateParagraphStyles(update);
- FileUnzip* fun = new FileUnzip(fileName);
- stylePath = fun->getFile(STYLE);
- contentPath = fun->getFile(CONTENT);
- // Qt4 NULL -> isNull()
- if ((!stylePath.isNull()) && (!contentPath.isNull()))
+ ScZipHandler* fun = new ScZipHandler();
+ if (fun->open(fileName))
{
- QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
- docname = docname.left(docname.lastIndexOf("."));
- StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
- sreader->parse(stylePath);
- ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
- creader->parse(contentPath);
- delete sreader;
- delete creader;
+ QTemporaryDir *dir = new QTemporaryDir();
+ QString baseDir = dir->path();
+ fun->extract(STYLE, baseDir);
+ fun->extract(CONTENT, baseDir);
+ stylePath = baseDir + "/" + STYLE;
+ contentPath = baseDir + "/" + CONTENT;
+ if ((!stylePath.isNull()) && (!contentPath.isNull()))
+ {
+ QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
+ docname = docname.left(docname.lastIndexOf("."));
+ StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
+ sreader->parse(stylePath);
+ ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
+ creader->parse(contentPath);
+ delete sreader;
+ delete creader;
+ }
+ delete dir;
}
delete fun;
}
Modified: trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/idml/importidml.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/idml/importidml.cpp Sat Mar 15 09:50:50 2014
@@ -105,25 +105,28 @@
{
QImage tmp;
QByteArray f;
- QString designMap;
if ( !QFile::exists(fName) )
return QImage();
QFileInfo fi = QFileInfo(fName);
QString ext = fi.suffix().toLower();
if (ext == "idml")
{
- fun = new FileUnzip(fName);
- designMap = fun->getFile("designmap.xml");
+ fun = new ScZipHandler();
+ if (!fun->open(fName))
+ {
+ delete fun;
+ return QImage();
+ }
+ if (fun->contains("designmap.xml"))
+ fun->read("designmap.xml", f);
+ delete fun;
}
else if (ext == "idms")
{
- designMap = fName;
- fun = NULL;
- }
- if (!designMap.isNull())
- {
- loadRawText(designMap, f);
- delete fun;
+ loadRawText(fName, f);
+ }
+ if (!f.isEmpty())
+ {
if(!designMapDom.setContent(f))
return QImage();
bool found = false;
@@ -220,22 +223,25 @@
m_Doc->addPage(0);
m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0);
QByteArray f;
- QString designMap;
QFileInfo fi = QFileInfo(fNameIn);
QString ext = fi.suffix().toLower();
if (ext == "idml")
{
- fun = new FileUnzip(fNameIn);
- designMap = fun->getFile("designmap.xml");
+ fun = new ScZipHandler();
+ if (!fun->open(fNameIn))
+ {
+ delete fun;
+ return false;
+ }
+ if (fun->contains("designmap.xml"))
+ fun->read("designmap.xml", f);
}
else if (ext == "idms")
{
- designMap = fNameIn;
- fun = NULL;
- }
- if (!designMap.isNull())
- {
- loadRawText(designMap, f);
+ loadRawText(fNameIn, f);
+ }
+ if (!f.isEmpty())
+ {
if(designMapDom.setContent(f))
{
QDomElement docElem = designMapDom.documentElement();
@@ -510,22 +516,25 @@
bool retVal = true;
bool firstSpread = true;
QByteArray f;
- QString designMap;
QFileInfo fi = QFileInfo(fn);
QString ext = fi.suffix().toLower();
if (ext == "idml")
{
- fun = new FileUnzip(fn);
- designMap = fun->getFile("designmap.xml");
+ fun = new ScZipHandler();
+ if (!fun->open(fn))
+ {
+ delete fun;
+ return false;
+ }
+ if (fun->contains("designmap.xml"))
+ fun->read("designmap.xml", f);
}
else if (ext == "idms")
{
- designMap = fn;
- fun = NULL;
- }
- if (!designMap.isNull())
- {
- loadRawText(designMap, f);
+ loadRawText(fn, f);
+ }
+ if (!f.isEmpty())
+ {
if(designMapDom.setContent(f))
{
QDomElement docElem = designMapDom.documentElement();
@@ -690,7 +699,7 @@
if (grElem.hasAttribute("src"))
{
QByteArray f2;
- loadRawText(fun->getFile(grElem.attribute("src")), f2);
+ fun->read(grElem.attribute("src"), f2);
if(grMapDom.setContent(f2))
grNode = grMapDom.documentElement();
else
@@ -738,7 +747,7 @@
if (grElem.hasAttribute("src"))
{
QByteArray f2;
- loadRawText(fun->getFile(grElem.attribute("src")), f2);
+ fun->read(grElem.attribute("src"), f2);
if(grMapDom.setContent(f2))
grNode = grMapDom.documentElement();
else
@@ -864,7 +873,7 @@
if (sElem.hasAttribute("src"))
{
QByteArray f2;
- loadRawText(fun->getFile(sElem.attribute("src")), f2);
+ fun->read(sElem.attribute("src"), f2);
if(sMapDom.setContent(f2))
sNode = sMapDom.documentElement();
else
@@ -1287,7 +1296,7 @@
if (prElem.hasAttribute("src"))
{
QByteArray f2;
- loadRawText(fun->getFile(prElem.attribute("src")), f2);
+ fun->read(prElem.attribute("src"), f2);
if(prMapDom.setContent(f2))
prNode = prMapDom.documentElement();
else
@@ -1500,7 +1509,7 @@
if (spElem.hasAttribute("src"))
{
QByteArray f2;
- loadRawText(fun->getFile(spElem.attribute("src")), f2);
+ fun->read(spElem.attribute("src"), f2);
if(spMapDom.setContent(f2))
spNode = spMapDom.documentElement();
else
@@ -2690,7 +2699,7 @@
if (stElem.hasAttribute("src"))
{
QByteArray f2;
- loadRawText(fun->getFile(stElem.attribute("src")), f2);
+ fun->read(stElem.attribute("src"), f2);
if(stMapDom.setContent(f2))
stNode = stMapDom.documentElement();
else
Modified: trunk/Scribus/scribus/plugins/import/idml/importidml.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/plugins/import/idml/importidml.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/idml/importidml.h (original)
+++ trunk/Scribus/scribus/plugins/import/idml/importidml.h Sat Mar 15 09:50:50 2014
@@ -16,7 +16,6 @@
#include "pluginapi.h"
#include "pageitem.h"
#include "sccolor.h"
-#include "fileunzip.h"
#include "fpointarray.h"
#include <QList>
#include <QTransform>
@@ -26,6 +25,8 @@
#include <QString>
#include <QDomDocument>
#include <QDomElement>
+
+#include "third_party/zip/scribus_zip.h"
class MultiProgressDialog;
class ScribusDoc;
@@ -186,7 +187,7 @@
QMap<QString, PageItem*> frameTargets;
QMap<QString, ObjectStyle> ObjectStyles;
- FileUnzip *fun;
+ ScZipHandler *fun;
public slots:
void cancelRequested() { cancel = true; }
Modified: trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp Sat Mar 15 09:50:50 2014
@@ -22,7 +22,6 @@
#include "color.h"
#include "commonstrings.h"
-#include "fileunzip.h"
#include "fpointarray.h"
#include "ui/scmwmenumanager.h"
#include "pageitem.h"
@@ -47,6 +46,7 @@
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
+#include "third_party/zip/scribus_zip.h"
using namespace std;
@@ -242,26 +242,26 @@
QByteArray f, f2, f3;
if ( !QFile::exists(fileName) )
return QImage();
- FileUnzip* fun = new FileUnzip(fileName);
- stylePath = fun->getFile("styles.xml");
- contentPath = fun->getFile("content.xml");
- metaPath = fun->getFile("meta.xml");
- // Qt4 NULL -> isNull()
- if ((!stylePath.isNull()) && (!contentPath.isNull()))
- {
- HaveMeta = false;
- QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
- docname = docname.left(docname.lastIndexOf("."));
- loadRawText(stylePath, f);
- loadRawText(contentPath, f2);
- HaveMeta = false;
- if (!metaPath.isEmpty())
- {
- loadRawText(metaPath, f3);
- HaveMeta = inpMeta.setContent(f3);
- }
- }
+ ScZipHandler* fun = new ScZipHandler();
+ if (!fun->open(fileName))
+ {
+ delete fun;
+ return QImage();
+ }
+ if (fun->contains("styles.xml"))
+ fun->read("styles.xml", f);
+ if (fun->contains("content.xml"))
+ fun->read("content.xml", f2);
+ if (fun->contains("meta.xml"))
+ fun->read("meta.xml", f3);
delete fun;
+ HaveMeta = inpMeta.setContent(f3);
+ QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
+ docname = docname.left(docname.lastIndexOf("."));
+ if (f.isEmpty())
+ return QImage();
+ if (f2.isEmpty())
+ return QImage();
if(!inpStyles.setContent(f))
return QImage();
if(!inpContents.setContent(f2))
@@ -365,26 +365,26 @@
QByteArray f, f2, f3;
if ( !QFile::exists(fileName) )
return false;
- FileUnzip* fun = new FileUnzip(fileName);
- stylePath = fun->getFile("styles.xml");
- contentPath = fun->getFile("content.xml");
- metaPath = fun->getFile("meta.xml");
- // Qt4 NULL -> isNull()
- if ((!stylePath.isNull()) && (!contentPath.isNull()))
- {
- HaveMeta = false;
- QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
- docname = docname.left(docname.lastIndexOf("."));
- loadRawText(stylePath, f);
- loadRawText(contentPath, f2);
- HaveMeta = false;
- if (!metaPath.isEmpty())
- {
- loadRawText(metaPath, f3);
- HaveMeta = inpMeta.setContent(f3);
- }
- }
+ ScZipHandler* fun = new ScZipHandler();
+ if (!fun->open(fileName))
+ {
+ delete fun;
+ return false;
+ }
+ if (fun->contains("styles.xml"))
+ fun->read("styles.xml", f);
+ if (fun->contains("content.xml"))
+ fun->read("content.xml", f2);
+ if (fun->contains("meta.xml"))
+ fun->read("meta.xml", f3);
delete fun;
+ HaveMeta = inpMeta.setContent(f3);
+ QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
+ docname = docname.left(docname.lastIndexOf("."));
+ if (f.isEmpty())
+ return false;
+ if (f2.isEmpty())
+ return false;
if(!inpStyles.setContent(f))
return false;
if(!inpContents.setContent(f2))
Modified: trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.h (original)
+++ trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.h Sat Mar 15 09:50:50 2014
@@ -146,9 +146,6 @@
QDomDocument inpMeta;
QHash<QString,QDomElement*> m_styles, m_draws;
StyleStack m_styleStack;
- QString stylePath;
- QString contentPath;
- QString metaPath;
double CurrX, CurrY, StartX, StartY;
int PathLen;
bool FirstM, WasM, PathClosed, HaveMeta;
Modified: trunk/Scribus/scribus/third_party/zip/scribus_zip.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/third_party/zip/scribus_zip.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/zip/scribus_zip.cpp (original)
+++ trunk/Scribus/scribus/third_party/zip/scribus_zip.cpp Sat Mar 15 09:50:50 2014
@@ -23,6 +23,7 @@
#include "unzip.h"
#include "scribus_zip.h"
#include "util.h"
+#include "scpaths.h"
ScZipHandler::ScZipHandler(bool forWrite)
{
@@ -109,6 +110,29 @@
return retVal;
}
+bool ScZipHandler::extract(QString name, QString path)
+{
+ bool retVal = false;
+ if (m_uz != NULL)
+ {
+ QString pwd = QDir::currentPath();
+ QString outDir;
+ if (path.isNull())
+ outDir = ScPaths::getTempFileDir();
+ else
+ outDir=path;
+ QFile f(outDir);
+ QFileInfo fi(f);
+ if (!fi.isWritable())
+ outDir = ScPaths::getApplicationDataDir();
+ QDir::setCurrent(outDir);
+ UnZip::ErrorCode ec = m_uz->extractFile(name, outDir, UnZip::SkipPaths);
+ retVal = (ec == UnZip::Ok);
+ QDir::setCurrent(pwd);
+ }
+ return retVal;
+}
+
QStringList ScZipHandler::files()
{
QStringList retVal = QStringList();
Modified: trunk/Scribus/scribus/third_party/zip/scribus_zip.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/third_party/zip/scribus_zip.h
==============================================================================
--- trunk/Scribus/scribus/third_party/zip/scribus_zip.h (original)
+++ trunk/Scribus/scribus/third_party/zip/scribus_zip.h Sat Mar 15 09:50:50 2014
@@ -35,6 +35,7 @@
bool contains(QString fileName);
bool read(QString fileName, QByteArray &buf);
bool write(QString dirName);
+ bool extract(QString name, QString path);
QStringList files();
private:
UnZip* m_uz;
Modified: trunk/Scribus/scribus/ui/prefs_spelling.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18913&path=/trunk/Scribus/scribus/ui/prefs_spelling.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_spelling.cpp (original)
+++ trunk/Scribus/scribus/ui/prefs_spelling.cpp Sat Mar 15 09:50:50 2014
@@ -17,13 +17,13 @@
#include "prefs_spelling.h"
-#include "fileunzip.h"
#include "langmgr.h"
#include "prefsstructs.h"
#include "scribusdoc.h"
#include "util_icon.h"
#include "util.h"
#include "util_file.h"
+#include "third_party/zip/scribus_zip.h"
#include "scribusapp.h"
#include "scpaths.h"
@@ -185,13 +185,17 @@
if (d.filetype=="zip")
{
//qDebug()<<"zip data found"<<filename;
- FileUnzip fun(filename);
- foreach (QString s, files)
- {
- //qDebug()<<"Unzipping"<<userDictDir+s;
- QString data = fun.getFileToPath(s, userDictDir);
- allFileList.removeOne(s);
- }
+ ScZipHandler* fun = new ScZipHandler();
+ if (fun->open(filename))
+ {
+ foreach (QString s, files)
+ {
+ //qDebug()<<"Unzipping"<<userDictDir+s;
+ fun->extract(s, userDictDir);
+ allFileList.removeOne(s);
+ }
+ }
+ delete fun;
}
if (d.filetype=="plain")
{
@@ -324,4 +328,4 @@
return file;
}
return QString();
-}
+}
More information about the scribus-commit
mailing list