parent
bb60925bdd
commit
8ecf99f838
@ -0,0 +1,69 @@ |
||||
#------------------------------------------------- |
||||
# |
||||
# 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 |
@ -0,0 +1,5 @@ |
||||
#!/bin/bash |
||||
SOURCE=$1 |
||||
DESTINATION=$2 |
||||
mkdir -p $DESTINATION |
||||
cp -R $SOURCE/ $DESTINATION |
After Width: | Height: | Size: 572 B |
@ -0,0 +1,5 @@ |
||||
<RCC> |
||||
<qresource prefix="/"> |
||||
<file>images/soundOn.svg</file> |
||||
</qresource> |
||||
</RCC> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,175 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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
|
@ -0,0 +1,34 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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
|
@ -0,0 +1,405 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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 ubNS = "http://uniboard.mnemis.com/document"; |
||||
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 ubNSPrefix = "ub"; |
||||
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
|
@ -0,0 +1,69 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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
|
||||
|
@ -0,0 +1,6 @@ |
||||
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 |
@ -0,0 +1,132 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>documentPublishingDialog</class> |
||||
<widget class="QDialog" name="documentPublishingDialog"> |
||||
<property name="windowModality"> |
||||
<enum>Qt::WindowModal</enum> |
||||
</property> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>607</width> |
||||
<height>405</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Dialog</string> |
||||
</property> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<layout class="QFormLayout" name="formLayout"> |
||||
<property name="fieldGrowthPolicy"> |
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> |
||||
</property> |
||||
<item row="0" column="0"> |
||||
<widget class="QLabel" name="titleLabel"> |
||||
<property name="text"> |
||||
<string>Title</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="1"> |
||||
<widget class="QLineEdit" name="title"> |
||||
<property name="maxLength"> |
||||
<number>60</number> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="0"> |
||||
<widget class="QLabel" name="label_2"> |
||||
<property name="text"> |
||||
<string>E-mail</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="1"> |
||||
<widget class="QLineEdit" name="email"/> |
||||
</item> |
||||
<item row="2" column="0"> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="text"> |
||||
<string>Author</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="2" column="1"> |
||||
<widget class="QLineEdit" name="author"/> |
||||
</item> |
||||
<item row="3" column="0"> |
||||
<widget class="QLabel" name="decriptionLabel"> |
||||
<property name="text"> |
||||
<string>Description</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="1"> |
||||
<widget class="QPlainTextEdit" name="description"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>0</width> |
||||
<height>168</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="4" column="1"> |
||||
<spacer name="verticalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>20</width> |
||||
<height>10</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
<item row="5" column="1"> |
||||
<widget class="QCheckBox" name="attachPDF"> |
||||
<property name="text"> |
||||
<string>Attach Downloadable PDF Version</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="6" column="1"> |
||||
<widget class="QCheckBox" name="attachUBZ"> |
||||
<property name="text"> |
||||
<string>Attach Downloadable Uniboard File (UBZ)</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="7" column="1"> |
||||
<widget class="QLabel" name="videoWarning"> |
||||
<property name="text"> |
||||
<string>Warning: This documents contains video, which will not be displayed properly on the Web</string> |
||||
</property> |
||||
<property name="wordWrap"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="8" column="1"> |
||||
<widget class="QDialogButtonBox" name="dialogButtons"> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,153 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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
|
@ -0,0 +1,99 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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" |
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include <QModelIndex> |
||||
#include <QObject> |
||||
|
||||
|
||||
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) |
||||
{ |
||||
QString src = pDocument->persistencePath(); |
||||
|
||||
if (!pDocument) |
||||
return; |
||||
|
||||
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(); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
bool UBExportCFF::associatedActionactionAvailableFor(const QModelIndex &selectedIndex) |
||||
{ |
||||
const UBDocumentTreeModel *docModel = qobject_cast<const UBDocumentTreeModel*>(selectedIndex.model()); |
||||
if (!selectedIndex.isValid() || docModel->isCatalog(selectedIndex)) { |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
@ -0,0 +1,49 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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); |
||||
virtual bool associatedActionactionAvailableFor(const QModelIndex &selectedIndex); |
||||
}; |
||||
|
||||
#endif /* UBExportCFF_H_ */ |
@ -0,0 +1,198 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
#include "UBExportDocumentSetAdaptor.h" |
||||
#include "UBExportDocument.h" |
||||
|
||||
#include "frameworks/UBPlatformUtils.h" |
||||
|
||||
#include "core/UBDocumentManager.h" |
||||
#include "core/UBApplication.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include "globals/UBGlobals.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBForeignObjectsHandler.h" |
||||
|
||||
THIRD_PARTY_WARNINGS_DISABLE |
||||
#include "quazip.h" |
||||
#include "quazipfile.h" |
||||
THIRD_PARTY_WARNINGS_ENABLE |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBExportDocumentSetAdaptor::UBExportDocumentSetAdaptor(QObject *parent) |
||||
: UBExportAdaptor(parent) |
||||
{ |
||||
|
||||
} |
||||
|
||||
UBExportDocumentSetAdaptor::~UBExportDocumentSetAdaptor() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
void UBExportDocumentSetAdaptor::persist(UBDocumentProxy* pDocumentProxy) |
||||
{ |
||||
QModelIndex treeViewParentIndex; |
||||
UBPersistenceManager *persistenceManager = UBPersistenceManager::persistenceManager(); |
||||
UBDocumentTreeModel *treeModel = persistenceManager->mDocumentTreeStructureModel; |
||||
QString filename; |
||||
|
||||
if (pDocumentProxy) { |
||||
treeViewParentIndex = treeModel->indexForProxy(pDocumentProxy); |
||||
if (!treeViewParentIndex.isValid()) { |
||||
qDebug() << "failed to export"; |
||||
UBApplication::showMessage(tr("Failed to export...")); |
||||
return; |
||||
} |
||||
filename = askForFileName(pDocumentProxy, tr("Export as UBX File")); |
||||
|
||||
} else { |
||||
treeViewParentIndex = UBApplication::documentController->firstSelectedTreeIndex(); |
||||
if (!treeViewParentIndex.isValid()) { |
||||
qDebug() << "failed to export"; |
||||
UBApplication::showMessage(tr("Failed to export...")); |
||||
return; |
||||
} |
||||
|
||||
UBDocumentTreeNode* node = treeModel->nodeFromIndex(treeViewParentIndex); |
||||
UBDocumentProxy proxy; |
||||
proxy.setMetaData(UBSettings::documentName,node->displayName()); |
||||
filename = askForFileName(&proxy, tr("Export as UBX File")); |
||||
} |
||||
|
||||
if (filename.length() > 0) |
||||
{ |
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||||
|
||||
if (mIsVerbose) |
||||
UBApplication::showMessage(tr("Exporting document...")); |
||||
|
||||
if (persistData(treeViewParentIndex, filename)) { |
||||
if (mIsVerbose) { |
||||
UBApplication::showMessage(tr("Export successful.")); |
||||
} |
||||
} else { |
||||
if (mIsVerbose) { |
||||
UBApplication::showMessage(tr("Export failed.")); |
||||
} |
||||
} |
||||
|
||||
QApplication::restoreOverrideCursor(); |
||||
} |
||||
} |
||||
|
||||
bool UBExportDocumentSetAdaptor::persistData(const QModelIndex &pRootIndex, QString filename) |
||||
{ |
||||
UBPersistenceManager *persistenceManager = UBPersistenceManager::persistenceManager(); |
||||
UBDocumentTreeModel *treeModel = persistenceManager->mDocumentTreeStructureModel; |
||||
|
||||
QModelIndex index = pRootIndex; |
||||
|
||||
if (!index.isValid()) { |
||||
return false; |
||||
} |
||||
|
||||
QuaZip zip(filename); |
||||
zip.setFileNameCodec("UTF-8"); |
||||
|
||||
if(!zip.open(QuaZip::mdCreate)) |
||||
{ |
||||
qWarning("Export failed. Cause: zip.open(): %d", zip.getZipError()); |
||||
return false; |
||||
} |
||||
|
||||
if (!addDocumentToZip(pRootIndex, treeModel, zip)) { |
||||
zip.close(); |
||||
return false; |
||||
} |
||||
|
||||
zip.close(); |
||||
UBPlatformUtils::setFileType(filename, 0x5542647A /* UBdz */); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
QString UBExportDocumentSetAdaptor::exportExtention() |
||||
{ |
||||
return QString(".ubx"); |
||||
} |
||||
|
||||
QString UBExportDocumentSetAdaptor::exportName() |
||||
{ |
||||
return tr("Export to Sankore UBX Format"); |
||||
} |
||||
|
||||
bool UBExportDocumentSetAdaptor::addDocumentToZip(const QModelIndex &pIndex, UBDocumentTreeModel *model, QuaZip &zip) |
||||
{ |
||||
static int i = 0; |
||||
i++; |
||||
|
||||
QModelIndex parentIndex = pIndex; |
||||
if (!parentIndex.isValid()) { |
||||
return false; |
||||
} |
||||
|
||||
UBDocumentProxy *pDocumentProxy = model->proxyForIndex(parentIndex); |
||||
if (pDocumentProxy) { |
||||
|
||||
// Q_ASSERT(QFileInfo(pDocumentProxy->persistencePath()).exists());
|
||||
// UBForeighnObjectsHandler cleaner;
|
||||
// cleaner.cure(pDocumentProxy->persistencePath());
|
||||
|
||||
//UniboardSankoreTransition document;
|
||||
QString documentPath(pDocumentProxy->persistencePath()); |
||||
//document.checkDocumentDirectory(documentPath);
|
||||
|
||||
QDir documentDir = QDir(pDocumentProxy->persistencePath()); |
||||
QuaZipFile zipFile(&zip); |
||||
UBFileSystemUtils::compressDirInZip(documentDir, QFileInfo(documentPath).fileName() + "/", &zipFile, false); |
||||
|
||||
if(zip.getZipError() != 0) |
||||
{ |
||||
qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); |
||||
} |
||||
} |
||||
|
||||
for (int i = 0; i < model->rowCount(parentIndex); ++i) { |
||||
QModelIndex curIndex = model->index(i, 0, parentIndex); |
||||
if (!addDocumentToZip(curIndex, model, zip)) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
bool UBExportDocumentSetAdaptor::associatedActionactionAvailableFor(const QModelIndex &selectedIndex) |
||||
{ |
||||
const UBDocumentTreeModel *docModel = qobject_cast<const UBDocumentTreeModel*>(selectedIndex.model()); |
||||
if (!selectedIndex.isValid() || docModel->isDocument(selectedIndex)) { |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
@ -0,0 +1,60 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
#ifndef UBEXPORTDOCUMENTSETADAPTOR_H |
||||
#define UBEXPORTDOCUMENTSETADAPTOR_H |
||||
|
||||
#include <QtCore> |
||||
#include "UBExportAdaptor.h" |
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
#include "globals/UBGlobals.h" |
||||
|
||||
THIRD_PARTY_WARNINGS_DISABLE |
||||
#include "quazip.h" |
||||
#include "quazipfile.h" |
||||
THIRD_PARTY_WARNINGS_ENABLE |
||||
|
||||
class UBDocumentProxy; |
||||
class UBDocumentTreeModel; |
||||
|
||||
|
||||
class UBExportDocumentSetAdaptor : public UBExportAdaptor |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBExportDocumentSetAdaptor(QObject *parent = 0); |
||||
virtual ~UBExportDocumentSetAdaptor(); |
||||
|
||||
virtual QString exportName(); |
||||
virtual QString exportExtention(); |
||||
|
||||
virtual void persist(UBDocumentProxy* pDocument); |
||||
bool persistData(const QModelIndex &pRootIndex, QString filename); |
||||
bool addDocumentToZip(const QModelIndex &pIndex, UBDocumentTreeModel *model, QuaZip &zip); |
||||
|
||||
virtual bool associatedActionactionAvailableFor(const QModelIndex &selectedIndex); |
||||
|
||||
|
||||
}; |
||||
|
||||
#endif // UBEXPORTDOCUMENTSETADAPTOR_H
|
@ -0,0 +1,294 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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() |
||||
,"" |
||||
,"" |
||||
,false |
||||
,false |
||||
,true); |
||||
|
||||
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; |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. 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
|
@ -0,0 +1,205 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
#include "UBImportDocumentSetAdaptor.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBSettings.h" |
||||
#include "core/UBPersistenceManager.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" |
||||
|
||||
UBImportDocumentSetAdaptor::UBImportDocumentSetAdaptor(QObject *parent) |
||||
:UBImportAdaptor(parent) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
UBImportDocumentSetAdaptor::~UBImportDocumentSetAdaptor() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
QStringList UBImportDocumentSetAdaptor::supportedExtentions() |
||||
{ |
||||
return QStringList("ubx"); |
||||
} |
||||
|
||||
|
||||
QString UBImportDocumentSetAdaptor::importFileFilter() |
||||
{ |
||||
return tr("Open-Sankore (set of documents) (*.ubx)"); |
||||
} |
||||
|
||||
QFileInfoList UBImportDocumentSetAdaptor::importData(const QString &zipFile, const QString &destination) |
||||
{ |
||||
//Create tmp directory to extract data, will be deleted after
|
||||
QString tmpDir; |
||||
int i = 0; |
||||
QFileInfoList result; |
||||
do { |
||||
tmpDir = QDir::tempPath() + "/Sankore_tmpImportUBX_" + QString::number(i++); |
||||
} while (QFileInfo(tmpDir).exists()); |
||||
|
||||
QDir(QDir::tempPath()).mkdir(tmpDir); |
||||
|
||||
QFile fZipFile(zipFile); |
||||
|
||||
if (!extractFileToDir(fZipFile, tmpDir)) { |
||||
UBFileSystemUtils::deleteDir(tmpDir); |
||||
return QFileInfoList(); |
||||
} |
||||
|
||||
QDir tDir(tmpDir); |
||||
|
||||
foreach(QFileInfo readDir, tDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden , QDir::Name)) { |
||||
QString newFileName = readDir.fileName(); |
||||
if (QFileInfo(destination + "/" + readDir.fileName()).exists()) { |
||||
newFileName = QFileInfo(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(tmpDir)).fileName(); |
||||
} |
||||
QString newFilePath = destination + "/" + newFileName; |
||||
if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath)) { |
||||
result.append(newFilePath); |
||||
} |
||||
} |
||||
|
||||
UBFileSystemUtils::deleteDir(tmpDir); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
|
||||
bool UBImportDocumentSetAdaptor::extractFileToDir(const QFile& pZipFile, const QString& pDir) |
||||
{ |
||||
QDir rootDir(pDir); |
||||
QuaZip zip(pZipFile.fileName()); |
||||
|
||||
if(!zip.open(QuaZip::mdUnzip)) |
||||
{ |
||||
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); |
||||
return false; |
||||
} |
||||
|
||||
zip.setFileNameCodec("UTF-8"); |
||||
QuaZipFileInfo info; |
||||
QuaZipFile file(&zip); |
||||
|
||||
QFile out; |
||||
char c; |
||||
|
||||
QString documentRoot = QFileInfo(pDir).absoluteFilePath(); |
||||
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 false; |
||||
} |
||||
|
||||
if(!file.open(QIODevice::ReadOnly)) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError(); |
||||
return false; |
||||
} |
||||
|
||||
if(file.getZipError()!= UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); |
||||
return false; |
||||
} |
||||
|
||||
QString actFileName = file.getActualFileName(); |
||||
// int ind = actFileName.indexOf("/");
|
||||
// if ( ind!= -1) {
|
||||
// actFileName.remove(0, ind + 1);
|
||||
// }
|
||||
QString newFileName = documentRoot + "/" + actFileName; |
||||
QFileInfo newFileInfo(newFileName); |
||||
if (!rootDir.mkpath(newFileInfo.absolutePath())) |
||||
return false; |
||||
|
||||
out.setFileName(newFileName); |
||||
if (!out.open(QIODevice::WriteOnly)) |
||||
return false; |
||||
|
||||
// Slow like hell (on GNU/Linux at least), but it is not my fault.
|
||||
// Not ZIP/UNZIP package's fault either.
|
||||
// The slowest thing here is out.putChar(c).
|
||||
QByteArray outFileContent = file.readAll(); |
||||
if (out.write(outFileContent) == -1) |
||||
{ |
||||
qWarning() << "Import failed. Cause: Unable to write file"; |
||||
out.close(); |
||||
return false; |
||||
} |
||||
|
||||
while(file.getChar(&c)) |
||||
out.putChar(c); |
||||
|
||||
out.close(); |
||||
|
||||
if(file.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: " << zip.getZipError(); |
||||
return false; |
||||
} |
||||
|
||||
if(!file.atEnd()) |
||||
{ |
||||
qWarning() << "Import failed. Cause: read all but not EOF"; |
||||
return false; |
||||
} |
||||
|
||||
file.close(); |
||||
|
||||
if(file.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
|
||||
zip.close(); |
||||
|
||||
if(zip.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
@ -0,0 +1,52 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
#ifndef UBIMPORTDOCUMENTSETADAPTOR_H |
||||
#define UBIMPORTDOCUMENTSETADAPTOR_H |
||||
|
||||
#include <QtGui> |
||||
#include "UBImportAdaptor.h" |
||||
|
||||
class UBDocumentProxy; |
||||
|
||||
class UBImportDocumentSetAdaptor : public UBImportAdaptor |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBImportDocumentSetAdaptor(QObject *parent = 0); |
||||
virtual ~UBImportDocumentSetAdaptor(); |
||||
|
||||
virtual QStringList supportedExtentions(); |
||||
virtual QString importFileFilter(); |
||||
|
||||
QFileInfoList importData(const QString &zipFile, const QString &destination); |
||||
|
||||
// virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup);
|
||||
// virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile);
|
||||
|
||||
private: |
||||
bool extractFileToDir(const QFile& pZipFile, const QString& pDir); |
||||
|
||||
}; |
||||
|
||||
#endif // UBIMPORTDOCUMENTSETADAPTOR_H
|
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#include "UBWebPublisher.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include "adaptors/publishing/UBDocumentPublisher.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBWebPublisher::UBWebPublisher(QObject *parent) |
||||
: UBExportAdaptor(parent) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
UBWebPublisher::~UBWebPublisher() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
QString UBWebPublisher::exportName() |
||||
{ |
||||
return tr("Publish Document on Sankore Web"); |
||||
} |
||||
|
||||
|
||||
void UBWebPublisher::persist(UBDocumentProxy* pDocumentProxy) |
||||
{ |
||||
if (!pDocumentProxy) |
||||
return; |
||||
|
||||
//UniboardSankoreTransition document;
|
||||
QString documentPath(pDocumentProxy->persistencePath()); |
||||
//document.checkDocumentDirectory(documentPath);
|
||||
|
||||
UBDocumentPublisher* publisher = new UBDocumentPublisher(pDocumentProxy, this); // the publisher will self delete when publication finishes
|
||||
publisher->publish(); |
||||
|
||||
} |
||||
|
||||
bool UBWebPublisher::associatedActionactionAvailableFor(const QModelIndex &selectedIndex) |
||||
{ |
||||
const UBDocumentTreeModel *docModel = qobject_cast<const UBDocumentTreeModel*>(selectedIndex.model()); |
||||
if (!selectedIndex.isValid() || docModel->isCatalog(selectedIndex)) { |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#ifndef UBWEBPUBLISHER_H_ |
||||
#define UBWEBPUBLISHER_H_ |
||||
|
||||
#include <QtGui> |
||||
|
||||
#include "UBExportAdaptor.h" |
||||
|
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
#include "ui_webPublishing.h" |
||||
|
||||
class UBDocumentProxy; |
||||
class UBServerXMLHttpRequest; |
||||
|
||||
class UBWebPublisher : public UBExportAdaptor |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBWebPublisher(QObject *parent = 0); |
||||
virtual ~UBWebPublisher(); |
||||
|
||||
virtual QString exportName(); |
||||
|
||||
virtual void persist(UBDocumentProxy* pDocument); |
||||
|
||||
virtual bool associatedActionactionAvailableFor(const QModelIndex &selectedIndex); |
||||
}; |
||||
|
||||
|
||||
#endif /* UBWEBPUBLISHER_H_ */ |
@ -0,0 +1,628 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBForeignObjectsHandler.h" |
||||
|
||||
#include <QtGui> |
||||
#include <QtXml> |
||||
#include "UBSettings.h" |
||||
|
||||
const QString tVideo = "video"; |
||||
const QString tAudio = "audio"; |
||||
const QString tImage = "image"; |
||||
const QString tForeignObject = "foreignObject"; |
||||
const QString tTeacherGuide = "teacherGuide"; |
||||
const QString tMedia = "media"; |
||||
const QString tGroups = "groups"; |
||||
|
||||
const QString aHref = "xlink:href"; |
||||
const QString aType = "ub:type"; |
||||
const QString aReqExt = "requiredExtensions"; |
||||
const QString aSrc = "ub:src"; |
||||
const QString aMediaType = "mediaType"; |
||||
const QString aRelativePath = "relativePath"; |
||||
const QString aActionMedia = "ub:actionFirstParameter"; |
||||
|
||||
const QString vText = "text"; |
||||
const QString vReqExt = "http://ns.adobe.com/pdf/1.3/"; |
||||
|
||||
const QString wgtSuff = ".wgt"; |
||||
const QString thumbSuff = ".png"; |
||||
|
||||
const QString scanDirs = "audios,images,videos,teacherGuideObjects,widgets"; |
||||
const QStringList trashFilter = QStringList() << "*.swf"; |
||||
|
||||
static QString strIdFrom(const QString &filePath) |
||||
{ |
||||
if ((filePath).isEmpty()) { |
||||
return QString(); |
||||
} |
||||
|
||||
QRegExp rx("\\{.(?!.*\\{).*\\}"); |
||||
if (rx.indexIn(filePath) == -1) { |
||||
return QString(); |
||||
} |
||||
|
||||
return rx.cap(); |
||||
} |
||||
|
||||
static bool rm_r(const QString &rmPath) |
||||
{ |
||||
QFileInfo fi(rmPath); |
||||
if (!fi.exists()) { |
||||
qDebug() << rmPath << "does not exist"; |
||||
return false; |
||||
} else if (fi.isFile()) { |
||||
if (!QFile::remove(rmPath)) { |
||||
qDebug() << "can't remove file" << rmPath; |
||||
return false; |
||||
} |
||||
return true; |
||||
} else if (fi.isDir()) { |
||||
QFileInfoList fList = QDir(rmPath).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); |
||||
foreach (QFileInfo sub, fList) { |
||||
rm_r(sub.absoluteFilePath()); |
||||
} |
||||
if (!QDir().rmdir(rmPath)) { |
||||
qDebug() << "can't remove dir" << rmPath; |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
static bool cp_rf(const QString &what, const QString &where) |
||||
{ |
||||
QFileInfo whatFi(what); |
||||
QFileInfo whereFi = QFileInfo(where); |
||||
|
||||
if (!whatFi.exists()) { |
||||
qDebug() << what << "does not exist" << Q_FUNC_INFO; |
||||
return false; |
||||
} else if (whatFi.isFile()) { |
||||
QString whereDir = where.section("/", 0, -2, QString::SectionSkipEmpty | QString::SectionIncludeLeadingSep); |
||||
QString newFilePath = where; |
||||
if (!whereFi.exists()) { |
||||
QDir().mkpath(whereDir); |
||||
} else if (whereFi.isDir()) { |
||||
newFilePath = whereDir + "/" + whatFi.fileName(); |
||||
} |
||||
if (QFile::exists(newFilePath)) { |
||||
QFile::remove(newFilePath); |
||||
} |
||||
if (!QFile::copy(what, newFilePath)) { |
||||
qDebug() << "can't copy" << what << "to" << where << Q_FUNC_INFO; |
||||
return false; |
||||
} |
||||
return true; |
||||
} else if (whatFi.isDir()) { |
||||
|
||||
if (whereFi.isFile() && whereFi.fileName().toLower() == whatFi.fileName().toLower()) { |
||||
qDebug() << "can't copy dir" << what << "to file" << where << Q_FUNC_INFO; |
||||
return false; |
||||
} else if (whereFi.isDir()) { |
||||
rm_r(where); |
||||
} |
||||
|
||||
QDir().mkpath(where); |
||||
|
||||
QFileInfoList fList = QDir(what).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); |
||||
foreach (QFileInfo sub, fList) { |
||||
if (!cp_rf(sub.absoluteFilePath(), where + "/" + sub.fileName())) |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
static QString thumbFileNameFrom(const QString &filePath) |
||||
{ |
||||
if (filePath.isEmpty()) { |
||||
return QString(); |
||||
} |
||||
|
||||
QString thumbPath = filePath; |
||||
thumbPath.replace(QRegExp("[\\{\\}]"), "").replace(wgtSuff, thumbSuff); |
||||
|
||||
return thumbPath; |
||||
} |
||||
|
||||
|
||||
QString svgPageName(int pageIndex) |
||||
{ |
||||
return QString("page%1.svg").arg(pageIndex, 3, 10, QLatin1Char('0')); |
||||
} |
||||
|
||||
static QDomDocument createDomFromSvg(const QString &svgUrl) |
||||
{ |
||||
Q_ASSERT(QFile::exists(svgUrl)); |
||||
QString mFoldersXmlStorageName = svgUrl; |
||||
|
||||
if (QFileInfo(mFoldersXmlStorageName).exists()) { |
||||
QDomDocument xmlDom; |
||||
QFile inFile(mFoldersXmlStorageName); |
||||
if (inFile.open(QIODevice::ReadOnly)) { |
||||
QString domString(inFile.readAll()); |
||||
|
||||
int errorLine = 0; int errorColumn = 0; |
||||
QString errorStr; |
||||
|
||||
if (xmlDom.setContent(domString, &errorStr, &errorLine, &errorColumn)) { |
||||
return xmlDom; |
||||
} else { |
||||
qDebug() << "Error reading content of " << mFoldersXmlStorageName << endl |
||||
<< "Error:" << inFile.errorString() |
||||
<< "Line:" << errorLine |
||||
<< "Column:" << errorColumn; |
||||
} |
||||
inFile.close(); |
||||
} else { |
||||
qDebug() << "Error reading" << mFoldersXmlStorageName << endl |
||||
<< "Error:" << inFile.errorString(); |
||||
} |
||||
} |
||||
|
||||
return QDomDocument(); |
||||
} |
||||
|
||||
class Cleaner |
||||
{ |
||||
public: |
||||
void cure(const QUrl &dir) |
||||
{ |
||||
mCurrentDir = dir.toLocalFile(); |
||||
cleanTrash(); |
||||
|
||||
// Gathering information from svg files
|
||||
QFileInfoList svgInfos = QDir(mCurrentDir).entryInfoList(QStringList() << "*.svg", QDir::NoDotAndDotDot | QDir::Files); |
||||
foreach (QFileInfo svgInfo, svgInfos) { |
||||
cureIdsFromSvgDom(createDomFromSvg(svgInfo.absoluteFilePath())); |
||||
} |
||||
|
||||
fitIdsFromFileSystem(); |
||||
QVector<QString> deleteCandidates; |
||||
findRedundandElements(deleteCandidates); |
||||
|
||||
foreach (QString key, deleteCandidates) { |
||||
QString delPath = mPresentIdsMap.value(key); |
||||
if (delPath.isNull()) { |
||||
continue; |
||||
} else if (delPath.endsWith(wgtSuff)) { //remove corresponding thumb
|
||||
QString thumbPath = thumbFileNameFrom(delPath); |
||||
|
||||
//N/C - NNE - 20140417
|
||||
if (QFile::exists(thumbPath)) { |
||||
rm_r(thumbPath); |
||||
} |
||||
} |
||||
rm_r(delPath); |
||||
// Clear parent dir if empty
|
||||
QDir dir(delPath); |
||||
dir.cdUp(); |
||||
if (dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) { |
||||
dir.rmdir(dir.absolutePath()); |
||||
} |
||||
} |
||||
|
||||
qDebug() << "Ok on cure"; |
||||
} |
||||
|
||||
private: |
||||
void cleanTrash() |
||||
{ |
||||
QFileInfoList ifs = QDir(mCurrentDir).entryInfoList(trashFilter, QDir::NoDotAndDotDot | QDir::Files); |
||||
foreach (QFileInfo ifo, ifs) { |
||||
rm_r(ifo.absoluteFilePath()); |
||||
} |
||||
} |
||||
|
||||
void cureIdsFromSvgDom(const QDomDocument &dom) |
||||
{ |
||||
Q_ASSERT(!dom.isNull()); |
||||
|
||||
QDomElement nextElement = dom.documentElement().firstChildElement(); |
||||
while (!nextElement.isNull()) { |
||||
QString nextTag = nextElement.tagName(); |
||||
qDebug() << "Tag name of the next parsed element is" << nextTag; |
||||
if (nextTag == tGroups) |
||||
{ |
||||
nextElement = nextElement.firstChildElement("group"); |
||||
} |
||||
|
||||
invokeFromText(nextTag, nextElement); |
||||
nextElement = nextElement.nextSiblingElement(); |
||||
} |
||||
} |
||||
|
||||
void fitIdsFromFileSystem() |
||||
{ |
||||
QString absPrefix = mCurrentDir + "/"; |
||||
QStringList dirsList = scanDirs.split(",", QString::SkipEmptyParts); |
||||
foreach (QString dirName, dirsList) { |
||||
QString absPath = absPrefix + dirName; |
||||
if (!QFile::exists(absPath)) { |
||||
continue; |
||||
} |
||||
fitIdsFromDir(absPath); |
||||
} |
||||
|
||||
} |
||||
|
||||
void fitIdsFromDir(const QString &scanDir) |
||||
{ |
||||
QFileInfoList fileList = QDir(scanDir).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); |
||||
foreach (QFileInfo nInfo, fileList) { |
||||
QString uid = strIdFrom(nInfo.fileName()); |
||||
if (uid.isNull()) { |
||||
continue; |
||||
} |
||||
mPresentIdsMap.insert(uid, nInfo.absoluteFilePath()); |
||||
} |
||||
} |
||||
|
||||
void findRedundandElements(QVector<QString> &v) |
||||
{ |
||||
// Taking information from the physical file system
|
||||
QStringList domIds = mDomIdsMap.keys(); |
||||
QStringList presentIds = mPresentIdsMap.keys(); |
||||
v.resize(qMax(domIds.count(), presentIds.count())); |
||||
QVector<QString>::iterator it_diff; |
||||
|
||||
it_diff=std::set_symmetric_difference(domIds.begin(), domIds.end() |
||||
, presentIds.begin(), presentIds.end() |
||||
, v.begin()); |
||||
v.resize(it_diff - v.begin()); |
||||
} |
||||
|
||||
void invokeFromText(const QString &what, const QDomElement &element) |
||||
{ |
||||
if (what == tVideo |
||||
|| what == tAudio |
||||
|| what == tImage) { |
||||
mediaToContainer(element); |
||||
} else if (what == tForeignObject) { |
||||
foreingObjectToContainer(element); |
||||
|
||||
//N/C - NNE - 20140317
|
||||
cleanObjectFolder(element); |
||||
|
||||
//N/C - NNE - 20140520
|
||||
//foreign object may referer resource which are not present in the svg
|
||||
addResourceIdToSvg(element); |
||||
} else if (what == tTeacherGuide) { |
||||
teacherGuideToContainer(element); |
||||
} |
||||
|
||||
pullActionFromElement(element); |
||||
} |
||||
|
||||
// N/C - NNE - 20140317 : When export, reduce the size of the ubz file
|
||||
void cleanObjectFolder(const QDomElement &element) |
||||
{ |
||||
//QDomElement preference = element.firstChildElement("ub:preference");
|
||||
|
||||
//N/C - NNE - 20141021
|
||||
QDomNodeList childrenNode = element.elementsByTagName("ub:preference"); |
||||
|
||||
QVector<QString> objectsIdUsed; |
||||
|
||||
for(int i = 0; i < childrenNode.size(); i++){ |
||||
QDomElement preference = childrenNode.at(i).toElement(); |
||||
|
||||
if(!preference.isNull()){ |
||||
QString value = preference.attribute("value"); |
||||
|
||||
int findPos = value.indexOf("objects/"); |
||||
int endPos; |
||||
|
||||
//find all objects used
|
||||
while(findPos != -1){ |
||||
endPos = value.indexOf("\"", findPos); |
||||
objectsIdUsed << value.mid(findPos, endPos - findPos); |
||||
findPos = value.indexOf("objects/", endPos); |
||||
} |
||||
} |
||||
} |
||||
//N/C - NNE - 20141021 : END
|
||||
|
||||
|
||||
QString path = element.attribute(aSrc); |
||||
QString objectsFolderPath = mCurrentDir + "/" + path + "/objects/"; |
||||
|
||||
QDir dir(objectsFolderPath); |
||||
dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot); |
||||
|
||||
//then check all files in the objects directory
|
||||
//delete the file not used (not in te objectIdUsed variable)
|
||||
QFileInfoList list = dir.entryInfoList(); |
||||
for (int i = 0; i < list.size(); i++) { |
||||
QFileInfo fileInfo = list.at(i); |
||||
|
||||
if(!objectsIdUsed.contains("objects/"+fileInfo.fileName())){ |
||||
QFile(fileInfo.filePath()).remove(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
// N/C - NNE - 20140317 : END
|
||||
|
||||
//N/C - NNE - 20140520
|
||||
void addResourceIdToSvg(const QDomElement& element) |
||||
{ |
||||
QDomElement textContent = element.firstChildElement("itemTextContent"); |
||||
|
||||
QString value = textContent.text(); |
||||
|
||||
int findPos = value.indexOf("images/"); |
||||
int endPos; |
||||
|
||||
//find all objects used
|
||||
while(findPos != -1){ |
||||
endPos = value.indexOf("\"", findPos); |
||||
|
||||
QString path = value.mid(findPos, endPos - findPos); |
||||
|
||||
QString uuid = path.split("/").at(1).split(".").at(0); |
||||
|
||||
mDomIdsMap.insert(uuid, path); |
||||
|
||||
findPos = value.indexOf("images/", endPos); |
||||
} |
||||
} |
||||
//N/C - NNE - 20140520 : END
|
||||
|
||||
void pullActionFromElement(const QDomElement &element) |
||||
{ |
||||
if (!element.hasAttribute(aActionMedia)) { |
||||
return; |
||||
} |
||||
|
||||
QString path = element.attribute(aActionMedia); |
||||
if (path.isNull()) { |
||||
return; |
||||
} |
||||
|
||||
QString uid = strIdFrom(path); |
||||
if (uid.isNull()) { |
||||
return; |
||||
} |
||||
|
||||
mDomIdsMap.insert(uid, path); |
||||
} |
||||
|
||||
void teacherGuideToContainer(const QDomElement &element) |
||||
{ |
||||
QDomElement nMediaElement = element.firstChildElement(tMedia); |
||||
while (!nMediaElement.isNull()) { |
||||
|
||||
QString path = nMediaElement.attribute(aRelativePath); |
||||
if (path.isNull()) { |
||||
continue; |
||||
} |
||||
|
||||
QString uid = strIdFrom(path); |
||||
if (uid.isNull()) { |
||||
return; |
||||
} |
||||
mDomIdsMap.insert(uid, path); |
||||
|
||||
nMediaElement = nMediaElement.nextSiblingElement(tMedia); |
||||
} |
||||
} |
||||
|
||||
void mediaToContainer(const QDomElement &element) |
||||
{ |
||||
QString path = element.attribute(aHref); |
||||
if (path.isNull()) { |
||||
return; |
||||
} |
||||
QString uid = strIdFrom(path); |
||||
if (uid.isNull()) { |
||||
return; |
||||
} |
||||
mDomIdsMap.insert(uid, path); |
||||
} |
||||
|
||||
void foreingObjectToContainer(const QDomElement &element) |
||||
{ |
||||
QString type = element.attribute(aType); |
||||
if (type == vText) { // We don't have to care of the text object
|
||||
return; |
||||
} |
||||
|
||||
QString path = element.attribute(aSrc); |
||||
if (path.isNull()) { |
||||
return; |
||||
} |
||||
|
||||
QString uid = strIdFrom(path); |
||||
if (uid.isNull()) { |
||||
return; |
||||
} |
||||
|
||||
mDomIdsMap.insert(uid, path); |
||||
} |
||||
|
||||
private: |
||||
QString mCurrentDir; |
||||
QDomDocument mSvgData; |
||||
QMap<QString, QString> mDomIdsMap; |
||||
QMap<QString, QString> mPresentIdsMap; |
||||
}; |
||||
|
||||
class PageCopier |
||||
{ |
||||
public: |
||||
void copyPage (const QUrl &fromDir, int fromIndex, const QUrl &toDir, int toIndex) |
||||
{ |
||||
mFromDir = fromDir.toLocalFile(); |
||||
mToDir = toDir.toLocalFile(); |
||||
mFromIndex = fromIndex; |
||||
mToIndex = toIndex; |
||||
|
||||
QString svgFrom = mFromDir + "/" + svgPageName(fromIndex); |
||||
QString svgTo = toDir.toLocalFile() + "/" + svgPageName(toIndex); |
||||
QDomDocument dd = createDomFromSvg(svgFrom); |
||||
QFile fl(svgTo); |
||||
if (!fl.open(QIODevice::WriteOnly)) { |
||||
qDebug() << Q_FUNC_INFO << "can't open" << fl.fileName() << "for writing"; |
||||
return; |
||||
} |
||||
cureIdsFromSvgDom(dd); |
||||
|
||||
QTextStream str(&fl); |
||||
dd.save(str, 0); |
||||
fl.close(); |
||||
qDebug() << Q_FUNC_INFO; |
||||
} |
||||
|
||||
private: |
||||
void cureIdsFromSvgDom(const QDomDocument &dom) |
||||
{ |
||||
Q_ASSERT(!dom.isNull()); |
||||
|
||||
QDomElement nextElement = dom.documentElement().firstChildElement(); |
||||
while (!nextElement.isNull( )) { |
||||
qDebug() << "Tag name of the next parsed element is" << nextElement.tagName(); |
||||
QString nextTag = nextElement.tagName(); |
||||
cureFromText(nextTag, nextElement); |
||||
nextElement = nextElement.nextSiblingElement(); |
||||
} |
||||
} |
||||
|
||||
void cureFromText(const QString &tagName, QDomElement element) |
||||
{ |
||||
if (tagName == tVideo |
||||
|| tagName == tAudio |
||||
|| tagName == tImage) { |
||||
QString newRelative = cureNCopy(element.attribute(aHref)); |
||||
element.setAttribute(aHref, newRelative); |
||||
if (element.hasAttribute(aActionMedia)) { |
||||
QString newActionPath = cureNCopy(element.attribute(aActionMedia)); |
||||
element.setAttribute(aActionMedia, newActionPath); |
||||
} |
||||
} else if (tagName == tForeignObject) { |
||||
//Pdf object is a special case. Detect if it ends with #reference
|
||||
QString reqExt = element.attribute(aReqExt); |
||||
if (reqExt == vReqExt) { //pdf reference
|
||||
QString ref = element.attribute(aHref); |
||||
if (ref.isEmpty()) { |
||||
return; |
||||
} |
||||
ref.replace(QRegExp("^(.*pdf\\#page\\=).*$"), QString("\\1%1").arg(mToIndex)); |
||||
return; |
||||
} |
||||
|
||||
QString type = element.attribute(aType); |
||||
if (type == vText) { // We don't have to care of the text object
|
||||
if (element.hasAttribute(aActionMedia)) { |
||||
QString newRelative = cureNCopy(element.attribute(aActionMedia)); |
||||
element.setAttribute(aActionMedia, newRelative); |
||||
} |
||||
return; |
||||
} |
||||
QString newRelative = cureNCopy(element.attribute(aSrc)); |
||||
element.setAttribute(aSrc, newRelative); |
||||
} else if (tagName == tTeacherGuide) { |
||||
QDomElement nMediaElement = element.firstChildElement(tMedia); |
||||
while (!nMediaElement.isNull()) { |
||||
QString newRelative = cureNCopy(nMediaElement.attribute(aRelativePath)); |
||||
nMediaElement.setAttribute(aRelativePath, newRelative); |
||||
nMediaElement = nMediaElement.nextSiblingElement(tMedia); |
||||
} |
||||
} |
||||
} |
||||
|
||||
QString cureNCopy(const QString &relativePath) |
||||
{ |
||||
QString relative = relativePath; |
||||
QUuid newUuid = QUuid::createUuid(); |
||||
QString newPath = relative.replace(QRegExp("\\{.*\\}"), newUuid.toString()); |
||||
cp_rf(mFromDir + "/" + relativePath, mToDir + "/" + newPath); |
||||
|
||||
return newPath; |
||||
} |
||||
|
||||
private: |
||||
QString mFromDir; |
||||
QString mToDir; |
||||
int mFromIndex; |
||||
int mToIndex; |
||||
}; |
||||
|
||||
class UBForeighnObjectsHandlerPrivate { |
||||
UBForeighnObjectsHandlerPrivate(UBForeighnObjectsHandler *pq) |
||||
: q(pq) |
||||
{ |
||||
} |
||||
|
||||
public: |
||||
void cure(const QUrl &dir) |
||||
{ |
||||
Cleaner *cleaner = new Cleaner; |
||||
cleaner->cure(dir); |
||||
delete cleaner; |
||||
cleaner = 0; |
||||
} |
||||
|
||||
void copyPage (const QUrl &fromDir, int fromIndex, const QUrl &toDir, int toIndex) |
||||
{ |
||||
PageCopier *copier = new PageCopier; |
||||
copier->copyPage(fromDir, fromIndex, toDir, toIndex); |
||||
delete copier; |
||||
copier = 0; |
||||
} |
||||
|
||||
private: |
||||
UBForeighnObjectsHandler *q; |
||||
friend class UBForeighnObjectsHandler; |
||||
}; |
||||
|
||||
UBForeighnObjectsHandler::UBForeighnObjectsHandler() |
||||
: d(new UBForeighnObjectsHandlerPrivate(this)) |
||||
{ |
||||
|
||||
} |
||||
|
||||
UBForeighnObjectsHandler::~UBForeighnObjectsHandler() |
||||
{ |
||||
delete d; |
||||
} |
||||
|
||||
void UBForeighnObjectsHandler::cure(const QList<QUrl> &dirs) |
||||
{ |
||||
foreach (QUrl dir, dirs) { |
||||
cure(dir); |
||||
} |
||||
} |
||||
|
||||
void UBForeighnObjectsHandler::cure(const QUrl &dir) |
||||
{ |
||||
d->cure(dir); |
||||
} |
||||
|
||||
void UBForeighnObjectsHandler::copyPage(const QUrl &fromDir, int fromIndex, const QUrl &toDir, int toIndex) |
||||
{ |
||||
d->copyPage(fromDir, fromIndex, toDir, toIndex); |
||||
} |
||||
|
@ -0,0 +1,49 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBFOREIGHNOBJECTSHANDLER_H |
||||
#define UBFOREIGHNOBJECTSHANDLER_H |
||||
|
||||
#include <QList> |
||||
#include <QUrl> |
||||
#include <algorithm> |
||||
|
||||
class UBForeighnObjectsHandlerPrivate; |
||||
|
||||
class UBForeighnObjectsHandler |
||||
{ |
||||
public: |
||||
UBForeighnObjectsHandler(); |
||||
~UBForeighnObjectsHandler(); |
||||
|
||||
void cure(const QList<QUrl> &dirs); |
||||
void cure(const QUrl &dir); |
||||
|
||||
void copyPage(const QUrl &fromDir, int fromIndex, |
||||
const QUrl &toDir, int toIndex); |
||||
|
||||
private: |
||||
UBForeighnObjectsHandlerPrivate *d; |
||||
|
||||
friend class UBForeighnObjectsHandlerPrivate; |
||||
}; |
||||
|
||||
#endif // UBFOREIGHNOBJECTSHANDLER_H
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,90 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#include <QPainter> |
||||
#include <QDebug> |
||||
|
||||
#include "UBActionableWidget.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBActionableWidget::UBActionableWidget(QWidget *parent, const char *name):QWidget(parent) |
||||
, mShowActions(false) |
||||
{ |
||||
setObjectName(name); |
||||
mActions.clear(); |
||||
mCloseButtons.setIcon(QIcon(QPixmap(":images/close.svg"))); |
||||
mCloseButtons.setGeometry(0, 0, 2*ACTIONSIZE, ACTIONSIZE); |
||||
mCloseButtons.setVisible(false); |
||||
connect(&mCloseButtons, SIGNAL(clicked()), this, SLOT(onCloseClicked())); |
||||
} |
||||
|
||||
UBActionableWidget::~UBActionableWidget() |
||||
{ |
||||
|
||||
} |
||||
|
||||
void UBActionableWidget::addAction(eAction act) |
||||
{ |
||||
if(!mActions.contains(act)){ |
||||
mActions << act; |
||||
} |
||||
} |
||||
|
||||
void UBActionableWidget::removeAction(eAction act) |
||||
{ |
||||
if(mActions.contains(act)){ |
||||
mActions.remove(mActions.indexOf(act)); |
||||
} |
||||
} |
||||
|
||||
void UBActionableWidget::removeAllActions() |
||||
{ |
||||
mActions.clear(); |
||||
} |
||||
|
||||
void UBActionableWidget::setActionsVisible(bool bVisible) |
||||
{ |
||||
if(!mActions.empty() && mActions.contains(eAction_Close)){ |
||||
mCloseButtons.setVisible(bVisible); |
||||
} |
||||
} |
||||
|
||||
void UBActionableWidget::onCloseClicked() |
||||
{ |
||||
emit close(this); |
||||
} |
||||
|
||||
void UBActionableWidget::setActionsParent(QWidget *parent) |
||||
{ |
||||
if(mActions.contains(eAction_Close)){ |
||||
mCloseButtons.setParent(parent); |
||||
} |
||||
} |
||||
|
||||
void UBActionableWidget::unsetActionsParent() |
||||
{ |
||||
if(mActions.contains(eAction_Close)){ |
||||
mCloseButtons.setParent(this); |
||||
} |
||||
} |
@ -0,0 +1,68 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#ifndef UBACTIONABLEWIDGET_H |
||||
#define UBACTIONABLEWIDGET_H |
||||
|
||||
#include <QWidget> |
||||
#include <QPaintEvent> |
||||
#include <QToolButton> |
||||
#include <QPushButton> |
||||
|
||||
#define ACTIONSIZE 16 |
||||
|
||||
typedef enum{ |
||||
eAction_Close, |
||||
eAction_MoveUp, |
||||
eAction_MoveDown |
||||
}eAction; |
||||
|
||||
class UBActionableWidget : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBActionableWidget(QWidget* parent=0, const char* name="UBActionableWidget"); |
||||
~UBActionableWidget(); |
||||
void addAction(eAction act); |
||||
void removeAction(eAction act); |
||||
void removeAllActions(); |
||||
void setActionsVisible(bool bVisible); |
||||
|
||||
signals: |
||||
void close(QWidget* w); |
||||
|
||||
protected: |
||||
void setActionsParent(QWidget* parent); |
||||
void unsetActionsParent(); |
||||
QVector<eAction> mActions; |
||||
QPushButton mCloseButtons; |
||||
|
||||
private slots: |
||||
void onCloseClicked(); |
||||
|
||||
private: |
||||
bool mShowActions; |
||||
|
||||
}; |
||||
|
||||
#endif // UBACTIONABLEWIDGET_H
|
@ -0,0 +1,212 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#include "UBGraphicsItemAction.h" |
||||
#include "core/UBApplication.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
#include "board/UBBoardController.h" |
||||
#include "web/UBWebController.h" |
||||
#include "document/UBDocumentController.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
#include "document/UBDocumentContainer.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
|
||||
UBGraphicsItemAction::UBGraphicsItemAction(eUBGraphicsItemLinkType linkType, QObject *parent) : |
||||
QObject(parent) |
||||
{ |
||||
mLinkType = linkType; |
||||
} |
||||
|
||||
void UBGraphicsItemAction::actionRemoved() |
||||
{ |
||||
//NOOP
|
||||
} |
||||
|
||||
|
||||
UBGraphicsItemPlayAudioAction::UBGraphicsItemPlayAudioAction(QString audioFile, bool onImport, QObject *parent) : |
||||
UBGraphicsItemAction(eLinkToAudio,parent) |
||||
, mMediaObject(0) |
||||
, mIsLoading(true) |
||||
{ |
||||
Q_ASSERT(audioFile.length() > 0); |
||||
|
||||
if(onImport){ |
||||
QString extension = QFileInfo(audioFile).completeSuffix(); |
||||
QString destDir = UBApplication::boardController->selectedDocument()->persistencePath() + "/" + UBPersistenceManager::audioDirectory; |
||||
QString destFile = destDir + "/" + QUuid::createUuid().toString() + "." + extension; |
||||
if(!QDir(destDir).exists()) |
||||
QDir(UBApplication::boardController->selectedDocument()->persistencePath()).mkdir(destDir); |
||||
//explanation : the audioFile could be relative. The method copy will return false so a second try is done adding
|
||||
// the document file path
|
||||
if(!QFile(audioFile).copy(destFile)) |
||||
QFile(UBApplication::boardController->selectedDocument()->persistencePath() + "/" + audioFile).copy(destFile); |
||||
mAudioPath = destFile; |
||||
mFullPath = destFile; |
||||
} |
||||
else |
||||
{ |
||||
//On import don't recreate the file
|
||||
mAudioPath = audioFile; |
||||
mFullPath = mAudioPath; |
||||
} |
||||
|
||||
mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); |
||||
mMediaObject = new Phonon::MediaObject(this); |
||||
Phonon::createPath(mMediaObject, mAudioOutput); |
||||
mMediaObject->setCurrentSource(Phonon::MediaSource(mAudioPath)); |
||||
} |
||||
|
||||
|
||||
UBGraphicsItemPlayAudioAction::UBGraphicsItemPlayAudioAction() : |
||||
UBGraphicsItemAction(eLinkToAudio,NULL) |
||||
, mMediaObject(0) |
||||
, mIsLoading(true) |
||||
{ |
||||
} |
||||
|
||||
|
||||
void UBGraphicsItemPlayAudioAction::setPath(QString audioPath) |
||||
{ |
||||
Q_ASSERT(audioPath.length() > 0); |
||||
mAudioPath = audioPath; |
||||
mFullPath = mAudioPath; |
||||
mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); |
||||
mMediaObject = new Phonon::MediaObject(this); |
||||
Phonon::createPath(mMediaObject, mAudioOutput); |
||||
mMediaObject->setCurrentSource(Phonon::MediaSource(mAudioPath)); |
||||
} |
||||
|
||||
QString UBGraphicsItemPlayAudioAction::fullPath() |
||||
{ |
||||
return mFullPath; |
||||
} |
||||
|
||||
UBGraphicsItemPlayAudioAction::~UBGraphicsItemPlayAudioAction() |
||||
{ |
||||
if(!mMediaObject && mMediaObject->state() == Phonon::PlayingState) |
||||
mMediaObject->stop(); |
||||
} |
||||
|
||||
void UBGraphicsItemPlayAudioAction::onSourceHide() |
||||
{ |
||||
if(mMediaObject && mMediaObject->state() == Phonon::PlayingState){ |
||||
mMediaObject->stop(); |
||||
} |
||||
} |
||||
|
||||
void UBGraphicsItemPlayAudioAction::play() |
||||
{ |
||||
if(mMediaObject->state() == Phonon::PlayingState){ |
||||
mMediaObject->stop(); |
||||
} |
||||
mMediaObject->seek(0); |
||||
mMediaObject->play(); |
||||
} |
||||
|
||||
|
||||
QStringList UBGraphicsItemPlayAudioAction::save() |
||||
{ |
||||
//Another hack
|
||||
if(UBApplication::documentController && UBApplication::documentController->selectedDocument()){ |
||||
QString documentPath = UBApplication::documentController->selectedDocument()->persistencePath() + "/"; |
||||
return QStringList() << QString("%1").arg(eLinkToAudio) << mAudioPath.replace(documentPath,""); |
||||
} |
||||
else{ |
||||
int index = mAudioPath.indexOf("/audios/"); |
||||
QString relativePath = mAudioPath.remove(0,index + 1); |
||||
return QStringList() << QString("%1").arg(eLinkToAudio) << relativePath; |
||||
} |
||||
} |
||||
|
||||
void UBGraphicsItemPlayAudioAction::actionRemoved() |
||||
{ |
||||
QFile(mAudioPath).remove(); |
||||
} |
||||
|
||||
|
||||
UBGraphicsItemMoveToPageAction::UBGraphicsItemMoveToPageAction(eUBGraphicsItemMovePageAction actionType, int page, QObject* parent) : |
||||
UBGraphicsItemAction(eLinkToPage,parent) |
||||
{ |
||||
mActionType = actionType; |
||||
mPage = page; |
||||
} |
||||
|
||||
void UBGraphicsItemMoveToPageAction::play() |
||||
{ |
||||
UBBoardController* boardController = UBApplication::boardController; |
||||
|
||||
switch (mActionType) { |
||||
case eMoveToFirstPage: |
||||
boardController->firstScene(); |
||||
break; |
||||
case eMoveToLastPage: |
||||
boardController->lastScene(); |
||||
break; |
||||
case eMoveToPreviousPage: |
||||
boardController->previousScene(); |
||||
break; |
||||
case eMoveToNextPage: |
||||
boardController->nextScene(); |
||||
break; |
||||
case eMoveToPage: |
||||
if(mPage >= 0 && mPage < boardController->pageCount()) |
||||
boardController->setActiveDocumentScene(mPage); |
||||
else |
||||
qWarning() << "scene number " << mPage << "ins't accessible anymore"; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
QStringList UBGraphicsItemMoveToPageAction::save() |
||||
{ |
||||
return QStringList() << QString("%1").arg(eLinkToPage) << QString("%1").arg(mActionType) << QString("%1").arg(mPage); |
||||
} |
||||
|
||||
|
||||
UBGraphicsItemLinkToWebPageAction::UBGraphicsItemLinkToWebPageAction(QString url, QObject *parent) : |
||||
UBGraphicsItemAction(eLinkToWebUrl,parent) |
||||
{ |
||||
if (url.length() > 0) |
||||
{ |
||||
if(!url.startsWith("http://")) |
||||
url = "http://" + url; |
||||
mUrl = url; |
||||
} |
||||
else |
||||
mUrl = QString(); |
||||
} |
||||
|
||||
void UBGraphicsItemLinkToWebPageAction::play() |
||||
{ |
||||
if (mUrl.length() > 0) |
||||
UBApplication::webController->loadUrl(QUrl(mUrl)); |
||||
} |
||||
|
||||
QStringList UBGraphicsItemLinkToWebPageAction::save() |
||||
{ |
||||
return QStringList() << QString("%1").arg(eLinkToWebUrl) << mUrl; |
||||
} |
@ -0,0 +1,124 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#ifndef UBGRAPHICSITEMSACTIONS_H |
||||
#define UBGRAPHICSITEMSACTIONS_H |
||||
|
||||
#include <QObject> |
||||
#include <phonon> |
||||
|
||||
|
||||
enum eUBGraphicsItemMovePageAction { |
||||
eMoveToFirstPage = 0, |
||||
eMoveToLastPage, |
||||
eMoveToPreviousPage, |
||||
eMoveToNextPage, |
||||
eMoveToPage |
||||
} ; |
||||
|
||||
enum eUBGraphicsItemLinkType |
||||
{ |
||||
eLinkToAudio = 0, |
||||
eLinkToPage, |
||||
eLinkToWebUrl |
||||
}; |
||||
|
||||
class UBGraphicsItemAction : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBGraphicsItemAction(eUBGraphicsItemLinkType linkType,QObject* parent = 0); |
||||
virtual void play() = 0; |
||||
virtual QStringList save() = 0; |
||||
virtual void actionRemoved(); |
||||
virtual QString path() {return "";} |
||||
eUBGraphicsItemLinkType linkType() { return mLinkType;} |
||||
|
||||
signals: |
||||
|
||||
public slots: |
||||
private: |
||||
eUBGraphicsItemLinkType mLinkType; |
||||
|
||||
}; |
||||
|
||||
|
||||
class UBGraphicsItemPlayAudioAction : public UBGraphicsItemAction |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBGraphicsItemPlayAudioAction(QString audioFile, bool onImport = true, QObject* parent = 0); |
||||
UBGraphicsItemPlayAudioAction(); |
||||
~UBGraphicsItemPlayAudioAction(); |
||||
void play(); |
||||
QStringList save(); |
||||
void actionRemoved(); |
||||
QString path() {return mAudioPath;} |
||||
void setPath(QString audioPath); |
||||
QString fullPath(); |
||||
|
||||
public slots: |
||||
void onSourceHide(); |
||||
|
||||
private: |
||||
QString mAudioPath; |
||||
Phonon::MediaObject *mMediaObject; |
||||
Phonon::AudioOutput *mAudioOutput; |
||||
bool mIsLoading; |
||||
QString mFullPath; |
||||
}; |
||||
|
||||
|
||||
class UBGraphicsItemMoveToPageAction : public UBGraphicsItemAction |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBGraphicsItemMoveToPageAction(eUBGraphicsItemMovePageAction actionType, int page = 0, QObject* parent = 0); |
||||
void play(); |
||||
QStringList save(); |
||||
int page(){return mPage;} |
||||
eUBGraphicsItemMovePageAction actionType(){return mActionType;} |
||||
|
||||
private: |
||||
eUBGraphicsItemMovePageAction mActionType; |
||||
int mPage; |
||||
|
||||
}; |
||||
|
||||
class UBGraphicsItemLinkToWebPageAction : public UBGraphicsItemAction |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBGraphicsItemLinkToWebPageAction(QString url, QObject* parent = 0); |
||||
void play(); |
||||
QStringList save(); |
||||
QString url(){return mUrl;} |
||||
|
||||
private: |
||||
QString mUrl; |
||||
}; |
||||
|
||||
#endif // UBGRAPHICSITEMSACTIONS_H
|
@ -0,0 +1,368 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "globals/UBGlobals.h" |
||||
#include "UBMediaWidget.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param type as the media type |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name):UBActionableWidget(parent, name) |
||||
, mpMediaObject(NULL) |
||||
, mpVideoWidget(NULL) |
||||
, mpAudioOutput(NULL) |
||||
, mpLayout(NULL) |
||||
, mpSeekerLayout(NULL) |
||||
, mpPlayStopButton(NULL) |
||||
, mpPauseButton(NULL) |
||||
, mpSlider(NULL) |
||||
, mAutoUpdate(false) |
||||
, mGeneratingThumbnail(false) |
||||
, mBorder(5) |
||||
, mpMediaContainer(NULL) |
||||
, mMediaLayout(NULL) |
||||
, mpCover(NULL) |
||||
{ |
||||
SET_STYLE_SHEET(); |
||||
|
||||
addAction(eAction_Close); |
||||
mType = type; |
||||
mpLayout = new QVBoxLayout(this); |
||||
setLayout(mpLayout); |
||||
|
||||
mpPlayStopButton = new UBMediaButton(this); |
||||
mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); |
||||
mpPauseButton = new UBMediaButton(this); |
||||
mpPauseButton->setPixmap(QPixmap(":images/pause.svg")); |
||||
mpPauseButton->setEnabled(false); |
||||
mpSlider = new QSlider(this); |
||||
mpSlider->setOrientation(Qt::Horizontal); |
||||
mpSlider->setMinimum(0); |
||||
mpSlider->setMaximum(0); |
||||
|
||||
mpSeekerLayout = new QHBoxLayout(); |
||||
mpSeekerLayout->addWidget(mpPlayStopButton, 0); |
||||
mpSeekerLayout->addWidget(mpPauseButton, 0); |
||||
mpSeekerLayout->addWidget(mpSlider, 1); |
||||
mpSeekerLayout->setContentsMargins(0, 0, 0, 0); |
||||
|
||||
connect(mpPlayStopButton, SIGNAL(clicked()), this, SLOT(onPlayStopClicked())); |
||||
connect(mpPauseButton, SIGNAL(clicked()), this, SLOT(onPauseClicked())); |
||||
connect(mpSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int))); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBMediaWidget::~UBMediaWidget() |
||||
{ |
||||
unsetActionsParent(); |
||||
DELETEPTR(mpMediaObject); |
||||
DELETEPTR(mpSlider); |
||||
DELETEPTR(mpPauseButton); |
||||
DELETEPTR(mpPlayStopButton); |
||||
DELETEPTR(mpAudioOutput); |
||||
DELETEPTR(mpVideoWidget); |
||||
DELETEPTR(mpCover); |
||||
DELETEPTR(mpMediaContainer); |
||||
DELETEPTR(mpSeekerLayout); |
||||
DELETEPTR(mpLayout); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the media file |
||||
* @param filePath as the media file path |
||||
*/ |
||||
void UBMediaWidget::setFile(const QString &filePath) |
||||
{ |
||||
Q_ASSERT("" != filePath); |
||||
mFilePath = filePath; |
||||
mpMediaObject = new Phonon::MediaObject(this); |
||||
mpMediaObject->setTickInterval(TICK_INTERVAL); |
||||
connect(mpMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State))); |
||||
connect(mpMediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(onTotalTimeChanged(qint64))); |
||||
connect(mpMediaObject, SIGNAL(tick(qint64)), this, SLOT(onTick(qint64))); |
||||
mpMediaObject->setCurrentSource(Phonon::MediaSource(filePath)); |
||||
createMediaPlayer(); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the media type |
||||
* @returns the media type |
||||
*/ |
||||
eMediaType UBMediaWidget::mediaType() |
||||
{ |
||||
return mType; |
||||
} |
||||
|
||||
void UBMediaWidget::showEvent(QShowEvent* event) |
||||
{ |
||||
if(mType == eMediaType_Audio){ |
||||
return; |
||||
}else{ |
||||
if(!mpVideoWidget){ |
||||
mpVideoWidget = new Phonon::VideoWidget(this); |
||||
mMediaLayout->addStretch(1); |
||||
mMediaLayout->addWidget(mpVideoWidget); |
||||
mMediaLayout->addStretch(1); |
||||
Phonon::createPath(mpMediaObject, mpVideoWidget); |
||||
adaptSizeToVideo(); |
||||
mpMediaObject->play(); |
||||
mpMediaObject->stop(); |
||||
} |
||||
QWidget::showEvent(event); |
||||
} |
||||
} |
||||
|
||||
void UBMediaWidget::hideEvent(QHideEvent* event) |
||||
{ |
||||
if(mpMediaObject->state() == Phonon::PlayingState) |
||||
mpMediaObject->stop(); |
||||
UBActionableWidget::hideEvent(event); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Create the media player |
||||
*/ |
||||
void UBMediaWidget::createMediaPlayer() |
||||
{ |
||||
mpMediaContainer = new QWidget(); |
||||
mpMediaContainer->setObjectName("UBMediaVideoContainer"); |
||||
mMediaLayout = new QHBoxLayout(); |
||||
mpMediaContainer->setLayout(mMediaLayout); |
||||
|
||||
if(eMediaType_Video == mType){ |
||||
mMediaLayout->setContentsMargins(10, 10, 10, 10); |
||||
if(isVisible()){ |
||||
mpVideoWidget = new Phonon::VideoWidget(this); |
||||
mMediaLayout->addStretch(1); |
||||
mMediaLayout->addWidget(mpVideoWidget); |
||||
mMediaLayout->addStretch(1); |
||||
Phonon::createPath(mpMediaObject, mpVideoWidget); |
||||
adaptSizeToVideo(); |
||||
} |
||||
mpAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); |
||||
Phonon::createPath(mpMediaObject, mpAudioOutput); |
||||
}else if(eMediaType_Audio == mType){ |
||||
mMediaLayout->setContentsMargins(10, 10, 10, 10); |
||||
mpCover = new QLabel(mpMediaContainer); |
||||
//mpMediaContainer->setStyleSheet(QString("background: none;"));
|
||||
setAudioCover(":images/libpalette/soundIcon.svg"); |
||||
mpCover->setScaledContents(true); |
||||
mMediaLayout->addStretch(1); |
||||
mMediaLayout->addWidget(mpCover); |
||||
mMediaLayout->addStretch(1); |
||||
mpAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); |
||||
Phonon::createPath(mpMediaObject, mpAudioOutput); |
||||
} |
||||
mpLayout->addWidget(mpMediaContainer, 1); |
||||
mpLayout->addLayout(mpSeekerLayout, 0); |
||||
setActionsParent(mpMediaContainer); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Adapt the widget size to the video in order to keep the good aspect ratio |
||||
*/ |
||||
void UBMediaWidget::adaptSizeToVideo() |
||||
{ |
||||
if(NULL != mpMediaContainer){ |
||||
int origW = mpMediaContainer->width(); |
||||
int origH = mpMediaContainer->height(); |
||||
int newW = width(); |
||||
float scaleFactor = (float)origW/(float)newW; |
||||
int newH = origH/scaleFactor; |
||||
resize(newW, height() + newH); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the media state change notification |
||||
* @param newState as the new state |
||||
* @param oldState as the old state |
||||
*/ |
||||
void UBMediaWidget::onStateChanged(Phonon::State newState, Phonon::State oldState) |
||||
{ |
||||
if(!mGeneratingThumbnail){ |
||||
if(Phonon::LoadingState == oldState && Phonon::StoppedState == newState){ |
||||
if(eMediaType_Video == mType){ |
||||
// We do that here to generate the thumbnail of the video
|
||||
mGeneratingThumbnail = true; |
||||
mpMediaObject->play(); |
||||
mpMediaObject->pause(); |
||||
mGeneratingThumbnail = false; |
||||
} |
||||
}else if(Phonon::PlayingState == oldState && Phonon::PausedState == newState){ |
||||
mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); |
||||
mpPauseButton->setEnabled(false); |
||||
}else if((Phonon::PausedState == oldState && Phonon::PlayingState == newState) || |
||||
(Phonon::StoppedState == oldState && Phonon::PlayingState == newState)){ |
||||
mpPlayStopButton->setPixmap(QPixmap(":images/stop.svg")); |
||||
mpPauseButton->setEnabled(true); |
||||
}else if(Phonon::PlayingState == oldState && Phonon::StoppedState == newState){ |
||||
mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); |
||||
mpPauseButton->setEnabled(false); |
||||
mpSlider->setValue(0); |
||||
} |
||||
|
||||
} |
||||
// if(mType == eMediaType_Video)
|
||||
// updateView(newState);
|
||||
} |
||||
|
||||
/**
|
||||
* \brief Handles the total time change notification |
||||
* @param total as the new total time |
||||
*/ |
||||
void UBMediaWidget::onTotalTimeChanged(qint64 total) |
||||
{ |
||||
mpSlider->setMaximum(total); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handles the tick notification |
||||
* @param currentTime as the current time |
||||
*/ |
||||
void UBMediaWidget::onTick(qint64 currentTime) |
||||
{ |
||||
mAutoUpdate = true; |
||||
mpSlider->setValue((int)currentTime); |
||||
mAutoUpdate = false; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handles the seeker value change notification |
||||
* @param value as the new seeker value |
||||
*/ |
||||
void UBMediaWidget::onSliderChanged(int value) |
||||
{ |
||||
if(!mAutoUpdate){ |
||||
mpMediaObject->seek(value); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Toggle Play-Stop |
||||
*/ |
||||
void UBMediaWidget::onPlayStopClicked() |
||||
{ |
||||
switch(mpMediaObject->state()){ |
||||
case Phonon::PlayingState: |
||||
mpMediaObject->stop(); |
||||
break; |
||||
|
||||
case Phonon::StoppedState: |
||||
case Phonon::PausedState: |
||||
mpMediaObject->play(); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Pause the media |
||||
*/ |
||||
void UBMediaWidget::onPauseClicked() |
||||
{ |
||||
mpMediaObject->pause(); |
||||
} |
||||
|
||||
/**
|
||||
* Get the border |
||||
* @returns the actual border |
||||
*/ |
||||
int UBMediaWidget::border() |
||||
{ |
||||
return mBorder; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handles the resize event |
||||
* @param ev as the resize event |
||||
*/ |
||||
void UBMediaWidget::resizeEvent(QResizeEvent* ev) |
||||
{ |
||||
Q_UNUSED(ev); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the audio cover |
||||
* @param coverPath as the cover image file path |
||||
*/ |
||||
void UBMediaWidget::setAudioCover(const QString &coverPath) |
||||
{ |
||||
if(NULL != mpCover){ |
||||
mpCover->setPixmap(QPixmap(coverPath)); |
||||
} |
||||
} |
||||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBMediaButton::UBMediaButton(QWidget *parent, const char *name):QLabel(parent) |
||||
, mPressed(false) |
||||
{ |
||||
setObjectName(name); |
||||
resize(UBMEDIABUTTON_SIZE, UBMEDIABUTTON_SIZE); |
||||
setStyleSheet(QString("padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;")); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBMediaButton::~UBMediaButton() |
||||
{ |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* \brief Handles the mouse press notification |
||||
* @param ev as the mouse press event |
||||
*/ |
||||
void UBMediaButton::mousePressEvent(QMouseEvent* ev) |
||||
{ |
||||
Q_UNUSED(ev); |
||||
mPressed = true; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handles the mouse release notification |
||||
* @param ev as the mouse release event |
||||
*/ |
||||
void UBMediaButton::mouseReleaseEvent(QMouseEvent* ev) |
||||
{ |
||||
Q_UNUSED(ev); |
||||
if(mPressed){ |
||||
mPressed = false; |
||||
emit clicked(); |
||||
} |
||||
} |
@ -0,0 +1,133 @@ |
||||
/*
|
||||
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour l'Education Numérique en Afrique (GIP ENA) |
||||
* |
||||
* This file is part of Open-Sankoré. |
||||
* |
||||
* Open-Sankoré 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). |
||||
* |
||||
* Open-Sankoré 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 Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
|
||||
|
||||
#ifndef UBMEDIAWIDGET_H |
||||
#define UBMEDIAWIDGET_H |
||||
|
||||
#include <QWidget> |
||||
#include <QVBoxLayout> |
||||
#include <QHBoxLayout> |
||||
#include <QLabel> |
||||
#include <QSlider> |
||||
#include <QMouseEvent> |
||||
#include <QStackedWidget> |
||||
|
||||
#include "UBActionableWidget.h" |
||||
|
||||
#define UBMEDIABUTTON_SIZE 32 |
||||
#define TICK_INTERVAL 1000 |
||||
|
||||
/**
|
||||
* \brief The media type |
||||
*/ |
||||
typedef enum{ |
||||
eMediaType_Video, |
||||
eMediaType_Audio |
||||
}eMediaType; |
||||
|
||||
class UBMediaButton : public QLabel |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBMediaButton(QWidget* parent=0, const char* name="UBMediaButton"); |
||||
~UBMediaButton(); |
||||
|
||||
signals: |
||||
void clicked(); |
||||
|
||||
protected: |
||||
void mousePressEvent(QMouseEvent* ev); |
||||
void mouseReleaseEvent(QMouseEvent* ev); |
||||
|
||||
private: |
||||
/** And indicator of the press event in progress */ |
||||
bool mPressed; |
||||
}; |
||||
|
||||
class UBMediaWidget : public UBActionableWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBMediaWidget(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBMediaWidget"); |
||||
~UBMediaWidget(); |
||||
void setFile(const QString& filePath); |
||||
eMediaType mediaType(); |
||||
int border(); |
||||
void setAudioCover(const QString& coverPath); |
||||
void setUrl(const QString& url){mUrl = url;} |
||||
QString url(){return mUrl;} |
||||
|
||||
protected: |
||||
void resizeEvent(QResizeEvent* ev); |
||||
void showEvent(QShowEvent* event); |
||||
void hideEvent(QHideEvent* event); |
||||
/** The current media file path */ |
||||
QString mFilePath; |
||||
|
||||
private slots: |
||||
void onPlayStopClicked(); |
||||
void onPauseClicked(); |
||||
void onStateChanged(Phonon::State newState, Phonon::State oldState); |
||||
void onTotalTimeChanged(qint64 total); |
||||
void onTick(qint64 currentTime); |
||||
void onSliderChanged(int value); |
||||
|
||||
private: |
||||
void createMediaPlayer(); |
||||
void adaptSizeToVideo(); |
||||
|
||||
/** The current media type */ |
||||
eMediaType mType; |
||||
/** The media object */ |
||||
Phonon::MediaObject* mpMediaObject; |
||||
/** The video renderer */ |
||||
Phonon::VideoWidget* mpVideoWidget; |
||||
/** The audio renderer */ |
||||
Phonon::AudioOutput* mpAudioOutput; |
||||
/** The principal layout of this widget */ |
||||
QVBoxLayout* mpLayout; |
||||
/** The seeker layout */ |
||||
QHBoxLayout* mpSeekerLayout; |
||||
/** The play-stop button */ |
||||
UBMediaButton* mpPlayStopButton; |
||||
/** The pause button */ |
||||
UBMediaButton* mpPauseButton; |
||||
/** The seeker slider */ |
||||
QSlider* mpSlider; |
||||
/** An indicator of the seeker auto update in progress */ |
||||
bool mAutoUpdate; |
||||
/** An indicator of the thumbnail generation in progress */ |
||||
bool mGeneratingThumbnail; |
||||
/** The border */ |
||||
int mBorder; |
||||
/** A widget that will contain the media */ |
||||
QWidget* mpMediaContainer; |
||||
/** The media layout */ |
||||
QHBoxLayout* mMediaLayout; |
||||
/** The audio cover */ |
||||
QLabel* mpCover; |
||||
/** The media url */ |
||||
QString mUrl; |
||||
}; |
||||
|
||||
#endif // UBMEDIAWIDGET_H
|
@ -0,0 +1,10 @@ |
||||
|
||||
HEADERS += \ |
||||
src/customWidgets/UBMediaWidget.h \ |
||||
src/customWidgets/UBActionableWidget.h \ |
||||
src/customWidgets/UBGraphicsItemAction.h |
||||
|
||||
SOURCES += \ |
||||
src/customWidgets/UBMediaWidget.cpp \ |
||||
src/customWidgets/UBActionableWidget.cpp \ |
||||
src/customWidgets/UBGraphicsItemAction.cpp |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,25 @@ |
||||
#include "UBSortFilterProxyModel.h" |
||||
#include "UBDocumentController.h" |
||||
|
||||
UBSortFilterProxyModel::UBSortFilterProxyModel(): |
||||
QSortFilterProxyModel() |
||||
{ |
||||
setDynamicSortFilter(true); |
||||
setSortCaseSensitivity(Qt::CaseInsensitive); |
||||
} |
||||
|
||||
bool UBSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const |
||||
{ |
||||
UBDocumentTreeModel *model = dynamic_cast<UBDocumentTreeModel*>(sourceModel()); |
||||
|
||||
if(model){ |
||||
//if it's a top level folder
|
||||
//in other words : myDocuments, models and trash folder
|
||||
if(model->isToplevel(left) || model->isToplevel(right)) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return QSortFilterProxyModel::lessThan(left, right); |
||||
} |
@ -0,0 +1,15 @@ |
||||
#ifndef UBSORTFILTERPROXYMODEL_H |
||||
#define UBSORTFILTERPROXYMODEL_H |
||||
|
||||
#include <QSortFilterProxyModel> |
||||
#include "core/UBPersistenceManager.h" |
||||
|
||||
class UBSortFilterProxyModel : public QSortFilterProxyModel |
||||
{ |
||||
public: |
||||
UBSortFilterProxyModel(); |
||||
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const; |
||||
}; |
||||
|
||||
#endif // UBSORTFILTERPROXYMODEL_H
|
@ -1,6 +1,11 @@ |
||||
HEADERS += src/document/UBDocumentController.h \ |
||||
HEADERS += \ |
||||
src/document/UBDocumentContainer.h \ |
||||
src/document/UBDocumentProxy.h |
||||
SOURCES += src/document/UBDocumentController.cpp \ |
||||
src/document/UBDocumentController.h \ |
||||
src/document/UBDocumentProxy.h \ |
||||
src/document/UBSortFilterProxyModel.h |
||||
SOURCES += \ |
||||
src/document/UBDocumentContainer.cpp \ |
||||
src/document/UBDocumentProxy.cpp |
||||
src/document/UBDocumentController.cpp \ |
||||
src/document/UBDocumentProxy.cpp \ |
||||
src/document/UBSortFilterProxyModel.cpp |
||||
|
||||
|
Loading…
Reference in new issue