delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kwalletd / kwalletd.h
blobe001d3fda684220803097fa09e898c2d8f8960cf
1 // -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
2 /*
3 This file is part of the KDE libraries
5 Copyright (c) 2002-2004 George Staikos <staikos@kde.org>
6 Copyright (c) 2008 Michael Leupold <lemma@confuego.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 #ifndef _KWALLETD_H_
25 #define _KWALLETD_H_
27 #include <QtCore/QString>
28 #include <QtGui/QImage>
29 #include <QtCore/QHash>
30 #include "kwalletbackend.h"
31 #include <QtCore/QPointer>
32 #include <time.h>
33 #include <stdlib.h>
34 #include <QtDBus/QtDBus>
36 #include "ktimeout.h"
37 #include "kwalletsessionstore.h"
39 class KDirWatch;
40 class KTimeout;
42 // @Private
43 class KWalletTransaction;
44 class KWalletSyncTimer;
45 class KWalletSessionStore;
47 class KWalletD : public QObject, protected QDBusContext {
48 Q_OBJECT
50 public:
51 KWalletD();
52 virtual ~KWalletD();
54 public Q_SLOTS:
55 // Is the wallet enabled? If not, all open() calls fail.
56 bool isEnabled() const;
58 // Open and unlock the wallet
59 int open(const QString& wallet, qlonglong wId, const QString& appid);
61 // Open and unlock the wallet with this path
62 int openPath(const QString& path, qlonglong wId, const QString& appid);
64 // Open the wallet asynchronously
65 int openAsync(const QString& wallet, qlonglong wId, const QString& appid,
66 bool handleSession);
68 // Open and unlock the wallet with this path asynchronously
69 int openPathAsync(const QString& path, qlonglong wId, const QString& appid,
70 bool handleSession);
72 // Close and lock the wallet
73 // If force = true, will close it for all users. Behave. This
74 // can break applications, and is generally intended for use by
75 // the wallet manager app only.
76 int close(const QString& wallet, bool force);
77 int close(int handle, bool force, const QString& appid);
79 // Save to disk but leave open
80 Q_NOREPLY void sync(int handle, const QString& appid);
82 // Physically deletes the wallet from disk.
83 int deleteWallet(const QString& wallet);
85 // Returns true if the wallet is open
86 bool isOpen(const QString& wallet);
87 bool isOpen(int handle);
89 // List the users of this wallet
90 QStringList users(const QString& wallet) const;
92 // Change the password of this wallet
93 void changePassword(const QString& wallet, qlonglong wId, const QString& appid);
95 // A list of all wallets
96 QStringList wallets() const;
98 // A list of all folders in this wallet
99 QStringList folderList(int handle, const QString& appid);
101 // Does this wallet have this folder?
102 bool hasFolder(int handle, const QString& folder, const QString& appid);
104 // Create this folder
105 bool createFolder(int handle, const QString& folder, const QString& appid);
107 // Remove this folder
108 bool removeFolder(int handle, const QString& folder, const QString& appid);
110 // List of entries in this folder
111 QStringList entryList(int handle, const QString& folder, const QString& appid);
113 // Read an entry. If the entry does not exist, it just
114 // returns an empty result. It is your responsibility to check
115 // hasEntry() first.
116 QByteArray readEntry(int handle, const QString& folder, const QString& key, const QString& appid);
117 QByteArray readMap(int handle, const QString& folder, const QString& key, const QString& appid);
118 QString readPassword(int handle, const QString& folder, const QString& key, const QString& appid);
119 QVariantMap readEntryList(int handle, const QString& folder, const QString& key, const QString& appid);
120 QVariantMap readMapList(int handle, const QString& folder, const QString& key, const QString& appid);
121 QVariantMap readPasswordList(int handle, const QString& folder, const QString& key, const QString& appid);
123 // Rename an entry. rc=0 on success.
124 int renameEntry(int handle, const QString& folder, const QString& oldName, const QString& newName, const QString& appid);
126 // Write an entry. rc=0 on success.
127 int writeEntry(int handle, const QString& folder, const QString& key, const QByteArray& value, int entryType, const QString& appid);
128 int writeEntry(int handle, const QString& folder, const QString& key, const QByteArray& value, const QString& appid);
129 int writeMap(int handle, const QString& folder, const QString& key, const QByteArray& value, const QString& appid);
130 int writePassword(int handle, const QString& folder, const QString& key, const QString& value, const QString& appid);
132 // Does the entry exist?
133 bool hasEntry(int handle, const QString& folder, const QString& key, const QString& appid);
135 // What type is the entry?
136 int entryType(int handle, const QString& folder, const QString& key, const QString& appid);
138 // Remove an entry. rc=0 on success.
139 int removeEntry(int handle, const QString& folder, const QString& key, const QString& appid);
141 // Disconnect an app from a wallet
142 bool disconnectApplication(const QString& wallet, const QString& application);
144 void reconfigure();
146 // Determine
147 bool folderDoesNotExist(const QString& wallet, const QString& folder);
148 bool keyDoesNotExist(const QString& wallet, const QString& folder, const QString& key);
150 void closeAllWallets();
152 QString networkWallet();
154 QString localWallet();
156 void screenSaverChanged(bool);
158 Q_SIGNALS:
159 void walletAsyncOpened(int id, int handle); // used to notify KWallet::Wallet
160 void walletListDirty();
161 void walletCreated(const QString& wallet);
162 void walletOpened(const QString& wallet);
163 void walletDeleted(const QString& wallet);
164 void walletClosed(const QString& wallet);
165 void walletClosed(int handle);
166 void allWalletsClosed();
167 void folderListUpdated(const QString& wallet);
168 void folderUpdated(const QString&, const QString&);
169 void applicationDisconnected(const QString& wallet, const QString& application);
171 private Q_SLOTS:
172 void slotServiceOwnerChanged(const QString& name, const QString &oldOwner,
173 const QString &newOwner);
174 void emitWalletListDirty();
175 void timedOutClose(int handle);
176 void timedOutSync(int handle);
177 void notifyFailures();
178 void processTransactions();
180 private:
181 // Internal - open a wallet
182 int internalOpen(const QString& appid, const QString& wallet, bool isPath, WId w,
183 bool modal, const QString& service);
184 // Internal - close this wallet.
185 int internalClose(KWallet::Backend *w, int handle, bool force);
187 bool isAuthorizedApp(const QString& appid, const QString& wallet, WId w);
188 // This also validates the handle. May return NULL.
189 KWallet::Backend* getWallet(const QString& appid, int handle);
190 // Generate a new unique handle.
191 int generateHandle();
192 // Emit signals about closing wallets
193 void doCloseSignals(int,const QString&);
194 void emitFolderUpdated(const QString&, const QString&);
195 // Implicitly allow access for this application
196 bool implicitAllow(const QString& wallet, const QString& app);
197 bool implicitDeny(const QString& wallet, const QString& app);
199 void doTransactionChangePassword(const QString& appid, const QString& wallet, qlonglong wId);
200 void doTransactionOpenCancelled(const QString& appid, const QString& wallet,
201 const QString& service);
202 int doTransactionOpen(const QString& appid, const QString& wallet, bool isPath,
203 qlonglong wId, bool modal, const QString& service);
204 void initiateSync(int handle);
206 void setupDialog( QWidget* dialog, WId wId, const QString& appid, bool modal );
207 void checkActiveDialog();
209 QPair<int, KWallet::Backend*> findWallet(const QString& walletName) const;
211 typedef QHash<int, KWallet::Backend *> Wallets;
212 Wallets _wallets;
213 KDirWatch *_dw;
214 int _failed;
216 // configuration values
217 bool _leaveOpen, _closeIdle, _launchManager, _enabled;
218 bool _openPrompt, _firstUse, _showingFailureNotify;
219 int _idleTime;
220 QMap<QString,QStringList> _implicitAllowMap, _implicitDenyMap;
221 KTimeout _closeTimers;
222 KTimeout _syncTimers;
223 const int _syncTime;
225 KWalletTransaction *_curtrans; // current transaction
226 QList<KWalletTransaction*> _transactions;
227 QPointer< QWidget > activeDialog;
228 #ifdef Q_WS_X11
229 QDBusInterface *screensaver;
230 #endif
232 // sessions
233 KWalletSessionStore _sessions;
237 #endif