|
|
@ -10,6 +10,7 @@ |
|
|
|
#include "core/UBDocumentManager.h" |
|
|
|
#include "core/UBDocumentManager.h" |
|
|
|
#include "core/UBApplication.h" |
|
|
|
#include "core/UBApplication.h" |
|
|
|
#include "core/UBPersistenceManager.h" |
|
|
|
#include "core/UBPersistenceManager.h" |
|
|
|
|
|
|
|
#include "core/UBApplicationController.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "gui/UBMainWindow.h" |
|
|
|
#include "gui/UBMainWindow.h" |
|
|
|
|
|
|
|
|
|
|
@ -27,64 +28,49 @@ |
|
|
|
#include "UBSvgSubsetRasterizer.h" |
|
|
|
#include "UBSvgSubsetRasterizer.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
#include <../Trolltech/Qt-4.7.0/include/QtWebKit/qwebview.h> |
|
|
|
|
|
|
|
|
|
|
|
UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent) |
|
|
|
UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent) |
|
|
|
: UBAbstractPublisher(parent) |
|
|
|
: UBAbstractPublisher(parent) |
|
|
|
, mSourceDocument(pDocument) |
|
|
|
, mSourceDocument(pDocument) |
|
|
|
, mPublishingDocument(0) |
|
|
|
, mPublishingDocument(0) |
|
|
|
|
|
|
|
, mUsername(0) |
|
|
|
|
|
|
|
, mPassword(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
connect(this, SIGNAL(authenticated(const QUuid&, const QString&)) |
|
|
|
mpWebView = new QWebView(0); |
|
|
|
, this, SLOT(postDocument(const QUuid&, const QString&))); |
|
|
|
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() |
|
|
|
UBDocumentPublisher::~UBDocumentPublisher() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
delete mpWebView; |
|
|
|
delete mPublishingDocument; |
|
|
|
delete mPublishingDocument; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublisher::publish() |
|
|
|
void UBDocumentPublisher::publish() |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBAbstractPublisher::authenticate(); |
|
|
|
//check that the username and password are stored on preferences
|
|
|
|
} |
|
|
|
mUsername = "Admin"; |
|
|
|
|
|
|
|
mPassword = "admin"; |
|
|
|
|
|
|
|
buildUbwFile(); |
|
|
|
void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token) |
|
|
|
UBApplication::showMessage(tr("Uploading Sankore File on Web.")); |
|
|
|
{ |
|
|
|
sendUbw(); |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString defaultAuthor = UBSettings::settings()->uniboardWebAuthor->get().toString(); |
|
|
|
|
|
|
|
dialog.author->setText(defaultAuthor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) |
|
|
|
void UBDocumentPublisher::buildUbwFile() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
|
|
|
|
|
|
|
UBApplication::showMessage(tr("Preparing document for upload..."), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTitle = dialog.title->text(); |
|
|
|
|
|
|
|
mDescription = dialog.description->toPlainText(); |
|
|
|
|
|
|
|
mEMail = dialog.email->text(); |
|
|
|
|
|
|
|
mAuthor = dialog.author->text(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool attachPDF = dialog.attachPDF->isChecked(); |
|
|
|
|
|
|
|
bool attachUBZ = dialog.attachUBZ->isChecked(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPublishingServiceUrl = UBSettings::settings()->documentsPublishingUrl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBSettings::settings()->uniboardWebEMail->set(mEMail); |
|
|
|
|
|
|
|
UBSettings::settings()->uniboardWebAuthor->set(mAuthor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QDir d; |
|
|
|
QDir d; |
|
|
|
d.mkpath(UBFileSystemUtils::defaultTempDirPath()); |
|
|
|
d.mkpath(UBFileSystemUtils::defaultTempDirPath()); |
|
|
|
|
|
|
|
|
|
|
@ -99,34 +85,21 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en |
|
|
|
|
|
|
|
|
|
|
|
rasterizeScenes(); |
|
|
|
rasterizeScenes(); |
|
|
|
|
|
|
|
|
|
|
|
//rasterizePDF(); // not needed as we do not publish svg file anymore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//rasterizeSVGImages(); // not needed as we do not publish svg file anymore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upgradeDocumentForPublishing(); |
|
|
|
upgradeDocumentForPublishing(); |
|
|
|
|
|
|
|
|
|
|
|
if (attachPDF) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBExportFullPDF pdfExporter; |
|
|
|
UBExportFullPDF pdfExporter; |
|
|
|
pdfExporter.setVerbode(false); |
|
|
|
pdfExporter.setVerbode(false); |
|
|
|
pdfExporter.persistsDocument(mSourceDocument, |
|
|
|
pdfExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf"); |
|
|
|
mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (attachUBZ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBExportDocument ubzExporter; |
|
|
|
UBExportDocument ubzExporter; |
|
|
|
ubzExporter.setVerbode(false); |
|
|
|
ubzExporter.setVerbode(false); |
|
|
|
ubzExporter.persistsDocument(mSourceDocument, |
|
|
|
ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); |
|
|
|
mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove all useless files
|
|
|
|
// remove all useless files
|
|
|
|
|
|
|
|
|
|
|
|
for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) |
|
|
|
for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { |
|
|
|
{ |
|
|
|
QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); |
|
|
|
QString filename = mPublishingDocument->persistencePath() + |
|
|
|
|
|
|
|
UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile::remove(filename); |
|
|
|
QFile::remove(filename); |
|
|
|
} |
|
|
|
} |
|
|
@ -136,16 +109,13 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en |
|
|
|
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); |
|
|
|
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); |
|
|
|
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); |
|
|
|
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); |
|
|
|
|
|
|
|
|
|
|
|
QString tempZipFile = UBFileSystemUtils::defaultTempDirPath() |
|
|
|
mTmpZipFile = UBFileSystemUtils::defaultTempDirPath() + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip"; |
|
|
|
+ "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//qDebug() << "compressing" << mPublishingDocument->persistencePath() << "in" << tempZipFile;
|
|
|
|
QuaZip zip(mTmpZipFile); |
|
|
|
|
|
|
|
|
|
|
|
QuaZip zip(tempZipFile); |
|
|
|
|
|
|
|
zip.setFileNameCodec("UTF-8"); |
|
|
|
zip.setFileNameCodec("UTF-8"); |
|
|
|
if (!zip.open(QuaZip::mdCreate)) |
|
|
|
if (!zip.open(QuaZip::mdCreate)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << tempZipFile; |
|
|
|
qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << mTmpZipFile; |
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -156,7 +126,6 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en |
|
|
|
{ |
|
|
|
{ |
|
|
|
qWarning("Export failed. compressDirInZip failed ..."); |
|
|
|
qWarning("Export failed. compressDirInZip failed ..."); |
|
|
|
zip.close(); |
|
|
|
zip.close(); |
|
|
|
//zip.remove();
|
|
|
|
|
|
|
|
UBApplication::showMessage(tr("Export failed.")); |
|
|
|
UBApplication::showMessage(tr("Export failed.")); |
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -166,7 +135,6 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en |
|
|
|
{ |
|
|
|
{ |
|
|
|
qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); |
|
|
|
qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); |
|
|
|
zip.close(); |
|
|
|
zip.close(); |
|
|
|
//zip.remove();
|
|
|
|
|
|
|
|
UBApplication::showMessage(tr("Export failed.")); |
|
|
|
UBApplication::showMessage(tr("Export failed.")); |
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -174,16 +142,6 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en |
|
|
|
|
|
|
|
|
|
|
|
zip.close(); |
|
|
|
zip.close(); |
|
|
|
|
|
|
|
|
|
|
|
mPublishingUrl = QUrl(mPublishingServiceUrl + "/documents/publish/" |
|
|
|
|
|
|
|
+ UBStringUtils::toCanonicalUuid(mSourceDocument->uuid())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sendZipToUniboardWeb(tempZipFile, publishingUuid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBApplication::showMessage(tr("Export failed ...")); |
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -192,53 +150,6 @@ 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() |
|
|
|
void UBDocumentPublisher::rasterizeScenes() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
@ -248,8 +159,7 @@ void UBDocumentPublisher::rasterizeScenes() |
|
|
|
|
|
|
|
|
|
|
|
UBSvgSubsetRasterizer rasterizer(mPublishingDocument, pageIndex); |
|
|
|
UBSvgSubsetRasterizer rasterizer(mPublishingDocument, pageIndex); |
|
|
|
|
|
|
|
|
|
|
|
QString filename = mPublishingDocument->persistencePath() + |
|
|
|
QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1); |
|
|
|
UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rasterizer.rasterizeToFile(filename); |
|
|
|
rasterizer.rasterizeToFile(filename); |
|
|
|
|
|
|
|
|
|
|
@ -306,25 +216,17 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() |
|
|
|
|
|
|
|
|
|
|
|
QList<UBGraphicsW3CWidgetItem*> widgets; |
|
|
|
QList<UBGraphicsW3CWidgetItem*> widgets; |
|
|
|
|
|
|
|
|
|
|
|
foreach(QGraphicsItem* item, scene->items()) |
|
|
|
foreach(QGraphicsItem* item, scene->items()){ |
|
|
|
{ |
|
|
|
|
|
|
|
UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(item); |
|
|
|
UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(item); |
|
|
|
|
|
|
|
|
|
|
|
if (widgetItem) |
|
|
|
if(widgetItem){ |
|
|
|
{ |
|
|
|
|
|
|
|
generateWidgetPropertyScript(widgetItem, pageIndex + 1); |
|
|
|
generateWidgetPropertyScript(widgetItem, pageIndex + 1); |
|
|
|
sceneHasWidget = true; |
|
|
|
sceneHasWidget = true; |
|
|
|
widgets << widgetItem; |
|
|
|
widgets << widgetItem; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//if (sceneHasWidget)
|
|
|
|
QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1); |
|
|
|
//{
|
|
|
|
|
|
|
|
// updateSVGForWidget(pageIndex); // not needed as we do not publish svg file anymore
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString filename = mPublishingDocument->persistencePath() + |
|
|
|
|
|
|
|
UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile jsonFile(filename); |
|
|
|
QFile jsonFile(filename); |
|
|
|
if (jsonFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) |
|
|
|
if (jsonFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) |
|
|
@ -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("<svg") && line.contains(">")) // TODO UB 4.6, this is naive ... the SVG tag may be on several lines
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
lines << "<?xml-stylesheet type=\"text/css\" href=\"" + UBSettings::settings()->documentPlayerCssUrl + "\" ?>"; |
|
|
|
|
|
|
|
lines << line; |
|
|
|
|
|
|
|
lines << ""; |
|
|
|
|
|
|
|
lines << " <script type=\"text/ecmascript\" xlink:href=\"" + UBSettings::settings()->documentPlayerScriptUrl + "\"/>"; |
|
|
|
|
|
|
|
lines << " <script type=\"text/ecmascript\" xlink:href=\"" + UBSettings::settings()->documentPlayerPageScriptUrl + "\"/>"; |
|
|
|
|
|
|
|
lines << ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
lines << line; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while (!line.isNull()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
svgFile.resize(0); |
|
|
|
|
|
|
|
svgFile.write(lines.join("\n").toUtf8()); // TODO UB 4.x detect real html encoding
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
svgFile.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber) |
|
|
|
void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
@ -487,9 +338,7 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem * |
|
|
|
|
|
|
|
|
|
|
|
if (!startFileName.startsWith("http://")) |
|
|
|
if (!startFileName.startsWith("http://")) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QString startFilePath = mPublishingDocument->persistencePath() + "/" |
|
|
|
QString startFilePath = mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + widgetItem->uuid().toString() + ".wgt/" + startFileName; |
|
|
|
+ UBPersistenceManager::widgetDirectory + "/" |
|
|
|
|
|
|
|
+ widgetItem->uuid().toString() + ".wgt/" + startFileName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile startFile(startFilePath); |
|
|
|
QFile startFile(startFilePath); |
|
|
|
|
|
|
|
|
|
|
@ -663,111 +512,138 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem * |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else{ |
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Remote Widget start file, cannot inject widget preferences and datastore entries"; |
|
|
|
qWarning() << "Remote Widget start file, cannot inject widget preferences and datastore entries"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublisher::sendZipToUniboardWeb(const QString& zipFilePath, const QUuid& publishingUuid) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QFile zipFile(zipFilePath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!zipFile.open(QIODevice::ReadOnly)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Cannot open file" << zipFilePath << "for upload to Sankore Web"; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QUrl publishingEndpoint = QUrl(mPublishingServiceUrl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mUploadRequest = new UBServerXMLHttpRequest(UBNetworkAccessManager::defaultAccessManager() |
|
|
|
|
|
|
|
, "application/octet-stream"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mUploadRequest->setVerbose(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(mUploadRequest, SIGNAL(progress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64))); |
|
|
|
|
|
|
|
connect(mUploadRequest, SIGNAL(finished(bool, const QByteArray&)), this, SLOT(postZipUploadResponse(bool, const QByteArray&))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mUploadRequest->addHeader("Publishing-UUID", UBStringUtils::toCanonicalUuid(publishingUuid)); |
|
|
|
void UBDocumentPublisher::init() |
|
|
|
mUploadRequest->addHeader("Document-UUID", UBStringUtils::toCanonicalUuid(mSourceDocument->uuid())); |
|
|
|
{ |
|
|
|
mUploadRequest->addHeader("Document-PageCount", QString("%1").arg(mSourceDocument->pageCount())); |
|
|
|
mCrlf=0x0d; |
|
|
|
mUploadRequest->addHeader("Document-Title", mTitle); |
|
|
|
mCrlf+=0x0a; |
|
|
|
mUploadRequest->addHeader("Document-Author", mAuthor); |
|
|
|
|
|
|
|
mUploadRequest->addHeader("Document-AuthorEMail", mEMail); |
|
|
|
|
|
|
|
mUploadRequest->addHeader("Document-Description", mDescription); |
|
|
|
|
|
|
|
mUploadRequest->addHeader("Deletion-Token", UBStringUtils::toCanonicalUuid(QUuid::createUuid())); |
|
|
|
|
|
|
|
mUploadRequest->addHeader("Token-UUID", UBStringUtils::toCanonicalUuid(mAuthenticationUuid)); |
|
|
|
|
|
|
|
mUploadRequest->addHeader("Token-Encrypted", mAuthenticationBase64Token); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mUploadRequest->post(publishingEndpoint, zipFile.readAll()); |
|
|
|
mpNetworkMgr = new QNetworkAccessManager(this); |
|
|
|
|
|
|
|
mpCookieJar = new QNetworkCookieJar(); |
|
|
|
|
|
|
|
|
|
|
|
zipFile.remove(); |
|
|
|
connect(mpNetworkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublisher::onFinished(QNetworkReply *reply) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QByteArray response = reply->readAll(); |
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublisher::uploadProgress(qint64 bytesSent, qint64 bytesTotal) |
|
|
|
if (!bCookieSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int percentage = (((qreal)bytesSent / (qreal)bytesTotal ) * 100); |
|
|
|
QList<QNetworkCookie> cookiesList; |
|
|
|
|
|
|
|
QVariant cookieHeader = reply->rawHeader("Set-Cookie"); |
|
|
|
|
|
|
|
qDebug() << cookieHeader.toString(); |
|
|
|
|
|
|
|
// First we concatenate all the Set-Cookie values (the packet can contains many of them)
|
|
|
|
|
|
|
|
QStringList qslCookie = cookieHeader.toString().split("\n"); |
|
|
|
|
|
|
|
QString qsCookieValue = qslCookie.at(0); |
|
|
|
|
|
|
|
for (int i = 1; i < qslCookie.size(); i++) { |
|
|
|
|
|
|
|
qsCookieValue += "; " +qslCookie.at(i); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
qDebug() << "qsCookieValue " << qsCookieValue; |
|
|
|
|
|
|
|
// Now we isolate every cookie value
|
|
|
|
|
|
|
|
QStringList qslCookieVals = qsCookieValue.split("; "); |
|
|
|
|
|
|
|
|
|
|
|
if (bytesSent < bytesTotal) |
|
|
|
// Finally we create the cookies
|
|
|
|
UBApplication::showMessage(tr("Upload to Sankore Web in progress %1 %").arg(percentage), true); |
|
|
|
for (int i = 0; i < qslCookieVals.size(); i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString cookieString = qslCookieVals.at(i); |
|
|
|
|
|
|
|
qDebug() << "qslCookieVals.at(i): " << cookieString.replace("\"", ""); |
|
|
|
|
|
|
|
QStringList qslCrntCookie = cookieString.split("="); |
|
|
|
|
|
|
|
QNetworkCookie crntCookie; |
|
|
|
|
|
|
|
if (qslCrntCookie.length() == 2) |
|
|
|
|
|
|
|
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData(), qslCrntCookie.at(1).toAscii().constData()); |
|
|
|
else |
|
|
|
else |
|
|
|
UBApplication::showMessage(tr("Sending document ..."), true); |
|
|
|
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData()); |
|
|
|
|
|
|
|
cookiesList << crntCookie; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the cookiejar : it set the cookies that will be sent with every packet.
|
|
|
|
|
|
|
|
qDebug() << reply->url().toString(); |
|
|
|
|
|
|
|
mpCookieJar->setCookiesFromUrl(cookiesList, reply->url()); |
|
|
|
|
|
|
|
mpNetworkMgr->setCookieJar(mpCookieJar); |
|
|
|
|
|
|
|
bCookieSet = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.isEmpty()){ |
|
|
|
|
|
|
|
emit loginDone(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else{ |
|
|
|
|
|
|
|
// Display the iframe
|
|
|
|
|
|
|
|
mpWebView->setHtml(response, QUrl("http://sankore.devxwiki.com/xwiki/bin/view/Test/FileUpload")); |
|
|
|
|
|
|
|
UBApplication::applicationController->showSankoreWebDocument(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublisher::postZipUploadResponse(bool success, const QByteArray& payload) |
|
|
|
void UBDocumentPublisher::sendUbw() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (success) |
|
|
|
if (QFile::exists(mTmpZipFile)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBApplication::showMessage(tr("The document has been sent to %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false); |
|
|
|
QFile f(mTmpZipFile); |
|
|
|
} |
|
|
|
if (f.open(QIODevice::ReadOnly)) |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
qWarning() << "error uploading document to Sankore Web" << QString::fromUtf8(payload); |
|
|
|
QByteArray ba = f.readAll(); |
|
|
|
|
|
|
|
QString boundary,data, multipartHeader; |
|
|
|
|
|
|
|
QByteArray datatoSend; |
|
|
|
|
|
|
|
|
|
|
|
QString errorMessage = QString::fromUtf8(payload); |
|
|
|
boundary = "---WebKitFormBoundaryDKBTgA53MiyWrzLY"; |
|
|
|
|
|
|
|
multipartHeader = "multipart/form-data; boundary="+boundary; |
|
|
|
|
|
|
|
|
|
|
|
if (errorMessage.length() == 0) |
|
|
|
data="--"+boundary+mCrlf; |
|
|
|
UBApplication::showMessage(tr("Error while publishing document to %1") |
|
|
|
data+="Content-Disposition: form-data; name=\"file\"; filename=\""+ f.fileName() +"\""+mCrlf; |
|
|
|
.arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false); |
|
|
|
data+="Content-Type: application/octet-stream"+mCrlf+mCrlf; |
|
|
|
else |
|
|
|
datatoSend=data.toAscii(); // convert data string to byte array for request
|
|
|
|
UBApplication::showMessage(tr("Error while publishing document to %1 : (%2)") |
|
|
|
datatoSend += ba; |
|
|
|
.arg(UBSettings::settings()->uniboardWebUrl->get().toString()) |
|
|
|
datatoSend += mCrlf.toAscii(); |
|
|
|
.arg(errorMessage), false); |
|
|
|
datatoSend += QString("--%0--%1").arg(boundary).arg(mCrlf).toAscii(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
QNetworkRequest request(QUrl("http://sankore.devxwiki.com/xwiki/bin/view/Test/FileUpload")); |
|
|
|
|
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader, multipartHeader); |
|
|
|
|
|
|
|
request.setHeader(QNetworkRequest::ContentLengthHeader,datatoSend.size()); |
|
|
|
|
|
|
|
request.setRawHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); |
|
|
|
|
|
|
|
request.setRawHeader("Accept-Language", "en-US,*"); |
|
|
|
|
|
|
|
request.setRawHeader("Referer", "http://sankore.devxwiki.com/xwiki/bin/view/Test/FileUpload"); |
|
|
|
|
|
|
|
request.setRawHeader("Origin", "http://sankore.devxwiki.com"); |
|
|
|
|
|
|
|
|
|
|
|
deleteLater(); |
|
|
|
QString b64Auth = getBase64Of(QString("%0:%1").arg(mUsername).arg(mPassword)); |
|
|
|
} |
|
|
|
request.setRawHeader("Authorization", QString("Basic %0").arg(b64Auth).toAscii().constData()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send the file
|
|
|
|
|
|
|
|
mpNetworkMgr->post(request,datatoSend); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBDocumentPublishingDialog::UBDocumentPublishingDialog(QWidget *parent) |
|
|
|
QString UBDocumentPublisher::getBase64Of(QString stringToEncode) |
|
|
|
: QDialog(parent) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Ui::documentPublishingDialog::setupUi(this); |
|
|
|
return stringToEncode.toAscii().toBase64(); |
|
|
|
|
|
|
|
} |
|
|
|
connect(dialogButtons, SIGNAL(accepted()), this, SLOT(accept())); |
|
|
|
|
|
|
|
connect(dialogButtons, SIGNAL(rejected()), this, SLOT(reject())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(title, SIGNAL(textChanged(const QString&)), this, SLOT(updateUIState(const QString&))); |
|
|
|
void UBDocumentPublisher::onLinkClicked(const QUrl &url) |
|
|
|
connect(email, SIGNAL(textChanged(const QString&)), this, SLOT(updateUIState(const QString&))); |
|
|
|
{ |
|
|
|
|
|
|
|
// [Basic Auth] Here we interpret the link and send the request with the basic auth header.
|
|
|
|
|
|
|
|
QNetworkRequest request; |
|
|
|
|
|
|
|
request.setUrl(url); |
|
|
|
|
|
|
|
QString b64Auth = getBase64Of(QString("%0:%1").arg(mUsername).arg(mPassword)); |
|
|
|
|
|
|
|
request.setRawHeader("Authorization", QString("Basic %0").arg(b64Auth).toAscii().constData()); |
|
|
|
|
|
|
|
mpNetworkMgr->get(request); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dialogButtons->button(QDialogButtonBox::Ok)->setEnabled(false); |
|
|
|
void UBDocumentPublisher::onLoadFinished(bool result) |
|
|
|
dialogButtons->button(QDialogButtonBox::Ok)->setText(tr("Publish")); |
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(result); |
|
|
|
|
|
|
|
// [Basic Auth] This line says: if the user click on a link, do not interpret it.
|
|
|
|
|
|
|
|
mpWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBDocumentPublishingDialog::updateUIState(const QString& string) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(string); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ok = title->text().length() > 0 |
|
|
|
|
|
|
|
&& email->text().length() > 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dialogButtons->button(QDialogButtonBox::Ok)->setEnabled(ok); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|