File indexing completed on 2024-04-28 16:21:26
0001 /* This file is part of the KDE project 0002 Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef CALLIGRA_SHEETS_PROTECTABLE_OBJECT 0021 #define CALLIGRA_SHEETS_PROTECTABLE_OBJECT 0022 0023 #include <KoXmlReader.h> 0024 0025 #include <QByteArray> 0026 0027 #include "sheets_odf_export.h" 0028 0029 namespace Calligra 0030 { 0031 namespace Sheets 0032 { 0033 0034 /** 0035 * \ingroup Protection 0036 * Provides methods for setting a password protection. 0037 * The inheriting object decides which of its data should be protected. 0038 * It has to use isProtected() to check whether it's protected. 0039 */ 0040 class CALLIGRA_SHEETS_ODF_EXPORT ProtectableObject 0041 { 0042 public: 0043 enum Mode { 0044 Lock, 0045 Unlock 0046 }; 0047 0048 /** 0049 * Retrieves the \p password. 0050 */ 0051 void password(QByteArray &password) const; 0052 0053 /** 0054 * \return \c true on enabled protection; \c false on disabled protection 0055 */ 0056 bool isProtected() const; 0057 0058 /** 0059 * Sets this object to be protected by \p password. 0060 */ 0061 void setProtected(QByteArray const &password); 0062 0063 /** 0064 * Checks if \p password matches the password of this object. 0065 */ 0066 bool checkPassword(QByteArray const &password) const; 0067 0068 /** 0069 * Shows a dialog for entering the password. 0070 * If the password is correct, the protection is enabled for 0071 * \p mode being \c Lock, or it is disabled for \p mode being \c Unlock. 0072 * \param parent the parent Qwidget 0073 * \param mode the mode 0074 * \param title the window title 0075 * \return \c true on success; \c false on failure 0076 */ 0077 bool showPasswordDialog(QWidget* parent, Mode mode, const QString& title); 0078 0079 /** 0080 * \ingroup NativeFormat 0081 */ 0082 void loadXmlProtection(const KoXmlElement& element); 0083 0084 private: 0085 // disable assignment operator 0086 void operator=(const ProtectableObject&); 0087 0088 QByteArray m_password; 0089 }; 0090 0091 } // namespace Sheets 0092 } // namespace Calligra 0093 0094 #endif // CALLIGRA_SHEETS_PROTECTABLE_OBJECT