6#include "identitytreemodel.h"
7#include "kidentitymanagementcore_debug.h"
8#include <KLocalizedString>
13using namespace KIdentityManagementCore;
16 , mIdentityManager(manager)
18 connect(mIdentityManager, &IdentityManager::needToReloadIdentitySettings,
this, &IdentityTreeModel::reloadUoidList);
19 connect(mIdentityManager, &IdentityManager::identitiesWereChanged,
this, &IdentityTreeModel::reloadUoidList);
25void IdentityTreeModel::reloadUoidList()
28 mIdentitiesUoid.clear();
29 for (
const auto &identity : *mIdentityManager) {
30 mIdentitiesUoid << identity.uoid();
35IdentityTreeModel::~IdentityTreeModel() =
default;
37int IdentityTreeModel::columnCount(
const QModelIndex &parent)
const
40 constexpr int nbCol =
static_cast<int>(IdentityRoles::LastColumn) + 1;
44QVariant IdentityTreeModel::data(
const QModelIndex &index,
int role)
const
46 if (!
index.isValid()) {
50 const auto &identity = mIdentityManager->modifyIdentityForUoid(mIdentitiesUoid[
index.row()]);
52 return identity.primaryEmailAddress();
55 if (
static_cast<IdentityRoles
>(
index.column()) == DisplayIdentityNameRole) {
56 if (identity.isDefault()) {
66 switch (
static_cast<IdentityRoles
>(
index.column())) {
68 return identity.fullEmailAddr();
70 return identity.primaryEmailAddress();
72 return identity.uoid();
73 case IdentityNameRole:
74 return identity.identityName();
75 case DisplayIdentityNameRole:
76 return generateIdentityName(identity);
78 return identity.isDefault();
80 return identity.activities();
81 case EnabledActivitiesRole:
82 return identity.enabledActivities();
88QString IdentityTreeModel::generateIdentityName(
const Identity &identity)
const
90 QString str = identity.identityName();
91 if (mShowDefault && identity.
isDefault()) {
92 str += QLatin1Char(
' ') +
i18nc(
"Default identity",
" (default)");
97KIdentityManagementCore::IdentityManager *IdentityTreeModel::identityManager()
const
99 return mIdentityManager;
102int IdentityTreeModel::rowCount(
const QModelIndex &parent)
const
105 return mIdentitiesUoid.
count();
108void IdentityTreeModel::setShowDefault(
bool show)
113uint IdentityTreeModel::identityUoid(
int index)
const
115 return mIdentitiesUoid.at(
index);
118int IdentityTreeModel::uoidIndex(
int uoid)
const
120 return mIdentitiesUoid.indexOf(uoid);
123QVariant IdentityTreeModel::headerData(
int section,
Qt::Orientation orientation,
int role)
const
126 switch (
static_cast<IdentityRoles
>(section)) {
127 case DisplayIdentityNameRole:
128 return i18n(
"Identity Name");
131 return i18n(
"Email Address");
134 case IdentityNameRole:
136 case EnabledActivitiesRole:
143Qt::ItemFlags IdentityTreeModel::flags(
const QModelIndex &index)
const
145 if (!
index.isValid())
148 if (
static_cast<IdentityRoles
>(
index.column()) == DisplayIdentityNameRole) {
154bool IdentityTreeModel::setData(
const QModelIndex &modelIndex,
const QVariant &value,
int role)
157 qCWarning(KIDENTITYMANAGEMENT_LOG) <<
"ERROR: invalid index";
163 const int idx = modelIndex.
row();
164 auto &identity = mIdentityManager->modifyIdentityForUoid(mIdentitiesUoid[idx]);
165 switch (
static_cast<IdentityRoles
>(modelIndex.
column())) {
166 case IdentityNameRole: {
167 const QModelIndex newIndex =
index(modelIndex.
row(), IdentityNameRole);
170 mIdentityManager->saveIdentity(identity);
174 const QModelIndex newIndex =
index(modelIndex.
row(), UoidRole);
175 mIdentityManager->setAsDefault(newIndex.
data().
toInt());
185void IdentityTreeModel::removeIdentities(
const QStringList &identitiesName)
187 for (
const QString &name : identitiesName) {
188 mIdentityManager->removeIdentity(name);
192#include "moc_identitytreemodel.cpp"
Manages the list of identities.
void added(const KIdentityManagementCore::Identity &ident)
Emitted on commit() for each new identity.
void deleted(uint uoid)
Emitted on commit() for each deleted identity.
User identity information.
void setIdentityName(const QString &name)
Identity/nickname for this collection.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual Qt::ItemFlags flags(const QModelIndex &index) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual QModelIndex parent(const QModelIndex &index) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void setBold(bool enable)
QVariant data(int role) const const
bool isValid() const const
qsizetype count() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
int toInt(bool *ok) const const
QString toString() const const