KWallet

kwallet.cpp
1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2002-2004 George Staikos <staikos@kde.org>
5 SPDX-FileCopyrightText: 2008 Michael Leupold <lemma@confuego.org>
6 SPDX-FileCopyrightText: 2011 Valentin Rusu <kde@rusu.info>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#include "kwallet.h"
12#include "kwallet_api_debug.h"
13
14#include <QApplication>
15#include <QDBusConnection>
16#include <QRegularExpression>
17
18#include <KConfigGroup>
19#include <KSharedConfig>
20
21#include "kwallet_interface.h"
22
24Q_DECLARE_METATYPE(StringByteArrayMap)
25
26namespace KWallet
27{
28class KWalletDLauncher
29{
30public:
31 KWalletDLauncher();
32 ~KWalletDLauncher();
33 KWalletDLauncher(const KWalletDLauncher &) = delete;
34 KWalletDLauncher &operator=(const KWalletDLauncher &) = delete;
35 org::kde::KWallet &getInterface();
36
37 org::kde::KWallet *m_wallet_deamon;
38 KConfigGroup m_cgroup;
39 bool m_walletEnabled;
40};
41
42Q_GLOBAL_STATIC(KWalletDLauncher, walletLauncher)
43
44static QString appid()
45{
46 return qApp->applicationName();
47}
48
49static void registerTypes()
50{
51 static bool registered = false;
52 if (!registered) {
53 qDBusRegisterMetaType<StringByteArrayMap>();
54 registered = true;
55 }
56}
57
59{
60 KConfigGroup cfg(KSharedConfig::openConfig(QStringLiteral("kwalletrc"))->group(QStringLiteral("Wallet")));
61 if (!cfg.readEntry("Use One Wallet", true)) {
62 QString tmp = cfg.readEntry("Local Wallet", "localwallet");
63 if (tmp.isEmpty()) {
64 return QStringLiteral("localwallet");
65 }
66 return tmp;
67 }
68
69 QString tmp = cfg.readEntry("Default Wallet", "kdewallet");
70 if (tmp.isEmpty()) {
71 return QStringLiteral("kdewallet");
72 }
73 return tmp;
74}
75
77{
78 KConfigGroup cfg(KSharedConfig::openConfig(QStringLiteral("kwalletrc"))->group(QStringLiteral("Wallet")));
79
80 QString tmp = cfg.readEntry("Default Wallet", "kdewallet");
81 if (tmp.isEmpty()) {
82 return QStringLiteral("kdewallet");
83 }
84 return tmp;
85}
86
88{
89 return QStringLiteral("Passwords");
90}
91
93{
94 return QStringLiteral("Form Data");
95}
96
97class Q_DECL_HIDDEN Wallet::WalletPrivate
98{
99public:
100 WalletPrivate(Wallet *wallet, int h, const QString &n)
101 : q(wallet)
102 , name(n)
103 , handle(h)
104 {
105 }
106
107 void walletServiceUnregistered();
108
109 Wallet *q;
110 QString name;
111 QString folder;
112 int handle;
113 int transactionId;
114};
115
116static const char s_kwalletdServiceName[] = "org.kde.kwalletd6";
117
118Wallet::Wallet(int handle, const QString &name)
119 : QObject(nullptr)
120 , d(new WalletPrivate(this, handle, name))
121{
122 QDBusServiceWatcher *watcher =
124 connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this]() {
125 d->walletServiceUnregistered();
126 });
127
128 connect(&walletLauncher()->getInterface(), &org::kde::KWallet::walletClosedId, this, &KWallet::Wallet::slotWalletClosed);
129 connect(&walletLauncher()->getInterface(), &org::kde::KWallet::folderListUpdated, this, &KWallet::Wallet::slotFolderListUpdated);
130 connect(&walletLauncher()->getInterface(), &org::kde::KWallet::folderUpdated, this, &KWallet::Wallet::slotFolderUpdated);
131 connect(&walletLauncher()->getInterface(), &org::kde::KWallet::applicationDisconnected, this, &KWallet::Wallet::slotApplicationDisconnected);
132
133 // Verify that the wallet is still open
134 if (d->handle != -1) {
135 QDBusReply<bool> r = walletLauncher()->getInterface().isOpen(d->handle);
136 if (r.isValid() && !r) {
137 d->handle = -1;
138 d->name.clear();
139 }
140 }
141}
142
144{
145 if (d->handle != -1) {
146 if (!walletLauncher.isDestroyed()) {
147 walletLauncher()->getInterface().close(d->handle, false, appid());
148 } else {
149 qCDebug(KWALLET_API_LOG) << "Problem with static destruction sequence."
150 "Destroy any static Wallet before the event-loop exits.";
151 }
152 d->handle = -1;
153 d->folder.clear();
154 d->name.clear();
155 }
156 delete d;
157}
158
160{
161 QStringList result;
162 if (walletLauncher()->m_walletEnabled) {
163 QDBusReply<QStringList> r = walletLauncher()->getInterface().wallets();
164
165 if (!r.isValid()) {
166 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
167 } else {
168 result = r;
169 }
170 }
171 return result;
172}
173
174void Wallet::changePassword(const QString &name, WId w)
175{
176 if (w == 0) {
177 qCDebug(KWALLET_API_LOG) << "Pass a valid window to KWallet::Wallet::changePassword().";
178 }
179
180 if (walletLauncher()->m_walletEnabled) {
181 walletLauncher()->getInterface().changePassword(name, (qlonglong)w, appid());
182 }
183}
184
186{
187 return walletLauncher()->m_walletEnabled;
188}
189
190bool Wallet::isOpen(const QString &name)
191{
192 if (walletLauncher()->m_walletEnabled) {
193 QDBusReply<bool> r = walletLauncher()->getInterface().isOpen(name);
194
195 if (!r.isValid()) {
196 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
197 return false;
198 } else {
199 return r;
200 }
201 } else {
202 return false;
203 }
204}
205
206int Wallet::closeWallet(const QString &name, bool force)
207{
208 if (walletLauncher()->m_walletEnabled) {
209 QDBusReply<int> r = walletLauncher()->getInterface().close(name, force);
210
211 if (!r.isValid()) {
212 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
213 return -1;
214 } else {
215 return r;
216 }
217 } else {
218 return -1;
219 }
220}
221
223{
224 if (walletLauncher->m_walletEnabled) {
225 QDBusReply<int> r = walletLauncher()->getInterface().deleteWallet(name);
226
227 if (!r.isValid()) {
228 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
229 return -1;
230 } else {
231 return r;
232 }
233 } else {
234 return -1;
235 }
236}
237
238Wallet *Wallet::openWallet(const QString &name, WId w, OpenType ot)
239{
240 if (w == 0) {
241 qCDebug(KWALLET_API_LOG) << "Pass a valid window to KWallet::Wallet::openWallet().";
242 }
243
244 if (!walletLauncher()->m_walletEnabled) {
245 qCDebug(KWALLET_API_LOG) << "User disabled the wallet system so returning 0 here.";
246 return nullptr;
247 }
248
249 Wallet *wallet = new Wallet(-1, name);
250
251 // connect the daemon's opened signal to the slot filtering the
252 // signals we need
253 connect(&walletLauncher()->getInterface(), &org::kde::KWallet::walletAsyncOpened, wallet, &KWallet::Wallet::walletAsyncOpened);
254
255 org::kde::KWallet &interface = walletLauncher->getInterface();
256
257 // do the call
259 if (ot == Synchronous) {
260 interface.setTimeout(0x7FFFFFFF); // Don't timeout after 25s, but 24 days
261 r = interface.open(name, (qlonglong)w, appid());
262 interface.setTimeout(-1); // Back to the default 25s
263 // after this call, r would contain a transaction id >0 if OK or -1 if NOK
264 // if OK, the slot walletAsyncOpened should have been received, but the transaction id
265 // will not match. We'll get that handle from the reply - see below
266 } else if (ot == Asynchronous) {
267 r = interface.openAsync(name, (qlonglong)w, appid(), true);
268 } else if (ot == Path) {
269 r = interface.openPathAsync(name, (qlonglong)w, appid(), true);
270 } else {
271 delete wallet;
272 return nullptr;
273 }
274 // error communicating with the daemon (maybe not running)
275 if (!r.isValid()) {
276 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
277 delete wallet;
278 return nullptr;
279 }
280 wallet->d->transactionId = r.value();
281
282 if (ot == Synchronous || ot == Path) {
283 // check for an immediate error
284 if (wallet->d->transactionId < 0) {
285 delete wallet;
286 wallet = nullptr;
287 } else {
288 wallet->d->handle = r.value();
289 }
290 } else if (ot == Asynchronous) {
291 if (wallet->d->transactionId < 0) {
292 QTimer::singleShot(0, wallet, SLOT(emitWalletAsyncOpenError()));
293 // client code is responsible for deleting the wallet
294 }
295 }
296
297 return wallet;
298}
299
300void Wallet::slotCollectionStatusChanged(int status)
301{
302 Q_UNUSED(status)
303}
304
305void Wallet::slotCollectionDeleted()
306{
307 d->folder.clear();
308 d->name.clear();
310}
311
312bool Wallet::disconnectApplication(const QString &wallet, const QString &app)
313{
314 if (walletLauncher()->m_walletEnabled) {
315 QDBusReply<bool> r = walletLauncher()->getInterface().disconnectApplication(wallet, app);
316
317 if (!r.isValid()) {
318 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
319 return false;
320 } else {
321 return r;
322 }
323 } else {
324 return true;
325 }
326}
327
329{
330 if (walletLauncher()->m_walletEnabled) {
331 QDBusReply<QStringList> r = walletLauncher()->getInterface().users(name);
332 if (!r.isValid()) {
333 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
334 return QStringList();
335 } else {
336 return r;
337 }
338 } else {
339 return QStringList();
340 }
341}
342
344{
345 if (d->handle == -1) {
346 return -1;
347 }
348
349 walletLauncher()->getInterface().sync(d->handle, appid());
350 return 0;
351}
352
354{
355 if (d->handle == -1) {
356 return -1;
357 }
358
359 QDBusReply<int> r = walletLauncher()->getInterface().close(d->handle, true, appid());
360 d->handle = -1;
361 d->folder.clear();
362 d->name.clear();
363 if (r.isValid()) {
364 return r;
365 } else {
366 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
367 return -1;
368 }
369}
370
372{
373 return d->name;
374}
375
376bool Wallet::isOpen() const
377{
378 return d->handle != -1;
379}
380
382{
383 if (w == 0) {
384 qCDebug(KWALLET_API_LOG) << "Pass a valid window to KWallet::Wallet::requestChangePassword().";
385 }
386
387 if (d->handle == -1) {
388 return;
389 }
390
391 walletLauncher()->getInterface().changePassword(d->name, (qlonglong)w, appid());
392}
393
394void Wallet::slotWalletClosed(int handle)
395{
396 if (d->handle == handle) {
397 d->handle = -1;
398 d->folder.clear();
399 d->name.clear();
401 }
402}
403
405{
406 if (d->handle == -1) {
407 return QStringList();
408 }
409
410 QDBusReply<QStringList> r = walletLauncher()->getInterface().folderList(d->handle, appid());
411 if (!r.isValid()) {
412 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
413 return QStringList();
414 } else {
415 return r;
416 }
417}
418
420{
421 if (d->handle == -1) {
422 return QStringList();
423 }
424
425 QDBusReply<QStringList> r = walletLauncher()->getInterface().entryList(d->handle, d->folder, appid());
426 if (!r.isValid()) {
427 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
428 return QStringList();
429 } else {
430 return r;
431 }
432}
433
435{
436 if (d->handle == -1) {
437 return false;
438 }
439
440 QDBusReply<bool> r = walletLauncher()->getInterface().hasFolder(d->handle, f, appid());
441 if (!r.isValid()) {
442 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
443 return false;
444 } else {
445 return r;
446 }
447}
448
450{
451 if (d->handle == -1) {
452 return false;
453 }
454
455 if (!hasFolder(f)) {
456 QDBusReply<bool> r = walletLauncher()->getInterface().createFolder(d->handle, f, appid());
457
458 if (!r.isValid()) {
459 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
460 return false;
461 } else {
462 return r;
463 }
464 }
465
466 return true; // folder already exists
467}
468
470{
471 bool rc = false;
472
473 if (d->handle == -1) {
474 return rc;
475 }
476
477 // Don't do this - the folder could have disappeared?
478#if 0
479 if (f == d->folder) {
480 return true;
481 }
482#endif
483
484 if (hasFolder(f)) {
485 d->folder = f;
486 rc = true;
487 }
488
489 return rc;
490}
491
493{
494 if (d->handle == -1) {
495 return false;
496 }
497
498 QDBusReply<bool> r = walletLauncher()->getInterface().removeFolder(d->handle, f, appid());
499 if (d->folder == f) {
501 }
502
503 if (!r.isValid()) {
504 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
505 return false;
506 } else {
507 return r;
508 }
509}
510
512{
513 return d->folder;
514}
515
516int Wallet::readEntry(const QString &key, QByteArray &value)
517{
518 int rc = -1;
519
520 if (d->handle == -1) {
521 return rc;
522 }
523
524 QDBusReply<QByteArray> r = walletLauncher()->getInterface().readEntry(d->handle, d->folder, key, appid());
525 if (r.isValid()) {
526 value = r;
527 rc = 0;
528 }
529
530 return rc;
531}
532
534{
536
537 registerTypes();
538
539 if (d->handle == -1) {
540 if (ok) {
541 *ok = false;
542 }
543 return entries;
544 }
545
546 QDBusReply<QVariantMap> reply = walletLauncher()->getInterface().entriesList(d->handle, d->folder, appid());
547 if (reply.isValid()) {
548 if (ok) {
549 *ok = true;
550 }
551 // convert <QString, QVariant> to <QString, QByteArray>
552 const QVariantMap val = reply.value();
553 for (QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it) {
554 entries.insert(it.key(), it.value().toByteArray());
555 }
556 }
557
558 return entries;
559}
560
561int Wallet::renameEntry(const QString &oldName, const QString &newName)
562{
563 int rc = -1;
564
565 if (d->handle == -1) {
566 return rc;
567 }
568
569 QT_WARNING_PUSH
570 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
571 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
572 QDBusReply<int> r = walletLauncher()->getInterface().renameEntry(d->handle, d->folder, oldName, newName, appid());
573 QT_WARNING_POP
574 if (r.isValid()) {
575 rc = r;
576 }
577
578 return rc;
579}
580
582{
583 int rc = -1;
584
585 registerTypes();
586
587 if (d->handle == -1) {
588 return rc;
589 }
590
591 QDBusReply<QByteArray> r = walletLauncher()->getInterface().readMap(d->handle, d->folder, key, appid());
592 if (r.isValid()) {
593 rc = 0;
594 QByteArray v = r;
595 if (!v.isEmpty()) {
597 ds >> value;
598 }
599 }
600
601 return rc;
602}
603
605{
607
608 registerTypes();
609
610 if (d->handle == -1) {
611 if (ok) {
612 *ok = false;
613 }
614 return list;
615 }
616
617 QDBusReply<QVariantMap> reply = walletLauncher()->getInterface().mapList(d->handle, d->folder, appid());
618 if (reply.isValid()) {
619 if (ok) {
620 *ok = true;
621 }
622 const QVariantMap val = reply.value();
623 for (QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it) {
624 QByteArray mapData = it.value().toByteArray();
625 if (!mapData.isEmpty()) {
626 QDataStream ds(&mapData, QIODevice::ReadOnly);
628 ds >> v;
629 list.insert(it.key(), v);
630 }
631 }
632 }
633
634 return list;
635}
636
637int Wallet::readPassword(const QString &key, QString &value)
638{
639 int rc = -1;
640
641 if (d->handle == -1) {
642 return rc;
643 }
644
645 QDBusReply<QString> r = walletLauncher()->getInterface().readPassword(d->handle, d->folder, key, appid());
646 if (r.isValid()) {
647 value = r;
648 rc = 0;
649 }
650
651 return rc;
652}
653
655{
656 QMap<QString, QString> passList;
657
658 registerTypes();
659
660 if (d->handle == -1) {
661 if (ok) {
662 *ok = false;
663 }
664 return passList;
665 }
666
667 QDBusReply<QVariantMap> reply = walletLauncher()->getInterface().passwordList(d->handle, d->folder, appid());
668 if (reply.isValid()) {
669 if (ok) {
670 *ok = true;
671 }
672 const QVariantMap val = reply.value();
673 for (QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it) {
674 passList.insert(it.key(), it.value().toString());
675 }
676 }
677
678 return passList;
679}
680
681int Wallet::writeEntry(const QString &key, const QByteArray &value, EntryType entryType)
682{
683 int rc = -1;
684
685 if (d->handle == -1) {
686 return rc;
687 }
688
689 QDBusReply<int> r = walletLauncher()->getInterface().writeEntry(d->handle, d->folder, key, value, int(entryType), appid());
690 if (r.isValid()) {
691 rc = r;
692 }
693
694 return rc;
695}
696
697int Wallet::writeEntry(const QString &key, const QByteArray &value)
698{
699 int rc = -1;
700
701 if (d->handle == -1) {
702 return rc;
703 }
704
705 QDBusReply<int> r = walletLauncher()->getInterface().writeEntry(d->handle, d->folder, key, value, appid());
706 if (r.isValid()) {
707 rc = r;
708 }
709
710 return rc;
711}
712
714{
715 int rc = -1;
716
717 registerTypes();
718
719 if (d->handle == -1) {
720 return rc;
721 }
722
723 QByteArray mapData;
724 QDataStream ds(&mapData, QIODevice::WriteOnly);
725 ds << value;
726 QDBusReply<int> r = walletLauncher()->getInterface().writeMap(d->handle, d->folder, key, mapData, appid());
727 if (r.isValid()) {
728 rc = r;
729 }
730
731 return rc;
732}
733
734int Wallet::writePassword(const QString &key, const QString &value)
735{
736 int rc = -1;
737
738 if (d->handle == -1) {
739 return rc;
740 }
741
742 QDBusReply<int> r = walletLauncher()->getInterface().writePassword(d->handle, d->folder, key, value, appid());
743 if (r.isValid()) {
744 rc = r;
745 }
746
747 return rc;
748}
749
750bool Wallet::hasEntry(const QString &key)
751{
752 if (d->handle == -1) {
753 return false;
754 }
755
756 QDBusReply<bool> r = walletLauncher()->getInterface().hasEntry(d->handle, d->folder, key, appid());
757 if (!r.isValid()) {
758 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
759 return false;
760 } else {
761 return r;
762 }
763}
764
766{
767 int rc = -1;
768
769 if (d->handle == -1) {
770 return rc;
771 }
772
773 QDBusReply<int> r = walletLauncher()->getInterface().removeEntry(d->handle, d->folder, key, appid());
774 if (r.isValid()) {
775 rc = r;
776 }
777
778 return rc;
779}
780
781Wallet::EntryType Wallet::entryType(const QString &key)
782{
783 int rc = 0;
784
785 if (d->handle == -1) {
786 return Wallet::Unknown;
787 }
788
789 QDBusReply<int> r = walletLauncher()->getInterface().entryType(d->handle, d->folder, key, appid());
790 if (r.isValid()) {
791 rc = r;
792 }
793 return static_cast<EntryType>(rc);
794}
795
796void Wallet::WalletPrivate::walletServiceUnregistered()
797{
798 if (handle >= 0) {
799 q->slotWalletClosed(handle);
800 }
801}
802
803void Wallet::slotFolderUpdated(const QString &wallet, const QString &folder)
804{
805 if (d->name == wallet) {
806 Q_EMIT folderUpdated(folder);
807 }
808}
809
810void Wallet::slotFolderListUpdated(const QString &wallet)
811{
812 if (d->name == wallet) {
814 }
815}
816
817void Wallet::slotApplicationDisconnected(const QString &wallet, const QString &application)
818{
819 if (d->handle >= 0 && d->name == wallet && application == appid()) {
820 slotWalletClosed(d->handle);
821 }
822}
823
824void Wallet::walletAsyncOpened(int tId, int handle)
825{
826 // ignore responses to calls other than ours
827 if (d->transactionId != tId || d->handle != -1) {
828 return;
829 }
830
831 // disconnect the async signal
832 disconnect(this, SLOT(walletAsyncOpened(int, int)));
833
834 d->handle = handle;
835 Q_EMIT walletOpened(handle > 0);
836}
837
838void Wallet::emitWalletAsyncOpenError()
839{
840 Q_EMIT walletOpened(false);
841}
842
843void Wallet::emitWalletOpened()
844{
845 Q_EMIT walletOpened(true);
846}
847
848bool Wallet::folderDoesNotExist(const QString &wallet, const QString &folder)
849{
850 if (walletLauncher()->m_walletEnabled) {
851 QDBusReply<bool> r = walletLauncher()->getInterface().folderDoesNotExist(wallet, folder);
852 if (!r.isValid()) {
853 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
854 return false;
855 } else {
856 return r;
857 }
858 } else {
859 return false;
860 }
861}
862
863bool Wallet::keyDoesNotExist(const QString &wallet, const QString &folder, const QString &key)
864{
865 if (walletLauncher()->m_walletEnabled) {
866 QDBusReply<bool> r = walletLauncher()->getInterface().keyDoesNotExist(wallet, folder, key);
867 if (!r.isValid()) {
868 qCDebug(KWALLET_API_LOG) << "Invalid DBus reply: " << r.error();
869 return false;
870 } else {
871 return r;
872 }
873 } else {
874 return false;
875 }
876}
877
878void Wallet::virtual_hook(int, void *)
879{
880 // BASE::virtual_hook( id, data );
881}
882
883KWalletDLauncher::KWalletDLauncher()
884 : m_wallet_deamon(nullptr)
885 , m_cgroup(KSharedConfig::openConfig(QStringLiteral("kwalletrc"), KConfig::NoGlobals)->group(QStringLiteral("Wallet")))
886 , m_walletEnabled(false)
887{
888 m_walletEnabled = m_cgroup.readEntry("Enabled", true);
889 if (!m_walletEnabled) {
890 qCDebug(KWALLET_API_LOG) << "The wallet service was disabled by the user";
891 return;
892 }
893 m_wallet_deamon = new org::kde::KWallet(QString::fromLatin1(s_kwalletdServiceName), QStringLiteral("/modules/kwalletd6"), QDBusConnection::sessionBus());
894}
895
896KWalletDLauncher::~KWalletDLauncher()
897{
898 delete m_wallet_deamon;
899}
900
901org::kde::KWallet &KWalletDLauncher::getInterface()
902{
903 Q_ASSERT(m_wallet_deamon != nullptr);
904
905 // check if kwalletd is already running
907 if (!bus->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName))) {
908 // not running! check if it is enabled.
909 if (m_walletEnabled) {
910 // wallet is enabled! try launching it
911 QDBusReply<void> reply = bus->startService(QString::fromLatin1(s_kwalletdServiceName));
912 if (!reply.isValid()) {
913 qCritical() << "Couldn't start kwalletd: " << reply.error();
914 }
915
916 if (!bus->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName))) {
917 qCDebug(KWALLET_API_LOG) << "The kwalletd service is still not registered";
918 } else {
919 qCDebug(KWALLET_API_LOG) << "The kwalletd service has been registered";
920 }
921 } else {
922 qCritical() << "The kwalletd service has been disabled";
923 }
924 }
925
926 return *m_wallet_deamon;
927}
928
929} // namespace KWallet
930
931#include "moc_kwallet.cpp"
QString readEntry(const char *key, const char *aDefault=nullptr) const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
KDE Wallet.
Definition kwallet.h:48
static const QString PasswordFolder()
The standardized name of the password folder.
Definition kwallet.cpp:87
Wallet(int handle, const QString &name)
Construct a KWallet object.
Definition kwallet.cpp:118
virtual void virtual_hook(int id, void *data)
Definition kwallet.cpp:878
virtual int renameEntry(const QString &oldName, const QString &newName)
Rename the entry oldName to newName.
Definition kwallet.cpp:561
virtual int sync()
This syncs the wallet file on disk with what is in memory.
Definition kwallet.cpp:343
virtual bool createFolder(const QString &f)
Created the folder f.
Definition kwallet.cpp:449
virtual int lockWallet()
This closes and locks the current wallet.
Definition kwallet.cpp:353
static QStringList users(const QString &wallet)
List the applications that are using the wallet wallet.
Definition kwallet.cpp:328
virtual int removeEntry(const QString &key)
Remove the entry key from the current folder.
Definition kwallet.cpp:765
void folderUpdated(const QString &folder)
Emitted when a folder in this wallet is updated.
static int closeWallet(const QString &name, bool force)
Close the wallet name.
Definition kwallet.cpp:206
virtual bool hasEntry(const QString &key)
Determine if the current folder has they entry key.
Definition kwallet.cpp:750
QMap< QString, QByteArray > entriesList(bool *ok) const
Get a list of all the entries in the current folder.
Definition kwallet.cpp:533
virtual QStringList folderList()
Obtain the list of all folders contained in the wallet.
Definition kwallet.cpp:404
static QStringList walletList()
List all the wallets available.
Definition kwallet.cpp:159
virtual bool isOpen() const
Determine if the current wallet is open, and is a valid wallet handle.
Definition kwallet.cpp:376
static const QString NetworkWallet()
The name of the wallet used to store network passwords.
Definition kwallet.cpp:76
virtual const QString & currentFolder() const
Determine the current working folder in the wallet.
Definition kwallet.cpp:511
void walletClosed()
Emitted when this wallet is closed.
static int deleteWallet(const QString &name)
Delete the wallet name.
Definition kwallet.cpp:222
void folderListUpdated()
Emitted when the folder list is changed in this wallet.
virtual int writeEntry(const QString &key, const QByteArray &value, EntryType entryType)
Write key = value as a binary entry to the current folder.
Definition kwallet.cpp:681
virtual bool hasFolder(const QString &f)
Determine if the folder f exists in the wallet.
Definition kwallet.cpp:434
static void changePassword(const QString &name, WId w)
Request to the wallet service to change the password of the wallet name.
Definition kwallet.cpp:174
virtual int readEntry(const QString &key, QByteArray &value)
Read the entry key from the current folder.
Definition kwallet.cpp:516
QMap< QString, QMap< QString, QString > > mapList(bool *ok) const
Get a list of all the maps in the current folder.
Definition kwallet.cpp:604
virtual QStringList entryList()
Return the list of keys of all entries in this folder.
Definition kwallet.cpp:419
~Wallet() override
Destroy a KWallet object.
Definition kwallet.cpp:143
virtual int readMap(const QString &key, QMap< QString, QString > &value)
Read the map entry key from the current folder.
Definition kwallet.cpp:581
virtual void requestChangePassword(WId w)
Request to the wallet service to change the password of the current wallet.
Definition kwallet.cpp:381
static bool isEnabled()
Determine if the KDE wallet is enabled.
Definition kwallet.cpp:185
static bool disconnectApplication(const QString &wallet, const QString &app)
Disconnect the application app from wallet.
Definition kwallet.cpp:312
virtual bool removeFolder(const QString &f)
Remove the folder f and all its entries from the wallet.
Definition kwallet.cpp:492
static const QString LocalWallet()
The name of the wallet used to store local passwords.
Definition kwallet.cpp:58
static bool folderDoesNotExist(const QString &wallet, const QString &folder)
Determine if a folder does not exist in a wallet.
Definition kwallet.cpp:848
virtual EntryType entryType(const QString &key)
Determine the type of the entry key in this folder.
Definition kwallet.cpp:781
virtual int readPassword(const QString &key, QString &value)
Read the password entry key from the current folder.
Definition kwallet.cpp:637
static Wallet * openWallet(const QString &name, WId w, OpenType ot=Synchronous)
Open the wallet name.
Definition kwallet.cpp:238
virtual int writePassword(const QString &key, const QString &value)
Write key = value as a password to the current folder.
Definition kwallet.cpp:734
virtual const QString & walletName() const
The name of the current wallet.
Definition kwallet.cpp:371
virtual bool setFolder(const QString &f)
Set the current working folder to f.
Definition kwallet.cpp:469
QMap< QString, QString > passwordList(bool *ok) const
Get a list of all the passwords in the current folder, which can be used to populate a list view in a...
Definition kwallet.cpp:654
void walletOpened(bool success)
Emitted when a wallet is opened in asynchronous mode.
static bool keyDoesNotExist(const QString &wallet, const QString &folder, const QString &key)
Determine if an entry in a folder does not exist in a wallet.
Definition kwallet.cpp:863
static const QString FormDataFolder()
The standardized name of the form data folder.
Definition kwallet.cpp:92
virtual int writeMap(const QString &key, const QMap< QString, QString > &value)
Write key = value as a map to the current folder.
Definition kwallet.cpp:713
Q_SCRIPTABLE CaptureState status()
bool isEmpty() const const
QDBusConnectionInterface * interface() const const
QDBusConnection sessionBus()
QDBusReply< bool > isServiceRegistered(const QString &serviceName) const const
QDBusReply< void > startService(const QString &name)
const QDBusError & error()
bool isValid() const const
void serviceUnregistered(const QString &serviceName)
iterator insert(const_iterator before, parameter_type value)
iterator insert(const Key &key, const T &value)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
void clear()
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:48:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.