parent
5cea797ef1
commit
b4bb6f0510
@ -1,69 +0,0 @@ |
|||||||
#------------------------------------------------- |
|
||||||
# |
|
||||||
# Project created by QtCreator 2012-02-14T13:30:14 |
|
||||||
# |
|
||||||
#------------------------------------------------- |
|
||||||
|
|
||||||
TARGET = CFF_Adaptor |
|
||||||
TEMPLATE = lib |
|
||||||
|
|
||||||
win32: SUB_DIR = win32 |
|
||||||
macx: SUB_DIR = macx |
|
||||||
linux-g++: SUB_DIR = linux |
|
||||||
linux-g++-32: SUB_DIR = linux |
|
||||||
linux-g++-64: SUB_DIR = linux |
|
||||||
|
|
||||||
THIRD_PARTY_PATH = ../../../Sankore-ThirdParty |
|
||||||
QUAZIP_DIR = "$$PWD/../../../Sankore-ThirdParty/quazip/quazip-0.3" |
|
||||||
|
|
||||||
BUILD_DIR = build/$$SUB_DIR |
|
||||||
CONFIG(debug, debug|release):BUILD_DIR = $$BUILD_DIR/debug |
|
||||||
CONFIG(release, debug|release) { |
|
||||||
BUILD_DIR = $$BUILD_DIR/release |
|
||||||
CONFIG += warn_off |
|
||||||
} |
|
||||||
|
|
||||||
win32{ |
|
||||||
CONFIG += dll |
|
||||||
} |
|
||||||
|
|
||||||
OBJECTS_DIR = $$BUILD_DIR/objects |
|
||||||
MOC_DIR = $$BUILD_DIR/moc |
|
||||||
DESTDIR = $$BUILD_DIR/lib |
|
||||||
RCC_DIR = $$BUILD_DIR/rcc |
|
||||||
SANKORE_DIR = ../.. |
|
||||||
win32:{ |
|
||||||
QMAKE_POST_LINK += copy $$replace(DESTDIR,/,\\)\\CFF_Adaptor.dll" $$replace(SANKORE_DIR,/,\\)\\CFF_Adaptor.dll /y" |
|
||||||
} |
|
||||||
macx:{ |
|
||||||
QMAKE_POST_LINK += bash postScript_mac.sh "$$DESTDIR" "$$SANKORE_DIR/$$BUILD_DIR/product/Open-Sankore.app/Contents/MacOS" |
|
||||||
} |
|
||||||
|
|
||||||
LIBS += "-L$$THIRD_PARTY_PATH/quazip/lib/$$SUB_DIR" "-lquazip" |
|
||||||
|
|
||||||
QT += xml xmlpatterns core |
|
||||||
QT += gui |
|
||||||
QT += svg |
|
||||||
|
|
||||||
|
|
||||||
DEFINES += UBCFFADAPTOR_LIBRARY |
|
||||||
DEFINES += NO_THIRD_PARTY_WARNINGS |
|
||||||
|
|
||||||
INCLUDEPATH += src |
|
||||||
|
|
||||||
DEPENDPATH += $$THIRD_PARTY_PATH/quazip/ |
|
||||||
INCLUDEPATH += $$THIRD_PARTY_PATH/quazip/ |
|
||||||
include($$THIRD_PARTY_PATH/quazip/quazip.pri) |
|
||||||
|
|
||||||
|
|
||||||
SOURCES += \ |
|
||||||
src/UBCFFAdaptor.cpp |
|
||||||
|
|
||||||
HEADERS +=\ |
|
||||||
$$PWD/../../src/globals/UBGlobals.h \ |
|
||||||
src/UBCFFAdaptor.h \ |
|
||||||
src/UBCFFAdaptor_global.h \ |
|
||||||
src/UBCFFConstants.h |
|
||||||
|
|
||||||
RESOURCES += \ |
|
||||||
resources/resources.qrc |
|
@ -1,5 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
SOURCE=$1 |
|
||||||
DESTINATION=$2 |
|
||||||
mkdir -p $DESTINATION |
|
||||||
cp -R $SOURCE/ $DESTINATION |
|
Before Width: | Height: | Size: 572 B |
@ -1,5 +0,0 @@ |
|||||||
<RCC> |
|
||||||
<qresource prefix="/"> |
|
||||||
<file>images/soundOn.svg</file> |
|
||||||
</qresource> |
|
||||||
</RCC> |
|
File diff suppressed because it is too large
Load Diff
@ -1,179 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBCFFADAPTOR_H |
|
||||||
#define UBCFFADAPTOR_H |
|
||||||
|
|
||||||
#include "UBCFFAdaptor_global.h" |
|
||||||
|
|
||||||
#include <QtCore> |
|
||||||
|
|
||||||
class QTransform; |
|
||||||
class QDomDocument; |
|
||||||
class QDomElement; |
|
||||||
class QDomNode; |
|
||||||
class QuaZipFile; |
|
||||||
|
|
||||||
class UBCFFADAPTORSHARED_EXPORT UBCFFAdaptor { |
|
||||||
class UBToCFFConverter; |
|
||||||
|
|
||||||
public: |
|
||||||
UBCFFAdaptor(); |
|
||||||
~UBCFFAdaptor(); |
|
||||||
|
|
||||||
bool convertUBZToIWB(const QString &from, const QString &to); |
|
||||||
bool deleteDir(const QString& pDirPath) const; |
|
||||||
QList<QString> getConversionMessages(); |
|
||||||
|
|
||||||
private: |
|
||||||
QString uncompressZip(const QString &zipFile); |
|
||||||
bool compressZip(const QString &source, const QString &destination); |
|
||||||
bool compressDir(const QString &dirName, const QString &parentDir, QuaZipFile *outZip); |
|
||||||
bool compressFile(const QString &fileName, const QString &parentDir, QuaZipFile *outZip); |
|
||||||
|
|
||||||
QString createNewTmpDir(); |
|
||||||
bool freeDir(const QString &dir); |
|
||||||
void freeTmpDirs(); |
|
||||||
|
|
||||||
private: |
|
||||||
QStringList tmpDirs; |
|
||||||
QList<QString> mConversionMessages; |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
class UBToCFFConverter { |
|
||||||
|
|
||||||
static const int DEFAULT_LAYER = -100000; |
|
||||||
|
|
||||||
public: |
|
||||||
UBToCFFConverter(const QString &source, const QString &destination); |
|
||||||
~UBToCFFConverter(); |
|
||||||
bool isValid() const; |
|
||||||
QString lastErrStr() const {return errorStr;} |
|
||||||
bool parse(); |
|
||||||
QList<QString> getMessages() {return mExportErrorList;} |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
void addLastExportError(QString error) {mExportErrorList.append(error);} |
|
||||||
|
|
||||||
void fillNamespaces(); |
|
||||||
|
|
||||||
bool parseMetadata(); |
|
||||||
bool parseContent(); |
|
||||||
QDomElement parsePageset(const QStringList &pageFileNames); |
|
||||||
QDomElement parsePage(const QString &pageFileName); |
|
||||||
QDomElement parseSvgPageSection(const QDomElement &element); |
|
||||||
void writeQDomElementToXML(const QDomNode &node); |
|
||||||
bool writeExtendedIwbSection(); |
|
||||||
QDomElement parseGroupsPageSection(const QDomElement &groupRoot); |
|
||||||
|
|
||||||
bool createBackground(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
QString createBackgroundImage(const QDomElement &element, QSize size); |
|
||||||
bool createPngFromSvg(QString &svgPath, QString &dstPath, QTransform transformation, QSize size = QSize()); |
|
||||||
|
|
||||||
bool parseSVGGGroup(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseUBZImage(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseUBZVideo(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseUBZAudio(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseForeignObject(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseUBZText(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
|
|
||||||
bool parseUBZPolygon(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseUBZPolyline(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
bool parseUBZLine(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); |
|
||||||
void addSVGElementToResultModel(const QDomElement &element, QMultiMap<int, QDomElement> &dstList, int layer = DEFAULT_LAYER); |
|
||||||
void addIWBElementToResultModel(const QDomElement &element); |
|
||||||
|
|
||||||
qreal getAngleFromTransform(const QTransform &tr); |
|
||||||
QString getDstContentFolderName(const QString &elementType); |
|
||||||
QString getSrcContentFolderName(QString href); |
|
||||||
QString getFileNameFromPath(QString sPath); |
|
||||||
QString getExtentionFromFileName(const QString &filename); |
|
||||||
QString convertExtention(const QString &ext); |
|
||||||
QString getElementTypeFromUBZ(const QDomElement &element); |
|
||||||
|
|
||||||
int getElementLayer(const QDomElement &element); |
|
||||||
|
|
||||||
bool itIsSupportedFormat(const QString &format) const; |
|
||||||
bool itIsFormatToConvert(const QString &format) const; |
|
||||||
bool itIsSVGElementAttribute(const QString ItemType, const QString &AttrName); |
|
||||||
bool itIsIWBAttribute(const QString &attribute) const; |
|
||||||
bool itIsUBZAttributeToConvert(const QString &attribute) const; |
|
||||||
|
|
||||||
bool ibwAddLine(int x1, int y1, int x2, int y2, QString color=QString(), int width=1, bool isBackground=false); |
|
||||||
|
|
||||||
QTransform getTransformFromUBZ(const QDomElement &ubzElement); |
|
||||||
void setGeometryFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement); |
|
||||||
void setCoordinatesFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement); |
|
||||||
bool setContentFromUBZ(const QDomElement &ubzElement, QDomElement &svgElement); |
|
||||||
void setCFFTextFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement); |
|
||||||
void setCFFTextFromHTMLTextNode(const QDomElement htmlTextNode, QDomElement &iwbElement); |
|
||||||
QString ubzAttrNameToCFFAttrName(QString cffAttrName); |
|
||||||
QString ubzAttrValueToCFFAttrName(QString cffAttrValue); |
|
||||||
|
|
||||||
bool setCFFAttribute(const QString &attributeName, const QString &attributeValue, const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement); |
|
||||||
bool setCommonAttributesFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement); |
|
||||||
void setViewBox(QRect viewbox); |
|
||||||
|
|
||||||
QDomNode findTextNode(const QDomNode &node); |
|
||||||
QDomNode findNodeByTagName(const QDomNode &node, QString tagName); |
|
||||||
|
|
||||||
QSize getSVGDimentions(const QString &element); |
|
||||||
|
|
||||||
inline QRect getViewboxRect(const QString &element) const; |
|
||||||
inline QString rectToIWBAttr(const QRect &rect) const; |
|
||||||
inline QString digitFileFormat(int num) const; |
|
||||||
inline bool strToBool(const QString &in) const {return in == "true";} |
|
||||||
QString contentIWBFileName() const; |
|
||||||
|
|
||||||
private: |
|
||||||
QList<QString> mExportErrorList; |
|
||||||
QMap<QString, QString> iwbSVGItemsAttributes; |
|
||||||
QDomDocument *mDataModel; //model for reading indata
|
|
||||||
QXmlStreamWriter *mIWBContentWriter; //stream to write outdata
|
|
||||||
QSize mSVGSize; //svg page size
|
|
||||||
QRect mViewbox; //Main viewbox parameter for CFF
|
|
||||||
QString sourcePath; // dir with unpacked source data (ubz)
|
|
||||||
QString destinationPath; //dir with unpacked destination data (iwb)
|
|
||||||
QDomDocument *mDocumentToWrite; //document for saved QDomElements from mSvgElements and mExtendedElements
|
|
||||||
QMultiMap<int, QDomElement> mSvgElements; //Saving svg elements to have a sorted by z order list of elements to write;
|
|
||||||
QList<QDomElement> mExtendedElements; //Saving extended options of elements to be able to add them to the end of result iwb document;
|
|
||||||
mutable QString errorStr; // last error string message
|
|
||||||
|
|
||||||
public: |
|
||||||
operator bool() const {return isValid();} |
|
||||||
}; |
|
||||||
|
|
||||||
class UBToUBZConverter { |
|
||||||
public: |
|
||||||
UBToUBZConverter(); |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBCFFADAPTOR_H
|
|
@ -1,38 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBCFFADAPTOR_GLOBAL_H |
|
||||||
#define UBCFFADAPTOR_GLOBAL_H |
|
||||||
|
|
||||||
#include <QtCore/qglobal.h> |
|
||||||
|
|
||||||
#if defined(UBCFFADAPTOR_LIBRARY) |
|
||||||
# define UBCFFADAPTORSHARED_EXPORT Q_DECL_EXPORT |
|
||||||
#else |
|
||||||
# define UBCFFADAPTORSHARED_EXPORT Q_DECL_IMPORT |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif // UBCFFADAPTOR_GLOBAL_H
|
|
@ -1,407 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBCFFCONSTANTS_H |
|
||||||
#define UBCFFCONSTANTS_H |
|
||||||
|
|
||||||
#define PI 3.1415926535 |
|
||||||
|
|
||||||
const int DEFAULT_BACKGROUND_LAYER = -20000002; |
|
||||||
const int DEFAULT_BACKGROUND_CROSS_LAYER = -20000001; |
|
||||||
|
|
||||||
// Constant names. Use only them instead const char* in each function
|
|
||||||
|
|
||||||
// Constant fileNames;
|
|
||||||
const QString fMetadata = "metadata.rdf"; |
|
||||||
const QString fIWBContent = "content.xml"; |
|
||||||
const QString fIWBBackground = "background.png"; |
|
||||||
const QString sAudioElementImage = ":images/soundOn.svg"; |
|
||||||
|
|
||||||
// Constant messages;
|
|
||||||
const QString noErrorMsg = "NoError"; |
|
||||||
|
|
||||||
// Tag names
|
|
||||||
const QString tDescription = "Description"; |
|
||||||
const QString tIWBRoot = "iwb"; |
|
||||||
const QString tIWBMeta = "meta"; |
|
||||||
const QString tUBZSize = "size"; |
|
||||||
const QString tSvg = "svg"; |
|
||||||
const QString tIWBPage = "page"; |
|
||||||
const QString tIWBPageSet = "pageset"; |
|
||||||
const QString tId = "id"; |
|
||||||
const QString tElement = "element"; |
|
||||||
const QString tUBZGroup = "group"; |
|
||||||
const QString tUBZGroups = "groups"; |
|
||||||
const QString tUBZG = "g"; |
|
||||||
const QString tUBZPolygon = "polygon"; |
|
||||||
const QString tUBZPolyline = "polyline"; |
|
||||||
const QString tUBZLine = "line"; |
|
||||||
const QString tUBZAudio = "audio"; |
|
||||||
const QString tUBZVideo = "video"; |
|
||||||
const QString tUBZImage = "image"; |
|
||||||
const QString tUBZForeignObject = "foreignObject"; |
|
||||||
const QString tUBZTextContent = "itemTextContent"; |
|
||||||
|
|
||||||
const QString tIWBA = "a"; |
|
||||||
const QString tIWBG = "g"; |
|
||||||
const QString tIWBSwitch = "switch"; |
|
||||||
const QString tIWBImage = "image"; |
|
||||||
const QString tIWBVideo = "video"; |
|
||||||
const QString tIWBAudio = "audio"; |
|
||||||
const QString tIWBText = "text"; |
|
||||||
const QString tIWBTextArea = "textarea"; |
|
||||||
const QString tIWBPolyLine = "polyline"; |
|
||||||
const QString tIWBPolygon = "polygon"; |
|
||||||
const QString tIWBFlash = "video"; |
|
||||||
const QString tIWBRect = "rect"; |
|
||||||
const QString tIWBLine = "line"; |
|
||||||
const QString tIWBTbreak = "tbreak"; |
|
||||||
const QString tIWBTspan = "tspan"; |
|
||||||
|
|
||||||
// Attributes names
|
|
||||||
const QString aIWBVersion = "version"; |
|
||||||
const QString aOwner = "owner"; |
|
||||||
const QString aDescription = "description"; |
|
||||||
const QString aCreator = "creator"; |
|
||||||
const QString aAbout = "about"; |
|
||||||
const QString aIWBViewBox = "viewbox"; |
|
||||||
const QString aUBZViewBox = "viewBox"; |
|
||||||
const QString aDarkBackground = "dark-background"; |
|
||||||
const QString aBackground = "background"; |
|
||||||
const QString aCrossedBackground = "crossed-background"; |
|
||||||
const QString aUBZType = "type"; |
|
||||||
const QString aUBZUuid = "uuid"; |
|
||||||
const QString aUBZParent = "parent"; |
|
||||||
const QString aFill = "fill"; // IWB attribute contans color to fill
|
|
||||||
|
|
||||||
const QString aID = "id"; // ID of any svg element can be placed in to iwb section
|
|
||||||
const QString aRef = "ref"; // as reference for applying additional attributes
|
|
||||||
const QString aSVGHref = "xlink:href"; // reference to file
|
|
||||||
const QString aIWBHref = "ref"; // reference to element ID
|
|
||||||
const QString aUBZHref = "href"; |
|
||||||
const QString aUBZSource = "source"; |
|
||||||
const QString aSrc = "src"; |
|
||||||
const QString aSVGRequiredExtension = "requiredExtensions"; |
|
||||||
|
|
||||||
const QString aX = "x"; |
|
||||||
const QString aY = "y"; |
|
||||||
const QString aWidth = "width"; |
|
||||||
const QString aHeight = "height"; |
|
||||||
const QString aStroke = "stroke"; |
|
||||||
const QString aStrokeWidth = "stroke-width"; |
|
||||||
const QString aPoints = "points"; |
|
||||||
const QString aZLayer = "z-value"; |
|
||||||
const QString aLayer = "layer"; |
|
||||||
const QString aTransform = "transform"; |
|
||||||
const QString aLocked = "locked"; |
|
||||||
const QString aIWBName = "name"; |
|
||||||
const QString aIWBContent = "content"; |
|
||||||
|
|
||||||
|
|
||||||
// Attribute values
|
|
||||||
const QString avIWBVersionNo = "1.0"; |
|
||||||
const QString avUBZText = "text"; |
|
||||||
const QString avFalse = "false"; |
|
||||||
const QString avTrue = "true"; |
|
||||||
|
|
||||||
// Namespaces and prefixes
|
|
||||||
const QString svgRequiredExtensionPrefix = "http://www.imsglobal.org/iwb/"; |
|
||||||
const QString dcNS = "http://purl.org/dc/elements/1.1/"; |
|
||||||
const QString svgUBZNS = "http://www.imsglobal.org/xsd/iwb_v1p0"; |
|
||||||
const QString svgIWBNS = "http://www.w3.org/2000/svg"; |
|
||||||
const QString xlinkNS = "http://www.w3.org/1999/xlink"; |
|
||||||
const QString iwbNS = "http://www.imsglobal.org/xsd/iwb_v1p0"; |
|
||||||
const QString xsiNS = "http://www.w3.org/2001/XMLSchema-instance"; |
|
||||||
const QString xsiShemaLocation = "\
|
|
||||||
http://www.imsglobal.org/xsd/iwb_v1p0 \
|
|
||||||
http://www.imsglobal.org/profile/iwb/iwbv1p0_v1p0.xsd \
|
|
||||||
http://www.w3.org/2000/svg http://www.imsglobal.org/profile/iwb/svgsubsetv1p0_v1p0.xsd \
|
|
||||||
http://www.w3.org/1999/xlink http://www.imsglobal.org/xsd/w3/1999/xlink.xsd";
|
|
||||||
const QString dcNSPrefix = "dc"; |
|
||||||
const QString svgIWBNSPrefix = "svg"; |
|
||||||
const QString xlinkNSPrefix = "xlink"; |
|
||||||
const QString iwbNsPrefix = "iwb"; |
|
||||||
const QString xsiPrefix = "xsi"; |
|
||||||
const QString xsiSchemaLocationPrefix = "schemaLocation"; |
|
||||||
|
|
||||||
const QString avOwner = ""; |
|
||||||
const QString avCreator = ""; |
|
||||||
const QString avDescription = ""; |
|
||||||
|
|
||||||
//constant symbols and words etc
|
|
||||||
const QString dimensionsDelimiter1 = "x"; |
|
||||||
const QString dimensionsDelimiter2 = " "; |
|
||||||
const QString pageAlias = "page"; |
|
||||||
const QString pageFileExtentionUBZ = "svg"; |
|
||||||
|
|
||||||
//content folder names
|
|
||||||
const QString cfImages = "images"; |
|
||||||
const QString cfVideos = "video"; |
|
||||||
const QString cfAudios = "audio"; |
|
||||||
const QString cfFlash = "flash"; |
|
||||||
|
|
||||||
//known file extentions
|
|
||||||
const QString feSvg = "svg"; |
|
||||||
const QString feWgt = "wgt"; |
|
||||||
const QString fePng = "png"; |
|
||||||
|
|
||||||
const int iCrossSize = 32; |
|
||||||
const int iCrossWidth = 1; |
|
||||||
|
|
||||||
// Image formats supported by CFF exclude wgt. Wgt is Sankore widget, which is considered as a .png preview.
|
|
||||||
const QString iwbElementImage(" \
|
|
||||||
wgt, \
|
|
||||||
jpeg, \
|
|
||||||
jpg, \
|
|
||||||
bmp, \
|
|
||||||
gif, \
|
|
||||||
wmf, \
|
|
||||||
emf, \
|
|
||||||
png, \
|
|
||||||
tif, \
|
|
||||||
tiff \
|
|
||||||
"); |
|
||||||
|
|
||||||
// Video formats supported by CFF
|
|
||||||
const QString iwbElementVideo(" \
|
|
||||||
mpg, \
|
|
||||||
mpeg, \
|
|
||||||
swf, \
|
|
||||||
"); |
|
||||||
|
|
||||||
// Audio formats supported by CFF
|
|
||||||
const QString iwbElementAudio(" \
|
|
||||||
mp3, \
|
|
||||||
wav \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString cffSupportedFileFormats(iwbElementImage + iwbElementVideo + iwbElementAudio); |
|
||||||
const QString ubzFormatsToConvert("svg"); |
|
||||||
|
|
||||||
|
|
||||||
const QString iwbSVGImageAttributes(" \
|
|
||||||
id, \
|
|
||||||
xlink:href, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
height, \
|
|
||||||
width, \
|
|
||||||
fill-opacity, \
|
|
||||||
requiredExtentions, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
|
|
||||||
const QString iwbSVGAudioAttributes(" \
|
|
||||||
id, \
|
|
||||||
xlink:href, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
height, \
|
|
||||||
width, \
|
|
||||||
fill-opacity, \
|
|
||||||
requiredExtentions, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGVideoAttributes(" \
|
|
||||||
id, \
|
|
||||||
xlink:href, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
height, \
|
|
||||||
width, \
|
|
||||||
fill-opacity, \
|
|
||||||
requiredExtentions, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGRectAttributes(" \
|
|
||||||
id, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
height, \
|
|
||||||
width, \
|
|
||||||
fill, \
|
|
||||||
fill-opacity, \
|
|
||||||
stroke, \
|
|
||||||
stroke-dasharray, \
|
|
||||||
stroke-linecap, \
|
|
||||||
stroke-linejoin, \
|
|
||||||
stroke-opacity, \
|
|
||||||
stroke-width, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const QString iwbSVGTextAttributes(" \
|
|
||||||
id, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
fill, \
|
|
||||||
font-family, \
|
|
||||||
font-size, \
|
|
||||||
font-style, \
|
|
||||||
font-weight, \
|
|
||||||
font-stretch, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGTextAreaAttributes(" \
|
|
||||||
id, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
height, \
|
|
||||||
width, \
|
|
||||||
fill, \
|
|
||||||
font-family, \
|
|
||||||
font-size, \
|
|
||||||
font-style, \
|
|
||||||
font-weight, \
|
|
||||||
font-stretch, \
|
|
||||||
text-align, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGTspanAttributes(" \
|
|
||||||
id, \
|
|
||||||
fill, \
|
|
||||||
font-family, \
|
|
||||||
font-size, \
|
|
||||||
font-style, \
|
|
||||||
font-weight, \
|
|
||||||
font-stretch, \
|
|
||||||
text-align, \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGLineAttributes(" \
|
|
||||||
id, \
|
|
||||||
x1, \
|
|
||||||
y1, \
|
|
||||||
x2, \
|
|
||||||
y2, \
|
|
||||||
stroke, \
|
|
||||||
stroke-dasharray, \
|
|
||||||
stroke-width, \
|
|
||||||
stroke-opacity, \
|
|
||||||
stroke-linecap, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGPolyLineAttributes(" \
|
|
||||||
id, \
|
|
||||||
points, \
|
|
||||||
stroke, \
|
|
||||||
stroke-width, \
|
|
||||||
stroke-dasharray, \
|
|
||||||
stroke-opacity, \
|
|
||||||
stroke-linecap, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString iwbSVGPolygonAttributes(" \
|
|
||||||
id, \
|
|
||||||
points, \
|
|
||||||
fill, \
|
|
||||||
fill-opacity, \
|
|
||||||
stroke, \
|
|
||||||
stroke-dasharray, \
|
|
||||||
stroke-width, \
|
|
||||||
stroke-linecap, \
|
|
||||||
stroke-linejoin, \
|
|
||||||
stroke-opacity, \
|
|
||||||
stroke-width, \
|
|
||||||
transform \
|
|
||||||
"); |
|
||||||
|
|
||||||
// 1 to 1 copy to SVG section
|
|
||||||
const QString iwbElementAttributes(" \
|
|
||||||
background, \
|
|
||||||
background-fill, \
|
|
||||||
background-posture, \
|
|
||||||
flip, \
|
|
||||||
freehand, \
|
|
||||||
highlight, \
|
|
||||||
highlight-fill, \
|
|
||||||
list-style-type, \
|
|
||||||
list-style-type-fill, \
|
|
||||||
locked, \
|
|
||||||
replicate, \
|
|
||||||
revealer, \
|
|
||||||
stroke-lineshape-start, \
|
|
||||||
stroke-lineshape-end \
|
|
||||||
"); |
|
||||||
|
|
||||||
// cannot be copied 1 to 1 to SVG section
|
|
||||||
const QString ubzElementAttributesToConvert(" \
|
|
||||||
xlink:href, \
|
|
||||||
src, \
|
|
||||||
transform, \
|
|
||||||
uuid \
|
|
||||||
" |
|
||||||
); |
|
||||||
|
|
||||||
// additional attributes. Have references in SVG section.
|
|
||||||
const QString svgElementAttributes(" \
|
|
||||||
points, \
|
|
||||||
fill, \
|
|
||||||
fill-opacity, \
|
|
||||||
stroke, \
|
|
||||||
stroke-dasharray, \
|
|
||||||
stroke-linecap, \
|
|
||||||
stroke-opacity, \
|
|
||||||
stroke-width, \
|
|
||||||
stroke_linejoin, \
|
|
||||||
requiredExtensions, \
|
|
||||||
viewbox, \
|
|
||||||
x, \
|
|
||||||
y, \
|
|
||||||
x1, \
|
|
||||||
y1, \
|
|
||||||
x2, \
|
|
||||||
y2, \
|
|
||||||
height, \
|
|
||||||
width, \
|
|
||||||
font-family, \
|
|
||||||
font-size, \
|
|
||||||
font-style, \
|
|
||||||
font-weight, \
|
|
||||||
font-stretch, \
|
|
||||||
text-align \
|
|
||||||
"); |
|
||||||
|
|
||||||
const QString ubzContentFolders("audios,videos,images,widgets"); |
|
||||||
|
|
||||||
struct UBItemLayerType |
|
||||||
{ |
|
||||||
enum Enum |
|
||||||
{ |
|
||||||
FixedBackground = -2000, Object = -1000, Graphic = 0, Tool = 1000, Control = 2000 |
|
||||||
}; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBCFFCONSTANTS_H
|
|
@ -1,73 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBGLOBALS_H |
|
||||||
#define UBGLOBALS_H |
|
||||||
|
|
||||||
#define DELETEPTR(ptr) if(NULL != ptr){ \ |
|
||||||
delete ptr; \
|
|
||||||
ptr = NULL; \
|
|
||||||
} |
|
||||||
|
|
||||||
#ifdef Q_WS_WIN |
|
||||||
|
|
||||||
#define WARNINGS_DISABLE __pragma(warning(push, 0)); |
|
||||||
#define WARNINGS_ENABLE __pragma(warning(pop)); |
|
||||||
|
|
||||||
#ifdef NO_THIRD_PARTY_WARNINGS |
|
||||||
// disabling warning level to 0 and save old state
|
|
||||||
#define THIRD_PARTY_WARNINGS_DISABLE WARNINGS_DISABLE |
|
||||||
#else |
|
||||||
// just save old state (needs for not empty define)
|
|
||||||
#define THIRD_PARTY_WARNINGS_DISABLE __pragma(warning(push)); |
|
||||||
#endif //#ifdef NO_THIRD_PARTY_WARNINGS
|
|
||||||
// anyway on WIN
|
|
||||||
#define THIRD_PARTY_WARNINGS_ENABLE WARNINGS_ENABLE |
|
||||||
|
|
||||||
#else //#ifdef Q_WS_WIN
|
|
||||||
|
|
||||||
#define WARNINGS_DISABLE _Pragma("GCC diagnostic push"); \ |
|
||||||
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\""); \
|
|
||||||
_Pragma("GCC diagnostic ignored \"-Wunused-variable\""); \
|
|
||||||
_Pragma("GCC diagnostic ignored \"-Wsign-compare\""); |
|
||||||
|
|
||||||
#define WARNINGS_ENABLE _Pragma("GCC diagnostic pop"); |
|
||||||
|
|
||||||
#ifdef NO_THIRD_PARTY_WARNINGS |
|
||||||
//disabling some warnings
|
|
||||||
#define THIRD_PARTY_WARNINGS_DISABLE WARNINGS_DISABLE |
|
||||||
|
|
||||||
#define THIRD_PARTY_WARNINGS_ENABLE WARNINGS_ENABLE |
|
||||||
#else |
|
||||||
// just save old state (needs for not empty define)
|
|
||||||
#define THIRD_PARTY_WARNINGS_ENABLE WARNINGS_ENABLE |
|
||||||
|
|
||||||
#endif //#ifdef NO_THIRD_PARTY_WARNINGS
|
|
||||||
|
|
||||||
#endif //#ifdef Q_WS_WIN
|
|
||||||
|
|
||||||
#endif // UBGLOBALS_H
|
|
||||||
|
|
@ -1,6 +0,0 @@ |
|||||||
HEADERS += plugins/cffadaptor/src/UBCFFAdaptor_global.h \ |
|
||||||
plugins/cffadaptor/src/UBCFFAdaptor.h \ |
|
||||||
plugins/cffadaptor/src/UBCFFConstants.h \ |
|
||||||
plugins/cffadaptor/src/UBGlobals.h |
|
||||||
|
|
||||||
SOURCES += plugins/cffadaptor/src/UBCFFAdaptor.cpp |
|
File diff suppressed because it is too large
Load Diff
@ -1,157 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBCFFSUBSETADAPTOR_H |
|
||||||
#define UBCFFSUBSETADAPTOR_H |
|
||||||
|
|
||||||
#include <QtXml> |
|
||||||
#include <QString> |
|
||||||
#include <QStack> |
|
||||||
#include <QDomDocument> |
|
||||||
#include <QHash> |
|
||||||
|
|
||||||
class UBDocumentProxy; |
|
||||||
class UBGraphicsScene; |
|
||||||
class QSvgGenerator; |
|
||||||
class UBGraphicsSvgItem; |
|
||||||
class UBGraphicsPixmapItem; |
|
||||||
class UBGraphicsItemDelegate; |
|
||||||
class QTransform; |
|
||||||
class QPainter; |
|
||||||
class UBGraphicsItem; |
|
||||||
class QGraphicsItem; |
|
||||||
class QTextBlockFormat; |
|
||||||
class QTextCharFormat; |
|
||||||
class QTextCursor; |
|
||||||
class UBGraphicsStrokesGroup; |
|
||||||
|
|
||||||
|
|
||||||
class UBCFFSubsetAdaptor |
|
||||||
{ |
|
||||||
public: |
|
||||||
UBCFFSubsetAdaptor(); |
|
||||||
static bool ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument); |
|
||||||
|
|
||||||
private: |
|
||||||
class UBCFFSubsetReader |
|
||||||
{ |
|
||||||
public: |
|
||||||
UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content); |
|
||||||
~UBCFFSubsetReader(); |
|
||||||
|
|
||||||
UBDocumentProxy *mProxy; |
|
||||||
QString pwdContent; |
|
||||||
|
|
||||||
bool parse(); |
|
||||||
|
|
||||||
private: |
|
||||||
QString mTempFilePath; |
|
||||||
UBGraphicsScene *mCurrentScene; |
|
||||||
QRectF mCurrentSceneRect; |
|
||||||
QString mIndent; |
|
||||||
QRectF mViewBox; |
|
||||||
QRectF mViewPort; |
|
||||||
qreal mVBTransFactor; |
|
||||||
QPointF mViewBoxCenter; |
|
||||||
QSize mSize; |
|
||||||
QPointF mShiftVector; |
|
||||||
bool mSvgGSectionIsOpened; |
|
||||||
UBGraphicsGroupContainerItem *mGSectionContainer; |
|
||||||
|
|
||||||
private: |
|
||||||
QDomDocument mDOMdoc; |
|
||||||
QDomNode mCurrentDOMElement; |
|
||||||
QHash<QString, UBGraphicsItem*> persistedItems; |
|
||||||
QMap<QString, QString> mRefToUuidMap; |
|
||||||
QDir mTmpFlashDir; |
|
||||||
|
|
||||||
void addItemToGSection(QGraphicsItem *item); |
|
||||||
bool hashElements(); |
|
||||||
void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup); |
|
||||||
|
|
||||||
void hashSvg(QDomNode *parent, QString prefix = ""); |
|
||||||
void hashSiblingIwbElements(QDomElement *parent, QDomElement *topGroup = 0); |
|
||||||
|
|
||||||
inline void parseSvgSectionAttr(const QDomElement &); |
|
||||||
bool parseSvgPage(const QDomElement &parent); |
|
||||||
bool parseSvgPageset(const QDomElement &parent); |
|
||||||
bool parseSvgElement(const QDomElement &parent); |
|
||||||
bool parseIwbMeta(const QDomElement &element); |
|
||||||
bool parseSvg(const QDomElement &svgSection); |
|
||||||
|
|
||||||
inline bool parseGSection(const QDomElement &element); |
|
||||||
inline bool parseSvgSwitchSection(const QDomElement &element); |
|
||||||
inline bool parseSvgRect(const QDomElement &element); |
|
||||||
inline bool parseSvgEllipse(const QDomElement &element); |
|
||||||
inline bool parseSvgPolygon(const QDomElement &element); |
|
||||||
inline bool parseSvgPolyline(const QDomElement &element); |
|
||||||
inline bool parseSvgText(const QDomElement &element); |
|
||||||
inline bool parseSvgTextarea(const QDomElement &element); |
|
||||||
inline bool parseSvgImage(const QDomElement &element); |
|
||||||
inline bool parseSvgFlash(const QDomElement &element); |
|
||||||
inline bool parseSvgAudio(const QDomElement &element); |
|
||||||
inline bool parseSvgVideo(const QDomElement &element); |
|
||||||
inline UBGraphicsGroupContainerItem *parseIwbGroup(QDomElement &parent); |
|
||||||
inline bool parseIwbElement(QDomElement &element); |
|
||||||
inline void parseTSpan(const QDomElement &parent, QPainter &painter |
|
||||||
, qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect |
|
||||||
, qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic |
|
||||||
, int &fontWeight, int &textAlign, QTransform &fontTransform); |
|
||||||
inline void parseTSpan(const QDomElement &element, QTextCursor &cursor |
|
||||||
, QTextBlockFormat &blockFormat, QTextCharFormat &charFormat); |
|
||||||
inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item); |
|
||||||
|
|
||||||
// to kill
|
|
||||||
inline void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor, |
|
||||||
QString &fontFamily, QString &fontStretch, bool &italic, |
|
||||||
int &fontWeight, int &textAlign, QTransform &fontTransform); |
|
||||||
inline void parseTextAttributes(const QDomElement &element, QFont &font, QColor); |
|
||||||
inline void readTextBlockAttr(const QDomElement &element, QTextBlockFormat &format); |
|
||||||
inline void readTextCharAttr(const QDomElement &element, QTextCharFormat &format); |
|
||||||
|
|
||||||
//elements parsing methods
|
|
||||||
bool parseDoc(); |
|
||||||
|
|
||||||
bool createNewScene(); |
|
||||||
bool persistCurrentScene(); |
|
||||||
bool persistScenes(); |
|
||||||
|
|
||||||
// helper methods
|
|
||||||
void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height, |
|
||||||
qreal x, qreal y, |
|
||||||
QTransform &transform); |
|
||||||
QColor colorFromString(const QString& clrString); |
|
||||||
QTransform transformFromString(const QString trString, QGraphicsItem *item = 0); |
|
||||||
bool getViewBoxDimenstions(const QString& viewBox); |
|
||||||
QSvgGenerator* createSvgGenerator(qreal width, qreal height); |
|
||||||
bool getTempFileName(); |
|
||||||
inline bool strToBool(QString); |
|
||||||
bool createTempFlashPath(); |
|
||||||
}; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBCFFSUBSETADAPTOR_H
|
|
@ -1,89 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "UBExportCFF.h" |
|
||||||
#include "UBCFFAdaptor.h" |
|
||||||
#include "document/UBDocumentProxy.h" |
|
||||||
#include "core/UBDocumentManager.h" |
|
||||||
#include "core/UBApplication.h" |
|
||||||
#include "core/memcheck.h" |
|
||||||
|
|
||||||
|
|
||||||
UBExportCFF::UBExportCFF(QObject *parent) |
|
||||||
: UBExportAdaptor(parent) |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
UBExportCFF::~UBExportCFF() |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
QString UBExportCFF::exportName() |
|
||||||
{ |
|
||||||
return tr("Export to IWB"); |
|
||||||
} |
|
||||||
|
|
||||||
QString UBExportCFF::exportExtention() |
|
||||||
{ |
|
||||||
return QString(".iwb"); |
|
||||||
} |
|
||||||
|
|
||||||
void UBExportCFF::persist(UBDocumentProxy* pDocument) |
|
||||||
{ |
|
||||||
if (!pDocument) |
|
||||||
return; |
|
||||||
|
|
||||||
QString src = pDocument->persistencePath(); |
|
||||||
|
|
||||||
QString filename = askForFileName(pDocument, tr("Export as IWB File")); |
|
||||||
|
|
||||||
if (filename.length() > 0) |
|
||||||
{ |
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
|
||||||
|
|
||||||
if (mIsVerbose) |
|
||||||
UBApplication::showMessage(tr("Exporting document...")); |
|
||||||
|
|
||||||
UBCFFAdaptor toIWBExporter; |
|
||||||
if (toIWBExporter.convertUBZToIWB(src, filename)) |
|
||||||
{ |
|
||||||
if (mIsVerbose) |
|
||||||
UBApplication::showMessage(tr("Export successful.")); |
|
||||||
} |
|
||||||
else
|
|
||||||
if (mIsVerbose) |
|
||||||
UBApplication::showMessage(tr("Export failed.")); |
|
||||||
|
|
||||||
showErrorsList(toIWBExporter.getConversionMessages()); |
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,52 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBExportCFF_H_ |
|
||||||
#define UBExportCFF_H_ |
|
||||||
|
|
||||||
#include <QtCore> |
|
||||||
|
|
||||||
#include "UBExportAdaptor.h" |
|
||||||
|
|
||||||
#include "frameworks/UBFileSystemUtils.h" |
|
||||||
|
|
||||||
class UBDocumentProxy; |
|
||||||
|
|
||||||
class UBExportCFF : public UBExportAdaptor |
|
||||||
{ |
|
||||||
Q_OBJECT; |
|
||||||
|
|
||||||
public: |
|
||||||
UBExportCFF(QObject *parent = 0); |
|
||||||
virtual ~UBExportCFF(); |
|
||||||
|
|
||||||
virtual QString exportName(); |
|
||||||
virtual QString exportExtention(); |
|
||||||
virtual void persist(UBDocumentProxy* pDocument); |
|
||||||
}; |
|
||||||
|
|
||||||
#endif /* UBExportCFF_H_ */ |
|
@ -1,292 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <QDir> |
|
||||||
#include <QList> |
|
||||||
|
|
||||||
#include "core/UBApplication.h" |
|
||||||
#include "core/UBPersistenceManager.h" |
|
||||||
#include "core/UBDocumentManager.h" |
|
||||||
#include "core/UBPersistenceManager.h" |
|
||||||
#include "document/UBDocumentProxy.h" |
|
||||||
#include "domain/UBGraphicsPDFItem.h" |
|
||||||
#include "frameworks/UBFileSystemUtils.h" |
|
||||||
#include "pdf/PDFRenderer.h" |
|
||||||
|
|
||||||
#include "UBCFFSubsetAdaptor.h" |
|
||||||
#include "UBImportCFF.h" |
|
||||||
|
|
||||||
#include "globals/UBGlobals.h" |
|
||||||
|
|
||||||
THIRD_PARTY_WARNINGS_DISABLE |
|
||||||
#include "quazip.h" |
|
||||||
#include "quazipfile.h" |
|
||||||
#include "quazipfileinfo.h" |
|
||||||
THIRD_PARTY_WARNINGS_ENABLE |
|
||||||
|
|
||||||
#include "core/memcheck.h" |
|
||||||
|
|
||||||
UBImportCFF::UBImportCFF(QObject *parent) |
|
||||||
: UBDocumentBasedImportAdaptor(parent) |
|
||||||
{ |
|
||||||
// NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
UBImportCFF::~UBImportCFF() |
|
||||||
{ |
|
||||||
// NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
QStringList UBImportCFF::supportedExtentions() |
|
||||||
{ |
|
||||||
return QStringList("iwb"); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
QString UBImportCFF::importFileFilter() |
|
||||||
{ |
|
||||||
QString filter = tr("Common File Format ("); |
|
||||||
QStringList formats = supportedExtentions(); |
|
||||||
bool isFirst = true; |
|
||||||
|
|
||||||
foreach(QString format, formats) |
|
||||||
{ |
|
||||||
if(isFirst) |
|
||||||
isFirst = false; |
|
||||||
else |
|
||||||
filter.append(" "); |
|
||||||
|
|
||||||
filter.append("*."+format); |
|
||||||
} |
|
||||||
|
|
||||||
filter.append(")"); |
|
||||||
|
|
||||||
return filter; |
|
||||||
} |
|
||||||
|
|
||||||
bool UBImportCFF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) |
|
||||||
{ |
|
||||||
QFileInfo fi(pFile); |
|
||||||
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); |
|
||||||
|
|
||||||
// first unzip the file to the correct place
|
|
||||||
//TODO create temporary path for iwb file content
|
|
||||||
QString path = QDir::tempPath(); |
|
||||||
|
|
||||||
QString documentRootFolder = expandFileToDir(pFile, path); |
|
||||||
QString contentFile; |
|
||||||
if (documentRootFolder.isEmpty()) //if file has failed to unzip it is probably just xml file
|
|
||||||
contentFile = pFile.fileName(); |
|
||||||
else //get path to content xml (according to iwbcff specification)
|
|
||||||
contentFile = documentRootFolder.append("/content.xml"); |
|
||||||
|
|
||||||
if(!contentFile.length()){ |
|
||||||
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); |
|
||||||
return false; |
|
||||||
} |
|
||||||
else{ |
|
||||||
//TODO convert expanded CFF file content to the destination document
|
|
||||||
//create destination document proxy
|
|
||||||
//fill metadata and save
|
|
||||||
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath()); |
|
||||||
QDir dir; |
|
||||||
dir.mkdir(destDocument->persistencePath()); |
|
||||||
|
|
||||||
//try to import cff to document
|
|
||||||
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument)) |
|
||||||
{ |
|
||||||
UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(destDocument->persistencePath(), pDocument); |
|
||||||
UBFileSystemUtils::deleteDir(destDocument->persistencePath()); |
|
||||||
delete destDocument; |
|
||||||
UBApplication::showMessage(tr("Import successful.")); |
|
||||||
return true; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
UBFileSystemUtils::deleteDir(destDocument->persistencePath()); |
|
||||||
delete destDocument; |
|
||||||
UBApplication::showMessage(tr("Import failed.")); |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir) |
|
||||||
{ |
|
||||||
QuaZip zip(pZipFile.fileName()); |
|
||||||
|
|
||||||
if(!zip.open(QuaZip::mdUnzip)) { |
|
||||||
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); |
|
||||||
return ""; |
|
||||||
} |
|
||||||
|
|
||||||
zip.setFileNameCodec("UTF-8"); |
|
||||||
QuaZipFileInfo info; |
|
||||||
QuaZipFile file(&zip); |
|
||||||
|
|
||||||
//create unique cff document root fodler
|
|
||||||
//use current date/time and temp number for folder name
|
|
||||||
QString documentRootFolder; |
|
||||||
int tmpNumber = 0; |
|
||||||
QDir rootDir; |
|
||||||
while (true) { |
|
||||||
QString tempPath = QString("%1/sank%2.%3") |
|
||||||
.arg(pDir) |
|
||||||
.arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm")) |
|
||||||
.arg(tmpNumber); |
|
||||||
if (!rootDir.exists(tempPath)) { |
|
||||||
documentRootFolder = tempPath; |
|
||||||
break; |
|
||||||
} |
|
||||||
tmpNumber++; |
|
||||||
if (tmpNumber == 100000) { |
|
||||||
qWarning() << "Import failed. Failed to create temporary directory for iwb file"; |
|
||||||
return ""; |
|
||||||
} |
|
||||||
} |
|
||||||
if (!rootDir.mkdir(documentRootFolder)) { |
|
||||||
qWarning() << "Import failed. Couse: failed to create temp folder for cff package"; |
|
||||||
} |
|
||||||
|
|
||||||
QFile out; |
|
||||||
char c; |
|
||||||
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) { |
|
||||||
if(!zip.getCurrentFileInfo(&info)) { |
|
||||||
//TOD UB 4.3 O display error to user or use crash reporter
|
|
||||||
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
|
||||||
return ""; |
|
||||||
} |
|
||||||
// if(!file.open(QIODevice::ReadOnly)) {
|
|
||||||
// qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
|
|
||||||
// return "";
|
|
||||||
// }
|
|
||||||
file.open(QIODevice::ReadOnly); |
|
||||||
if(file.getZipError()!= UNZ_OK) { |
|
||||||
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); |
|
||||||
return ""; |
|
||||||
} |
|
||||||
|
|
||||||
QString newFileName = documentRootFolder + "/" + file.getActualFileName(); |
|
||||||
|
|
||||||
QFileInfo newFileInfo(newFileName); |
|
||||||
rootDir.mkpath(newFileInfo.absolutePath()); |
|
||||||
|
|
||||||
out.setFileName(newFileName); |
|
||||||
out.open(QIODevice::WriteOnly); |
|
||||||
|
|
||||||
while(file.getChar(&c)) |
|
||||||
out.putChar(c); |
|
||||||
|
|
||||||
out.close(); |
|
||||||
|
|
||||||
if(file.getZipError()!=UNZ_OK) { |
|
||||||
qWarning() << "Import failed. Cause: " << zip.getZipError(); |
|
||||||
return ""; |
|
||||||
} |
|
||||||
if(!file.atEnd()) { |
|
||||||
qWarning() << "Import failed. Cause: read all but not EOF"; |
|
||||||
return ""; |
|
||||||
} |
|
||||||
|
|
||||||
file.close(); |
|
||||||
|
|
||||||
if(file.getZipError()!=UNZ_OK) { |
|
||||||
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); |
|
||||||
return ""; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
zip.close(); |
|
||||||
|
|
||||||
if(zip.getZipError()!=UNZ_OK) { |
|
||||||
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); |
|
||||||
return ""; |
|
||||||
} |
|
||||||
|
|
||||||
return documentRootFolder; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup) |
|
||||||
{ |
|
||||||
Q_UNUSED(pGroup); // group is defined in the imported file
|
|
||||||
|
|
||||||
QFileInfo fi(pFile); |
|
||||||
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); |
|
||||||
|
|
||||||
// first unzip the file to the correct place
|
|
||||||
//TODO create temporary path for iwb file content
|
|
||||||
QString path = QDir::tempPath(); |
|
||||||
|
|
||||||
QString documentRootFolder = expandFileToDir(pFile, path); |
|
||||||
QString contentFile; |
|
||||||
if (documentRootFolder.isEmpty()) |
|
||||||
//if file has failed to umzip it is probably just xml file
|
|
||||||
contentFile = pFile.fileName(); |
|
||||||
else |
|
||||||
//get path to content xml
|
|
||||||
contentFile = QString("%1/content.xml").arg(documentRootFolder); |
|
||||||
|
|
||||||
if(!contentFile.length()){ |
|
||||||
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); |
|
||||||
return 0; |
|
||||||
} |
|
||||||
else{ |
|
||||||
//create destination document proxy
|
|
||||||
//fill metadata and save
|
|
||||||
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath()); |
|
||||||
QDir dir; |
|
||||||
dir.mkdir(destDocument->persistencePath()); |
|
||||||
if (pGroup.length() > 0) |
|
||||||
destDocument->setMetaData(UBSettings::documentGroupName, pGroup); |
|
||||||
if (fi.baseName() > 0) |
|
||||||
destDocument->setMetaData(UBSettings::documentName, fi.baseName()); |
|
||||||
|
|
||||||
destDocument->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion); |
|
||||||
destDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); |
|
||||||
|
|
||||||
UBDocumentProxy* newDocument = NULL; |
|
||||||
//try to import cff to document
|
|
||||||
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument)) |
|
||||||
{ |
|
||||||
newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(destDocument->persistencePath()); |
|
||||||
UBApplication::showMessage(tr("Import successful.")); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
UBFileSystemUtils::deleteDir(destDocument->persistencePath()); |
|
||||||
UBApplication::showMessage(tr("Import failed.")); |
|
||||||
} |
|
||||||
delete destDocument; |
|
||||||
|
|
||||||
if (documentRootFolder.length() != 0) |
|
||||||
UBFileSystemUtils::deleteDir(documentRootFolder); |
|
||||||
return newDocument; |
|
||||||
} |
|
||||||
} |
|
@ -1,54 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Open Education Foundation |
|
||||||
* |
|
||||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
|
||||||
* l'Education Numérique en Afrique (GIP ENA) |
|
||||||
* |
|
||||||
* This file is part of OpenBoard. |
|
||||||
* |
|
||||||
* OpenBoard is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, version 3 of the License, |
|
||||||
* with a specific linking exception for the OpenSSL project's |
|
||||||
* "OpenSSL" library (or with modified versions of it that use the |
|
||||||
* same license as the "OpenSSL" library). |
|
||||||
* |
|
||||||
* OpenBoard 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 General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UBIMPORTCFF_H |
|
||||||
#define UBIMPORTCFF_H |
|
||||||
|
|
||||||
#include <QtGui> |
|
||||||
#include "UBImportAdaptor.h" |
|
||||||
|
|
||||||
class UBDocumentProxy; |
|
||||||
|
|
||||||
class UBImportCFF : public UBDocumentBasedImportAdaptor |
|
||||||
{ |
|
||||||
Q_OBJECT; |
|
||||||
|
|
||||||
public: |
|
||||||
UBImportCFF(QObject *parent = 0); |
|
||||||
virtual ~UBImportCFF(); |
|
||||||
|
|
||||||
virtual QStringList supportedExtentions(); |
|
||||||
virtual QString importFileFilter(); |
|
||||||
|
|
||||||
virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); |
|
||||||
virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup); |
|
||||||
|
|
||||||
private: |
|
||||||
QString expandFileToDir(const QFile& pZipFile, const QString& pDir); |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBIMPORTCFF_H
|
|
Loading…
Reference in new issue