added web pubblication interface

preferencesAboutTextFull
Claudio Valerio 14 years ago
parent 3bdc181c94
commit 30b87f02e7
  1. 522
      src/adaptors/publishing/UBDocumentPublisher.cpp
  2. 82
      src/adaptors/publishing/UBDocumentPublisher.h
  3. 4
      src/board/UBBoardPaletteManager.cpp
  4. 20
      src/core/UBApplication.cpp
  5. 1
      src/core/UBApplication.h
  6. 28
      src/core/UBApplicationController.cpp
  7. 4
      src/core/UBApplicationController.h
  8. 6
      src/core/UBDocumentManager.cpp
  9. 6
      src/document/UBDocumentController.h
  10. 14
      src/gui/UBMainWindow.cpp
  11. 5
      src/gui/UBMainWindow.h

@ -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"
@ -27,163 +28,120 @@
#include "UBSvgSubsetRasterizer.h"
#include "core/memcheck.h"
#include <../Trolltech/Qt-4.7.0/include/QtWebKit/qwebview.h>
UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent)
: UBAbstractPublisher(parent)
, mSourceDocument(pDocument)
, mPublishingDocument(0)
: UBAbstractPublisher(parent)
, mSourceDocument(pDocument)
, mPublishingDocument(0)
, mUsername(0)
, mPassword(0)
{
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);
QDir d;
d.mkpath(UBFileSystemUtils::defaultTempDirPath());
dialog.videoWarning->setVisible(UBPersistenceManager::persistenceManager()->mayHaveVideo(mSourceDocument));
QString tmpDir = UBFileSystemUtils::createTempDir();
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)
if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir))
{
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();
QUuid publishingUuid = QUuid::createUuid();
bool attachPDF = dialog.attachPDF->isChecked();
bool attachUBZ = dialog.attachUBZ->isChecked();
mPublishingDocument = new UBDocumentProxy(tmpDir);
mPublishingDocument->setPageCount(mSourceDocument->pageCount());
mPublishingServiceUrl = UBSettings::settings()->documentsPublishingUrl;
rasterizeScenes();
UBSettings::settings()->uniboardWebEMail->set(mEMail);
UBSettings::settings()->uniboardWebAuthor->set(mAuthor);
upgradeDocumentForPublishing();
QDir d;
d.mkpath(UBFileSystemUtils::defaultTempDirPath());
UBExportFullPDF pdfExporter;
pdfExporter.setVerbode(false);
pdfExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf");
QString tmpDir = UBFileSystemUtils::createTempDir();
UBExportDocument ubzExporter;
ubzExporter.setVerbode(false);
ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz");
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
// remove all useless files
//rasterizeSVGImages(); // not needed as we do not publish svg file anymore
for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) {
QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1);
upgradeDocumentForPublishing();
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);
QFile::remove(filename);
}
QString tempZipFile = UBFileSystemUtils::defaultTempDirPath()
+ "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip";
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory);
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory);
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory);
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory);
//qDebug() << "compressing" << mPublishingDocument->persistencePath() << "in" << tempZipFile;
mTmpZipFile = UBFileSystemUtils::defaultTempDirPath() + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip";
QuaZip zip(tempZipFile);
zip.setFileNameCodec("UTF-8");
if (!zip.open(QuaZip::mdCreate))
{
qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << tempZipFile;
QApplication::restoreOverrideCursor();
return;
}
QuaZipFile outFile(&zip);
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 (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true))
{
qWarning("Export failed. compressDirInZip failed ...");
zip.close();
//zip.remove();
UBApplication::showMessage(tr("Export failed."));
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<UBGraphicsW3CWidgetItem*> widgets;
foreach(QGraphicsItem* item, scene->items())
{
foreach(QGraphicsItem* item, scene->items()){
UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(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("<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)
{
@ -487,15 +338,13 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
if (!startFileName.startsWith("http://"))
{
QString startFilePath = mPublishingDocument->persistencePath() + "/"
+ UBPersistenceManager::widgetDirectory + "/"
+ widgetItem->uuid().toString() + ".wgt/" + startFileName;
QString startFilePath = mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + widgetItem->uuid().toString() + ".wgt/" + startFileName;
QFile startFile(startFilePath);
if(startFile.exists())
if (startFile.exists())
{
if(startFile.open(QIODevice::ReadWrite))
if (startFile.open(QIODevice::ReadWrite))
{
QTextStream stream(&startFile);
QStringList lines;
@ -663,111 +512,138 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
}
}
}
else
{
else{
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));
mUploadRequest->addHeader("Document-UUID", UBStringUtils::toCanonicalUuid(mSourceDocument->uuid()));
mUploadRequest->addHeader("Document-PageCount", QString("%1").arg(mSourceDocument->pageCount()));
mUploadRequest->addHeader("Document-Title", mTitle);
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());
zipFile.remove();
}
void UBDocumentPublisher::uploadProgress(qint64 bytesSent, qint64 bytesTotal)
void UBDocumentPublisher::init()
{
int percentage = (((qreal)bytesSent / (qreal)bytesTotal ) * 100);
mCrlf=0x0d;
mCrlf+=0x0a;
if (bytesSent < bytesTotal)
UBApplication::showMessage(tr("Upload to Sankore Web in progress %1 %").arg(percentage), true);
else
UBApplication::showMessage(tr("Sending document ..."), true);
mpNetworkMgr = new QNetworkAccessManager(this);
mpCookieJar = new QNetworkCookieJar();
connect(mpNetworkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
}
void UBDocumentPublisher::postZipUploadResponse(bool success, const QByteArray& payload)
void UBDocumentPublisher::onFinished(QNetworkReply *reply)
{
if (success)
{
UBApplication::showMessage(tr("The document has been sent to %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false);
}
else
QByteArray response = reply->readAll();
if (!bCookieSet)
{
qWarning() << "error uploading document to Sankore Web" << QString::fromUtf8(payload);
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("; ");
QString errorMessage = QString::fromUtf8(payload);
// Finally we create the cookies
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
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData());
cookiesList << crntCookie;
}
if (errorMessage.length() == 0)
UBApplication::showMessage(tr("Error while publishing document to %1")
.arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false);
else
UBApplication::showMessage(tr("Error while publishing document to %1 : (%2)")
.arg(UBSettings::settings()->uniboardWebUrl->get().toString())
.arg(errorMessage), false);
// 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;
}
QApplication::restoreOverrideCursor();
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();
deleteLater();
}
}
UBDocumentPublishingDialog::UBDocumentPublishingDialog(QWidget *parent)
: QDialog(parent)
void UBDocumentPublisher::sendUbw()
{
Ui::documentPublishingDialog::setupUi(this);
if (QFile::exists(mTmpZipFile))
{
QFile f(mTmpZipFile);
if (f.open(QIODevice::ReadOnly))
{
QByteArray ba = f.readAll();
QString boundary,data, multipartHeader;
QByteArray datatoSend;
boundary = "---WebKitFormBoundaryDKBTgA53MiyWrzLY";
multipartHeader = "multipart/form-data; boundary="+boundary;
data="--"+boundary+mCrlf;
data+="Content-Disposition: form-data; name=\"file\"; filename=\""+ f.fileName() +"\""+mCrlf;
data+="Content-Type: application/octet-stream"+mCrlf+mCrlf;
datatoSend=data.toAscii(); // convert data string to byte array for request
datatoSend += ba;
datatoSend += mCrlf.toAscii();
datatoSend += QString("--%0--%1").arg(boundary).arg(mCrlf).toAscii();
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");
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);
}
}
}
connect(dialogButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(dialogButtons, SIGNAL(rejected()), this, SLOT(reject()));
QString UBDocumentPublisher::getBase64Of(QString stringToEncode)
{
return stringToEncode.toAscii().toBase64();
}
connect(title, SIGNAL(textChanged(const QString&)), this, SLOT(updateUIState(const QString&)));
connect(email, SIGNAL(textChanged(const QString&)), this, SLOT(updateUIState(const QString&)));
void UBDocumentPublisher::onLinkClicked(const QUrl &url)
{
// [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);
dialogButtons->button(QDialogButtonBox::Ok)->setText(tr("Publish"));
void UBDocumentPublisher::onLoadFinished(bool result)
{
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);
}

@ -10,74 +10,56 @@
class UBDocumentProxy;
class UBServerXMLHttpRequest;
class UBGraphicsW3CWidgetItem;
class QWebView;
class UBDocumentPublisher : public UBAbstractPublisher
{
Q_OBJECT;
public:
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0);
virtual ~UBDocumentPublisher();
public:
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0);
virtual ~UBDocumentPublisher();
void publish();
void publish();
protected:
signals:
// not needed as we do not publish svg file anymore
//virtual void rasterizePDF();
//virtual void rasterizeSVGImages();
//virtual void updateSVGForWidget(int sceneIndex);
void loginDone();
virtual void updateGoogleMapApiKey();
protected:
virtual void rasterizeScenes();
virtual void updateGoogleMapApiKey();
virtual void rasterizeScenes();
virtual void upgradeDocumentForPublishing();
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
virtual void upgradeDocumentForPublishing();
private slots:
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
void onFinished(QNetworkReply* reply);
void onLinkClicked(const QUrl& url);
void onLoadFinished(bool result);
void sendZipToUniboardWeb(const QString& zipFile, const QUuid& publishingUuid);
private slots:
private:
void postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token);
void uploadProgress(qint64, qint64);
void postZipUploadResponse(bool, const QByteArray&);
void init();
void sendUbw();
QString getBase64Of(QString stringToEncode);
private:
QWebView* mpWebView;
QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar;
QString mUsername;
QString mPassword;
QString mCrlf;
bool bCookieSet;
UBDocumentProxy *mSourceDocument;
UBDocumentProxy *mPublishingDocument;
void buildUbwFile();
QString mTmpZipFile;
UBServerXMLHttpRequest* mUploadRequest;
QString mTitle;
QString mAuthor;
QString mDescription;
QString mEMail;
bool mAttachPDF;
bool mAttachUBZ;
QUrl mPublishingUrl;
QString mPublishingServiceUrl;
QUuid mAuthenticationUuid;
QString mAuthenticationBase64Token;
};
class UBDocumentPublishingDialog : public QDialog, public Ui::documentPublishingDialog
{
Q_OBJECT;
public:
UBDocumentPublishingDialog(QWidget *parent = 0);
~UBDocumentPublishingDialog(){}
private slots:
void updateUIState(const QString& string);
UBDocumentProxy *mSourceDocument;
UBDocumentProxy *mPublishingDocument;
};
#endif // UBDOCUMENTPUBLISHER_H

@ -152,7 +152,7 @@ void UBBoardPaletteManager::setupPalettes()
addItemActions << UBApplication::mainWindow->actionAddItemToCurrentPage;
addItemActions << UBApplication::mainWindow->actionAddItemToNewPage;
addItemActions << UBApplication::mainWindow->actionAddItemToLibrary;
//addItemActions << UBApplication::mainWindow->actionShareItemOnWeb;
addItemActions << UBApplication::mainWindow->actionShareItemOnWeb;
mAddItemPalette = new UBActionPalette(addItemActions, Qt::Horizontal, 0);
mAddItemPalette->setButtonIconSize(QSize(128, 128));
@ -306,7 +306,7 @@ void UBBoardPaletteManager::connectPalettes()
connect(UBApplication::mainWindow->actionAddItemToCurrentPage, SIGNAL(triggered()), this, SLOT(addItemToCurrentPage()));
connect(UBApplication::mainWindow->actionAddItemToNewPage, SIGNAL(triggered()), this, SLOT(addItemToNewPage()));
connect(UBApplication::mainWindow->actionAddItemToLibrary, SIGNAL(triggered()), this, SLOT(addItemToLibrary()));
//connect(UBApplication::mainWindow->actionShareItemOnWeb, SIGNAL(triggered()), this, SLOT(shareItemOnWeb()));
connect(UBApplication::mainWindow->actionShareItemOnWeb, SIGNAL(triggered()), this, SLOT(shareItemOnWeb()));
connect(UBApplication::mainWindow->actionEraseItems, SIGNAL(triggered()), mErasePalette, SLOT(close()));
connect(UBApplication::mainWindow->actionEraseAnnotations, SIGNAL(triggered()), mErasePalette, SLOT(close()));

@ -53,7 +53,6 @@ UBApplicationController* UBApplication::applicationController = 0;
UBBoardController* UBApplication::boardController = 0;
UBWebController* UBApplication::webController = 0;
UBDocumentController* UBApplication::documentController = 0;
//UBSoftwareUpdateController* UBApplication::softwareUpdateController = 0;
UniboardSankoreTransition* UBApplication::mUniboardSankoreTransition = 0;
UBMainWindow* UBApplication::mainWindow = 0;
@ -91,9 +90,8 @@ static OSStatus ub_appleEventProcessor(const AppleEvent *ae, AppleEvent *event,
#endif
UBApplication::UBApplication(const QString &id, int &argc, char **argv)
: QtSingleApplication(id, argc, argv),
mPreferencesController(NULL)
UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSingleApplication(id, argc, argv),
mPreferencesController(NULL)
{
staticMemoryCleaner = new QObject(0); // deleted in UBApplication destructor
@ -186,11 +184,11 @@ UBApplication::~UBApplication()
delete mUniboardSankoreTransition;
mUniboardSankoreTransition = 0;
if (mPreferencesController)
{
delete mPreferencesController;
mPreferencesController = 0;
}
if (mPreferencesController)
{
delete mPreferencesController;
mPreferencesController = 0;
}
}
int UBApplication::exec(const QString& pFileToImport)
@ -343,6 +341,10 @@ void UBApplication::showDocument()
applicationController->showDocument();
}
void UBApplication::showSankoreWebDocument()
{
applicationController->showSankoreWebDocument();
}
int UBApplication::toolBarHeight()
{

@ -88,6 +88,7 @@ class UBApplication : public QtSingleApplication
void showBoard();
void showInternet();
void showDocument();
void showSankoreWebDocument();
void toolBarPositionChanged(QVariant topOrBottom);
void toolBarDisplayTextChanged(QVariant display);

@ -325,7 +325,7 @@ void UBApplicationController::showBoard()
if (UBApplication::boardController)
UBApplication::boardController->show();
UBPlatformUtils::setDesktopMode(false);
UBPlatformUtils::setDesktopMode(false);
mUninoteController->hideWindow();
mMainWindow->show();
@ -396,6 +396,32 @@ void UBApplicationController::showDocument()
emit mainModeChanged(Document);
}
void UBApplicationController::showSankoreWebDocument()
{
mMainWindow->webToolBar->hide();
mMainWindow->boardToolBar->hide();
mMainWindow->tutorialToolBar->hide();
mMainWindow->documentToolBar->show();
mMainMode = WebDocument;
adaptToolBar();
mirroringEnabled(false);
mMainWindow->switchToSankoreWebDocumentWidget();
UBApplication::documentController->hide();
mMainWindow->show();
mUninoteController->hideWindow();
emit mainModeChanged(WebDocument);
}
void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
{

@ -53,6 +53,8 @@ class UBApplicationController : public QObject
void showDocument();
void showSankoreWebDocument();
void showMessage(const QString& message, bool showSpinningWheel);
void importFile(const QString& pFilePath);
@ -69,7 +71,7 @@ class UBApplicationController : public QObject
enum MainMode
{
Board = 0, Internet, Document, Tutorial, ParaschoolEditor
Board = 0, Internet, Document, Tutorial, ParaschoolEditor, WebDocument
};
MainMode displayMode()

@ -56,8 +56,10 @@ UBDocumentManager::UBDocumentManager(QObject *parent)
mExportAdaptors.append(exportFullPdf);
UBExportDocument* exportDocument = new UBExportDocument(this);
mExportAdaptors.append(exportDocument);
UBExportWeb* exportWeb = new UBExportWeb(this);
mExportAdaptors.append(exportWeb);
// UBExportWeb* exportWeb = new UBExportWeb(this);
// mExportAdaptors.append(exportWeb);
UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(webPublished);
UBImportDocument* documentImport = new UBImportDocument(this);
mImportAdaptors.append(documentImport);

@ -33,10 +33,10 @@ class UBDocumentController : public QObject
QWidget* controlView();
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy);
bool addFileToDocument(UBDocumentProxy* document);
UBDocumentProxy* getCurrentDocument();
UBDocumentProxy* getCurrentDocument();
signals:
void refreshThumbnails();
void refreshThumbnails();
void exportDone();
public slots:
@ -91,7 +91,7 @@ class UBDocumentController : public QObject
UBDocumentToolsPalette *mToolsPalette;
bool mToolsPalettePositionned;
UBDocumentGroupTreeItem* mTrashTi;
UBDocumentProxy* mCurrentDocument;
UBDocumentProxy* mCurrentDocument;
private slots:
void documentZoomSliderValueChanged (int value);

@ -14,6 +14,7 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
, mBoardWidget(0)
, mWebWidget(0)
, mDocumentsWidget(0)
, mSankoreWebDocumentWidget(0)
{
Ui::MainWindow::setupUi(this);
@ -91,6 +92,19 @@ void UBMainWindow::switchToDocumentsWidget()
}
}
void UBMainWindow::addSankoreWebDocumentWidget(QWebView* pWidget)
{
if(!mSankoreWebDocumentWidget){
mSankoreWebDocumentWidget = pWidget;
mStackedLayout->addWidget(mSankoreWebDocumentWidget);
}
}
void UBMainWindow::switchToSankoreWebDocumentWidget()
{
if(mSankoreWebDocumentWidget)
mStackedLayout->setCurrentWidget(mSankoreWebDocumentWidget);
}
void UBMainWindow::keyPressEvent(QKeyEvent *event)
{
QMainWindow::keyPressEvent(event);

@ -5,6 +5,7 @@
#include <QMainWindow>
#include <QWidget>
#include <QWebView>
class QStackedLayout;
@ -27,6 +28,9 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
void addDocumentsWidget(QWidget *pWidget);
void switchToDocumentsWidget();
void addSankoreWebDocumentWidget(QWebView* pWidget);
void switchToSankoreWebDocumentWidget();
public slots:
void onExportDone();
@ -45,6 +49,7 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
QWidget *mBoardWidget;
QWidget *mWebWidget;
QWidget *mDocumentsWidget;
QWebView* mSankoreWebDocumentWidget;
};

Loading…
Cancel
Save