delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kwalletd / backend / kwalletbackend.h
blob99e29ae165fab1ec526d6de6e2aadc50a240a2c6
1 /* This file is part of the KDE project
3 * Copyright (C) 2001-2004 George Staikos <staikos@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef _KWALLETBACKEND_H
23 #define _KWALLETBACKEND_H
25 #include <kcodecs.h>
27 #include <QtCore/QString>
28 #include <QtCore/QStringList>
29 #include <QtCore/QMap>
30 #include "kwalletentry.h"
33 namespace KWallet {
35 /**
36 * @internal
38 class MD5Digest : public QByteArray {
39 public:
40 MD5Digest() : QByteArray(16, 0) {}
41 MD5Digest(const char *data) : QByteArray(data, 16) {}
42 MD5Digest(const KMD5::Digest d) : QByteArray(reinterpret_cast<const char *>(d), 16) {}
43 virtual ~MD5Digest() {}
45 int operator<(const MD5Digest& r) const {
46 int i = 0;
47 char x, y;
48 for (; i < 16; ++i) {
49 x = at(i);
50 y = r.at(i);
51 if (x != y) {
52 break;
55 if (i < 16 && x < y) {
56 return 1;
58 return 0;
63 /* @internal
65 class KDE_EXPORT Backend {
66 public:
67 explicit Backend(const QString& name = QLatin1String("kdewallet"), bool isPath = false);
68 ~Backend();
70 // Open and unlock the wallet.
71 // If opening succeeds, the password's hash will be remembered.
72 // If opening fails, the password's hash will be cleared.
73 int open(const QByteArray& password);
75 // Close the wallet, losing any changes.
76 // if save is true, the wallet is saved prior to closing it.
77 int close(bool save = false);
79 // Write the wallet to disk
80 int sync();
82 // Returns true if the current wallet is open.
83 bool isOpen() const;
85 // Returns the current wallet name.
86 const QString& walletName() const;
88 // The list of folders.
89 QStringList folderList() const;
91 // Force creation of a folder.
92 bool createFolder(const QString& f);
94 // Change the folder.
95 void setFolder(const QString& f) { _folder = f; }
97 // Current folder. If empty, it's the global folder.
98 const QString& folder() const { return _folder; }
100 // Does it have this folder?
101 bool hasFolder(const QString& f) const { return _entries.contains(f); }
103 // Look up an entry. Returns null if it doesn't exist.
104 Entry *readEntry(const QString& key);
106 // Look up a list of entries. Supports wildcards.
107 // You delete the list
108 QList<Entry*> readEntryList(const QString& key);
110 // Store an entry.
111 void writeEntry(Entry *e);
113 // Does this folder contain this entry?
114 bool hasEntry(const QString& key) const;
116 // Returns true if the entry was removed
117 bool removeEntry(const QString& key);
119 // Returns true if the folder was removed
120 bool removeFolder(const QString& f);
122 // The list of entries in this folder.
123 QStringList entryList() const;
125 // Rename an entry in this folder.
126 int renameEntry(const QString& oldName, const QString& newName);
128 // Set the password used for opening/closing the wallet.
129 // This does not sync the wallet to disk!
130 void setPassword(const QByteArray &password);
132 int ref() { return ++_ref; }
134 int deref();
136 int refCount() const { return _ref; }
138 static bool exists(const QString& wallet);
140 bool folderDoesNotExist(const QString& folder) const;
142 bool entryDoesNotExist(const QString& folder, const QString& entry) const;
144 static QString openRCToString(int rc);
146 private:
147 Q_DISABLE_COPY( Backend )
148 class BackendPrivate;
149 BackendPrivate *const d;
150 QString _name;
151 QString _path;
152 bool _open;
153 QString _folder;
154 int _ref;
155 // Map Folder->Entries
156 typedef QMap< QString, Entry* > EntryMap;
157 typedef QMap< QString, EntryMap > FolderMap;
158 FolderMap _entries;
159 typedef QMap<MD5Digest, QList<MD5Digest> > HashMap;
160 HashMap _hashes;
161 QByteArray _passhash; // password hash used for saving the wallet
166 #endif