[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice
From: Stefan Nikolaus <nikolaus4 () googlemail ! com>
Date: 2010-06-05 12:49:31
Message-ID: 20100605124931.CA6BCAC8CC () svn ! kde ! org
[Download RAW message or body]
SVN commit 1134831 by nikolaus:
FIX: Fix map/sheet protection.
Factor the password protection out of Map and Sheet into ProtableObject.
Move the password dialog to ProtectableObject.
Export, because the filters need access.
M +1 -0 kspread/CHANGES
M +1 -0 kspread/CMakeLists.txt
M +15 -42 kspread/Map.cpp
M +3 -6 kspread/Map.h
A kspread/ProtectableObject.cpp [License: LGPL (v2+)]
A kspread/ProtectableObject.h [License: LGPL (v2+)]
M +5 -40 kspread/Sheet.cpp
M +3 -29 kspread/Sheet.h
M +16 -80 kspread/part/View.cpp
M +2 -1 libs/flake/KoShapeUserData.cpp
M +1 -1 libs/flake/KoShapeUserData.h
--- trunk/koffice/kspread/CHANGES #1134830:1134831
@@ -10,6 +10,7 @@
Bug Fixes
---------
Fix text/background/border color actions by using KoColorPopupAction (if pigment is built).
+Fix map/sheet protection action.
208868: Fix action triggering on selection changes, which resulted in style changes.
Fix cell removal by shifting cells up.
--- trunk/koffice/kspread/CMakeLists.txt #1134830:1134831
@@ -185,6 +185,7 @@
Number.cpp
PageManager.cpp
PrintSettings.cpp
+ ProtectableObject.cpp
RecalcManager.cpp
Region.cpp
RegionModel.cpp
--- trunk/koffice/kspread/Map.cpp #1134830:1134831
@@ -87,11 +87,6 @@
QList<Sheet*> lstSheets;
QList<Sheet*> lstDeletedSheets;
- /**
- * Password to protect the map from being changed.
- */
- QByteArray strPassword;
-
// used to give every Sheet a unique default name.
int tableId;
@@ -320,11 +315,6 @@
return d->calculationSettings;
}
-void Map::setProtected(QByteArray const & passwd)
-{
- d->strPassword = passwd;
-}
-
Sheet* Map::createSheet()
{
QString name(i18n("Sheet%1", d->tableId++));
@@ -442,11 +432,13 @@
defaultRowStyle.setDefaultStyle(true);
savingContext.mainStyles().insert(defaultRowStyle, "Default", KoGenStyles::DontAddNumberToName);
- if (!d->strPassword.isNull()) {
+ QByteArray password;
+ this->password(password);
+ if (!password.isNull()) {
xmlWriter.addAttribute("table:structure-protected", "true");
- QByteArray str = KCodecs::base64Encode(d->strPassword);
+ QByteArray str = KCodecs::base64Encode( password );
// FIXME Stefan: see OpenDocument spec, ch. 17.3 Encryption
- xmlWriter.addAttribute("table:protection-key", QString(str));
+ xmlWriter.addAttribute("table:protection-key", QString(str.data()));
}
OdfSavingContext tableContext(savingContext);
@@ -493,10 +485,16 @@
mymap.setAttribute("yOffset", canvas->yOffset());
}
- if (!d->strPassword.isNull()) {
- QByteArray str = KCodecs::base64Encode(d->strPassword);
+ QByteArray password;
+ this->password(password);
+ if (!password.isNull()) {
+ if (password.size() > 0) {
+ QByteArray str = KCodecs::base64Encode(password);
mymap.setAttribute("protected", QString(str.data()));
+ } else {
+ mymap.setAttribute("protected", "");
}
+ }
foreach(Sheet* sheet, d->lstSheets) {
QDomElement e = sheet->saveXML(doc);
@@ -594,14 +592,8 @@
d->calculationSettings->loadOdf(body); // table::calculation-settings
if (body.hasAttributeNS(KoXmlNS::table, "structure-protected")) {
- if (body.hasAttributeNS(KoXmlNS::table, "protection-key")) {
- QString p = body.attributeNS(KoXmlNS::table, "protection-key", QString());
- if(!p.isNull()) {
- QByteArray str(p.toUtf8());
- d->strPassword = KCodecs::base64Decode(str);
+ loadOdfProtection(body);
}
- }
- }
KoXmlNode sheetNode = KoXml::namedItemNS(body, KoXmlNS::table, "table");
@@ -706,11 +698,7 @@
n = n.nextSibling();
}
- if (mymap.hasAttribute("protected")) {
- QString passwd = mymap.attribute("protected");
- QByteArray str(passwd.toUtf8());
- d->strPassword = KCodecs::base64Decode(str);
- }
+ loadXmlProtection(mymap);
if (!activeSheet.isEmpty()) {
// Used by View's constructor
@@ -812,21 +800,6 @@
return result;
}
-void Map::password(QByteArray & passwd) const
-{
- passwd = d->strPassword;
-}
-
-bool Map::isProtected() const
-{
- return !d->strPassword.isNull();
-}
-
-bool Map::checkPassword(QByteArray const & passwd) const
-{
- return (passwd == d->strPassword);
-}
-
Sheet* Map::sheet(int index) const
{
return d->lstSheets.value(index);
--- trunk/koffice/kspread/Map.h #1134830:1134831
@@ -25,6 +25,8 @@
#include <QString>
#include <QStringList>
+#include "ProtectableObject.h"
+
#include "kspread_export.h"
#include <KoDataCenterBase.h>
@@ -68,7 +70,7 @@
* The "embedded document".
* The Map holds all the document data.
*/
-class KSPREAD_EXPORT Map : public QObject, public KoDataCenterBase
+class KSPREAD_EXPORT Map : public QObject, public KoDataCenterBase, public ProtectableObject
{
Q_OBJECT
public:
@@ -225,11 +227,6 @@
bool loadChildren(KoStore* _store);
bool saveChildren(KoStore* _store);
- void password(QByteArray & passwd) const;
- bool isProtected() const;
- void setProtected(QByteArray const & passwd);
- bool checkPassword(QByteArray const & passwd) const;
-
/**
* The sheet named @p _from is being moved to the sheet @p _to.
* If @p _before is true @p _from is inserted before (after otherwise)
--- trunk/koffice/kspread/Sheet.cpp #1134830:1134831
@@ -132,9 +132,6 @@
// true if sheet is hidden
bool hide;
- // password of protected sheet
- QByteArray password;
-
bool showGrid;
bool showFormula;
bool showFormulaIndicator;
@@ -181,7 +178,7 @@
}
Sheet::Sheet(Map* map, const QString& sheetName)
- : KoShapeUserData()
+ : KoShapeUserData(map)
, KoShapeControllerBase()
, d(new Private)
{
@@ -244,8 +241,9 @@
}
Sheet::Sheet(const Sheet& other)
- : KoShapeUserData()
+ : KoShapeUserData(other.d->workbook)
, KoShapeControllerBase()
+ , ProtectableObject(other)
, d(new Private)
{
d->workbook = other.d->workbook;
@@ -271,7 +269,6 @@
d->layoutDirection = other.d->layoutDirection;
d->hide = other.d->hide;
- d->password = other.d->password;
d->showGrid = other.d->showGrid;
d->showFormula = other.d->showFormula;
d->showFormulaIndicator = other.d->showFormulaIndicator;
@@ -578,26 +575,6 @@
return d->cellStorage->valueStorage();
}
-void Sheet::password(QByteArray & passwd) const
-{
- passwd = d->password;
-}
-
-bool Sheet::isProtected() const
-{
- return !d->password.isNull();
-}
-
-void Sheet::setProtected(QByteArray const & passwd)
-{
- d->password = passwd;
-}
-
-bool Sheet::checkPassword(QByteArray const & passwd) const
-{
- return (passwd == d->password);
-}
-
SheetPrint* Sheet::print() const
{
return d->print;
@@ -2525,16 +2502,8 @@
}
if (sheetElement.attributeNS(KoXmlNS::table, "protected", QString()) == "true") {
- if (sheetElement.hasAttributeNS(KoXmlNS::table, "protection-key")) {
- QString p = sheetElement.attributeNS(KoXmlNS::table, "protection-key", QString());
- if(!p.isNull()) {
- QByteArray str(p.toUtf8());
- QByteArray passwd = KCodecs::base64Decode(str);
- kDebug(30518) << "Password password:" << str << "hash:" << passwd;
- setProtected(passwd);
+ loadOdfProtection(sheetElement);
}
- }
- }
return true;
}
@@ -3973,11 +3942,7 @@
convertObscuringBorders();
}
- if (sheet.hasAttribute("protected")) {
- QString passwd = sheet.attribute("protected");
- QByteArray str(passwd.toUtf8());
- setProtected(KCodecs::base64Decode(str));
- }
+ loadXmlProtection(sheet);
return true;
}
--- trunk/koffice/kspread/Sheet.h #1134830:1134831
@@ -38,6 +38,7 @@
#include "Cell.h"
#include "Style.h"
#include "Global.h"
+#include "ProtectableObject.h"
#include "kspread_export.h"
@@ -87,7 +88,8 @@
/**
* A sheet contains several cells.
*/
-class KSPREAD_EXPORT Sheet : public KoShapeUserData, public KoShapeControllerBase
+class KSPREAD_EXPORT Sheet : public KoShapeUserData, public KoShapeControllerBase,
+ public ProtectableObject
{
Q_OBJECT
Q_PROPERTY(QString sheetName READ sheetName)
@@ -407,34 +409,6 @@
//
//////////////////////////////////////////////////////////////////////////
//
- //BEGIN Methods related to protection
- //
-
- /**
- * \ingroup Protection
- */
- void password(QByteArray & passwd) const ;
-
- /**
- * \ingroup Protection
- */
- bool isProtected() const;
-
- /**
- * \ingroup Protection
- */
- void setProtected(QByteArray const & passwd);
-
- /**
- * \ingroup Protection
- */
- bool checkPassword(QByteArray const & passwd) const;
-
- //
- //END Methods related to protection
- //
- //////////////////////////////////////////////////////////////////////////
- //
//BEGIN Methods related to row formats
//
--- trunk/koffice/kspread/part/View.cpp #1134830:1134831
@@ -66,9 +66,7 @@
#include <KFontChooser>
#include <kinputdialog.h>
#include <kmessagebox.h>
-#include <knewpassworddialog.h>
#include <kpassivepopup.h>
-#include <kpassworddialog.h>
#include <kreplace.h>
#include <kreplacedialog.h>
#include <kstatusbar.h>
@@ -114,7 +112,6 @@
#include "CellView.h"
#include "Damages.h"
#include "DependencyManager.h"
-#include "Digest.h"
#include "Doc.h"
#include "Factory.h"
#include "LoadingInfo.h"
@@ -364,13 +361,13 @@
actions->protectSheet = new KToggleAction(i18n("Protect &Sheet..."), view);
ac->addAction("protectSheet", actions->protectSheet);
actions->protectSheet->setToolTip(i18n("Protect the sheet from being modified"));
- connect(actions->protectSheet, SIGNAL(toggled(bool)),
+ connect(actions->protectSheet, SIGNAL(triggered(bool)),
view, SLOT(toggleProtectSheet(bool)));
actions->protectDoc = new KToggleAction(i18n("Protect &Document..."), view);
ac->addAction("protectDoc", actions->protectDoc);
actions->protectDoc->setToolTip(i18n("Protect the document from being modified"));
- connect(actions->protectDoc, SIGNAL(toggled(bool)), view, SLOT(toggleProtectDoc(bool)));
+ connect(actions->protectDoc, SIGNAL(triggered(bool)), view, SLOT(toggleProtectDoc(bool)));
// -- misc actions --
@@ -1663,48 +1660,19 @@
if (!doc() || !doc()->map())
return;
+ bool success;
if (mode) {
- KNewPasswordDialog dlg(this);
- dlg.setPrompt(i18n("Enter a password."));
- dlg.setWindowTitle(i18n("Protect Document"));
- if (dlg.exec() != KPasswordDialog::Accepted) {
- d->actions->protectDoc->blockSignals(true);
- d->actions->protectDoc->setChecked(false);
- d->actions->protectDoc->blockSignals(false);
- return;
- }
-
- QByteArray hash("");
- QString password = dlg.password();
- if (password.length() > 0)
- SHA1::getHash(password, hash);
- doc()->map()->setProtected(hash);
+ success = doc()->map()->showPasswordDialog(this, ProtectableObject::Lock,
+ i18n("Protect Document"));
} else {
- KPasswordDialog dlg(this);
- dlg.setPrompt(i18n("Enter the password."));
- dlg.setWindowTitle(i18n("Unprotect Document"));
- if (dlg.exec() != KPasswordDialog::Accepted) {
- d->actions->protectDoc->blockSignals(true);
- d->actions->protectDoc->setChecked(true);
- d->actions->protectDoc->blockSignals(false);
- return;
+ success = doc()->map()->showPasswordDialog(this, ProtectableObject::Unlock,
+ i18n("Unprotect Document"));
}
-
- QByteArray hash("");
- QString password(dlg.password());
- if (password.length() > 0)
- SHA1::getHash(password, hash);
- if (!doc()->map()->checkPassword(hash)) {
- KMessageBox::error(0, i18n("Password is incorrect."));
- d->actions->protectDoc->blockSignals(true);
- d->actions->protectDoc->setChecked(true);
- d->actions->protectDoc->blockSignals(false);
+ if (!success) {
+ d->actions->protectDoc->setChecked(!mode);
return;
}
- doc()->map()->setProtected(QByteArray());
- }
-
doc()->setModified(true);
d->adjustWorkbookActions(!mode);
}
@@ -1714,51 +1682,19 @@
if (!d->activeSheet)
return;
+ bool success;
if (mode) {
- KNewPasswordDialog dlg(this);
- dlg.setPrompt(i18n("Enter a password."));
- dlg.setWindowTitle(i18n("Protect Sheet"));
- if (dlg.exec() != KPasswordDialog::Accepted) {
- d->actions->protectSheet->blockSignals(true);
- d->actions->protectSheet->setChecked(false);
- d->actions->protectSheet->blockSignals(false);
- return;
- }
-
- QByteArray hash("");
- QString password = dlg.password();
- if (password.length() > 0)
- SHA1::getHash(password, hash);
- d->activeSheet->setProtected(hash);
+ success = activeSheet()->showPasswordDialog(this, ProtectableObject::Lock,
+ i18n("Protect Sheet"));
} else {
- KPasswordDialog dlg(this);
- dlg.setPrompt(i18n("Enter the password."));
- dlg.setWindowTitle(i18n("Unprotect Sheet"));
- if (dlg.exec() != KPasswordDialog::Accepted) {
- d->actions->protectSheet->blockSignals(true);
- d->actions->protectSheet->setChecked(true);
- d->actions->protectSheet->blockSignals(false);
- return;
+ success = activeSheet()->showPasswordDialog(this, ProtectableObject::Unlock,
+ i18n("Unprotect Sheet"));
}
-
- QByteArray hash("");
- QString password(dlg.password());
- if (password.length() > 0)
- SHA1::getHash(password, hash);
-
-
- if (!d->activeSheet->checkPassword(hash)) {
- KMessageBox::error(0, i18n("Password is incorrect."));
- d->actions->protectSheet->blockSignals(true);
- d->actions->protectSheet->setChecked(true);
- d->actions->protectSheet->blockSignals(false);
+ if (!success) {
+ d->actions->protectSheet->setChecked(!mode);
return;
}
- d->activeSheet->setProtected(QByteArray());
-
- }
-
doc()->setModified(true);
d->adjustActions(!mode);
// d->activeSheet->setRegionPaintDirty( QRect(QPoint( 0, 0 ), QPoint( KS_colMax, KS_rowMax ) ) );
--- trunk/koffice/libs/flake/KoShapeUserData.cpp #1134830:1134831
@@ -19,7 +19,8 @@
#include "KoShapeUserData.h"
-KoShapeUserData::KoShapeUserData()
+KoShapeUserData::KoShapeUserData(QObject *parent)
+ : QObject(parent)
{
}
--- trunk/koffice/libs/flake/KoShapeUserData.h #1134830:1134831
@@ -47,7 +47,7 @@
Q_OBJECT
public:
/// Constructor
- KoShapeUserData();
+ KoShapeUserData(QObject *parent = 0);
virtual ~KoShapeUserData();
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic