Commit 27e20ccc authored by unknown's avatar unknown

Merge branch 'master' of github.com:Sankore/Sankore-3.1

parents 95ae6f8b 782a518c
...@@ -7,9 +7,9 @@ CONFIG += debug_and_release \ ...@@ -7,9 +7,9 @@ CONFIG += debug_and_release \
no_include_pwd no_include_pwd
VERSION_MAJ = 1 VERSION_MAJ = 1
VERSION_MIN = 10 VERSION_MIN = 11
VERSION_TYPE = b # a = alpha, b = beta, r = release, other => error VERSION_TYPE = b # a = alpha, b = beta, r = release, other => error
VERSION_PATCH = 01 VERSION_PATCH = 00
VERSION = "$${VERSION_MAJ}.$${VERSION_MIN}.$${VERSION_TYPE}.$${VERSION_PATCH}" VERSION = "$${VERSION_MAJ}.$${VERSION_MIN}.$${VERSION_TYPE}.$${VERSION_PATCH}"
VERSION = $$replace(VERSION, "\\.r", "") VERSION = $$replace(VERSION, "\\.r", "")
......
This diff is collapsed.
#ifndef UBCFFSUBSETADAPTOR_H
#define UBCFFSUBSETADAPTOR_H
#include <QtXml>
#include <QString>
#include <QStack>
class UBDocumentProxy;
class UBGraphicsScene;
class QSvgGenerator;
class UBCFFSubsetAdaptor
{
public:
UBCFFSubsetAdaptor();
static bool ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument);
private:
class UBCFFSubsetReader
{
//xml parse states definition
enum
{
NONE,
IWB,
SVG,
PAGESET,
PAGE,
TEXTAREA,
TSPAN
};
public:
UBCFFSubsetReader(UBDocumentProxy *proxy, QByteArray &content);
QXmlStreamReader mReader;
UBDocumentProxy *mProxy;
bool parse();
private:
QString mTempFilePath;
UBGraphicsScene *mCurrentScene;
QString mIndent;
QRectF mViewBox;
QSize mSize;
//methods to store current xml parse state
int PopState();
void PushState(int state);
//elements parsing methods
bool parseDoc();
bool parseCurrentElementStart();
bool parseCurrentElementCharacters();
bool parseCurrentElementEnd();
bool parseIwb();
bool parseIwbMeta();
bool parseSvg();
bool parseRect();
bool parseEllipse();
bool parseTextArea();
bool parsePolygon();
bool parsePage();
bool parsePageSet();
bool parseIwbElementRef();
bool createNewScene();
bool persistCurrentScene();
QStack<int> stateStack;
int currentState;
//helper methods
QColor colorFromString(const QString& clrString);
QTransform transformFromString(const QString trString);
bool getViewBoxDimenstions(const QString& viewBox);
QSvgGenerator* createSvgGenerator();
bool getTempFileName();
};
};
#endif // UBCFFSUBSETADAPTOR_H
#include <QDir>
#include "UBImportCFF.h"
#include "document/UBDocumentProxy.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBDocumentManager.h"
#include "core/memcheck.h"
#include "core/UBPersistenceManager.h"
#include "frameworks/UBFileSystemUtils.h"
#include "domain/UBGraphicsPDFItem.h"
#include "pdf/PDFRenderer.h"
#include "UBCFFSubsetAdaptor.h"
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
UBImportCFF::UBImportCFF(QObject *parent)
: UBImportAdaptor(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";
}
// first we search the metadata.rdf to check the document properties
for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
{
if(!zip.getCurrentFileInfo(&info))
{
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
return "";
}
QFileInfo currentFileInfo(pDir + "/" + file.getActualFileName());
}
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 "";
}
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);
// 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 "";
}
while(file.getChar(&c))
out.putChar(c);
out.close();
if(file.getZipError()!=UNZ_OK)
{
qWarning() << "Import failed. Cause: " << zip.getZipError();
return "";
}
if(!file.atEnd())
{
qWarning() << "Import failed. Cause: read all but not EOF";
return "";
}
file.close();
if(file.getZipError()!=UNZ_OK)
{
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError();
return "";
}
}
zip.close();
if(zip.getZipError()!=UNZ_OK)
{
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
return "";
}
return documentRootFolder;
}
UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup)
{
Q_UNUSED(pGroup); // group is defined in the imported file
QFileInfo fi(pFile);
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString path = QDir::tempPath();
QString documentRootFolder = expandFileToDir(pFile, path);
QString contentFile;
if (documentRootFolder.isEmpty())
//if file has failed to umzip it is probably just xml file
contentFile = pFile.fileName();
else
//get path to content xml
contentFile = QString("%1/content.xml").arg(documentRootFolder);
if(!contentFile.length()){
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return 0;
}
else{
//create destination document proxy
//fill metadata and save
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath());
QDir dir;
dir.mkdir(destDocument->persistencePath());
if (pGroup.length() > 0)
destDocument->setMetaData(UBSettings::documentGroupName, pGroup);
if (fi.baseName() > 0)
destDocument->setMetaData(UBSettings::documentName, fi.baseName());
destDocument->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion);
destDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBDocumentProxy* newDocument = NULL;
//try to import cff to document
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument))
{
newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(destDocument->persistencePath());
UBApplication::showMessage(tr("Import successful."));
}
else
{
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
UBApplication::showMessage(tr("Import failed."));
}
delete destDocument;
if (documentRootFolder.length() != 0)
UBFileSystemUtils::deleteDir(documentRootFolder);
return newDocument;
}
}
#ifndef UBIMPORTCFF_H
#define UBIMPORTCFF_H
#include <QtGui>
#include "UBImportAdaptor.h"
class UBDocumentProxy;
class UBImportCFF : public UBImportAdaptor
{
Q_OBJECT;
public:
UBImportCFF(QObject *parent = 0);
virtual ~UBImportCFF();
virtual QStringList supportedExtentions();
virtual QString importFileFilter();
virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile);
//base class method override
virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup);
private:
virtual QString expandFileToDir(const QFile& pZipFile, const QString& pDir);
};
#endif // UBIMPORTCFF_H
HEADERS += src/adaptors/UBExportAdaptor.h\ HEADERS += src/adaptors/UBExportAdaptor.h\
src/adaptors/UBExportPDF.h \ src/adaptors/UBExportPDF.h \
src/adaptors/UBExportFullPDF.h \ src/adaptors/UBExportFullPDF.h \
src/adaptors/UBExportDocument.h \ src/adaptors/UBExportDocument.h \
src/adaptors/UBSvgSubsetAdaptor.h \ src/adaptors/UBSvgSubsetAdaptor.h \
src/adaptors/UBMetadataDcSubsetAdaptor.h \ src/adaptors/UBMetadataDcSubsetAdaptor.h \
src/adaptors/UBImportAdaptor.h \ src/adaptors/UBImportAdaptor.h \
src/adaptors/UBImportDocument.h \ src/adaptors/UBImportDocument.h \
src/adaptors/UBThumbnailAdaptor.h \ src/adaptors/UBThumbnailAdaptor.h \
src/adaptors/UBImportPDF.h \ src/adaptors/UBImportPDF.h \
src/adaptors/UBImportImage.h \ src/adaptors/UBImportImage.h \
src/adaptors/UBIniFileParser.h \ src/adaptors/UBIniFileParser.h \
src/adaptors/UBExportWeb.h \ src/adaptors/UBExportWeb.h \
src/adaptors/UBWebPublisher.h src/adaptors/UBWebPublisher.h \
src/adaptors/UBImportCFF.h \
HEADERS += src/adaptors/publishing/UBDocumentPublisher.h \ src/adaptors/UBCFFSubsetAdaptor.h
src/adaptors/publishing/UBCapturePublisher.h \
src/adaptors/publishing/UBAbstractPublisher.h \ HEADERS += src/adaptors/publishing/UBDocumentPublisher.h \
src/adaptors/publishing/UBSvgSubsetRasterizer.h src/adaptors/publishing/UBCapturePublisher.h \
src/adaptors/publishing/UBAbstractPublisher.h \
HEADERS += src/adaptors/voting/UBAbstractVotingSystem.h src/adaptors/publishing/UBSvgSubsetRasterizer.h
HEADERS += src/adaptors/voting/UBAbstractVotingSystem.h
SOURCES += src/adaptors/UBExportAdaptor.cpp\
src/adaptors/UBExportPDF.cpp \
src/adaptors/UBExportFullPDF.cpp \ SOURCES += src/adaptors/UBExportAdaptor.cpp\
src/adaptors/UBExportDocument.cpp \ src/adaptors/UBExportPDF.cpp \
src/adaptors/UBSvgSubsetAdaptor.cpp \ src/adaptors/UBExportFullPDF.cpp \
src/adaptors/UBMetadataDcSubsetAdaptor.cpp \ src/adaptors/UBExportDocument.cpp \
src/adaptors/UBImportAdaptor.cpp \ src/adaptors/UBSvgSubsetAdaptor.cpp \
src/adaptors/UBImportDocument.cpp \ src/adaptors/UBMetadataDcSubsetAdaptor.cpp \
src/adaptors/UBThumbnailAdaptor.cpp \ src/adaptors/UBImportAdaptor.cpp \
src/adaptors/UBImportPDF.cpp \ src/adaptors/UBImportDocument.cpp \
src/adaptors/UBImportImage.cpp \ src/adaptors/UBThumbnailAdaptor.cpp \
src/adaptors/UBIniFileParser.cpp \ src/adaptors/UBImportPDF.cpp \
src/adaptors/UBExportWeb.cpp \ src/adaptors/UBImportImage.cpp \
src/adaptors/UBWebPublisher.cpp src/adaptors/UBIniFileParser.cpp \
src/adaptors/UBExportWeb.cpp \
SOURCES += src/adaptors/publishing/UBDocumentPublisher.cpp \ src/adaptors/UBWebPublisher.cpp \
src/adaptors/publishing/UBCapturePublisher.cpp \ src/adaptors/UBImportCFF.cpp \
src/adaptors/publishing/UBAbstractPublisher.cpp \ src/adaptors/UBCFFSubsetAdaptor.cpp
src/adaptors/publishing/UBSvgSubsetRasterizer.cpp
SOURCES += src/adaptors/publishing/UBDocumentPublisher.cpp \
SOURCES += src/adaptors/voting/UBAbstractVotingSystem.cpp src/adaptors/publishing/UBCapturePublisher.cpp \
src/adaptors/publishing/UBAbstractPublisher.cpp \
src/adaptors/publishing/UBSvgSubsetRasterizer.cpp
win32 {
SOURCES += src/adaptors/voting/UBAbstractVotingSystem.cpp
SOURCES += src/adaptors/voting/UBReply2005VotingSystem.cpp \
src/adaptors/voting/UBReplyWRS970VotingSystem.cpp
win32 {
HEADERS += src/adaptors/voting/UBReply2005VotingSystem.h \
src/adaptors/voting/UBReplyWRS970VotingSystem.h SOURCES += src/adaptors/voting/UBReply2005VotingSystem.cpp \
} src/adaptors/voting/UBReplyWRS970VotingSystem.cpp
HEADERS += src/adaptors/voting/UBReply2005VotingSystem.h \
src/adaptors/voting/UBReplyWRS970VotingSystem.h
}
...@@ -268,11 +268,6 @@ int UBApplication::exec(const QString& pFileToImport) ...@@ -268,11 +268,6 @@ int UBApplication::exec(const QString& pFileToImport)
connect(mainWindow->actionCopy, SIGNAL(triggered()), applicationController, SLOT(actionCopy())); connect(mainWindow->actionCopy, SIGNAL(triggered()), applicationController, SLOT(actionCopy()));
connect(mainWindow->actionPaste, SIGNAL(triggered()), applicationController, SLOT(actionPaste())); connect(mainWindow->actionPaste, SIGNAL(triggered()), applicationController, SLOT(actionPaste()));
//#ifndef __ppc__
// // this cause a problem on MACX/PPC (see https://trac.assembla.com/uniboard/ticket/862)
// installEventFilter(new UBIdleTimer(this));
//#endif
applicationController->initScreenLayout(); applicationController->initScreenLayout();
boardController->setupLayout(); boardController->setupLayout();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "adaptors/UBImportDocument.h" #include "adaptors/UBImportDocument.h"
#include "adaptors/UBImportPDF.h" #include "adaptors/UBImportPDF.h"
#include "adaptors/UBImportImage.h" #include "adaptors/UBImportImage.h"
#include "adaptors/UBImportCFF.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsSvgItem.h"
...@@ -75,6 +76,8 @@ UBDocumentManager::UBDocumentManager(QObject *parent) ...@@ -75,6 +76,8 @@ UBDocumentManager::UBDocumentManager(QObject *parent)
mImportAdaptors.append(pdfImport); mImportAdaptors.append(pdfImport);
UBImportImage* imageImport = new UBImportImage(this); UBImportImage* imageImport = new UBImportImage(this);
mImportAdaptors.append(imageImport); mImportAdaptors.append(imageImport);
UBImportCFF* cffImport = new UBImportCFF(this);
mImportAdaptors.append(cffImport);
} }
......
...@@ -65,7 +65,6 @@ UBPreferencesController::UBPreferencesController(QWidget *parent) ...@@ -65,7 +65,6 @@ UBPreferencesController::UBPreferencesController(QWidget *parent)
, mMarkerProperties(0) , mMarkerProperties(0)
{ {
mPreferencesWindow = new UBPreferencesDialog(this,parent, Qt::Dialog); mPreferencesWindow = new UBPreferencesDialog(this,parent, Qt::Dialog);
// mPreferencesWindow = new QDialog(parent, Qt::Dialog);
mPreferencesUI = new Ui::preferencesDialog(); // deleted in mPreferencesUI = new Ui::preferencesDialog(); // deleted in
mPreferencesUI->setupUi(mPreferencesWindow); mPreferencesUI->setupUi(mPreferencesWindow);
connect(mPreferencesUI->Username_textBox, SIGNAL(editingFinished()), this, SLOT(onCommunityUsernameChanged())); connect(mPreferencesUI->Username_textBox, SIGNAL(editingFinished()), this, SLOT(onCommunityUsernameChanged()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment