Commit d5021c74 authored by Claudio Valerio's avatar Claudio Valerio

Fixed export to planet sankore

parent 70f6231f
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -44,6 +44,7 @@
#include "UBSvgSubsetRasterizer.h"
#include "core/memcheck.h"
#include "../../core/UBApplication.h"
UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent)
......@@ -54,90 +55,52 @@ UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *pa
, mPassword("")
, bLoginCookieSet(false)
{
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)));
connect(this, SIGNAL(loginDone()), this, SLOT(onLoginDone()));
init();
}
UBDocumentPublisher::~UBDocumentPublisher()
{
//delete mpWebView;
//delete mPublishingDocument;
if(mSourceDocument){
delete mSourceDocument;
mSourceDocument = NULL;
}
if(mPublishingDocument){
delete mPublishingDocument;
mPublishingDocument = NULL;
}
}
void UBDocumentPublisher::publish()
{
//check that the username and password are stored on preferences
UBSettings* settings = UBSettings::settings();
if(settings->communityUsername().isEmpty() || settings->communityPassword().isEmpty()){
UBApplication::showMessage(tr("Credentials has to not been filled out yet."));
qDebug() << "trying to connect to community without the required credentials";
return;
}
mUsername = settings->communityUsername();
mPassword = settings->communityPassword();
UBPublicationDlg dlg;
if(QDialog::Accepted == dlg.exec())
{
mDocInfos.title = dlg.title();
mDocInfos.description = dlg.description();
//check that the username and password are stored on preferences
UBSettings* settings = UBSettings::settings();
mUsername = settings->communityUsername();
mPassword = settings->communityPassword();
buildUbwFile();
UBApplication::showMessage(tr("Uploading Sankore File on Web."));
login(mUsername, mPassword);
//sendUbw();
sendUbw(mUsername, mPassword);
}
}
void UBDocumentPublisher::onLoginDone()
{
sendUbw();
}
void UBDocumentPublisher::login(QString username, QString password)
{
QString data,crlf;
QByteArray datatoSend;
// Create the request body
data="srid=&j_username=" +username +"&j_password=" +password +crlf+crlf;
datatoSend=data.toAscii(); // convert data string to byte array for request
// Create the request header
QString qsLoginURL = QString("http://sankore.devxwiki.com/xwiki/bin/loginsubmit/XWiki/XWikiLogin?xredirect=%0").arg(DOCPUBLICATION_URL);
QNetworkRequest request(QUrl(qsLoginURL.toAscii().constData()));
request.setRawHeader("Origin", "http://sankore.devxwiki.com");
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
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("Referer", DOCPUBLICATION_URL);
request.setHeader(QNetworkRequest::ContentLengthHeader,datatoSend.size());
request.setRawHeader("Accept-Language", "en-US,*");
// Generate a session id
//mSessionID = getSessionID();
// Create the cookie
//QList<QNetworkCookie> cookiesList;
//QString qsCookieValue;
//qsCookieValue = mSessionID;
//qsCookieValue += "; language=en";
//QNetworkCookie cookie("JSESSIONID", qsCookieValue.toAscii().constData());
//cookiesList << cookie;
//request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(cookiesList));
// Send the request
mpNetworkMgr->post(request,datatoSend);
}
void UBDocumentPublisher::buildUbwFile()
{
QDir d;
......@@ -164,7 +127,6 @@ void UBDocumentPublisher::buildUbwFile()
ubzExporter.setVerbode(false);
ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz");
// remove all useless files
for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) {
......@@ -586,9 +548,6 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
}
}
void UBDocumentPublisher::init()
{
mCrlf=0x0d;
......@@ -599,21 +558,11 @@ void UBDocumentPublisher::init()
mpNetworkMgr = new QNetworkAccessManager(this);
mpCookieJar = new QNetworkCookieJar();
// QNetworkProxy* pProxy = UBSettings::settings()->httpProxy();
// if(NULL != pProxy)
// {
// mpNetworkMgr->setProxy(*pProxy);
// qDebug() << "Proxy set!";
// }
connect(mpNetworkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
connect(mpNetworkMgr, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(onProxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
}
void UBDocumentPublisher::onFinished(QNetworkReply *reply)
{
QByteArray response = reply->readAll();
QVariant cookieHeader = reply->rawHeader("Set-Cookie");
// First we concatenate all the Set-Cookie values (the packet can contains many of them)
QStringList qslCookie = cookieHeader.toString().split("\n");
......@@ -625,49 +574,6 @@ void UBDocumentPublisher::onFinished(QNetworkReply *reply)
// Now we isolate every cookie value
QStringList qslCookieVals = qsCookieValue.split("; ");
if (!bLoginCookieSet)
{
// Finally we create the cookies
for (int i = 0; i < qslCookieVals.size(); i++)
{
QString cookieString = qslCookieVals.at(i);
QStringList qslCrntCookie = cookieString.split("=");
QNetworkCookie crntCookie;
if (qslCrntCookie.length() == 2)
{
QString qsValue = qslCrntCookie.at(1);
qsValue.remove("\"");
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData(), qsValue.toAscii().constData());
}
else
{
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData());
}
// HACK : keep only the same cookies as the XWiki website does.
if(crntCookie.name() == "JSESSIONID" ||
crntCookie.name() == "username" ||
crntCookie.name() == "password" ||
crntCookie.name() == "rememberme" ||
crntCookie.name() == "validation")
{
mCookies << crntCookie;
}
}
QNetworkCookie langCookie("language", "en");
mCookies << langCookie;
// Set the cookiejar : it set the cookies that will be sent with every packet.
mpCookieJar->setCookiesFromUrl(mCookies, QUrl(DOCPUBLICATION_URL)/*reply->url()*/);
mpNetworkMgr->setCookieJar(mpCookieJar);
bLoginCookieSet = true;
emit loginDone();
}
else
{
if (response.isEmpty())
{
// Verify that the UBW file has been sent correctly
bool bTransferOk = false;
for(int j = 0; j <= qslCookieVals.size(); j++)
{
......@@ -689,12 +595,10 @@ void UBDocumentPublisher::onFinished(QNetworkReply *reply)
{
UBApplication::showMessage(tr("Failed to upload document on the web."));
}
}
}
reply->deleteLater();
}
void UBDocumentPublisher::sendUbw()
void UBDocumentPublisher::sendUbw(QString username, QString password)
{
if (QFile::exists(mTmpZipFile))
{
......@@ -710,6 +614,10 @@ void UBDocumentPublisher::sendUbw()
multipartHeader = "multipart/form-data; boundary="+boundary;
data="--"+boundary+mCrlf;
data+="Content-Disposition: form-data; name=\"title\"" + mCrlf + mCrlf + mDocInfos.title + mCrlf;
data+="--"+boundary+mCrlf;
data+="Content-Disposition: form-data; name=\"description\"" + mCrlf + mCrlf + mDocInfos.description.remove("\n") + mCrlf;
data+="--"+boundary+mCrlf;
data+="Content-Disposition: form-data; name=\"file\"; filename=\""+ fi.fileName() +"\""+mCrlf;
data+="Content-Type: application/octet-stream"+mCrlf+mCrlf;
datatoSend=data.toAscii(); // convert data string to byte array for request
......@@ -717,18 +625,15 @@ void UBDocumentPublisher::sendUbw()
datatoSend += mCrlf;
datatoSend += QString("--%0--%1").arg(boundary).arg(mCrlf);
QNetworkRequest request(QUrl(DOCPUBLICATION_URL));
QNetworkRequest request(QUrl(QString(DOCPUBLICATION_URL).toAscii().constData()));
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");
QString b64Auth = getBase64Of(QString("%0:%1").arg(username).arg(password));
request.setRawHeader("Authorization", QString("Basic %0").arg(b64Auth).toAscii().constData());
request.setRawHeader("Host", "sankore.devxwiki.com");
request.setRawHeader("Accept", "*/*");
request.setRawHeader("Accept-Language", "en-US,*");
request.setRawHeader("Referer", DOCPUBLICATION_URL);
QNetworkCookie titleCookie("title", mDocInfos.title.toAscii().constData());
QNetworkCookie descCookie("description", mDocInfos.description.remove("\n").toAscii().constData());
mCookies << titleCookie;
mCookies << descCookie;
mpCookieJar->setCookiesFromUrl(mCookies, QUrl(DOCPUBLICATION_URL));
mpNetworkMgr->setCookieJar(mpCookieJar);
......@@ -744,37 +649,6 @@ QString UBDocumentPublisher::getBase64Of(QString stringToEncode)
return stringToEncode.toAscii().toBase64();
}
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);
}
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);
mpWebView->page()->setNetworkAccessManager(mpNetworkMgr);
}
void UBDocumentPublisher::onProxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
{
Q_UNUSED(proxy);
UBProxyLoginDlg dlg;
if(QDialog::Accepted == dlg.exec())
{
authenticator->setUser(dlg.username());
authenticator->setPassword(dlg.password());
}
}
// ---------------------------------------------------------
UBProxyLoginDlg::UBProxyLoginDlg(QWidget *parent, const char *name):QDialog(parent)
, mpLayout(NULL)
......
......@@ -21,7 +21,7 @@
#include "ui_webPublishing.h"
#include "UBAbstractPublisher.h"
#define DOCPUBLICATION_URL "http://sankore.devxwiki.com/xwiki/bin/view/CreateResources/UniboardUpload"
#define DOCPUBLICATION_URL "http://sankore.devxwiki.com/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain"
#define XWIKI_ORIGIN_HEADER "http://sankore.devxwiki.com"
typedef struct
......@@ -104,21 +104,15 @@ protected:
private slots:
void onFinished(QNetworkReply* reply);
void onLinkClicked(const QUrl& url);
void onLoadFinished(bool result);
void onLoginDone();
void onProxyAuthenticationRequired(const QNetworkProxy & proxy, QAuthenticator * authenticator);
private:
UBDocumentProxy *mSourceDocument;
UBDocumentProxy *mPublishingDocument;
void init();
void sendUbw();
void sendUbw(QString username, QString password);
QString getBase64Of(QString stringToEncode);
QWebView* mpWebView;
QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar;
......@@ -128,7 +122,6 @@ private:
bool bLoginCookieSet;
void buildUbwFile();
void login(QString username, QString password);
QString mTmpZipFile;
QList<QNetworkCookie> mCookies;
sDocumentInfos mDocInfos;
......
......@@ -349,11 +349,6 @@ void UBApplication::showDocument()
applicationController->showDocument();
}
void UBApplication::showSankoreWebDocument()
{
applicationController->showSankoreWebDocument();
}
int UBApplication::toolBarHeight()
{
return mainWindow->boardToolBar->rect().height();
......
......@@ -96,7 +96,6 @@ class UBApplication : public QtSingleApplication
void showBoard();
void showInternet();
void showDocument();
void showSankoreWebDocument();
void toolBarPositionChanged(QVariant topOrBottom);
void toolBarDisplayTextChanged(QVariant display);
......
......@@ -417,33 +417,6 @@ 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)
{
int desktopWidgetIndex = qApp->desktop()->screenNumber(mMainWindow);
......
......@@ -66,8 +66,6 @@ class UBApplicationController : public QObject
void showDocument();
void showSankoreWebDocument();
void showMessage(const QString& message, bool showSpinningWheel);
void importFile(const QString& pFilePath);
......
......@@ -36,6 +36,27 @@ qreal UBPreferencesController::sSliderRatio = 10.0;
qreal UBPreferencesController::sMinPenWidth = 0.5;
qreal UBPreferencesController::sMaxPenWidth = 50.0;
UBPreferencesDialog::UBPreferencesDialog(UBPreferencesController* prefController, QWidget* parent,Qt::WindowFlags f)
:QDialog(parent,f)
,mPreferencesController(prefController)
{
}
UBPreferencesDialog::~UBPreferencesDialog()
{
}
void UBPreferencesDialog::closeEvent(QCloseEvent* e)
{
if(mPreferencesController->inputValuesConsistence())
e->accept();
else
e->ignore();
}
UBPreferencesController::UBPreferencesController(QWidget *parent)
: QObject(parent)
, mPreferencesWindow(0)
......@@ -43,8 +64,9 @@ UBPreferencesController::UBPreferencesController(QWidget *parent)
, mPenProperties(0)
, mMarkerProperties(0)
{
mPreferencesWindow = new QDialog(parent, Qt::Dialog);
mPreferencesUI = new Ui::preferencesDialog(); // deleted in UBPreferencesController::destructor
mPreferencesWindow = new UBPreferencesDialog(this,parent, Qt::Dialog);
// mPreferencesWindow = new QDialog(parent, Qt::Dialog);
mPreferencesUI = new Ui::preferencesDialog(); // deleted in
mPreferencesUI->setupUi(mPreferencesWindow);
connect(mPreferencesUI->Username_textBox, SIGNAL(editingFinished()), this, SLOT(onCommunityUsernameChanged()));
connect(mPreferencesUI->Password_textEdit, SIGNAL(editingFinished()), this, SLOT(onCommunityPasswordChanged()));
......@@ -201,15 +223,48 @@ void UBPreferencesController::onCommunityPasswordChanged()
settings->setCommunityPassword(mPreferencesUI->Password_textEdit->text());
}
bool UBPreferencesController::inputValuesConsistence()
{
QString backgroundStyle = "QWidget {background-color: white}";
mPreferencesUI->Username_textBox->setStyleSheet(backgroundStyle);
mPreferencesUI->Password_textEdit->setStyleSheet(backgroundStyle);
QString username = mPreferencesUI->Username_textBox->text();
QString password = mPreferencesUI->Password_textEdit->text();
bool isConsistent = true;
if (username.length() + password.length()){
backgroundStyle = "QWidget {background-color: magenta}";
if(username.isEmpty()){
isConsistent = false;
mPreferencesUI->mainTabWidget->setCurrentWidget(mPreferencesUI->networkTab);
mPreferencesUI->Username_textBox->setStyleSheet(backgroundStyle);
mPreferencesUI->Username_textBox->setFocus();
mPreferencesUI->Username_textBox->setCursorPosition(0);
}
else if(password.isEmpty()){
isConsistent = false;
mPreferencesUI->mainTabWidget->setCurrentWidget(mPreferencesUI->networkTab);
mPreferencesUI->Password_textEdit->setStyleSheet(backgroundStyle);
mPreferencesUI->Password_textEdit->setFocus();
mPreferencesUI->Password_textEdit->setCursorPosition(0);
}
}
return isConsistent;
}
void UBPreferencesController::close()
{
//web
QString homePage = mPreferencesUI->webHomePage->text();
UBSettings::settings()->webHomePage->set(homePage);
UBSettings::settings()->webHomePage->set(homePage);
UBSettings::settings()->setProxyUsername(mPreferencesUI->proxyUsername->text());
UBSettings::settings()->setProxyPassword(mPreferencesUI->proxyPassword->text());
if (!inputValuesConsistence())
return;
mPreferencesWindow->accept();
}
......@@ -485,4 +540,3 @@ UBBrushPropertiesFrame::UBBrushPropertiesFrame(QFrame* owner, const QList<QColor
}
}
......@@ -21,6 +21,7 @@
class UBColorPicker;
class UBApplication;
class UBSettings;
class UBPreferencesController;
namespace Ui
{
......@@ -31,6 +32,21 @@ namespace Ui
class UBBrushPropertiesFrame;
class UBPreferencesDialog : public QDialog
{
Q_OBJECT;
public:
UBPreferencesDialog(UBPreferencesController* prefController, QWidget* parent = 0,Qt::WindowFlags f = 0 );
~UBPreferencesDialog();
protected:
void closeEvent(QCloseEvent* e);
UBPreferencesController *mPreferencesController;
};
class UBPreferencesController : public QObject
{
Q_OBJECT;
......@@ -39,6 +55,8 @@ class UBPreferencesController : public QObject
UBPreferencesController(QWidget *parent);
virtual ~UBPreferencesController();
bool inputValuesConsistence();
public slots:
void show();
......@@ -48,7 +66,7 @@ class UBPreferencesController : public QObject
void wire();
void init();
QDialog* mPreferencesWindow;
UBPreferencesDialog* mPreferencesWindow;
Ui::preferencesDialog* mPreferencesUI;
UBBrushPropertiesFrame* mPenProperties;
UBBrushPropertiesFrame* mMarkerProperties;
......@@ -78,9 +96,7 @@ class UBBrushPropertiesFrame : public Ui::brushProperties
{
public:
UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors,
const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors,
const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller);
UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors,const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors,const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller);
virtual ~UBBrushPropertiesFrame(){}
......
......@@ -43,7 +43,7 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
actionPreferences->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return));
actionQuit->setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4));
#else
// No shortcut on Linux (like GEdit/Nautilius)
actionQuit->setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4));
#endif
}
......@@ -106,19 +106,6 @@ 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);
......
......@@ -42,9 +42,6 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
void addDocumentsWidget(QWidget *pWidget);
void switchToDocumentsWidget();
void addSankoreWebDocumentWidget(QWebView* pWidget);
void switchToSankoreWebDocumentWidget();
public slots:
void onExportDone();
......
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