[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:07:25 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=f0e026d
The following commit has been merged in the master branch:
commit f0e026da0656e835e70baa8d2d5a9f347c29af41
Author: Vishesh Handa <handa.vish at gmail.com>
Date: Wed Feb 15 19:16:41 2012 +0530
Make setting Contact Properties asynchronous
It caches all the required changes for 500 mseconds, and then does
them all in one go.
This decreases the startup time exponentially.
---
kpeople/nepomuk-feeder/contact.cpp | 6 +-
kpeople/nepomuk-feeder/nepomuk-storage.cpp | 236 +++++++++++++++--------------
kpeople/nepomuk-feeder/nepomuk-storage.h | 16 +-
3 files changed, 142 insertions(+), 116 deletions(-)
diff --git a/kpeople/nepomuk-feeder/contact.cpp b/kpeople/nepomuk-feeder/contact.cpp
index 2e1a95e..b182173 100644
--- a/kpeople/nepomuk-feeder/contact.cpp
+++ b/kpeople/nepomuk-feeder/contact.cpp
@@ -100,7 +100,7 @@ void Contact::init()
Contact::~Contact()
{
- kDebug();
+ //kDebug();
}
void Contact::shutdown()
@@ -122,14 +122,14 @@ void Contact::onPresenceChanged(const Tp::Presence &presence)
void Contact::onAddedToGroup(const QString &group)
{
- kDebug() << "On added to group " << group;
+// kDebug() << "On added to group " << group;
emit groupsChanged(m_contact->id(), m_contact->groups());
}
void Contact::onRemovedFromGroup(const QString &group)
{
- kDebug() << "On removed from group " << group;
+// kDebug() << "On removed from group " << group;
emit groupsChanged(m_contact->id(), m_contact->groups());
}
diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.cpp b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
index 533fe12..61ca8db 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.cpp
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
@@ -261,6 +261,11 @@ bool ContactResources::operator!=(const ContactResources& other) const
return !(*this == other);
}
+bool ContactResources::isEmpty() const
+{
+ return d->person.isEmpty() && d->personContact.isEmpty() && d->imAccount.isEmpty();
+}
+
NepomukStorage::NepomukStorage(QObject *parent)
: AbstractStorage(parent)
@@ -278,6 +283,9 @@ NepomukStorage::NepomukStorage(QObject *parent)
SLOT(onNepomukError(QString,int)));
QTimer::singleShot(0, this, SLOT(init()));
+
+ m_contactsTimer.setSingleShot( true );
+ connect( &m_contactsTimer, SIGNAL(timeout()), this, SLOT(onContactTimer()) );
}
NepomukStorage::~NepomukStorage()
@@ -582,14 +590,6 @@ void NepomukStorage::cleanupAccounts(const QList<QString> &paths)
}
}
-void NepomukStorage::saveGraph(const Nepomuk::SimpleResourceGraph &graph)
-{
- KJob *job = Nepomuk::storeResources(graph, Nepomuk::IdentifyNew, Nepomuk::OverwriteProperties);
- connect(job, SIGNAL(result(KJob*)),
- this, SLOT(onSaveJobResult(KJob*)));
- job->start();
-}
-
void NepomukStorage::createAccount(const QString &path, const QString &id, const QString &protocol)
{
kDebug() << "Creating a new Account";
@@ -691,6 +691,33 @@ void NepomukStorage::setAccountCurrentPresence(const QString &path, const Tp::Si
}
}
+//
+// Contact Functions
+//
+
+ContactResources NepomukStorage::findContact(const QString& path, const QString& id)
+{
+ const ContactIdentifier identifier(path, id);
+
+ // Check the Contact exists.
+ QHash<ContactIdentifier, ContactResources>::const_iterator it = m_contacts.find(identifier);
+ const bool found = (it != m_contacts.constEnd());
+ if (!found) {
+ kWarning() << "Contact not found:" << path << id;
+ return ContactResources();
+ }
+
+ return it.value();
+}
+
+void NepomukStorage::fireContactTimer()
+{
+ if( !m_contactsTimer.isActive() )
+ m_contactsTimer.start( 500 );
+}
+
+
+
void NepomukStorage::cleanupAccountContacts(const QString &path, const QList<QString> &ids)
{
kDebug() << path << ids;
@@ -725,15 +752,15 @@ void NepomukStorage::cleanupAccountContacts(const QString &path, const QList<QSt
void NepomukStorage::createContact(const QString &path, const QString &id)
{
- kDebug() << path << id;
// First, check that we don't already have a record for this contact.
ContactIdentifier identifier(path, id);
if (m_contacts.contains(identifier)) {
- kDebug() << "Contact record already exists. Return.";
+// kDebug() << "Contact record already exists. Return.";
return;
}
// Contact not found. Need to create it.
+ kDebug() << path << id;
kDebug() << "Contact not found in Nepomuk. Creating it.";
Q_ASSERT(m_accounts.contains(path));
@@ -793,29 +820,20 @@ void NepomukStorage::destroyContact(const QString &path, const QString &id)
void NepomukStorage::setContactAlias(const QString &path, const QString &id, const QString &alias)
{
- ContactIdentifier identifier(path, id);
-
- // Check the Contact exists.
- QHash<ContactIdentifier, ContactResources>::const_iterator it = m_contacts.find(identifier);
- const bool found = (it != m_contacts.constEnd());
- Q_ASSERT(found);
- if (!found) {
- kWarning() << "Contact not found.";
+ ContactResources contact = findContact(path, id);
+ if( contact.isEmpty() )
return;
- }
- ContactResources resources = it.value();
+ QUrl imAccountUri = contact.imAccount();
- // vHanda: FIXME: Can a person have multiple nick names?
- KJob *job = Nepomuk::setProperty( QList<QUrl>() << resources.imAccount(), NCO::imNickname(),
- QVariantList() << alias );
+ Nepomuk::SimpleResource &res = m_contactGraph[imAccountUri];
+ res.setUri( imAccountUri );
+ res.setProperty( NCO::imNickname(), alias );
- job->exec();
- if( job->error() ) {
- kWarning() << job->errorString();
- }
+ fireContactTimer();
- if (!Nepomuk::Resource(resources.person()).hasProperty(Soprano::Vocabulary::NAO::prefLabel())) {
+ // vHanda; WTF!! This is not good.
+ /*if (!Nepomuk::Resource(resources.person()).hasProperty(Soprano::Vocabulary::NAO::prefLabel())) {
KJob *job = Nepomuk::setProperty( QList<QUrl>() << resources.person(), Soprano::Vocabulary::NAO::prefLabel(),
QVariantList() << alias );
@@ -823,40 +841,28 @@ void NepomukStorage::setContactAlias(const QString &path, const QString &id, con
if( job->error() ) {
kWarning() << job->errorString();
}
- }
+ }*/
}
void NepomukStorage::setContactPresence(const QString &path,
const QString &id,
const Tp::SimplePresence &presence)
{
- ContactIdentifier identifier(path, id);
-
- // Check the Contact exists.
- QHash<ContactIdentifier, ContactResources>::const_iterator it = m_contacts.find(identifier);
- const bool found = (it != m_contacts.constEnd());
- Q_ASSERT(found);
- if (!found) {
- kWarning() << "Contact not found.";
+ ContactResources contact = findContact(path, id);
+ if( contact.isEmpty() )
return;
- }
- ContactResources resources = it.value();
+ QUrl imAccountUri = contact.imAccount();
- Nepomuk::SimpleResource imAccount(resources.imAccount());
- // Set the contact presence.
+ hasInvalidResources();
+ Nepomuk::SimpleResource &imAccount = m_contactGraph[imAccountUri];
+ imAccount.setUri( imAccountUri );
imAccount.setProperty(NCO::imStatus(), presence.status);
- imAccount.setProperty(Telepathy::statusType(), presence.type);
imAccount.setProperty(NCO::imStatusMessage(), presence.statusMessage);
+ imAccount.setProperty(Telepathy::statusType(), presence.type);
- // We're using 'OverwriteProperties' cause the above properties can already have existing
- // values which we don't care about
- KJob *job = Nepomuk::storeResources( Nepomuk::SimpleResourceGraph() << imAccount,
- Nepomuk::IdentifyNew, Nepomuk::OverwriteProperties );
- job->exec();
- if( job->error() ) {
- kWarning() << job->errorString();
- }
+ hasInvalidResources();
+ fireContactTimer();
}
void NepomukStorage::setContactGroups(const QString &path,
@@ -929,27 +935,19 @@ void NepomukStorage::setContactGroups(const QString &path,
void NepomukStorage::setContactBlockStatus(const QString &path, const QString &id, bool blocked)
{
- ContactIdentifier identifier(path, id);
-
- // Check if the Contact exists.
- QHash<ContactIdentifier, ContactResources>::const_iterator it = m_contacts.find(identifier);
- const bool found = (it != m_contacts.constEnd());
- Q_ASSERT(found);
- if (!found) {
- kWarning() << "Contact not found.";
+ ContactResources contact = findContact(path, id);
+ if( contact.isEmpty() )
return;
- }
- ContactResources resources = it.value();
+ QUrl imAccountUri = contact.imAccount();
- // vHanda: FIXME: Can a person have multiple nick names?
- KJob *job = Nepomuk::setProperty( QList<QUrl>() << resources.imAccount(), NCO::isBlocked(),
- QVariantList() << blocked );
+ hasInvalidResources();
+ Nepomuk::SimpleResource &imAccount = m_contactGraph[imAccountUri];
+ imAccount.setUri( imAccountUri );
+ imAccount.setProperty( NCO::isBlocked(), blocked );
- job->exec();
- if( job->error() ) {
- kWarning() << job->errorString();
- }
+ hasInvalidResources();
+ fireContactTimer();
}
void NepomukStorage::setContactPublishState(const QString &path,
@@ -1077,22 +1075,14 @@ void NepomukStorage::setContactCapabilities(const QString &path,
const QString &id,
const Tp::ContactCapabilities &capabilities)
{
- ContactIdentifier identifier(path, id);
-
- // Check the Contact exists.
- QHash<ContactIdentifier, ContactResources>::const_iterator it = m_contacts.find(identifier);
- const bool found = (it != m_contacts.constEnd());
- Q_ASSERT(found);
- if (!found) {
- kWarning() << "Contact not found.";
+ ContactResources contact = findContact(path, id);
+ if( contact.isEmpty() )
return;
- }
- ContactResources resources = it.value();
-
- Nepomuk::SimpleResource imAccount(resources.imAccount());
+ QUrl imAccountUri = contact.imAccount();
// For each supported (by the ontology) capability, check it and save the correct value
+ // FIXME: Add other caps to the ontologies so that we can add them here.
QVariantList capList;
if (capabilities.textChats())
capList << NCO::imCapabilityText();
@@ -1101,38 +1091,27 @@ void NepomukStorage::setContactCapabilities(const QString &path,
if (capabilities.streamedMediaVideoCalls())
capList << NCO::imCapabilityVideo();
- // FIXME: Add other caps to the ontologies so that we can add them here.
+ hasInvalidResources();
+ Nepomuk::SimpleResource &imAccount = m_contactGraph[imAccountUri];
+ imAccount.setUri( imAccountUri );
+ imAccount.setProperty( NCO::hasIMCapability(), capList );
- KJob *job = Nepomuk::setProperty( QList<QUrl>() << resources.imAccount(),
- NCO::hasIMCapability(),
- capList );
- job->exec();
- if( job->error() ) {
- kWarning() << job->errorString();
- }
+ hasInvalidResources();
+ fireContactTimer();
}
void NepomukStorage::setContactAvatar(const QString &path,
const QString &id,
const Tp::AvatarData &avatar)
{
- ContactIdentifier identifier(path, id);
-
- // Check the Contact exists.
- QHash<ContactIdentifier, ContactResources>::const_iterator it = m_contacts.find(identifier);
- const bool found = (it != m_contacts.constEnd());
- Q_ASSERT(found);
- if (!found) {
- kWarning() << "Contact not found.";
+ ContactResources contact = findContact(path, id);
+ if( contact.isEmpty() )
return;
- }
-
- ContactResources resources = it.value();
if( avatar.fileName.isEmpty() ) {
- kDebug() << "No Avatar set";
+ //kDebug() << "No Avatar set";
- KJob *job = Nepomuk::removeProperties( QList<QUrl>() << resources.imAccount(),
+ KJob *job = Nepomuk::removeProperties( QList<QUrl>() << contact.imAccount(),
QList<QUrl>() << Telepathy::avatar() );
job->exec();
if( job->error() ) {
@@ -1142,27 +1121,44 @@ void NepomukStorage::setContactAvatar(const QString &path,
}
//FIXME: Remove the old avatar from the photos list?
- // Otherwise
- Nepomuk::SimpleResource personContact(resources.personContact());
- Nepomuk::SimpleResource imAccount(resources.imAccount());
-
QUrl fileUrl( avatar.fileName );
fileUrl.setScheme(QLatin1String("file"));
+ hasInvalidResources();
+ Nepomuk::SimpleResource& personContact = m_contactGraph[contact.personContact()];
+ personContact.setUri(contact.personContact());
personContact.setProperty( NCO::photo(), fileUrl );
+
+ hasInvalidResources();
+ Nepomuk::SimpleResource& imAccount = m_contactGraph[contact.imAccount()];
+ imAccount.setUri(contact.imAccount());
imAccount.setProperty( Telepathy::avatar(), fileUrl );
- KJob *job = Nepomuk::storeResources( Nepomuk::SimpleResourceGraph() << personContact << imAccount,
- Nepomuk::IdentifyNew, Nepomuk::OverwriteProperties );
- job->exec();
+ hasInvalidResources();
+ fireContactTimer();
+ //TODO: Find a way to index the file as well.
+}
+
+void NepomukStorage::onContactTimer()
+{
+// kDebug() << m_contactGraph;
+ hasInvalidResources();
+ KJob *job = Nepomuk::storeResources( m_contactGraph, Nepomuk::IdentifyNew, Nepomuk::OverwriteProperties );
+ connect( job, SIGNAL(finished(KJob*)), this, SLOT(onContactGraphJob(KJob*)) );
+
+ m_contactGraph.clear();
+}
+
+void NepomukStorage::onContactGraphJob(KJob* job)
+{
if( job->error() ) {
kWarning() << job->errorString();
}
-
- //TODO: Find a way to index the file as well.
+ else {
+ kWarning() << "Done";
+ }
}
-
int qHash(ContactIdentifier c)
{
// FIXME: This is a shit way of doing it.
@@ -1174,6 +1170,26 @@ int qHash(ContactIdentifier c)
return qHash(temp);
}
+bool NepomukStorage::hasInvalidResources() const
+{
+ /*QList<Nepomuk::SimpleResource> list = m_contactGraph.toList();
+ foreach( const Nepomuk::SimpleResource& res, list ) {
+ if( !res.isValid() ) {
+ kWarning() << "Found invalid resource";
+ Q_ASSERT( false );
+ return true;
+ }
+ if( res.contains( Telepathy::statusType() ) ) {
+ QVariantList list = res.property( Telepathy::statusType() );
+ if( list.size() > 1 ) {
+ kWarning() << "oh noez!!";
+ Q_ASSERT( false );
+ }
+ }
+ }*/
+ return false;
+}
+
#include "nepomuk-storage.moc"
diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.h b/kpeople/nepomuk-feeder/nepomuk-storage.h
index f463c67..e6f8f64 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.h
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.h
@@ -31,9 +31,11 @@
#include <TelepathyQt/Contact>
#include <TelepathyQt/Types>
+#include <nepomuk/simpleresourcegraph.h>
+#include <KJob>
+
namespace Nepomuk {
class ResourceManager;
- class SimpleResourceGraph;
namespace Query {
class Result;
}
@@ -99,6 +101,7 @@ public:
bool operator==(const ContactResources &other) const;
bool operator!=(const ContactResources &other) const;
+ bool isEmpty() const;
private:
class Data;
QSharedDataPointer<Data> d;
@@ -149,18 +152,25 @@ private Q_SLOTS:
void onContactsQueryError(const QString &errorMessage);
void onContactsQueryFinishedListing();
+ void onContactTimer();
+ void onContactGraphJob(KJob *job);
private:
Q_DISABLE_COPY(NepomukStorage);
friend class TestBackdoors;
- void saveGraph(const Nepomuk::SimpleResourceGraph &graph);
-
Nepomuk::ResourceManager *m_resourceManager;
QUrl m_mePersonContact;
QHash<QString, AccountResources> m_accounts;
QHash<ContactIdentifier, ContactResources> m_contacts;
+
+ Nepomuk::SimpleResourceGraph m_contactGraph;
+ QTimer m_contactsTimer;
+
+ ContactResources findContact(const QString& path, const QString& id);
+ void fireContactTimer();
+ bool hasInvalidResources() const;
};
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list