File indexing completed on 2024-05-19 05:55:46
0001 /* 0002 SPDX-FileCopyrightText: 2013 Valentin Rusu <kde@rusu.info> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "connectedappmodel.h" 0008 #include "kwalletmanager_debug.h" 0009 0010 #include <KWallet> 0011 0012 0013 ConnectedAppModel::ConnectedAppModel(KWallet::Wallet *wallet): 0014 QStandardItemModel(), 0015 _wallet(wallet) 0016 { 0017 refresh(); 0018 } 0019 0020 void ConnectedAppModel::refresh() 0021 { 0022 clear(); 0023 _connectedAppsIndexMap.clear(); 0024 0025 _connectedApps = KWallet::Wallet::users(_wallet->walletName()); 0026 int row = 0; 0027 for (const QString &appName : std::as_const(_connectedApps)) { 0028 // for un unknown reason, kwalletd returs empty strings so lets avoid inserting them 0029 // FIXME: find out why kwalletd returns empty strings here 0030 if (!appName.isEmpty()) { 0031 auto item = new QStandardItem(appName); 0032 item->setEditable(false); 0033 setItem(row, 0, item); 0034 // this item will be hidden by the disconnect button, see below setIndexWidget call 0035 setItem(row, 1, new QStandardItem(QStringLiteral("dummy"))); 0036 _connectedAppsIndexMap.insert(appName, QPersistentModelIndex(index(row, 0))); 0037 row++; 0038 } 0039 } 0040 } 0041 0042 void ConnectedAppModel::removeApp(const QString &appName) 0043 { 0044 if (_connectedAppsIndexMap.contains(appName)) { 0045 QPersistentModelIndex idx = _connectedAppsIndexMap[appName]; 0046 if (idx.isValid()) { 0047 if (!removeRow(idx.row())) { 0048 qCDebug(KWALLETMANAGER_LOG) << "Remove row failed for app " << appName; 0049 } 0050 } 0051 } else { 0052 qCDebug(KWALLETMANAGER_LOG) << "Attempting to remove unknown application " << appName; 0053 } 0054 } 0055 0056 #include "moc_connectedappmodel.cpp"