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 @@ ...@@ -44,6 +44,7 @@
#include "UBSvgSubsetRasterizer.h" #include "UBSvgSubsetRasterizer.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "../../core/UBApplication.h"
UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent) UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent)
...@@ -54,90 +55,52 @@ UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *pa ...@@ -54,90 +55,52 @@ UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *pa
, mPassword("") , mPassword("")
, bLoginCookieSet(false) , 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(); init();
} }
UBDocumentPublisher::~UBDocumentPublisher() UBDocumentPublisher::~UBDocumentPublisher()
{ {
//delete mpWebView; if(mSourceDocument){
//delete mPublishingDocument; delete mSourceDocument;
mSourceDocument = NULL;
}
if(mPublishingDocument){
delete mPublishingDocument;
mPublishingDocument = NULL;
}
} }
void UBDocumentPublisher::publish() 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; UBPublicationDlg dlg;
if(QDialog::Accepted == dlg.exec()) if(QDialog::Accepted == dlg.exec())
{ {
mDocInfos.title = dlg.title(); mDocInfos.title = dlg.title();
mDocInfos.description = dlg.description(); 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(); buildUbwFile();
UBApplication::showMessage(tr("Uploading Sankore File on Web.")); UBApplication::showMessage(tr("Uploading Sankore File on Web."));
login(mUsername, mPassword); sendUbw(mUsername, mPassword);
//sendUbw();
} }
} }
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() void UBDocumentPublisher::buildUbwFile()
{ {
QDir d; QDir d;
...@@ -164,7 +127,6 @@ void UBDocumentPublisher::buildUbwFile() ...@@ -164,7 +127,6 @@ void UBDocumentPublisher::buildUbwFile()
ubzExporter.setVerbode(false); ubzExporter.setVerbode(false);
ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); ubzExporter.persistsDocument(mSourceDocument, 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++) {
...@@ -586,9 +548,6 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem * ...@@ -586,9 +548,6 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
} }
} }
void UBDocumentPublisher::init() void UBDocumentPublisher::init()
{ {
mCrlf=0x0d; mCrlf=0x0d;
...@@ -599,21 +558,11 @@ void UBDocumentPublisher::init() ...@@ -599,21 +558,11 @@ void UBDocumentPublisher::init()
mpNetworkMgr = new QNetworkAccessManager(this); mpNetworkMgr = new QNetworkAccessManager(this);
mpCookieJar = new QNetworkCookieJar(); 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(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
connect(mpNetworkMgr, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(onProxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
} }
void UBDocumentPublisher::onFinished(QNetworkReply *reply) void UBDocumentPublisher::onFinished(QNetworkReply *reply)
{ {
QByteArray response = reply->readAll();
QVariant cookieHeader = reply->rawHeader("Set-Cookie"); QVariant cookieHeader = reply->rawHeader("Set-Cookie");
// First we concatenate all the Set-Cookie values (the packet can contains many of them) // First we concatenate all the Set-Cookie values (the packet can contains many of them)
QStringList qslCookie = cookieHeader.toString().split("\n"); QStringList qslCookie = cookieHeader.toString().split("\n");
...@@ -625,49 +574,6 @@ void UBDocumentPublisher::onFinished(QNetworkReply *reply) ...@@ -625,49 +574,6 @@ void UBDocumentPublisher::onFinished(QNetworkReply *reply)
// Now we isolate every cookie value // Now we isolate every cookie value
QStringList qslCookieVals = qsCookieValue.split("; "); 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; bool bTransferOk = false;
for(int j = 0; j <= qslCookieVals.size(); j++) for(int j = 0; j <= qslCookieVals.size(); j++)
{ {
...@@ -689,12 +595,10 @@ void UBDocumentPublisher::onFinished(QNetworkReply *reply) ...@@ -689,12 +595,10 @@ void UBDocumentPublisher::onFinished(QNetworkReply *reply)
{ {
UBApplication::showMessage(tr("Failed to upload document on the web.")); UBApplication::showMessage(tr("Failed to upload document on the web."));
} }
}
}
reply->deleteLater(); reply->deleteLater();
} }
void UBDocumentPublisher::sendUbw() void UBDocumentPublisher::sendUbw(QString username, QString password)
{ {
if (QFile::exists(mTmpZipFile)) if (QFile::exists(mTmpZipFile))
{ {
...@@ -710,6 +614,10 @@ void UBDocumentPublisher::sendUbw() ...@@ -710,6 +614,10 @@ void UBDocumentPublisher::sendUbw()
multipartHeader = "multipart/form-data; boundary="+boundary; multipartHeader = "multipart/form-data; boundary="+boundary;
data="--"+boundary+mCrlf; 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-Disposition: form-data; name=\"file\"; filename=\""+ fi.fileName() +"\""+mCrlf;
data+="Content-Type: application/octet-stream"+mCrlf+mCrlf; data+="Content-Type: application/octet-stream"+mCrlf+mCrlf;
datatoSend=data.toAscii(); // convert data string to byte array for request datatoSend=data.toAscii(); // convert data string to byte array for request
...@@ -717,18 +625,15 @@ void UBDocumentPublisher::sendUbw() ...@@ -717,18 +625,15 @@ void UBDocumentPublisher::sendUbw()
datatoSend += mCrlf; datatoSend += mCrlf;
datatoSend += QString("--%0--%1").arg(boundary).arg(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::ContentTypeHeader, multipartHeader);
request.setHeader(QNetworkRequest::ContentLengthHeader,datatoSend.size()); 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("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)); mpCookieJar->setCookiesFromUrl(mCookies, QUrl(DOCPUBLICATION_URL));
mpNetworkMgr->setCookieJar(mpCookieJar); mpNetworkMgr->setCookieJar(mpCookieJar);
...@@ -744,37 +649,6 @@ QString UBDocumentPublisher::getBase64Of(QString stringToEncode) ...@@ -744,37 +649,6 @@ QString UBDocumentPublisher::getBase64Of(QString stringToEncode)
return stringToEncode.toAscii().toBase64(); 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) UBProxyLoginDlg::UBProxyLoginDlg(QWidget *parent, const char *name):QDialog(parent)
, mpLayout(NULL) , mpLayout(NULL)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ui_webPublishing.h" #include "ui_webPublishing.h"
#include "UBAbstractPublisher.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" #define XWIKI_ORIGIN_HEADER "http://sankore.devxwiki.com"
typedef struct typedef struct
...@@ -104,21 +104,15 @@ protected: ...@@ -104,21 +104,15 @@ protected:
private slots: private slots:
void onFinished(QNetworkReply* reply); void onFinished(QNetworkReply* reply);
void onLinkClicked(const QUrl& url);
void onLoadFinished(bool result);
void onLoginDone();
void onProxyAuthenticationRequired(const QNetworkProxy & proxy, QAuthenticator * authenticator);
private: private:
UBDocumentProxy *mSourceDocument; UBDocumentProxy *mSourceDocument;
UBDocumentProxy *mPublishingDocument; UBDocumentProxy *mPublishingDocument;
void init(); void init();
void sendUbw(); void sendUbw(QString username, QString password);
QString getBase64Of(QString stringToEncode); QString getBase64Of(QString stringToEncode);
QWebView* mpWebView;
QHBoxLayout* mpLayout; QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr; QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar; QNetworkCookieJar* mpCookieJar;
...@@ -128,7 +122,6 @@ private: ...@@ -128,7 +122,6 @@ private:
bool bLoginCookieSet; bool bLoginCookieSet;
void buildUbwFile(); void buildUbwFile();
void login(QString username, QString password);
QString mTmpZipFile; QString mTmpZipFile;
QList<QNetworkCookie> mCookies; QList<QNetworkCookie> mCookies;
sDocumentInfos mDocInfos; sDocumentInfos mDocInfos;
......
...@@ -349,11 +349,6 @@ void UBApplication::showDocument() ...@@ -349,11 +349,6 @@ void UBApplication::showDocument()
applicationController->showDocument(); applicationController->showDocument();
} }
void UBApplication::showSankoreWebDocument()
{
applicationController->showSankoreWebDocument();
}
int UBApplication::toolBarHeight() int UBApplication::toolBarHeight()
{ {
return mainWindow->boardToolBar->rect().height(); return mainWindow->boardToolBar->rect().height();
......
...@@ -96,7 +96,6 @@ class UBApplication : public QtSingleApplication ...@@ -96,7 +96,6 @@ class UBApplication : public QtSingleApplication
void showBoard(); void showBoard();
void showInternet(); void showInternet();
void showDocument(); void showDocument();
void showSankoreWebDocument();
void toolBarPositionChanged(QVariant topOrBottom); void toolBarPositionChanged(QVariant topOrBottom);
void toolBarDisplayTextChanged(QVariant display); void toolBarDisplayTextChanged(QVariant display);
......
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBApplicationController.h" #include "UBApplicationController.h"
#include "frameworks/UBPlatformUtils.h" #include "frameworks/UBPlatformUtils.h"
...@@ -365,7 +365,7 @@ void UBApplicationController::showInternet() ...@@ -365,7 +365,7 @@ void UBApplicationController::showInternet()
{ {
showDesktop(true); showDesktop(true);
} }
else else
{ {
mMainWindow->boardToolBar->hide(); mMainWindow->boardToolBar->hide();
mMainWindow->documentToolBar->hide(); mMainWindow->documentToolBar->hide();
...@@ -417,33 +417,6 @@ void UBApplicationController::showDocument() ...@@ -417,33 +417,6 @@ void UBApplicationController::showDocument()
emit mainModeChanged(Document); 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) void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
{ {
int desktopWidgetIndex = qApp->desktop()->screenNumber(mMainWindow); int desktopWidgetIndex = qApp->desktop()->screenNumber(mMainWindow);
......
...@@ -66,8 +66,6 @@ class UBApplicationController : public QObject ...@@ -66,8 +66,6 @@ class UBApplicationController : public QObject
void showDocument(); void showDocument();
void showSankoreWebDocument();
void showMessage(const QString& message, bool showSpinningWheel); void showMessage(const QString& message, bool showSpinningWheel);
void importFile(const QString& pFilePath); void importFile(const QString& pFilePath);
......
...@@ -36,6 +36,27 @@ qreal UBPreferencesController::sSliderRatio = 10.0; ...@@ -36,6 +36,27 @@ qreal UBPreferencesController::sSliderRatio = 10.0;
qreal UBPreferencesController::sMinPenWidth = 0.5; qreal UBPreferencesController::sMinPenWidth = 0.5;
qreal UBPreferencesController::sMaxPenWidth = 50.0; 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) UBPreferencesController::UBPreferencesController(QWidget *parent)
: QObject(parent) : QObject(parent)
, mPreferencesWindow(0) , mPreferencesWindow(0)
...@@ -43,8 +64,9 @@ UBPreferencesController::UBPreferencesController(QWidget *parent) ...@@ -43,8 +64,9 @@ UBPreferencesController::UBPreferencesController(QWidget *parent)
, mPenProperties(0) , mPenProperties(0)
, mMarkerProperties(0) , mMarkerProperties(0)
{ {
mPreferencesWindow = new QDialog(parent, Qt::Dialog); mPreferencesWindow = new UBPreferencesDialog(this,parent, Qt::Dialog);
mPreferencesUI = new Ui::preferencesDialog(); // deleted in UBPreferencesController::destructor // mPreferencesWindow = new QDialog(parent, Qt::Dialog);
mPreferencesUI = new Ui::preferencesDialog(); // deleted in
mPreferencesUI->setupUi(mPreferencesWindow); mPreferencesUI->setupUi(mPreferencesWindow);
connect(mPreferencesUI->Username_textBox, SIGNAL(editingFinished()), this, SLOT(onCommunityUsernameChanged())); connect(mPreferencesUI->Username_textBox, SIGNAL(editingFinished()), this, SLOT(onCommunityUsernameChanged()));
connect(mPreferencesUI->Password_textEdit, SIGNAL(editingFinished()), this, SLOT(onCommunityPasswordChanged())); connect(mPreferencesUI->Password_textEdit, SIGNAL(editingFinished()), this, SLOT(onCommunityPasswordChanged()));
...@@ -108,8 +130,8 @@ void UBPreferencesController::wire() ...@@ -108,8 +130,8 @@ void UBPreferencesController::wire()
QList<QColor> penDarkBackgroundSelectedColors = settings->boardPenDarkBackgroundSelectedColors->colors(); QList<QColor> penDarkBackgroundSelectedColors = settings->boardPenDarkBackgroundSelectedColors->colors();
mPenProperties = new UBBrushPropertiesFrame(mPreferencesUI->penFrame, mPenProperties = new UBBrushPropertiesFrame(mPreferencesUI->penFrame,
penLightBackgroundColors, penDarkBackgroundColors, penLightBackgroundSelectedColors, penLightBackgroundColors, penDarkBackgroundColors, penLightBackgroundSelectedColors,
penDarkBackgroundSelectedColors, this); penDarkBackgroundSelectedColors, this);
mPenProperties->opacityFrame->hide(); mPenProperties->opacityFrame->hide();
...@@ -125,8 +147,8 @@ void UBPreferencesController::wire() ...@@ -125,8 +147,8 @@ void UBPreferencesController::wire()
QList<QColor> markerDarkBackgroundSelectedColors = settings->boardMarkerDarkBackgroundSelectedColors->colors(); QList<QColor> markerDarkBackgroundSelectedColors = settings->boardMarkerDarkBackgroundSelectedColors->colors();
mMarkerProperties = new UBBrushPropertiesFrame(mPreferencesUI->markerFrame, markerLightBackgroundColors, mMarkerProperties = new UBBrushPropertiesFrame(mPreferencesUI->markerFrame, markerLightBackgroundColors,
markerDarkBackgroundColors, markerLightBackgroundSelectedColors, markerDarkBackgroundColors, markerLightBackgroundSelectedColors,
markerDarkBackgroundSelectedColors, this); markerDarkBackgroundSelectedColors, this);
mMarkerProperties->pressureSensitiveCheckBox->setText(tr("Marker is pressure sensitive")); mMarkerProperties->pressureSensitiveCheckBox->setText(tr("Marker is pressure sensitive"));
...@@ -151,7 +173,7 @@ void UBPreferencesController::init() ...@@ -151,7 +173,7 @@ void UBPreferencesController::init()
mPreferencesUI->keyboardPaletteAutoMinimize->setChecked(settings->boardKeyboardPaletteAutoMinimize->get().toBool()); mPreferencesUI->keyboardPaletteAutoMinimize->setChecked(settings->boardKeyboardPaletteAutoMinimize->get().toBool());
for(int i=0; i<mPreferencesUI->keyboardPaletteKeyButtonSize->count(); i++) for(int i=0; i<mPreferencesUI->keyboardPaletteKeyButtonSize->count(); i++)
if (mPreferencesUI->keyboardPaletteKeyButtonSize->itemText(i) == if (mPreferencesUI->keyboardPaletteKeyButtonSize->itemText(i) ==
settings->boardKeyboardPaletteKeyBtnSize->get().toString()) settings->boardKeyboardPaletteKeyBtnSize->get().toString())
{ {
mPreferencesUI->keyboardPaletteKeyButtonSize->setCurrentIndex(i); mPreferencesUI->keyboardPaletteKeyButtonSize->setCurrentIndex(i);
break; break;
...@@ -201,15 +223,48 @@ void UBPreferencesController::onCommunityPasswordChanged() ...@@ -201,15 +223,48 @@ void UBPreferencesController::onCommunityPasswordChanged()
settings->setCommunityPassword(mPreferencesUI->Password_textEdit->text()); 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() void UBPreferencesController::close()
{ {
//web //web
QString homePage = mPreferencesUI->webHomePage->text(); QString homePage = mPreferencesUI->webHomePage->text();
UBSettings::settings()->webHomePage->set(homePage);
UBSettings::settings()->webHomePage->set(homePage);
UBSettings::settings()->setProxyUsername(mPreferencesUI->proxyUsername->text()); UBSettings::settings()->setProxyUsername(mPreferencesUI->proxyUsername->text());
UBSettings::settings()->setProxyPassword(mPreferencesUI->proxyPassword->text()); UBSettings::settings()->setProxyPassword(mPreferencesUI->proxyPassword->text());
if (!inputValuesConsistence())
return;
mPreferencesWindow->accept(); mPreferencesWindow->accept();
} }
...@@ -253,8 +308,8 @@ void UBPreferencesController::defaultSettings() ...@@ -253,8 +308,8 @@ void UBPreferencesController::defaultSettings()
for (int i = 0 ; i < settings->colorPaletteSize ; i++) for (int i = 0 ; i < settings->colorPaletteSize ; i++)
{ {
mPenProperties->lightBackgroundColorPickers[i]->setSelectedColorIndex(lightBackgroundSelectedColors.indexOf(settings->penColors(false).at(i))); mPenProperties->lightBackgroundColorPickers[i]->setSelectedColorIndex(lightBackgroundSelectedColors.indexOf(settings->penColors(false).at(i)));
mPenProperties->darkBackgroundColorPickers[i]->setSelectedColorIndex(darkBackgroundSelectedColors.indexOf(settings->penColors(true).at(i))); mPenProperties->darkBackgroundColorPickers[i]->setSelectedColorIndex(darkBackgroundSelectedColors.indexOf(settings->penColors(true).at(i)));
} }
} }
else if (mPreferencesUI->mainTabWidget->currentWidget() == mPreferencesUI->markerTab) else if (mPreferencesUI->mainTabWidget->currentWidget() == mPreferencesUI->markerTab)
...@@ -274,8 +329,8 @@ void UBPreferencesController::defaultSettings() ...@@ -274,8 +329,8 @@ void UBPreferencesController::defaultSettings()
for (int i = 0 ; i < settings->colorPaletteSize ; i++) for (int i = 0 ; i < settings->colorPaletteSize ; i++)
{ {
mMarkerProperties->lightBackgroundColorPickers[i]->setSelectedColorIndex(lightBackgroundSelectedColors.indexOf(settings->markerColors(false).at(i))); mMarkerProperties->lightBackgroundColorPickers[i]->setSelectedColorIndex(lightBackgroundSelectedColors.indexOf(settings->markerColors(false).at(i)));
mMarkerProperties->darkBackgroundColorPickers[i]->setSelectedColorIndex(darkBackgroundSelectedColors.indexOf(settings->markerColors(true).at(i))); mMarkerProperties->darkBackgroundColorPickers[i]->setSelectedColorIndex(darkBackgroundSelectedColors.indexOf(settings->markerColors(true).at(i)));
} }
} }
else if (mPreferencesUI->mainTabWidget->currentWidget() == mPreferencesUI->aboutTab) else if (mPreferencesUI->mainTabWidget->currentWidget() == mPreferencesUI->aboutTab)
...@@ -412,8 +467,8 @@ void UBPreferencesController::toolbarOrientationHorizontal(bool checked) ...@@ -412,8 +467,8 @@ void UBPreferencesController::toolbarOrientationHorizontal(bool checked)
} }
UBBrushPropertiesFrame::UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors, UBBrushPropertiesFrame::UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors,
const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors, const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors,
const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller) const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller)
{ {
setupUi(owner); setupUi(owner);
...@@ -485,4 +540,3 @@ UBBrushPropertiesFrame::UBBrushPropertiesFrame(QFrame* owner, const QList<QColor ...@@ -485,4 +540,3 @@ UBBrushPropertiesFrame::UBBrushPropertiesFrame(QFrame* owner, const QList<QColor
} }
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
class UBColorPicker; class UBColorPicker;
class UBApplication; class UBApplication;
class UBSettings; class UBSettings;
class UBPreferencesController;
namespace Ui namespace Ui
{ {
...@@ -31,6 +32,21 @@ namespace Ui ...@@ -31,6 +32,21 @@ namespace Ui
class UBBrushPropertiesFrame; 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 class UBPreferencesController : public QObject
{ {
Q_OBJECT; Q_OBJECT;
...@@ -39,6 +55,8 @@ class UBPreferencesController : public QObject ...@@ -39,6 +55,8 @@ class UBPreferencesController : public QObject
UBPreferencesController(QWidget *parent); UBPreferencesController(QWidget *parent);
virtual ~UBPreferencesController(); virtual ~UBPreferencesController();
bool inputValuesConsistence();
public slots: public slots:
void show(); void show();
...@@ -48,7 +66,7 @@ class UBPreferencesController : public QObject ...@@ -48,7 +66,7 @@ class UBPreferencesController : public QObject
void wire(); void wire();
void init(); void init();
QDialog* mPreferencesWindow; UBPreferencesDialog* mPreferencesWindow;
Ui::preferencesDialog* mPreferencesUI; Ui::preferencesDialog* mPreferencesUI;
UBBrushPropertiesFrame* mPenProperties; UBBrushPropertiesFrame* mPenProperties;
UBBrushPropertiesFrame* mMarkerProperties; UBBrushPropertiesFrame* mMarkerProperties;
...@@ -78,9 +96,7 @@ class UBBrushPropertiesFrame : public Ui::brushProperties ...@@ -78,9 +96,7 @@ class UBBrushPropertiesFrame : public Ui::brushProperties
{ {
public: public:
UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors, UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors,const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors,const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller);
const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors,
const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller);
virtual ~UBBrushPropertiesFrame(){} virtual ~UBBrushPropertiesFrame(){}
......
...@@ -43,7 +43,7 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags) ...@@ -43,7 +43,7 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
actionPreferences->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return)); actionPreferences->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return));
actionQuit->setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4)); actionQuit->setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4));
#else #else
// No shortcut on Linux (like GEdit/Nautilius) actionQuit->setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4));
#endif #endif
} }
...@@ -106,19 +106,6 @@ void UBMainWindow::switchToDocumentsWidget() ...@@ -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) void UBMainWindow::keyPressEvent(QKeyEvent *event)
{ {
QMainWindow::keyPressEvent(event); QMainWindow::keyPressEvent(event);
......
...@@ -42,9 +42,6 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow ...@@ -42,9 +42,6 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
void addDocumentsWidget(QWidget *pWidget); void addDocumentsWidget(QWidget *pWidget);
void switchToDocumentsWidget(); void switchToDocumentsWidget();
void addSankoreWebDocumentWidget(QWebView* pWidget);
void switchToSankoreWebDocumentWidget();
public slots: public slots:
void onExportDone(); 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