From 90c03c866ce5cd7c7dec149590289625e7cb3479 Mon Sep 17 00:00:00 2001 From: Guillaume Burel Date: Mon, 24 Sep 2012 16:30:45 +0200 Subject: [PATCH 1/3] Implemented SANKORE-765. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User is aksed for a login+password couple if none of these have been filled in preferences. He can allow Sankoré to store it in checking "Remember credentials". --- .../publishing/UBDocumentPublisher.cpp | 83 +++++++++++++++++-- src/adaptors/publishing/UBDocumentPublisher.h | 29 +++++++ 2 files changed, 106 insertions(+), 6 deletions(-) diff --git a/src/adaptors/publishing/UBDocumentPublisher.cpp b/src/adaptors/publishing/UBDocumentPublisher.cpp index 39174dba..87e78ad4 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.cpp +++ b/src/adaptors/publishing/UBDocumentPublisher.cpp @@ -77,15 +77,19 @@ 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(); + if (mUsername.isEmpty() || mPassword.isEmpty()){ + UBLoginDlg dlg; + if (dlg.exec() == QDialog::Accepted) { + mUsername = dlg.username(); + mPassword = dlg.password(); + } + else + return; + } + UBPublicationDlg dlg; if(QDialog::Accepted == dlg.exec()) { @@ -651,6 +655,73 @@ QString UBDocumentPublisher::getBase64Of(QString stringToEncode) return stringToEncode.toAscii().toBase64(); } +UBLoginDlg::UBLoginDlg(QWidget *parent, const char *name) + : QDialog(parent) + , mUsernameLabel(tr("Username:"), this) + , mUsernameLineEdit(this) + , mPasswordLabel(tr("Password:"), this) + , mPasswordLineEdit(this) + , mRememberLabel(tr("Remember credentials"), this) + , mButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this) +{ + setObjectName(name); + setFixedSize(400, 150); + setWindowTitle(tr("Login")); + + setLayout(&mLayout); + mLayout.addLayout(&mUsernameLayout); + mLayout.addLayout(&mPasswordLayout); + mLayout.addLayout(&mRememberLayout); + + mUsernameLayout.addWidget(&mUsernameLabel, 0); + mUsernameLayout.addWidget(&mUsernameLineEdit, 1); + + mPasswordLayout.addWidget(&mPasswordLabel, 0); + mPasswordLineEdit.setEchoMode(QLineEdit::Password); + mPasswordLayout.addWidget(&mPasswordLineEdit, 1); + + mRememberLayout.addWidget(&mRememberCheckBox, 0); + mRememberLayout.addWidget(&mRememberLabel, 1); + + mLayout.addWidget(&mButtons); + + connect(&mButtons, SIGNAL(accepted()), this, SLOT(onButtonsAccepted())); + connect(&mButtons, SIGNAL(rejected()), this, SLOT(reject())); + +} + +UBLoginDlg::~UBLoginDlg() +{ + /* NOOP */ +} + +QString UBLoginDlg::username() +{ + return mUsernameLineEdit.text(); +} + +QString UBLoginDlg::password() +{ + return mPasswordLineEdit.text(); +} + +bool UBLoginDlg::hasToRemember() +{ + return mRememberCheckBox.checkState() == Qt::Checked; +} + +void UBLoginDlg::onButtonsAccepted() +{ + if (username().isEmpty() || password().isEmpty()) + return; + if (hasToRemember()) { + UBSettings* settings = UBSettings::settings(); + settings->setCommunityUsername(username()); + settings->setCommunityPassword(password()); + } + accept(); +} + // --------------------------------------------------------- UBProxyLoginDlg::UBProxyLoginDlg(QWidget *parent, const char *name):QDialog(parent) , mpLayout(NULL) diff --git a/src/adaptors/publishing/UBDocumentPublisher.h b/src/adaptors/publishing/UBDocumentPublisher.h index 4babbec8..b9578eef 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.h +++ b/src/adaptors/publishing/UBDocumentPublisher.h @@ -33,6 +33,35 @@ class UBServerXMLHttpRequest; class UBGraphicsW3CWidgetItem; class QWebView; +class UBLoginDlg : public QDialog +{ +Q_OBJECT +public: + UBLoginDlg(QWidget* parent = 0, const char* name = "LoginDlg"); + ~UBLoginDlg(); + + QString username(); + QString password(); + +private slots: + void onButtonsAccepted(); + +private: + bool hasToRemember(); + + QVBoxLayout mLayout; + QHBoxLayout mUsernameLayout; + QHBoxLayout mPasswordLayout; + QHBoxLayout mRememberLayout; + QLabel mUsernameLabel; + QLineEdit mUsernameLineEdit; + QLabel mPasswordLabel; + QLineEdit mPasswordLineEdit; + QCheckBox mRememberCheckBox; + QLabel mRememberLabel; + QDialogButtonBox mButtons; +}; + class UBProxyLoginDlg : public QDialog { Q_OBJECT From 076e0edf3668d0eff9bdc0c94cbbce430b12bbea Mon Sep 17 00:00:00 2001 From: Guillaume Burel Date: Tue, 25 Sep 2012 10:44:53 +0200 Subject: [PATCH 2/3] Revert "Implemented SANKORE-765." This reverts commit 90c03c866ce5cd7c7dec149590289625e7cb3479. --- .../publishing/UBDocumentPublisher.cpp | 83 ++----------------- src/adaptors/publishing/UBDocumentPublisher.h | 29 ------- 2 files changed, 6 insertions(+), 106 deletions(-) diff --git a/src/adaptors/publishing/UBDocumentPublisher.cpp b/src/adaptors/publishing/UBDocumentPublisher.cpp index 87e78ad4..39174dba 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.cpp +++ b/src/adaptors/publishing/UBDocumentPublisher.cpp @@ -77,19 +77,15 @@ 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(); - if (mUsername.isEmpty() || mPassword.isEmpty()){ - UBLoginDlg dlg; - if (dlg.exec() == QDialog::Accepted) { - mUsername = dlg.username(); - mPassword = dlg.password(); - } - else - return; - } - UBPublicationDlg dlg; if(QDialog::Accepted == dlg.exec()) { @@ -655,73 +651,6 @@ QString UBDocumentPublisher::getBase64Of(QString stringToEncode) return stringToEncode.toAscii().toBase64(); } -UBLoginDlg::UBLoginDlg(QWidget *parent, const char *name) - : QDialog(parent) - , mUsernameLabel(tr("Username:"), this) - , mUsernameLineEdit(this) - , mPasswordLabel(tr("Password:"), this) - , mPasswordLineEdit(this) - , mRememberLabel(tr("Remember credentials"), this) - , mButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this) -{ - setObjectName(name); - setFixedSize(400, 150); - setWindowTitle(tr("Login")); - - setLayout(&mLayout); - mLayout.addLayout(&mUsernameLayout); - mLayout.addLayout(&mPasswordLayout); - mLayout.addLayout(&mRememberLayout); - - mUsernameLayout.addWidget(&mUsernameLabel, 0); - mUsernameLayout.addWidget(&mUsernameLineEdit, 1); - - mPasswordLayout.addWidget(&mPasswordLabel, 0); - mPasswordLineEdit.setEchoMode(QLineEdit::Password); - mPasswordLayout.addWidget(&mPasswordLineEdit, 1); - - mRememberLayout.addWidget(&mRememberCheckBox, 0); - mRememberLayout.addWidget(&mRememberLabel, 1); - - mLayout.addWidget(&mButtons); - - connect(&mButtons, SIGNAL(accepted()), this, SLOT(onButtonsAccepted())); - connect(&mButtons, SIGNAL(rejected()), this, SLOT(reject())); - -} - -UBLoginDlg::~UBLoginDlg() -{ - /* NOOP */ -} - -QString UBLoginDlg::username() -{ - return mUsernameLineEdit.text(); -} - -QString UBLoginDlg::password() -{ - return mPasswordLineEdit.text(); -} - -bool UBLoginDlg::hasToRemember() -{ - return mRememberCheckBox.checkState() == Qt::Checked; -} - -void UBLoginDlg::onButtonsAccepted() -{ - if (username().isEmpty() || password().isEmpty()) - return; - if (hasToRemember()) { - UBSettings* settings = UBSettings::settings(); - settings->setCommunityUsername(username()); - settings->setCommunityPassword(password()); - } - accept(); -} - // --------------------------------------------------------- UBProxyLoginDlg::UBProxyLoginDlg(QWidget *parent, const char *name):QDialog(parent) , mpLayout(NULL) diff --git a/src/adaptors/publishing/UBDocumentPublisher.h b/src/adaptors/publishing/UBDocumentPublisher.h index b9578eef..4babbec8 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.h +++ b/src/adaptors/publishing/UBDocumentPublisher.h @@ -33,35 +33,6 @@ class UBServerXMLHttpRequest; class UBGraphicsW3CWidgetItem; class QWebView; -class UBLoginDlg : public QDialog -{ -Q_OBJECT -public: - UBLoginDlg(QWidget* parent = 0, const char* name = "LoginDlg"); - ~UBLoginDlg(); - - QString username(); - QString password(); - -private slots: - void onButtonsAccepted(); - -private: - bool hasToRemember(); - - QVBoxLayout mLayout; - QHBoxLayout mUsernameLayout; - QHBoxLayout mPasswordLayout; - QHBoxLayout mRememberLayout; - QLabel mUsernameLabel; - QLineEdit mUsernameLineEdit; - QLabel mPasswordLabel; - QLineEdit mPasswordLineEdit; - QCheckBox mRememberCheckBox; - QLabel mRememberLabel; - QDialogButtonBox mButtons; -}; - class UBProxyLoginDlg : public QDialog { Q_OBJECT From ed67f1badab13e0339ae462e03851f249f2df1f4 Mon Sep 17 00:00:00 2001 From: Guillaume Burel Date: Tue, 25 Sep 2012 12:39:55 +0200 Subject: [PATCH 3/3] Fixed SANKORE-1044 "multiples caches". Now, only one instance per scene is allowed in calling UBGraphicsCache instance() static function. --- src/adaptors/UBSvgSubsetAdaptor.cpp | 2 +- src/domain/UBGraphicsScene.cpp | 21 ++++++++++++--------- src/tools/UBGraphicsCache.cpp | 15 +++++++++++++-- src/tools/UBGraphicsCache.h | 12 +++++++++--- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index bcfa5199..53868e35 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -3120,7 +3120,7 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() UBGraphicsCache* UBSvgSubsetAdaptor::UBSvgSubsetReader::cacheFromSvg() { - UBGraphicsCache* pCache = new UBGraphicsCache(); + UBGraphicsCache* pCache = UBGraphicsCache::instance(mScene); pCache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); graphicsItemFromSvg(pCache); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 22ff3379..6fdd79f6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1603,6 +1603,9 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) --mItemCount; mFastAccessItems.removeAll(item); + /* delete the item if it is cache to allow its reinstanciation, because Cache implements design pattern Singleton. */ + if (dynamic_cast(item)) + UBCoreGraphicsScene::deleteItem(item); } void UBGraphicsScene::removeItems(const QSet& items) @@ -1956,17 +1959,17 @@ void UBGraphicsScene::addAristo(QPointF center) void UBGraphicsScene::addCache() { - UBGraphicsCache* cache = new UBGraphicsCache(); - mTools << cache; + UBGraphicsCache* cache = UBGraphicsCache::instance(this); + if (!items().contains(cache)) { + addItem(cache); - addItem(cache); + cache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); - cache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); - - cache->setVisible(true); - cache->setSelected(true); - UBApplication::boardController->notifyCache(true); - UBApplication::boardController->notifyPageChanged(); + cache->setVisible(true); + cache->setSelected(true); + UBApplication::boardController->notifyCache(true); + UBApplication::boardController->notifyPageChanged(); + } } void UBGraphicsScene::addMask(const QPointF ¢er) diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index 7a89c534..dfde3b4f 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -24,11 +24,21 @@ #include "core/memcheck.h" -UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem() +QMap UBGraphicsCache::sInstances; + +UBGraphicsCache* UBGraphicsCache::instance(UBGraphicsScene *scene) +{ + if (!sInstances.contains(scene)) + sInstances.insert(scene, new UBGraphicsCache(scene)); + return sInstances[scene]; +} + +UBGraphicsCache::UBGraphicsCache(UBGraphicsScene *scene) : QGraphicsRectItem() , mMaskColor(Qt::black) , mMaskShape(eMaskShape_Circle) , mShapeWidth(100) , mDrawMask(false) + , mScene(scene) { // Get the board size and pass it to the shape QRect boardRect = UBApplication::boardController->displayView()->rect(); @@ -39,11 +49,12 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem() UBGraphicsCache::~UBGraphicsCache() { + sInstances.remove(mScene); } UBItem* UBGraphicsCache::deepCopy() const { - UBGraphicsCache* copy = new UBGraphicsCache(); + UBGraphicsCache* copy = new UBGraphicsCache(mScene); copyItemParameters(copy); diff --git a/src/tools/UBGraphicsCache.h b/src/tools/UBGraphicsCache.h index 9ca07d0d..413aa352 100644 --- a/src/tools/UBGraphicsCache.h +++ b/src/tools/UBGraphicsCache.h @@ -30,7 +30,7 @@ typedef enum class UBGraphicsCache : public QGraphicsRectItem, public UBItem { public: - UBGraphicsCache(); + static UBGraphicsCache* instance(UBGraphicsScene *scene); ~UBGraphicsCache(); enum { Type = UBGraphicsItemType::cacheItemType }; @@ -55,8 +55,7 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); private: - void init(); - QRectF updateRect(QPointF currentPoint); + static QMap sInstances; QColor mMaskColor; eMaskShape mMaskShape; @@ -65,6 +64,13 @@ private: QPointF mShapePos; int mOldShapeWidth; QPointF mOldShapePos; + UBGraphicsScene* mScene; + + + UBGraphicsCache(UBGraphicsScene *scene); + + void init(); + QRectF updateRect(QPointF currentPoint); }; #endif // UBGRAPHICSCACHE_H