1 | /* This file is part of the KDE project |
2 | Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef CALLIGRA_SHEETS_PROTECTABLE_OBJECT |
21 | #define CALLIGRA_SHEETS_PROTECTABLE_OBJECT |
22 | |
23 | #include <KoXmlReader.h> |
24 | |
25 | #include <QByteArray> |
26 | |
27 | #include "calligra_sheets_export.h" |
28 | |
29 | namespace Calligra |
30 | { |
31 | namespace Sheets |
32 | { |
33 | |
34 | /** |
35 | * \ingroup Protection |
36 | * Provides methods for setting a password protection. |
37 | * The inheriting object decides which of its data should be protected. |
38 | * It has to use isProtected() to check whether it's protected. |
39 | */ |
40 | class CALLIGRA_SHEETS_ODF_EXPORT ProtectableObject |
41 | { |
42 | public: |
43 | enum Mode { |
44 | Lock, |
45 | Unlock |
46 | }; |
47 | |
48 | /** |
49 | * Retrieves the \p password. |
50 | */ |
51 | void password(QByteArray &password) const; |
52 | |
53 | /** |
54 | * \return \c true on enabled protection; \c false on disabled protection |
55 | */ |
56 | bool isProtected() const; |
57 | |
58 | /** |
59 | * Sets this object to be protected by \p password. |
60 | */ |
61 | void setProtected(QByteArray const &password); |
62 | |
63 | /** |
64 | * Checks if \p password matches the password of this object. |
65 | */ |
66 | bool checkPassword(QByteArray const &password) const; |
67 | |
68 | /** |
69 | * Shows a dialog for entering the password. |
70 | * If the password is correct, the protection is enabled for |
71 | * \p mode being \c Lock, or it is disabled for \p mode being \c Unlock. |
72 | * \param title the window title |
73 | * \return \c true on success; \c false on failure |
74 | */ |
75 | bool showPasswordDialog(QWidget* parent, Mode mode, const QString& title); |
76 | |
77 | /** |
78 | * \ingroup NativeFormat |
79 | */ |
80 | void loadXmlProtection(const KoXmlElement& element); |
81 | |
82 | /** |
83 | * \ingroup OpenDocument |
84 | */ |
85 | void loadOdfProtection(const KoXmlElement& element); |
86 | |
87 | private: |
88 | // disable assignment operator |
89 | void operator=(const ProtectableObject&); |
90 | |
91 | QByteArray m_password; |
92 | }; |
93 | |
94 | } // namespace Sheets |
95 | } // namespace Calligra |
96 | |
97 | #endif // CALLIGRA_SHEETS_PROTECTABLE_OBJECT |
98 | |