[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [libkpeople/mklapetek/toplevel_contacts] src: Coding style++ (following kdelibs coding style)
From: Martin Klapetek <martin.klapetek () gmail ! com>
Date: 2012-11-16 12:48:52
Message-ID: 20121116124852.227DBA60D2 () git ! kde ! org
[Download RAW message or body]
Git commit cbb6398fa2d58c6b1eb20c2faccc5f8a50fccd70 by Martin Klapetek.
Committed on 16/11/2012 at 13:44.
Pushed by mklapetek into branch 'mklapetek/toplevel_contacts'.
Coding style++ (following kdelibs coding style)
M +19 -17 src/duplicatesfinder.cpp
M +4 -4 src/duplicatesfinder.h
M +8 -7 src/match.cpp
M +2 -2 src/match.h
M +12 -10 src/matchessolver.cpp
M +5 -6 src/matchessolver.h
M +14 -14 src/nepomuk-tp-channel-delegate.cpp
M +2 -2 src/nepomuk-tp-channel-delegate.h
M +23 -19 src/personactions.cpp
M +9 -9 src/personactions.h
M +12 -9 src/persondata.cpp
M +3 -3 src/persondata.h
M +16 -10 src/persons-model-contact-item.cpp
M +7 -7 src/persons-model-contact-item.h
M +21 -18 src/persons-model-item.cpp
M +4 -4 src/persons-model-item.h
M +35 -30 src/persons-model.cpp
M +10 -10 src/persons-model.h
http://commits.kde.org/libkpeople/cbb6398fa2d58c6b1eb20c2faccc5f8a50fccd70
diff --git a/src/duplicatesfinder.cpp b/src/duplicatesfinder.cpp
index cb9f682..f26386a 100644
--- a/src/duplicatesfinder.cpp
+++ b/src/duplicatesfinder.cpp
@@ -21,7 +21,7 @@
#include "persons-model.h"
#include <QDebug>
-DuplicatesFinder::DuplicatesFinder(PersonsModel* model, QObject* parent)
+DuplicatesFinder::DuplicatesFinder(PersonsModel *model, QObject *parent)
: KJob(parent)
, m_model(model)
{
@@ -43,22 +43,23 @@ void DuplicatesFinder::doSearch()
m_matches.clear();
int count = m_model->rowCount();
- for(int i=0; i<count; i++) {
+ for (int i=0; i < count; i++) {
QModelIndex idx = m_model->index(i, 0);
//we gather the values
QVariantList values;
- for(int role=0; role<m_compareRoles.size(); role++) {
+ for (int role = 0; role < m_compareRoles.size(); role++) {
values += idx.data(m_compareRoles[role]);
}
- Q_ASSERT(values.size()==m_compareRoles.size());
+ Q_ASSERT(values.size() == m_compareRoles.size());
//we check if it matches
- int j=0;
- foreach(const QVariantList& valueToCompare, collectedValues) {
+ int j = 0;
+ foreach (const QVariantList &valueToCompare, collectedValues) {
QList< int > matchedRoles = matchAt(values, valueToCompare);
- if(!matchedRoles.isEmpty())
+ if (!matchedRoles.isEmpty()) {
m_matches.append(Match(matchedRoles, i, j));
+ }
j++;
}
@@ -68,24 +69,25 @@ void DuplicatesFinder::doSearch()
emitResult();
}
-QList<int> DuplicatesFinder::matchAt(const QVariantList& value, const QVariantList& \
toCompare) const +QList<int> DuplicatesFinder::matchAt(const QVariantList &value, \
const QVariantList &toCompare) const {
QList<int> ret;
- Q_ASSERT(value.size()==toCompare.size());
- for(int i=0; i<toCompare.size(); i++) {
- const QVariant& v = value[i];
- if(v.type()==QVariant::List) {
+ Q_ASSERT(value.size() == toCompare.size());
+ for (int i = 0; i<toCompare.size(); i++) {
+ const QVariant &v = value[i];
+ if (v.type() == QVariant::List) {
QList<QVariant> listA = v.toList(), listB=toCompare[i].toList();
- if(!listA.isEmpty())
- foreach(const QVariant& v, listB) {
- if(listA.contains(v)) {
+ if (!listA.isEmpty()) {
+ foreach (const QVariant &v, listB) {
+ if (listA.contains(v)) {
Q_ASSERT(!ret.contains(m_compareRoles[i]) && "B");
ret += m_compareRoles[i];
break;
}
}
- } else if(!v.isNull() && v==toCompare[i]
- && (v.type()!=QVariant::String || !v.toString().isEmpty()))
+ }
+ } else if (!v.isNull() && v == toCompare[i]
+ && (v.type() != QVariant::String || !v.toString().isEmpty()))
{
Q_ASSERT(!ret.contains(m_compareRoles[i]) && "A");
ret += m_compareRoles[i];
diff --git a/src/duplicatesfinder.h b/src/duplicatesfinder.h
index 099cc74..e722af3 100644
--- a/src/duplicatesfinder.h
+++ b/src/duplicatesfinder.h
@@ -31,8 +31,8 @@ class KPEOPLE_EXPORT DuplicatesFinder : public KJob
{
Q_OBJECT
public:
- explicit DuplicatesFinder(PersonsModel* model, QObject* parent = 0);
-
+ explicit DuplicatesFinder(PersonsModel *model, QObject *parent = 0);
+
virtual void start();
QList<Match> results() const;
@@ -40,8 +40,8 @@ class KPEOPLE_EXPORT DuplicatesFinder : public KJob
void doSearch();
private:
- QList< int > matchAt(const QVariantList& value, const QVariantList& \
toCompare) const;
- PersonsModel* m_model;
+ QList< int > matchAt(const QVariantList &value, const QVariantList \
&toCompare) const; + PersonsModel *m_model;
QList<Match> m_matches;
QVector<int> m_compareRoles;
};
diff --git a/src/match.cpp b/src/match.cpp
index 4f23d40..cda232a 100644
--- a/src/match.cpp
+++ b/src/match.cpp
@@ -19,18 +19,19 @@
#include "match.h"
-Match::Match(const QList< int >& r, int a, int b)
+Match::Match(const QList< int > &r, int a, int b)
: role(r), rowA(a), rowB(b)
{}
-bool Match::operator==(const Match& m) const
+bool Match::operator==(const Match &m) const
{
- return role==m.role
- && rowA==m.rowA
- && rowB==m.rowB;
+ return role == m.role
+ && rowA == m.rowA
+ && rowB == m.rowB;
}
-bool Match::operator<(const Match& m) const
+bool Match::operator<(const Match &m) const
{
- return rowA<m.rowA || (rowA==m.rowA && rowB<m.rowB);
+ return rowA < m.rowA
+ || (rowA == m.rowA && rowB < m.rowB);
}
diff --git a/src/match.h b/src/match.h
index ac8861d..5e2c80f 100644
--- a/src/match.h
+++ b/src/match.h
@@ -25,8 +25,8 @@
struct Match
{
Match(const QList<int>& r, int a, int b);
- bool operator==(const Match& m) const;
- bool operator<(const Match& m) const;
+ bool operator==(const Match &m) const;
+ bool operator<(const Match &m) const;
QList<int> role;
int rowA, rowB;
diff --git a/src/matchessolver.cpp b/src/matchessolver.cpp
index ac32ab9..abb65b2 100644
--- a/src/matchessolver.cpp
+++ b/src/matchessolver.cpp
@@ -23,11 +23,12 @@
#include <nepomuk2/datamanagement.h>
#include <QUrl>
-MatchesSolver::MatchesSolver(const QList<Match>& matches, PersonsModel* model, \
QObject* parent) +MatchesSolver::MatchesSolver(const QList<Match> &matches, \
PersonsModel *model, QObject *parent) : KJob(parent)
, m_matches(matches)
, m_model(model)
-{}
+{
+}
void MatchesSolver::start()
{
@@ -36,33 +37,34 @@ void MatchesSolver::start()
void MatchesSolver::startMatching()
{
- foreach(const Match& m, m_matches) {
+ foreach(const Match &m, m_matches) {
QModelIndex idxDestination = m_model->index(m.rowA, 0);
QModelIndex idxOrigin = m_model->index(m.rowB, 0);
-
+
QList<QUrl> persons;
persons << idxDestination.data(PersonsModel::UriRole).toUrl();
persons << idxOrigin.data(PersonsModel::UriRole).toUrl();
-
- KJob* job = Nepomuk2::mergeResources( persons );
+
+ KJob *job = Nepomuk2::mergeResources(persons);
connect(job, SIGNAL(finished(KJob*)), SLOT(jobDone(KJob*)));
}
jobDone(0);
}
-QList<QUrl> MatchesSolver::contactUris(const QModelIndex& idxOrigin)
+QList<QUrl> MatchesSolver::contactUris(const QModelIndex &idxOrigin)
{
QList<QUrl> ret;
QModelIndex idx=idxOrigin.child(0,0);
- for(; idx.isValid(); idx=idx.sibling(idx.row()+1, 0)) {
+ for (; idx.isValid(); idx = idx.sibling(idx.row() + 1, 0)) {
ret += idx.data(PersonsModel::UriRole).toUrl();
}
return ret;
}
-void MatchesSolver::jobDone(KJob* job)
+void MatchesSolver::jobDone(KJob *job)
{
m_pending.remove(job);
- if(m_pending.isEmpty())
+ if (m_pending.isEmpty()) {
emitResult();
+ }
}
diff --git a/src/matchessolver.h b/src/matchessolver.h
index 93ea66b..d7e5c04 100644
--- a/src/matchessolver.h
+++ b/src/matchessolver.h
@@ -1,5 +1,4 @@
/*
- Persons Model
Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
This library is free software; you can redistribute it and/or
@@ -33,19 +32,19 @@ class KPEOPLE_EXPORT MatchesSolver : public KJob
{
Q_OBJECT
public:
- explicit MatchesSolver(const QList<Match>& matches, PersonsModel* model, \
QObject* parent = 0); + explicit MatchesSolver(const QList<Match> &matches, \
PersonsModel *model, QObject *parent = 0); virtual void start();
public slots:
void startMatching();
- void jobDone(KJob* job=0);
+ void jobDone(KJob *job=0);
private:
- QList<QUrl> contactUris(const QModelIndex& idxOrigin);
-
+ QList<QUrl> contactUris(const QModelIndex &idxOrigin);
+
QList<Match> m_matches;
QSet<KJob*> m_pending;
- PersonsModel* m_model;
+ PersonsModel *m_model;
};
#endif // MATCHESSOLVER_H
diff --git a/src/nepomuk-tp-channel-delegate.cpp \
b/src/nepomuk-tp-channel-delegate.cpp index 57dc0cc..0a22276 100644
--- a/src/nepomuk-tp-channel-delegate.cpp
+++ b/src/nepomuk-tp-channel-delegate.cpp
@@ -35,7 +35,7 @@ public:
Tp::AccountPtr account;
};
-NepomukTpChannelDelegate::NepomukTpChannelDelegate(QObject* parent)
+NepomukTpChannelDelegate::NepomukTpChannelDelegate(QObject *parent)
: QObject(parent),
d_ptr(new NepomukTpChannelDelegatePrivate)
{
@@ -45,27 +45,27 @@ NepomukTpChannelDelegate::NepomukTpChannelDelegate(QObject* \
parent) // Start setting up the Telepathy AccountManager.
Tp::AccountFactoryPtr accountFactory = \
Tp::AccountFactory::create(QDBusConnection::sessionBus(),
\
Tp::Features() << Tp::Account::FeatureCore
- << \
Tp::Account::FeatureAvatar
- << \
Tp::Account::FeatureCapabilities
- << \
Tp::Account::FeatureProtocolInfo
- << \
Tp::Account::FeatureProfile); + \
<< Tp::Account::FeatureAvatar + \
<< Tp::Account::FeatureCapabilities + \
<< Tp::Account::FeatureProtocolInfo + \
<< Tp::Account::FeatureProfile);
Tp::ConnectionFactoryPtr connectionFactory = \
Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
\
Tp::Features() << Tp::Connection::FeatureCore
- << \
Tp::Connection::FeatureSelfContact); + \
<< Tp::Connection::FeatureSelfContact);
Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(Tp::Features() \
<< Tp::Contact::FeatureAlias
- << Tp::Contact::FeatureAvatarData
- << Tp::Contact::FeatureSimplePresence
- << Tp::Contact::FeatureCapabilities);
+ \
<< Tp::Contact::FeatureAvatarData + \
<< Tp::Contact::FeatureSimplePresence + \
<< Tp::Contact::FeatureCapabilities);
Tp::ChannelFactoryPtr channelFactory = \
Tp::ChannelFactory::create(QDBusConnection::sessionBus());
d->accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
- accountFactory,
- connectionFactory,
- channelFactory,
- contactFactory);
+ accountFactory,
+ connectionFactory,
+ channelFactory,
+ contactFactory);
connect(d->accountManager->becomeReady(), \
SIGNAL(finished(Tp::PendingOperation*)), this, \
SLOT(onAccountManagerReady(Tp::PendingOperation*))); @@ -81,7 +81,7 @@ void \
NepomukTpChannelDelegate::onAccountManagerReady(Tp::PendingOperation*) kDebug() << \
"Account manager ready"; }
-void NepomukTpChannelDelegate::startIM(const QString& accountId, const QString& \
contactId, const QUrl& capability) +void NepomukTpChannelDelegate::startIM(const \
QString &accountId, const QString &contactId, const QUrl &capability) {
Q_D(NepomukTpChannelDelegate);
if (!d->accountManager->isReady()) {
diff --git a/src/nepomuk-tp-channel-delegate.h b/src/nepomuk-tp-channel-delegate.h
index e0d92a8..d7601db 100644
--- a/src/nepomuk-tp-channel-delegate.h
+++ b/src/nepomuk-tp-channel-delegate.h
@@ -39,10 +39,10 @@ class KPEOPLE_EXPORT NepomukTpChannelDelegate : public QObject
{
Q_OBJECT
public:
- explicit NepomukTpChannelDelegate(QObject* parent = 0);
+ explicit NepomukTpChannelDelegate(QObject *parent = 0);
~NepomukTpChannelDelegate();
- void startIM(const QString& accountId, const QString& contactId, const QUrl& \
capability); + void startIM(const QString &accountId, const QString &contactId, \
const QUrl &capability);
private Q_SLOTS:
void onAccountManagerReady(Tp::PendingOperation *op);
diff --git a/src/personactions.cpp b/src/personactions.cpp
index 9e7ca5c..2ca9c4a 100644
--- a/src/personactions.cpp
+++ b/src/personactions.cpp
@@ -49,15 +49,15 @@ struct PersonActionsPrivate {
QList<QAction*> actions;
PersonData *person;
- QAction* createEmailAction(PersonActions* pactions, const QIcon& icon, const \
QString& name, const QString& email) + QAction* createEmailAction(PersonActions \
*pactions, const QIcon &icon, const QString &name, const QString &email) {
- QAction* action = new QAction(icon, i18n("Send e-mail to '%1'", name), \
pactions); + QAction *action = new QAction(icon, i18n("Send e-mail to '%1'", \
name), pactions); action->setProperty("email", email);
QObject::connect(action, SIGNAL(triggered(bool)), pactions, \
SLOT(emailTriggered())); return action;
}
- QList<QAction*> createIMActions(PersonActions* pactions, const QUrl& contactUri, \
const QString& imrole, const QString& nickname) + QList<QAction*> \
createIMActions(PersonActions* pactions, const QUrl &contactUri, const QString \
&imrole, const QString &nickname) {
Q_ASSERT(!contactUri.isEmpty());
QList<QAction*> actions;
@@ -67,7 +67,7 @@ struct PersonActionsPrivate {
" }").arg( Soprano::Node::resourceToN3(contactUri) );
Soprano::Model* m = Nepomuk2::ResourceManager::instance()->mainModel();
Soprano::QueryResultIterator it = m->executeQuery(query, \
Soprano::Query::QueryLanguageSparql);
- while(it.next()) {
+ while (it.next()) {
QString ss = it["cap"].toString();
QAction *action = new QAction(pactions);
@@ -82,6 +82,8 @@ struct PersonActionsPrivate {
}
};
+//=====================================================================================
+
PersonActions::PersonActions(QObject* parent)
: QAbstractListModel(parent)
, d_ptr(new PersonActionsPrivate)
@@ -104,7 +106,7 @@ const QAbstractItemModel* PersonActions::model() const
return d->model;
}
-void PersonActions::setModel(const QAbstractItemModel* model)
+void PersonActions::setModel(const QAbstractItemModel *model)
{
Q_D(PersonActions);
d->model = model;
@@ -124,10 +126,11 @@ void PersonActions::setRow(int row)
initialize(d->model, d->row);
}
-void PersonActions::initialize(const QAbstractItemModel* model, int row)
+void PersonActions::initialize(const QAbstractItemModel *model, int row)
{
- if(!model || row<0)
+ if (!model || row<0) {
return;
+ }
Q_D(PersonActions);
QModelIndex idx = model->index(row, 0);
@@ -137,7 +140,7 @@ void PersonActions::initialize(const QAbstractItemModel* model, \
int row) initialize(idx);
}
-void PersonActions::initialize(const QModelIndex& idx)
+void PersonActions::initialize(const QModelIndex &idx)
{
Q_D(PersonActions);
Q_ASSERT(idx.isValid());
@@ -156,7 +159,7 @@ void PersonActions::initialize(const QModelIndex& idx)
beginResetModel();
qDeleteAll(d->actions);
d->actions.clear();
- for(int i=0; i<rows; i++) {
+ for (int i = 0; i < rows; i++) {
QModelIndex idxContact;
if (idx.data(PersonsModel::ResourceTypeRole) == PersonsModel::Person) {
@@ -184,28 +187,28 @@ void PersonActions::initialize(const QModelIndex& idx)
void PersonActions::emailTriggered()
{
- QAction* action = qobject_cast<QAction*>(sender());
+ QAction *action = qobject_cast<QAction*>(sender());
KToolInvocation::invokeMailer(action->property("email").toString(), QString());
}
void PersonActions::imTriggered()
{
- QAction* action = qobject_cast<QAction*>(sender());
+ QAction *action = qobject_cast<QAction*>(sender());
const QString query = QString::fromLatin1("select ?telepathy_accountIdentifier \
WHERE {"
"%1 nco:hasIMAccount ?nco_hasIMAccount . \
"
"?nco_hasIMAccount nco:isAccessedBy ?nco_isAccessedBy . \
"
"?nco_isAccessedBy telepathy:accountIdentifier \
?telepathy_accountIdentifier . "
" }").arg( Soprano::Node::resourceToN3(action->property("uri").toUrl()) );
- Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
- Soprano::QueryResultIterator qit = model->executeQuery( query, \
Soprano::Query::QueryLanguageSparql ); + Soprano::Model *model = \
Nepomuk2::ResourceManager::instance()->mainModel(); + Soprano::QueryResultIterator \
qit = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
QString account;
- if( qit.next() ) {
+ if (qit.next()) {
account = qit["telepathy_accountIdentifier"].toString();
}
- if(!account.isEmpty()) {
+ if (!account.isEmpty()) {
Q_D(const PersonActions);
qobject_cast<const \
PersonsModel*>(d->model)->tpChannelDelegate()->startIM(account,
\
action->property("imrole").toString(), @@ -213,11 +216,11 @@ void \
PersonActions::imTriggered() }
}
-QVariant PersonActions::data(const QModelIndex& index, int role) const
+QVariant PersonActions::data(const QModelIndex &index, int role) const
{
Q_D(const PersonActions);
int row = index.row();
- if(index.isValid() && row<d->actions.size()) {
+ if (index.isValid() && row<d->actions.size()) {
switch(role) {
case Qt::DisplayRole: return d->actions[row]->text();
case Qt::DecorationRole: return d->actions[row]->icon();
@@ -227,7 +230,7 @@ QVariant PersonActions::data(const QModelIndex& index, int role) \
const return QVariant();
}
-int PersonActions::rowCount(const QModelIndex& parent) const
+int PersonActions::rowCount(const QModelIndex &parent) const
{
Q_D(const PersonActions);
return parent.isValid() ? 0 : d->actions.size();
@@ -242,8 +245,9 @@ void PersonActions::trigger(int actionsRow)
void PersonActions::setPerson(PersonData* data)
{
Q_D(PersonActions);
- if(d->person == data)
+ if (d->person == data) {
return;
+ }
initialize(data->personIndex());
}
diff --git a/src/personactions.h b/src/personactions.h
index 769cfe7..80ab2ba 100644
--- a/src/personactions.h
+++ b/src/personactions.h
@@ -31,26 +31,26 @@ struct PersonActionsPrivate;
class KPEOPLE_EXPORT PersonActions : public QAbstractListModel
{
Q_OBJECT
- Q_PROPERTY(const QAbstractItemModel* peopleModel READ model WRITE setModel)
+ Q_PROPERTY(const QAbstractItemModel *peopleModel READ model WRITE setModel)
Q_PROPERTY(int row READ row WRITE setRow)
- Q_PROPERTY(PersonData* person READ person WRITE setPerson)
+ Q_PROPERTY(PersonData *person READ person WRITE setPerson)
public:
- explicit PersonActions(QObject* parent = 0);
+ explicit PersonActions(QObject *parent = 0);
virtual ~PersonActions();
QList<QAction*> actions();
- void setModel(const QAbstractItemModel* model);
+ void setModel(const QAbstractItemModel *model);
const QAbstractItemModel* model() const;
int row() const;
void setRow(int row);
PersonData* person() const;
- void setPerson(PersonData* data);
+ void setPerson(PersonData *data);
Q_INVOKABLE void trigger(int actionsRow);
- virtual QVariant data(const QModelIndex& index, int role) const;
- virtual int rowCount(const QModelIndex& parent=QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
private slots:
void emailTriggered();
@@ -60,8 +60,8 @@ class KPEOPLE_EXPORT PersonActions : public QAbstractListModel
void actionsChanged();
private:
- void initialize(const QAbstractItemModel* model, int row);
- void initialize(const QModelIndex& personIndex);
+ void initialize(const QAbstractItemModel *model, int row);
+ void initialize(const QModelIndex &personIndex);
friend class PersonsModelContactItem;
diff --git a/src/persondata.cpp b/src/persondata.cpp
index efe1533..3c65557 100644
--- a/src/persondata.cpp
+++ b/src/persondata.cpp
@@ -32,21 +32,23 @@
struct PersonDataPrivate {
PersonDataPrivate() : model(0) {}
- PersonsModel* model;
+ PersonsModel *model;
QString id;
QUrl uri;
};
-PersonData::PersonData(QObject* parent)
- : QObject(parent)
- , d_ptr(new PersonDataPrivate)
-{}
+PersonData::PersonData(QObject *parent)
+ : QObject(parent),
+ d_ptr(new PersonDataPrivate)
+{
+}
-void PersonData::setContactId(const QString& id)
+void PersonData::setContactId(const QString &id)
{
Q_D(PersonData);
- if(d->id==id)
+ if (d->id == id) {
return;
+ }
//it should be basically the same query as in the persons model
//only that here we're restricting it to a person
@@ -88,8 +90,9 @@ void PersonData::setContactId(const QString& id)
void PersonData::setContactUri(const QUrl &uri)
{
Q_D(PersonData);
- if(d->uri == uri)
+ if (d->uri == uri) {
return;
+ }
bool isContact = false;
bool isPerson = false;
@@ -97,7 +100,7 @@ void PersonData::setContactUri(const QUrl &uri)
QString query = QString::fromLatin1("select ?type WHERE { <%1> a ?type. \
}").arg(uri.toString());
Soprano::QueryResultIterator it = \
Nepomuk2::ResourceManager::instance()->mainModel()->executeQuery( query, \
Soprano::Query::QueryLanguageSparql );
- while( it.next() ) {
+ while (it.next()) {
kDebug() << it["type"];
if (it["type"].toString() == \
Nepomuk2::Vocabulary::PIMO::Person().toString()) { isPerson = true;
diff --git a/src/persondata.h b/src/persondata.h
index cbbc901..96250a2 100644
--- a/src/persondata.h
+++ b/src/persondata.h
@@ -36,17 +36,17 @@ class KPEOPLE_EXPORT PersonData : public QObject
Q_PROPERTY(QUrl uri READ uri NOTIFY contactChanged)
Q_PROPERTY(QUrl avatar READ avatar NOTIFY dataChanged)
- Q_PROPERTY(QString nickname READ nickname NOTIFY dataChanged)
+ Q_PROPERTY(QString imNickname READ nickname NOTIFY dataChanged)
Q_PROPERTY(QString status READ status NOTIFY dataChanged)
Q_PROPERTY(QStringList contacts READ contacts NOTIFY dataChanged)
public:
- explicit PersonData(QObject* parent = 0);
+ explicit PersonData(QObject *parent = 0);
/** @returns the uri of the current person */
QUrl uri() const;
/** @p id will specify the person we're offering by finding the pimo:Person \
related to it */
- void setContactId(const QString& id);
+ void setContactId(const QString &id);
QString contactId() const;
/** @returns a url pointing to the avatar image */
diff --git a/src/persons-model-contact-item.cpp b/src/persons-model-contact-item.cpp
index fed365a..061d263 100644
--- a/src/persons-model-contact-item.cpp
+++ b/src/persons-model-contact-item.cpp
@@ -44,7 +44,7 @@ public:
mutable QList<QAction *> actions;
};
-PersonsModelContactItem::PersonsModelContactItem(const QUrl& uri)
+PersonsModelContactItem::PersonsModelContactItem(const QUrl &uri)
: d_ptr(new PersonsModelContactItemPrivate)
{
// setData(uri, PersonsModel::UriRole);
@@ -52,7 +52,7 @@ PersonsModelContactItem::PersonsModelContactItem(const QUrl& uri)
setType(PersonsModel::MobilePhone);
}
-PersonsModelContactItem::PersonsModelContactItem(const Nepomuk2::Resource& contact)
+PersonsModelContactItem::PersonsModelContactItem(const Nepomuk2::Resource &contact)
: d_ptr(new PersonsModelContactItemPrivate)
{
// setData(contact.uri(), PersonsModel::UriRole);
@@ -60,10 +60,14 @@ PersonsModelContactItem::PersonsModelContactItem(const \
Nepomuk2::Resource& conta pullResourceProperties(contact);
QUrl val = d_ptr->data.value(Nepomuk2::Vocabulary::NCO::hasIMAccount()).toUrl();
- if(val.isValid()) pullResourceProperties(Nepomuk2::Resource(val));
+ if (val.isValid()) {
+ pullResourceProperties(Nepomuk2::Resource(val));
+ }
val = d_ptr->data.value(Nepomuk2::Vocabulary::NCO::photo()).toUrl();
- if(val.isValid()) pullResourceProperties(Nepomuk2::Resource(val));
+ if (val.isValid()) {
+ pullResourceProperties(Nepomuk2::Resource(val));
+ }
}
PersonsModelContactItem::~PersonsModelContactItem()
@@ -71,10 +75,10 @@ PersonsModelContactItem::~PersonsModelContactItem()
delete d_ptr;
}
-void PersonsModelContactItem::pullResourceProperties(const Nepomuk2::Resource& res)
+void PersonsModelContactItem::pullResourceProperties(const Nepomuk2::Resource &res)
{
QHash<QUrl, Nepomuk2::Variant> props = res.properties();
- for(QHash<QUrl, Nepomuk2::Variant>::const_iterator it=props.constBegin(), \
itEnd=props.constEnd(); it!=itEnd; ++it) { + for (QHash<QUrl, \
Nepomuk2::Variant>::const_iterator it = props.constBegin(), itEnd = props.constEnd(); \
it != itEnd; ++it) { addData(it.key(), it->variant());
}
}
@@ -170,8 +174,10 @@ QVariant PersonsModelContactItem::data(int role) const
case PersonsModel::MobilePhone: role = PersonsModel::PhoneRole; \
break; case PersonsModel::Postal: role = -1; break;
}
- if(role>=0)
+
+ if (role >= 0) {
return data(role);
+ }
} break;
case PersonsModel::ContactActionsRole:
if (d->actions.isEmpty()) {
@@ -188,14 +194,14 @@ QVariant PersonsModelContactItem::data(int role) const
return QStandardItem::data(role);
}
-void PersonsModelContactItem::modifyData(const QUrl& name, const QVariantList& \
added) +void PersonsModelContactItem::modifyData(const QUrl &name, const QVariantList \
&added) {
Q_D(PersonsModelContactItem);
d->data[name] = added;
emitDataChanged();
}
-void PersonsModelContactItem::modifyData(const QUrl& name, const QVariant& newValue)
+void PersonsModelContactItem::modifyData(const QUrl &name, const QVariant &newValue)
{
Q_D(PersonsModelContactItem);
kDebug() << "Old data:" << d->data[name];
@@ -205,7 +211,7 @@ void PersonsModelContactItem::modifyData(const QUrl& name, const \
QVariant& newVa }
-void PersonsModelContactItem::removeData(const QUrl& uri)
+void PersonsModelContactItem::removeData(const QUrl &uri)
{
Q_D(PersonsModelContactItem);
d->data.remove(uri);
diff --git a/src/persons-model-contact-item.h b/src/persons-model-contact-item.h
index bb2f50f..f66ec6f 100644
--- a/src/persons-model-contact-item.h
+++ b/src/persons-model-contact-item.h
@@ -37,21 +37,21 @@ public:
* @param displayName - What will be visible to the user (used as \
Qt::DisplayRole)
* @param type - What kind of contact this is
*/
- explicit PersonsModelContactItem(const QUrl& uri);
- explicit PersonsModelContactItem(const Nepomuk2::Resource& res);
+ explicit PersonsModelContactItem(const QUrl &uri);
+ explicit PersonsModelContactItem(const Nepomuk2::Resource &res);
virtual ~PersonsModelContactItem();
QUrl uri() const;
void addData(const QUrl &key, const QVariant &value);
- void modifyData(const QUrl& name, const QVariantList& newValue);
- void modifyData(const QUrl& name, const QVariant& newValue);
+ void modifyData(const QUrl &name, const QVariantList &newValue);
+ void modifyData(const QUrl &name, const QVariant &newValue);
void setType(PersonsModel::ContactType type);
- QVariant dataValue(const QUrl& key);
+ QVariant dataValue(const QUrl &key);
virtual QVariant data(int role = Qt::UserRole + 1) const;
- void removeData(const QUrl& uri);
- void pullResourceProperties(const Nepomuk2::Resource& res);
+ void removeData(const QUrl &uri);
+ void pullResourceProperties(const Nepomuk2::Resource &res);
private:
void refreshIcon();
diff --git a/src/persons-model-item.cpp b/src/persons-model-item.cpp
index c8adb11..16c6709 100644
--- a/src/persons-model-item.cpp
+++ b/src/persons-model-item.cpp
@@ -34,7 +34,7 @@ PersonsModelItem::PersonsModelItem(const QUrl &personUri)
setData(personUri, PersonsModel::UriRole);
}
-PersonsModelItem::PersonsModelItem(const Nepomuk2::Resource& person)
+PersonsModelItem::PersonsModelItem(const Nepomuk2::Resource &person)
{
setData(person.uri(), PersonsModel::UriRole);
setContacts(person.property(Nepomuk2::Vocabulary::PIMO::groundingOccurrence()).toUrlList());
@@ -70,12 +70,14 @@ QVariant PersonsModelItem::data(int role) const
case PersonsModel::NameRole:
case Qt::DisplayRole: {
QVariant value = queryChildrenForRole(Qt::DisplayRole);
- if(value.isNull())
+ if (value.isNull()) {
value = queryChildrenForRole(PersonsModel::ContactIdRole);
- if(value.isNull())
+ }
+ if (value.isNull()) {
return QString("PIMO:Person - \
%1").arg(data(PersonsModel::UriRole).toString());
- else
+ } else {
return value;
+ }
}
case PersonsModel::StatusRole: //TODO: use a better algorithm for finding \
the actual status case PersonsModel::NickRole:
@@ -97,31 +99,32 @@ QVariant PersonsModelItem::data(int role) const
return QStandardItem::data(role);
}
-void PersonsModelItem::removeContacts(const QList<QUrl>& contacts)
+void PersonsModelItem::removeContacts(const QList<QUrl> &contacts)
{
kDebug() << "remove contacts" << contacts;
- for(int i=0; i<rowCount(); ) {
+ for (int i = 0; i < rowCount(); ) {
QStandardItem* item = child(i);
- if(contacts.contains(item->data(PersonsModel::UriRole).toUrl()))
+ if (contacts.contains(item->data(PersonsModel::UriRole).toUrl())) {
removeRow(i);
- else
+ } else {
++i;
+ }
}
emitDataChanged();
}
-void PersonsModelItem::addContacts(const QList<QUrl>& _contacts)
+void PersonsModelItem::addContacts(const QList<QUrl> &_contacts)
{
QList<QUrl> contacts(_contacts);
//get existing child-contacts and remove them from the new ones
QVariantList uris = queryChildrenForRoleList(PersonsModel::UriRole);
- foreach(const QVariant& uri, uris) {
+ foreach (const QVariant &uri, uris) {
contacts.removeOne(uri.toUrl());
}
//query the model for the contacts, if they are present, then need to be just \
moved QList<QStandardItem*> toplevelContacts;
- foreach(const QUrl &uri, contacts) {
+ foreach (const QUrl &uri, contacts) {
QModelIndex contactIndex = \
qobject_cast<PersonsModel*>(model())->indexForUri(uri); if (contactIndex.isValid()) \
{
toplevelContacts.append(qobject_cast<PersonsModel*>(model())->takeRow(contactIndex.row()));
@@ -130,7 +133,7 @@ void PersonsModelItem::addContacts(const QList<QUrl>& _contacts)
//append the moved contacts to this person and remove them from 'contacts'
//so they are not added twice
- foreach(QStandardItem *contactItem, toplevelContacts) {
+ foreach (QStandardItem *contactItem, toplevelContacts) {
PersonsModelContactItem *contact = \
dynamic_cast<PersonsModelContactItem*>(contactItem); appendRow(contact);
contacts.removeOne(contact->uri());
@@ -138,13 +141,13 @@ void PersonsModelItem::addContacts(const QList<QUrl>& \
_contacts)
kDebug() << "add contacts" << contacts;
QList<PersonsModelContactItem*> rows;
- foreach(const QUrl& uri, contacts) {
+ foreach (const QUrl &uri, contacts) {
appendRow(new PersonsModelContactItem(Nepomuk2::Resource(uri)));
}
emitDataChanged();
}
-void PersonsModelItem::setContacts(const QList<QUrl>& contacts)
+void PersonsModelItem::setContacts(const QList<QUrl> &contacts)
{
kDebug() << "set contacts" << contacts;
if (contacts.isEmpty()) {
@@ -152,18 +155,18 @@ void PersonsModelItem::setContacts(const QList<QUrl>& contacts)
return;
}
- if(hasChildren()) {
+ if (hasChildren()) {
QList<QUrl> toRemove;
QVariantList uris = queryChildrenForRoleList(PersonsModel::UriRole);
- foreach(const QVariant& contact, uris) {
- if(!contacts.contains(contact.toUrl()))
+ foreach (const QVariant &contact, uris) {
+ if (!contacts.contains(contact.toUrl()))
toRemove += contact.toUrl();
}
removeContacts(toRemove);
}
QList<QUrl> toAdd;
- foreach(const QUrl& contact, contacts) {
+ foreach (const QUrl &contact, contacts) {
toAdd += contact;
}
addContacts(toAdd);
diff --git a/src/persons-model-item.h b/src/persons-model-item.h
index b46d7c7..82dbc27 100644
--- a/src/persons-model-item.h
+++ b/src/persons-model-item.h
@@ -37,13 +37,13 @@ class KPEOPLE_EXPORT PersonsModelItem : public QStandardItem
{
public:
PersonsModelItem(const QUrl &personUri);
- PersonsModelItem(const Nepomuk2::Resource& person);
+ PersonsModelItem(const Nepomuk2::Resource &person);
virtual QVariant data(int role) const;
- void removeContacts(const QList<QUrl>& contacts);
- void addContacts(const QList<QUrl>& contacts);
- void setContacts(const QList< QUrl >& contacts);
+ void removeContacts(const QList<QUrl> &contacts);
+ void addContacts(const QList<QUrl> &contacts);
+ void setContacts(const QList< QUrl > &contacts);
private:
QVariant queryChildrenForRole(int role) const;
diff --git a/src/persons-model.cpp b/src/persons-model.cpp
index b027a5f..30f45bd 100644
--- a/src/persons-model.cpp
+++ b/src/persons-model.cpp
@@ -38,6 +38,7 @@
#include <Nepomuk2/SimpleResource>
#include <Nepomuk2/SimpleResourceGraph>
#include <Nepomuk2/StoreResourcesJob>
+
#include <KDebug>
struct PersonsModelPrivate {
@@ -48,7 +49,7 @@ struct PersonsModelPrivate {
NepomukTpChannelDelegate *ktpDelegate;
};
-PersonsModel::PersonsModel(QObject *parent, bool init, const QString& customQuery)
+PersonsModel::PersonsModel(QObject *parent, bool init, const QString &customQuery)
: QStandardItemModel(parent)
, d_ptr(new PersonsModelPrivate)
{
@@ -67,9 +68,9 @@ PersonsModel::PersonsModel(QObject *parent, bool init, const \
QString& customQuer names.insert(PersonsModel::ContactActionsRole, \
"contactActions"); setRoleNames(names);
- if(init) {
+ if (init) {
QString nco_query = customQuery;
- if(customQuery.isEmpty())
+ if (customQuery.isEmpty()) {
nco_query = QString::fromUtf8(
"select DISTINCT ?uri ?pimo_groundingOccurrence ?nco_hasIMAccount "
"?nco_imNickname ?telepathy_statusType ?nco_imID ?nco_imAccountType \
?nco_hasEmailAddress " @@ -98,6 +99,7 @@ PersonsModel::PersonsModel(QObject *parent, \
bool init, const QString& customQuer
"?nco_hasEmailAddress nco:emailAddress \
?nco_emailAddress. " " } "
"}");
+ }
QMetaObject::invokeMethod(this, "query", Qt::QueuedConnection, \
Q_ARG(QString, nco_query)); new ResourceWatcherService(this);
@@ -105,10 +107,10 @@ PersonsModel::PersonsModel(QObject *parent, bool init, const \
QString& customQuer }
template <class T>
-QList<QStandardItem*> toStandardItems(const QList<T*>& items)
+QList<QStandardItem*> toStandardItems(const QList<T*> &items)
{
QList<QStandardItem*> ret;
- foreach(QStandardItem* it, items) {
+ foreach (QStandardItem *it, items) {
ret += it;
}
return ret;
@@ -131,7 +133,7 @@ QHash<QString, QUrl> initUriToBinding()
<< Nepomuk2::Vocabulary::NCO::emailAddress()
<< Nepomuk2::Vocabulary::NIE::url();
- foreach(const QUrl& keyUri, list) {
+ foreach (const QUrl &keyUri, list) {
QString keyString = keyUri.toString();
//convert every key to correspond to the nepomuk bindings
keyString = keyString.mid(keyString.lastIndexOf(QLatin1Char('/')) + \
1).replace(QLatin1Char('#'), QLatin1Char('_')); @@ -140,28 +142,28 @@ QHash<QString, \
QUrl> initUriToBinding() return ret;
}
-void PersonsModel::query(const QString& nco_query)
+void PersonsModel::query(const QString &nco_query)
{
- Q_ASSERT(rowCount()==0);
+ Q_ASSERT(rowCount() == 0);
QHash<QString, QUrl> uriToBinding = initUriToBinding();
- Soprano::Model* m = Nepomuk2::ResourceManager::instance()->mainModel();
+ Soprano::Model *m = Nepomuk2::ResourceManager::instance()->mainModel();
Soprano::QueryResultIterator it = m->executeQuery(nco_query, \
Soprano::Query::QueryLanguageSparql); QHash<QUrl, PersonsModelContactItem*> \
contacts; QHash<QUrl, PersonsModelItem*> persons;
- while(it.next()) {
+ while (it.next()) {
QUrl currentUri = it[QLatin1String("uri")].uri();
if (currentUri == QUrl(QLatin1String("nepomuk:/me"))) {
continue;
}
PersonsModelContactItem* contactNode = contacts.value(currentUri);
bool newContact = !contactNode;
- if(!contactNode) {
+ if (!contactNode) {
contactNode = new PersonsModelContactItem(currentUri);
}
- for(QHash<QString, QUrl>::const_iterator iter=uriToBinding.constBegin(), \
itEnd=uriToBinding.constEnd(); iter!=itEnd; ++iter) { + for(QHash<QString, \
QUrl>::const_iterator iter = uriToBinding.constBegin(), itEnd = \
uriToBinding.constEnd(); iter != itEnd; ++iter) {
contactNode->addData(iter.value(), it[iter.key()].toString());
}
@@ -189,10 +191,10 @@ void PersonsModel::query(const QString& nco_query)
kDebug() << "Model ready";
}
-void PersonsModel::unmerge(const QUrl& contactUri, const QUrl& personUri)
+void PersonsModel::unmerge(const QUrl &contactUri, const QUrl &personUri)
{
Nepomuk2::Resource oldPerson(personUri);
- Q_ASSERT(oldPerson.property(Nepomuk2::Vocabulary::PIMO::groundingOccurrence()).toUrlList().size()>=2 \
&& "there's nothing to unmerge..."); + \
Q_ASSERT(oldPerson.property(Nepomuk2::Vocabulary::PIMO::groundingOccurrence()).toUrlList().size() \
>= 2 && "there's nothing to unmerge...");
oldPerson.removeProperty(Nepomuk2::Vocabulary::PIMO::groundingOccurrence(), \
contactUri);
if (!oldPerson.hasProperty(Nepomuk2::Vocabulary::PIMO::groundingOccurrence())) {
oldPerson.remove();
@@ -212,49 +214,52 @@ void PersonsModel::unmerge(const QUrl& contactUri, const QUrl& \
personUri) // job->start();
}
-void PersonsModel::merge(const QList< QUrl >& persons)
+void PersonsModel::merge(const QList<QUrl> &persons)
{
- KJob* job = Nepomuk2::mergeResources( persons );
+ KJob *job = Nepomuk2::mergeResources(persons);
job->setObjectName("Merge");
connect(job, SIGNAL(finished(KJob*)), SLOT(jobFinished(KJob*)));
}
-void PersonsModel::merge(const QVariantList& persons)
+void PersonsModel::merge(const QVariantList &persons)
{
QList<QUrl> conv;
- foreach(const QVariant& p, persons)
+ foreach (const QVariant &p, persons)
conv += p.toUrl();
merge(conv);
}
-void PersonsModel::jobFinished(KJob* job)
+void PersonsModel::jobFinished(KJob *job)
{
- if(job->error()!=0) {
+ if (job->error()!=0) {
kWarning() << job->objectName() << " failed for "<< \
job->property("uri").toString() << job->errorText() << job->errorString(); } else {
kWarning() << job->objectName() << " done: "<< \
job->property("uri").toString(); }
}
-QModelIndex PersonsModel::findRecursively(int role, const QVariant& value, const \
QModelIndex& idx) const +QModelIndex PersonsModel::findRecursively(int role, const \
QVariant &value, const QModelIndex &idx) const {
- if(idx.isValid() && data(idx, role)==value)
+ if (idx.isValid() && data(idx, role) == value) {
return idx;
+ }
int rows = rowCount(idx);
- for(int i=0; i<rows; i++) {
+ for (int i = 0; i < rows; i++) {
QModelIndex ret = findRecursively(role, value, index(i, 0, idx));
- if(ret.isValid())
+ if (ret.isValid()) {
return ret;
+ }
}
+
return QModelIndex();
}
-QModelIndex PersonsModel::indexForUri(const QUrl& uri) const
+QModelIndex PersonsModel::indexForUri(const QUrl &uri) const
{
return findRecursively(PersonsModel::UriRole, uri);
}
-void PersonsModel::createPerson(const Nepomuk2::Resource& res)
+void PersonsModel::createPerson(const Nepomuk2::Resource &res)
{
Q_ASSERT(!indexForUri(res.uri()).isValid());
//pass only the uri as that will not add the contacts from groundingOccurrence
@@ -269,18 +274,18 @@ void PersonsModel::createPerson(const Nepomuk2::Resource& res)
appendRow(new PersonsModelItem(res.uri()));
}
-void PersonsModel::createContact(const Nepomuk2::Resource& res)
+void PersonsModel::createContact(const Nepomuk2::Resource &res)
{
appendRow(new PersonsModelContactItem(res.uri()));
}
-PersonsModelContactItem* PersonsModel::contactForIMAccount(const QUrl& uri) const
+PersonsModelContactItem* PersonsModel::contactForIMAccount(const QUrl &uri) const
{
- QStandardItem* it = \
itemFromIndex(findRecursively(PersonsModel::IMAccountUriRole, uri)); + \
QStandardItem *it = itemFromIndex(findRecursively(PersonsModel::IMAccountUriRole, \
uri)); return dynamic_cast<PersonsModelContactItem*>(it);
}
-void PersonsModel::createPersonFromContacts(const QList<QUrl>& contacts)
+void PersonsModel::createPersonFromContacts(const QList<QUrl> &contacts)
{
Nepomuk2::SimpleResource newPimoPerson;
newPimoPerson.addType(Nepomuk2::Vocabulary::PIMO::Person());
diff --git a/src/persons-model.h b/src/persons-model.h
index 70e8c5c..a840ffa 100644
--- a/src/persons-model.h
+++ b/src/persons-model.h
@@ -74,19 +74,19 @@ public:
* @p initialize set it to false if you don't want it to use nepomuk values
* useful for unit testing.
*/
- explicit PersonsModel(QObject* parent=0, bool init=true, const QString& \
customQuery=QString()); + PersonsModel(QObject *parent = 0, bool init = true, \
const QString &customQuery = QString());
/**
* The @p contactUri will be removed from @p personUri and it will be added to a \
new
* empty pimo:Person instance.
*/
- Q_SCRIPTABLE void unmerge(const QUrl& contactUri, const QUrl& personUri);
+ Q_SCRIPTABLE void unmerge(const QUrl &contactUri, const QUrl &personUri);
/** Merge all the contacts inside the @p persons */
- void merge(const QList<QUrl>& persons);
+ void merge(const QList<QUrl> &persons);
/** this one is because QML is not smart enough to understand what's going on */
- Q_SCRIPTABLE void merge(const QVariantList& persons);
+ Q_SCRIPTABLE void merge(const QVariantList &persons);
/** Creates a pimo:person with contacts as groundingOccurances */
void createPersonFromContacts(const QList<QUrl> &contacts);
@@ -96,23 +96,23 @@ public:
//FIXME: maybe merge with ^ ?
void removePersonFromModel(const QModelIndex &index);
- QModelIndex indexForUri(const QUrl& uri) const;
+ QModelIndex indexForUri(const QUrl &uri) const;
- void createPerson(const Nepomuk2::Resource& res);
+ void createPerson(const Nepomuk2::Resource &res);
void createContact(const Nepomuk2::Resource &res);
- PersonsModelContactItem* contactForIMAccount(const QUrl& uri) const;
+ PersonsModelContactItem* contactForIMAccount(const QUrl &uri) const;
NepomukTpChannelDelegate* tpChannelDelegate() const;
private slots:
- void jobFinished(KJob*);
- void query(const QString& queryString);
+ void jobFinished(KJob *job);
+ void query(const QString &queryString);
signals:
void peopleAdded();
private:
- QModelIndex findRecursively(int role, const QVariant& value, const QModelIndex& \
idx=QModelIndex()) const; + QModelIndex findRecursively(int role, const QVariant \
&value, const QModelIndex &idx = QModelIndex()) const;
PersonsModelPrivate * const d_ptr;
Q_DECLARE_PRIVATE(PersonsModel)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic