diff --git a/src/adaptors/UBExportDocument.cpp b/src/adaptors/UBExportDocument.cpp index af2ba68f..962b9502 100644 --- a/src/adaptors/UBExportDocument.cpp +++ b/src/adaptors/UBExportDocument.cpp @@ -99,5 +99,5 @@ QString UBExportDocument::exportExtention() QString UBExportDocument::exportName() { - return tr("Export to Uniboard Format"); + return tr("Export to Sankore Format"); } diff --git a/src/adaptors/UBImportVirtualPrinter.cpp b/src/adaptors/UBImportVirtualPrinter.cpp index ca7919c0..95fecea4 100644 --- a/src/adaptors/UBImportVirtualPrinter.cpp +++ b/src/adaptors/UBImportVirtualPrinter.cpp @@ -132,7 +132,7 @@ void UBImportVirtualPrinter::cleanUp(const QFile& pFile, const QString& pPdfFile UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QString& pGroup) { - UBApplication::showMessage(tr("Importing Uniboard printer file ...")); + UBApplication::showMessage(tr("Importing Sankore printer file ...")); UBDocumentProxy *document = 0; QString pdfFilename = pdfFileName(pFile); @@ -159,7 +159,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS if (!document) { - UBApplication::showMessage(tr("Error while importing Uniboard printer file.")); + UBApplication::showMessage(tr("Error while importing Sankore printer file.")); } cleanUp(pFile, pdfFilename, emfFileNames(pFile)); @@ -170,7 +170,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { - UBApplication::showMessage(tr("Importing Uniboard printer file ...")); + UBApplication::showMessage(tr("Importing Sankore printer file ...")); bool result = false; QString pdfFilename = pdfFileName(pFile); @@ -183,7 +183,7 @@ bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const if (!result) { - UBApplication::showMessage(tr("Error while importing Uniboard printer file.")); + UBApplication::showMessage(tr("Error while importing Sankore printer file.")); } cleanUp(pFile, pdfFilename, emfFileNames(pFile)); diff --git a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp index 72a54552..4bb689e5 100644 --- a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp +++ b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp @@ -204,7 +204,7 @@ QMap UBMetadataDcSubsetAdaptor::load(QString pPath) if (xml.hasError()) { - qWarning() << "error parsing uniboard metadata.rdf file " << xml.errorString(); + qWarning() << "error parsing sankore metadata.rdf file " << xml.errorString(); } } diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 022ce2f4..e95ae96e 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -781,7 +781,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() if (mXmlReader.hasError()) { - qWarning() << "error parsing uniboard file " << mXmlReader.errorString(); + qWarning() << "error parsing Sankore file " << mXmlReader.errorString(); } if (scene) @@ -2576,31 +2576,16 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() graphicsItemFromSvg(triangle); - //QStringRef angle = mXmlReader.attributes().value(mNamespaceUri, "angle"); - //if (!angle.isNull()) - //{ - // protractor->setAngle(angle.toString().toFloat()); - //} - - //QStringRef markerAngle = mXmlReader.attributes().value(mNamespaceUri, "marker-angle"); - //if (!markerAngle.isNull()) - //{ - // protractor->setMarkerAngle(markerAngle.toString().toFloat()); - //} - QStringRef svgX = mXmlReader.attributes().value("x"); QStringRef svgY = mXmlReader.attributes().value("y"); QStringRef svgWidth = mXmlReader.attributes().value("width"); QStringRef svgHeight = mXmlReader.attributes().value("height"); - - UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation = - UBGraphicsTriangle::orientationFromStr((mXmlReader.attributes().value("orientation"))); + QStringRef orientationStringRef = mXmlReader.attributes().value("orientation"); + UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation = UBGraphicsTriangle::orientationFromStr(orientationStringRef); if (!svgX.isNull() && !svgY.isNull() && !svgWidth.isNull() && !svgHeight.isNull()) { - triangle->setRect(svgX.toString().toFloat(), svgY.toString().toFloat() - , svgWidth.toString().toFloat(), svgHeight.toString().toFloat(), - orientation); + triangle->setRect(svgX.toString().toFloat(), svgY.toString().toFloat(), svgWidth.toString().toFloat(), svgHeight.toString().toFloat(), orientation); } triangle->setVisible(true); diff --git a/src/adaptors/UBWebPublisher.cpp b/src/adaptors/UBWebPublisher.cpp index 80133b34..36b3c08c 100644 --- a/src/adaptors/UBWebPublisher.cpp +++ b/src/adaptors/UBWebPublisher.cpp @@ -28,7 +28,7 @@ UBWebPublisher::~UBWebPublisher() QString UBWebPublisher::exportName() { - return tr("Publish Document on Uniboard Web"); + return tr("Publish Document on Sankore Web"); } diff --git a/src/adaptors/publishing/UBDocumentPublisher.cpp b/src/adaptors/publishing/UBDocumentPublisher.cpp index 3d98d92d..e2201f05 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.cpp +++ b/src/adaptors/publishing/UBDocumentPublisher.cpp @@ -1,4 +1,4 @@ -#include "UBDocumentPublisher.h" + #include "UBDocumentPublisher.h" #include "frameworks/UBPlatformUtils.h" #include "frameworks/UBFileSystemUtils.h" @@ -10,6 +10,7 @@ #include "core/UBDocumentManager.h" #include "core/UBApplication.h" #include "core/UBPersistenceManager.h" +#include "core/UBApplicationController.h" #include "gui/UBMainWindow.h" @@ -28,162 +29,119 @@ #include "core/memcheck.h" + UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent) - : UBAbstractPublisher(parent) - , mSourceDocument(pDocument) - , mPublishingDocument(0) + : UBAbstractPublisher(parent) + , mSourceDocument(pDocument) + , mPublishingDocument(0) + , mUsername("") + , mPassword("") { - connect(this, SIGNAL(authenticated(const QUuid&, const QString&)) - , this, SLOT(postDocument(const QUuid&, const QString&))); + mpWebView = new QWebView(0); + UBApplication::mainWindow->addSankoreWebDocumentWidget(mpWebView); + mpWebView->setWindowTitle(tr("Sankore Uploading Page")); + mpWebView->setAcceptDrops(false); + + connect(mpWebView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); + connect(mpWebView, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl))); + + + init(); } UBDocumentPublisher::~UBDocumentPublisher() { + delete mpWebView; delete mPublishingDocument; } void UBDocumentPublisher::publish() { - UBAbstractPublisher::authenticate(); + //check that the username and password are stored on preferences + mUsername = "Admin"; + mPassword = "admin"; + buildUbwFile(); + UBApplication::showMessage(tr("Uploading Sankore File on Web.")); + sendUbw(); + } -void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token) +void UBDocumentPublisher::buildUbwFile() { - mAuthenticationUuid = tokenUuid; - mAuthenticationBase64Token = encryptedBase64Token; - - UBDocumentPublishingDialog dialog(UBApplication::mainWindow); - - dialog.videoWarning->setVisible(UBPersistenceManager::persistenceManager()->mayHaveVideo(mSourceDocument)); - - dialog.title->setText(mSourceDocument->name()); - - QString defaultEMail = UBSettings::settings()->uniboardWebEMail->get().toString(); - dialog.email->setText(defaultEMail); + QDir d; + d.mkpath(UBFileSystemUtils::defaultTempDirPath()); - QString defaultAuthor = UBSettings::settings()->uniboardWebAuthor->get().toString(); - dialog.author->setText(defaultAuthor); + QString tmpDir = UBFileSystemUtils::createTempDir(); - if (dialog.exec() == QDialog::Accepted) + if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir)) { - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - UBApplication::showMessage(tr("Preparing document for upload..."), true); + QUuid publishingUuid = QUuid::createUuid(); - mTitle = dialog.title->text(); - mDescription = dialog.description->toPlainText(); - mEMail = dialog.email->text(); - mAuthor = dialog.author->text(); + mPublishingDocument = new UBDocumentProxy(tmpDir); + mPublishingDocument->setPageCount(mSourceDocument->pageCount()); - bool attachPDF = dialog.attachPDF->isChecked(); - bool attachUBZ = dialog.attachUBZ->isChecked(); + rasterizeScenes(); - mPublishingServiceUrl = UBSettings::settings()->documentsPublishingUrl; + upgradeDocumentForPublishing(); - UBSettings::settings()->uniboardWebEMail->set(mEMail); - UBSettings::settings()->uniboardWebAuthor->set(mAuthor); + UBExportFullPDF pdfExporter; + pdfExporter.setVerbode(false); + pdfExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf"); - QDir d; - d.mkpath(UBFileSystemUtils::defaultTempDirPath()); + UBExportDocument ubzExporter; + ubzExporter.setVerbode(false); + ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); - QString tmpDir = UBFileSystemUtils::createTempDir(); - if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir)) - { - QUuid publishingUuid = QUuid::createUuid(); - - mPublishingDocument = new UBDocumentProxy(tmpDir); - mPublishingDocument->setPageCount(mSourceDocument->pageCount()); - - rasterizeScenes(); - - //rasterizePDF(); // not needed as we do not publish svg file anymore - - //rasterizeSVGImages(); // not needed as we do not publish svg file anymore + // remove all useless files - upgradeDocumentForPublishing(); + for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); - if (attachPDF) - { - UBExportFullPDF pdfExporter; - pdfExporter.setVerbode(false); - pdfExporter.persistsDocument(mSourceDocument, - mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf"); - } - - if (attachUBZ) - { - UBExportDocument ubzExporter; - ubzExporter.setVerbode(false); - ubzExporter.persistsDocument(mSourceDocument, - mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); - } - - // remove all useless files - - for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) - { - QString filename = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); - - QFile::remove(filename); - } - - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory); - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory); - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); - - QString tempZipFile = UBFileSystemUtils::defaultTempDirPath() - + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip"; - - //qDebug() << "compressing" << mPublishingDocument->persistencePath() << "in" << tempZipFile; + QFile::remove(filename); + } - QuaZip zip(tempZipFile); - zip.setFileNameCodec("UTF-8"); - if (!zip.open(QuaZip::mdCreate)) - { - qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << tempZipFile; - QApplication::restoreOverrideCursor(); - return; - } + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory); + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory); + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); - QuaZipFile outFile(&zip); + mTmpZipFile = UBFileSystemUtils::defaultTempDirPath() + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip"; - if (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true)) - { - qWarning("Export failed. compressDirInZip failed ..."); - zip.close(); - //zip.remove(); - UBApplication::showMessage(tr("Export failed.")); - QApplication::restoreOverrideCursor(); - return; - } + QuaZip zip(mTmpZipFile); + zip.setFileNameCodec("UTF-8"); + if (!zip.open(QuaZip::mdCreate)) + { + qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << mTmpZipFile; + QApplication::restoreOverrideCursor(); + return; + } - if (zip.getZipError() != 0) - { - qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); - zip.close(); - //zip.remove(); - UBApplication::showMessage(tr("Export failed.")); - QApplication::restoreOverrideCursor(); - return; - } + QuaZipFile outFile(&zip); + if (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true)) + { + qWarning("Export failed. compressDirInZip failed ..."); zip.close(); - - mPublishingUrl = QUrl(mPublishingServiceUrl + "/documents/publish/" - + UBStringUtils::toCanonicalUuid(mSourceDocument->uuid())); - - sendZipToUniboardWeb(tempZipFile, publishingUuid); + UBApplication::showMessage(tr("Export failed.")); + QApplication::restoreOverrideCursor(); + return; } - else + + if (zip.getZipError() != 0) { - UBApplication::showMessage(tr("Export failed ...")); + qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); + zip.close(); + UBApplication::showMessage(tr("Export failed.")); QApplication::restoreOverrideCursor(); + return; } + + zip.close(); + } else { @@ -192,64 +150,16 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en } } - -/* - * // not needed as we do not publish svg file anymore - * - -void UBDocumentPublisher::rasterizePDF() -{ - if (UBPersistenceManager::persistenceManager()->mayHavePDF(mPublishingDocument)) - { - UBSvgSubsetAdaptor::convertPDFObjectsToImages(mPublishingDocument); - - QDir objectDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory); - - QStringList filters; - filters << "*.pdf"; - - foreach(QFileInfo fi, objectDir.entryInfoList(filters)) - { - QFile::remove(fi.absoluteFilePath()); - } - } -} -*/ - -/* - * // not needed as we do not publish svg file anymore - - -void UBDocumentPublisher::rasterizeSVGImages() -{ - if (UBPersistenceManager::persistenceManager()->mayHaveSVGImages(mPublishingDocument)) - { - UBSvgSubsetAdaptor::convertSvgImagesToImages(mPublishingDocument); - - QDir objectDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory); - - QStringList filters; - filters << "*.svg"; - - foreach(QFileInfo fi, objectDir.entryInfoList(filters)) - { - QFile::remove(fi.absoluteFilePath()); - } - } -} -*/ - void UBDocumentPublisher::rasterizeScenes() { - for(int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) + for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { UBApplication::showMessage(tr("Converting page %1/%2 ...").arg(pageIndex + 1).arg(mPublishingDocument->pageCount()), true); UBSvgSubsetRasterizer rasterizer(mPublishingDocument, pageIndex); - QString filename = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1); + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1); rasterizer.rasterizeToFile(filename); @@ -275,7 +185,7 @@ void UBDocumentPublisher::updateGoogleMapApiKey() { QFile file(fileInfo.absoluteFilePath()); - if(file.open(QIODevice::ReadWrite)) + if (file.open(QIODevice::ReadWrite)) { QTextStream stream(&file); QString content = stream.readAll(); @@ -298,7 +208,7 @@ void UBDocumentPublisher::updateGoogleMapApiKey() void UBDocumentPublisher::upgradeDocumentForPublishing() { - for(int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) + for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { UBGraphicsScene *scene = UBSvgSubsetAdaptor::loadScene(mPublishingDocument, pageIndex); @@ -306,25 +216,17 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() QList widgets; - foreach(QGraphicsItem* item, scene->items()) - { + foreach(QGraphicsItem* item, scene->items()){ UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast(item); - if (widgetItem) - { + if(widgetItem){ generateWidgetPropertyScript(widgetItem, pageIndex + 1); sceneHasWidget = true; widgets << widgetItem; } } - //if (sceneHasWidget) - //{ - // updateSVGForWidget(pageIndex); // not needed as we do not publish svg file anymore - //} - - QString filename = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1); + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1); QFile jsonFile(filename); if (jsonFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) @@ -381,10 +283,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() sep = ""; jsonFile.write(QString(" \"%1\": \"%2\"%3\n") - .arg(key) - .arg(preferences.value(key)) - .arg(sep) - .toUtf8()); + .arg(key) + .arg(preferences.value(key)) + .arg(sep) + .toUtf8()); } jsonFile.write(QString(" },\n").toUtf8()); @@ -399,10 +301,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() sep = ""; jsonFile.write(QString(" \"%1\": \"%2\"%3\n") - .arg(entry) - .arg(datastoreEntries.value(entry)) - .arg(sep) - .toUtf8()); + .arg(entry) + .arg(datastoreEntries.value(entry)) + .arg(sep) + .toUtf8()); } jsonFile.write(QString(" }\n").toUtf8()); @@ -426,57 +328,6 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() } -/** // not needed as we do not publish svg file anymore -void UBDocumentPublisher::updateSVGForWidget(int pageIndex) -{ - QString fileName = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); - - QFile svgFile(fileName); - - if (svgFile.exists()) - { - if (!svgFile.open(QIODevice::ReadWrite)) - { - qWarning() << "Cannot open file " << fileName << " for widget upgrade ..."; - return; - } - - QTextStream stream(&svgFile); - QStringList lines; - - QString line; - do - { - line = stream.readLine(); - if (!line.isNull()) - { - if (line.contains("")) // TODO UB 4.6, this is naive ... the SVG tag may be on several lines - { - lines << "documentPlayerCssUrl + "\" ?>"; - lines << line; - lines << ""; - lines << "