28 class KTp::WalletInterfacePrivate :
public QObject
33 WalletInterfacePrivate();
34 void ensureWalletIsReady();
36 QScopedPointer<KWallet::Wallet> wallet;
37 static const QLatin1String folderName;
38 static const QLatin1String mapsPrefix;
43 void onWalletOpened(
bool success);
47 using KTp::WalletInterfacePrivate;
49 const QLatin1String WalletInterfacePrivate::folderName = QLatin1String(
"telepathy-kde");
50 const QLatin1String WalletInterfacePrivate::mapsPrefix = QLatin1String(
"maps/");
52 void WalletInterfacePrivate::ensureWalletIsReady()
56 if (!wallet || !wallet->isOpen()) {
60 wallet.reset(KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous));
61 connect(wallet.data(), SIGNAL(walletOpened(
bool)), SLOT(onWalletOpened(
bool)));
67 WalletInterfacePrivate::WalletInterfacePrivate() :
71 ensureWalletIsReady();
78 s_instance->d->ensureWalletIsReady();
82 void WalletInterfacePrivate::onWalletOpened(
bool success)
85 kWarning() <<
"Couldn't open wallet";
88 disconnect(wallet.data(), SIGNAL(walletOpened(
bool)),
this, SLOT(onWalletOpened(
bool)));
93 WalletInterface::WalletInterface():
94 d(new WalletInterfacePrivate)
98 WalletInterface::~WalletInterface()
105 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
109 d->wallet->setFolder(d->folderName);
110 return d->wallet->hasEntry(account->uniqueIdentifier());
115 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
119 d->wallet->setFolder(d->folderName);
121 if (d->wallet->hasEntry(account->uniqueIdentifier())) {
122 int rc = d->wallet->readPassword(account->uniqueIdentifier(),
password);
125 kWarning() <<
"failed to read password from KWallet";
133 if (d->wallet.isNull()) {
137 if (!d->wallet->hasFolder(d->folderName)) {
138 d->wallet->createFolder(d->folderName);
141 d->wallet->setFolder(d->folderName);
142 d->wallet->writePassword(account->uniqueIdentifier(),
password);
153 setEntry(account, QLatin1String(
"lastLoginFailed"), QLatin1String(
"true"));
155 if (
hasEntry(account, QLatin1String(
"lastLoginFailed"))) {
156 removeEntry(account, QLatin1String(
"lastLoginFailed"));
163 if (d->wallet.isNull()) {
166 return hasEntry(account, QLatin1String(
"lastLoginFailed"));
171 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
175 d->wallet->setFolder(d->folderName);
176 d->wallet->removeEntry(account->uniqueIdentifier());
182 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
186 d->wallet->setFolder(d->folderName);
187 QMap< QString, QString > map;
188 if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
189 int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
191 kWarning() <<
"failed to read map from KWallet (probably it is not a map)";
195 return map.contains(key);
200 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
204 d->wallet->setFolder(d->folderName);
206 QMap< QString, QString > map;
207 if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
208 int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
210 kWarning() <<
"failed to read map from KWallet (probably it is not a map)";
214 return map.value(key);
219 if (d->wallet.isNull()) {
223 if (! d->wallet->hasFolder(d->folderName)) {
224 d->wallet->createFolder(d->folderName);
227 d->wallet->setFolder(d->folderName);
228 QMap< QString, QString > map;
229 if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
230 int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
232 kWarning() <<
"failed to read map from KWallet (probably it is not a map)";
238 d->wallet->writeMap(d->mapsPrefix + account->uniqueIdentifier(), map);
245 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
249 d->wallet->setFolder(d->folderName);
250 QMap< QString, QString > map;
251 if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
252 int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
254 kWarning() <<
"failed to read map from KWallet (probably it is not a map)";
261 d->wallet->writeMap(d->mapsPrefix + account->uniqueIdentifier(), map);
263 d->wallet->removeEntry(d->mapsPrefix + account->uniqueIdentifier());
271 if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
275 d->wallet->setFolder(d->folderName);
276 d->wallet->removeEntry(d->mapsPrefix + account->uniqueIdentifier());
287 return (!d->wallet.isNull() && d->wallet->isOpen());
292 return d->wallet.data();
295 #include "wallet-interface.moc"