[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:31 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=e0e5b6d
The following commit has been merged in the master branch:
commit e0e5b6d367e7783aeb6da369dd2998e8858c4d20
Author: Vishesh Handa <me at vhanda.in>
Date: Wed Aug 29 04:10:12 2012 +0530
NepomukFeeder class
A horrible horrible hack that I just wanted to try out. It seems to
simplify the code a lot, but is NOT the proper way of doing things as it
skips all the checks we spent years building.
The relevant code should probably go in the DMS under a new function -
overWriteProperties or something.
---
kpeople/nepomuk-feeder/CMakeLists.txt | 1 +
kpeople/nepomuk-feeder/nepomuk-storage.cpp | 184 +++++++----------------------
kpeople/nepomuk-feeder/nepomuk-storage.h | 5 -
kpeople/nepomuk-feeder/nepomukfeeder.cpp | 90 ++++++++++++++
kpeople/nepomuk-feeder/nepomukfeeder.h | 37 ++++++
5 files changed, 169 insertions(+), 148 deletions(-)
diff --git a/kpeople/nepomuk-feeder/CMakeLists.txt b/kpeople/nepomuk-feeder/CMakeLists.txt
index aa0907f..c00d067 100644
--- a/kpeople/nepomuk-feeder/CMakeLists.txt
+++ b/kpeople/nepomuk-feeder/CMakeLists.txt
@@ -53,6 +53,7 @@ set (nepomuktelepathyservice_static_SRCS
contact.cpp
abstract-storage.cpp
nepomuk-storage.cpp
+ nepomukfeeder.cpp
test-backdoors.cpp
)
diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.cpp b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
index 2dc3962..f889fd5 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.cpp
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
@@ -22,6 +22,7 @@
*/
#include "nepomuk-storage.h"
+#include "nepomukfeeder.h"
#include "telepathy.h"
#include <KDebug>
@@ -278,16 +279,6 @@ NepomukStorage::~NepomukStorage()
{
}
-void NepomukStorage::onSaveJobResult(KJob *job)
-{
- if (job->error()) {
- kWarning() << "Error Code:" << job->error() << job->errorString() << job->errorText();
- return;
- }
-
- kDebug() << "Save job succeeded.";
-}
-
void NepomukStorage::init()
{
// *********************************************************************************************
@@ -516,13 +507,10 @@ void NepomukStorage::setAccountNickname(const QString &path, const QString &nick
if( account.isEmpty() )
return;
- QUrl accountUri = account.account();
+ Nepomuk2::SimpleResource &accountRes = m_graph[account.account()];
+ accountRes.setProperty( NCO::imNickname(), nickname );
- // imNickName does not have a max cardinality of 1
- // so we cannot use to storeResources, as it will just add another value
- KJob* job = Nepomuk2::setProperty( QList<QUrl>() << accountUri, NCO::imNickname(),
- QVariantList() << nickname );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onSaveJobResult(KJob*)) );
+ fireGraphTimer();
}
void NepomukStorage::setAccountCurrentPresence(const QString &path, const Tp::SimplePresence &presence)
@@ -531,10 +519,7 @@ void NepomukStorage::setAccountCurrentPresence(const QString &path, const Tp::Si
if( account.isEmpty() )
return;
- QUrl accountUri = account.account();
-
- Nepomuk2::SimpleResource &accountRes = m_graph[accountUri];
- accountRes.setUri( accountUri );
+ Nepomuk2::SimpleResource &accountRes = m_graph[account.account()];
accountRes.setProperty(NCO::imStatus(), presence.status);
accountRes.setProperty(NCO::imStatusMessage(), presence.statusMessage);
accountRes.setProperty(Telepathy::statusType(), presence.type);
@@ -667,13 +652,10 @@ void NepomukStorage::setContactAlias(const QString &path, const QString &id, con
if( contact.isEmpty() )
return;
- QUrl imAccountUri = contact.imAccount();
+ Nepomuk2::SimpleResource &imAccount = m_graph[contact.imAccount()];
+ imAccount.setProperty( NCO::imNickname(), alias);
- // imNickName does not have a max cardinality of 1
- // so we cannot use to storeResources, as it will just add another value
- KJob* job = Nepomuk2::setProperty( QList<QUrl>() << imAccountUri, NCO::imNickname(),
- QVariantList() << alias );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onSaveJobResult(KJob*)) );
+ fireGraphTimer();
}
void NepomukStorage::setContactPresence(const QString &path,
@@ -684,16 +666,11 @@ void NepomukStorage::setContactPresence(const QString &path,
if( contact.isEmpty() )
return;
- QUrl imAccountUri = contact.imAccount();
-
- hasInvalidResources();
- Nepomuk2::SimpleResource &imAccount = m_graph[imAccountUri];
- imAccount.setUri( imAccountUri );
+ Nepomuk2::SimpleResource &imAccount = m_graph[contact.imAccount()];
imAccount.setProperty(NCO::imStatus(), presence.status);
imAccount.setProperty(NCO::imStatusMessage(), presence.statusMessage);
imAccount.setProperty(Telepathy::statusType(), presence.type);
- hasInvalidResources();
fireGraphTimer();
}
@@ -701,6 +678,7 @@ void NepomukStorage::setContactGroups(const QString &path,
const QString &id,
const QStringList &groups)
{
+ /*
//kDebug() << path << id << groups;
ContactResources contact = findContact(path, id);
if( contact.isEmpty() )
@@ -732,6 +710,7 @@ void NepomukStorage::setContactGroups(const QString &path,
contactRes.setProperty( NCO::belongsToGroup(), groupUris );
fireGraphTimer();
+ */
}
void NepomukStorage::setContactBlockStatus(const QString &path, const QString &id, bool blocked)
@@ -740,14 +719,9 @@ void NepomukStorage::setContactBlockStatus(const QString &path, const QString &i
if( contact.isEmpty() )
return;
- QUrl imAccountUri = contact.imAccount();
-
- hasInvalidResources();
- Nepomuk2::SimpleResource &imAccount = m_graph[imAccountUri];
- imAccount.setUri( imAccountUri );
+ Nepomuk2::SimpleResource &imAccount = m_graph[contact.imAccount()];
imAccount.setProperty( NCO::isBlocked(), blocked );
- hasInvalidResources();
fireGraphTimer();
}
@@ -787,35 +761,23 @@ void NepomukStorage::setContactPublishState(const QString &path,
Q_ASSERT(false);
}
+ Nepomuk2::SimpleResource &localAccountRes = m_graph[localAccountUri];
if( usRequest ) {
- Nepomuk2::SimpleResource &localAccountRes = m_graph[localAccountUri];
- localAccountRes.setUri( localAccountUri );
localAccountRes.setProperty( NCO::requestedPresenceSubscriptionTo(), imAccountUri );
-
- fireGraphTimer();
}
else {
- // Remove us from the requested-to-them list
- KJob* job = Nepomuk2::removeProperty( QList<QUrl>() << localAccountUri,
- NCO::requestedPresenceSubscriptionTo(),
- QVariantList() << imAccountUri );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onRemovePropertiesJob(KJob*)) );
+ localAccountRes.setProperty(NCO::requestedPresenceSubscriptionTo(), QVariant());
}
+ Nepomuk2::SimpleResource &imAccount = m_graph[imAccountUri];
if( themPublish ) {
- Nepomuk2::SimpleResource &imAccount = m_graph[imAccountUri];
- imAccount.setUri( imAccountUri );
imAccount.setProperty( NCO::publishesPresenceTo(), localAccountUri );
-
- fireGraphTimer();
}
else {
- // Remove us from their publish list
- KJob* job = Nepomuk2::removeProperty( QList<QUrl>() << imAccountUri,
- NCO::publishesPresenceTo(),
- QVariantList() << localAccountUri );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onRemovePropertiesJob(KJob*)) );
+ imAccount.setProperty( NCO::publishesPresenceTo(), QVariant() );
}
+
+ fireGraphTimer();
}
void NepomukStorage::setContactSubscriptionState(const QString &path,
@@ -854,35 +816,23 @@ void NepomukStorage::setContactSubscriptionState(const QString &path,
Q_ASSERT(false);
}
+ Nepomuk2::SimpleResource &localAccountRes = m_graph[localAccountUri];
if( usPublish ) {
- Nepomuk2::SimpleResource &localAccountRes = m_graph[localAccountUri];
- localAccountRes.setUri( localAccountUri );
localAccountRes.setProperty( NCO::publishesPresenceTo(), imAccountUri );
-
- fireGraphTimer();
}
else {
- // Remove us from the requested-to-them list
- KJob* job = Nepomuk2::removeProperty( QList<QUrl>() << localAccountUri,
- NCO::publishesPresenceTo(),
- QVariantList() << imAccountUri );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onRemovePropertiesJob(KJob*)) );
+ localAccountRes.setProperty( NCO::publishesPresenceTo(), QVariant() );
}
+ Nepomuk2::SimpleResource &imAccount = m_graph[imAccountUri];
if( themRequest ) {
- Nepomuk2::SimpleResource &imAccount = m_graph[imAccountUri];
- imAccount.setUri( imAccountUri );
imAccount.setProperty( NCO::requestedPresenceSubscriptionTo(), localAccountUri );
-
- fireGraphTimer();
}
else {
- // Remove us from their publish list
- KJob* job = Nepomuk2::removeProperties( QList<QUrl>() << imAccountUri,
- QList<QUrl>() << NCO::requestedPresenceSubscriptionTo()
- << NCO::publishesPresenceTo() );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onRemovePropertiesJob(KJob*)) );
+ imAccount.setProperty( NCO::requestedPresenceSubscriptionTo(), QVariant() );
}
+
+ fireGraphTimer();
}
void NepomukStorage::setContactCapabilities(const QString &path,
@@ -893,21 +843,16 @@ void NepomukStorage::setContactCapabilities(const QString &path,
if( contact.isEmpty() )
return;
- QUrl imAccountUri = contact.imAccount();
+ Nepomuk2::SimpleResource &imAccount = m_graph[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();
+ imAccount.addProperty( NCO::hasIMCapability(), NCO::imCapabilityText() );
if (capabilities.streamedMediaAudioCalls())
- capList << NCO::imCapabilityAudio();
+ imAccount.addProperty( NCO::hasIMCapability(), NCO::imCapabilityAudio() );
if (capabilities.streamedMediaVideoCalls())
- capList << NCO::imCapabilityVideo();
-
- // Cannot use storeResources as nco:hasIMCapability doesn't have a cardinality of 1
- KJob* job = Nepomuk2::setProperty(QList<QUrl>() << imAccountUri, NCO::hasIMCapability(), capList );
- connect(job, SIGNAL(finished(KJob*)), this, SLOT(onSaveJobResult(KJob*)));
+ imAccount.addProperty( NCO::hasIMCapability(), NCO::imCapabilityVideo() );
}
void NepomukStorage::setContactAvatar(const QString &path,
@@ -918,65 +863,37 @@ void NepomukStorage::setContactAvatar(const QString &path,
if( contact.isEmpty() )
return;
- if( avatar.fileName.isEmpty() ) {
- //kDebug() << "No Avatar set";
+ QUrl avatarUri;
+ if( !avatar.fileName.isEmpty() ) {
+ Nepomuk2::Resource res( avatar.fileName );
+ // Save the resource
+ res.setProperty( NAO::numericRating(), 0 );
+ res.removeProperty( NAO::numericRating() );
- KJob *job = Nepomuk2::removeProperties( QList<QUrl>() << contact.imAccount(),
- QList<QUrl>() << Telepathy::avatar() );
- job->exec();
- if( job->error() ) {
- kWarning() << job->errorString();
- }
- return;
+ avatarUri = res.uri();
}
- //FIXME: Remove the old avatar from the photos list?
- QUrl fileUrl( avatar.fileName );
- fileUrl.setScheme(QLatin1String("file"));
-
- hasInvalidResources();
+ //FIXME: Do not remove the old avatar from the photos list?
Nepomuk2::SimpleResource& personContact = m_graph[contact.personContact()];
- personContact.setUri(contact.personContact());
- personContact.setProperty( NCO::photo(), fileUrl );
+ personContact.setProperty( NCO::photo(), avatarUri );
- hasInvalidResources();
Nepomuk2::SimpleResource& imAccount = m_graph[contact.imAccount()];
- imAccount.setUri(contact.imAccount());
- imAccount.setProperty( Telepathy::avatar(), fileUrl );
+ imAccount.setProperty( Telepathy::avatar(), avatarUri );
- hasInvalidResources();
fireGraphTimer();
//TODO: Find a way to index the file as well.
}
void NepomukStorage::onContactTimer()
{
-// kDebug() << m_contactGraph;
- hasInvalidResources();
- kDebug() << m_graph;
- KJob *job = Nepomuk2::storeResources( m_graph, Nepomuk2::IdentifyNew, Nepomuk2::OverwriteProperties );
- connect( job, SIGNAL(finished(KJob*)), this, SLOT(onContactGraphJob(KJob*)) );
+ NepomukFeeder feeder;
+ feeder.setGraph( m_graph );
+ feeder.push();
m_graph.clear();
}
-void NepomukStorage::onContactGraphJob(KJob* job)
-{
- if( job->error() ) {
- kWarning() << job->errorString();
- return;
- }
- emit graphSaved();
-}
-
-void NepomukStorage::onRemovePropertiesJob(KJob* job)
-{
- if( job->error() ) {
- kWarning() << job->errorString();
- return;
- }
-}
int qHash(ContactIdentifier c)
{
@@ -989,25 +906,6 @@ int qHash(ContactIdentifier c)
return qHash(temp);
}
-bool NepomukStorage::hasInvalidResources() const
-{
- /*QList<Nepomuk2::SimpleResource> list = m_contactGraph.toList();
- foreach( const Nepomuk2::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 68f1cc4..e0b902e 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.h
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.h
@@ -143,13 +143,9 @@ signals:
private Q_SLOTS:
void init();
- void onSaveJobResult(KJob *job);
void onAccountsQueryFinishedListing();
-
void onContactTimer();
- void onContactGraphJob(KJob *job);
- void onRemovePropertiesJob(KJob *job);
private:
Q_DISABLE_COPY(NepomukStorage);
@@ -167,7 +163,6 @@ private:
AccountResources findAccount(const QString& path);
void fireGraphTimer();
- bool hasInvalidResources() const;
};
diff --git a/kpeople/nepomuk-feeder/nepomukfeeder.cpp b/kpeople/nepomuk-feeder/nepomukfeeder.cpp
new file mode 100644
index 0000000..61708c4
--- /dev/null
+++ b/kpeople/nepomuk-feeder/nepomukfeeder.cpp
@@ -0,0 +1,90 @@
+/*
+ <one line to give the library's name and an idea of what it does.>
+ Copyright (C) 2012 Vishesh Handa <me at vhanda.in>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include "nepomukfeeder.h"
+
+#include <Nepomuk2/ResourceManager>
+
+#include <Soprano/Model>
+#include <Soprano/StatementIterator>
+#include <Soprano/NodeIterator>
+#include <KDebug>
+
+void NepomukFeeder::setGraph(const Nepomuk2::SimpleResourceGraph& graph)
+{
+ m_graph = graph;
+}
+
+namespace {
+ QUrl fetchGraph( const QUrl& uri, const QUrl& prop = QUrl() ) {
+ Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
+ QList< Soprano::Node > list = model->listStatements( uri, prop, QUrl() ).iterateContexts().allNodes();
+ if( list.isEmpty() )
+ return QUrl();
+
+ return list.first().uri();
+ }
+
+ Soprano::Node variantToNode( const QVariant& var ) {
+ if( var.type() == QVariant::Url )
+ return var.toUrl();
+ else {
+ Soprano::LiteralValue lv( var );
+ return Soprano::Node( lv );
+ }
+ }
+}
+
+// TODO: Move to the DMS
+void NepomukFeeder::push()
+{
+ Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
+
+ QList<Nepomuk2::SimpleResource> resList = m_graph.toList();
+ foreach( const Nepomuk2::SimpleResource& res, resList ) {
+ const QUrl uri = res.uri();
+
+ QUrl lastGraph = fetchGraph( uri );
+
+ const Nepomuk2::PropertyHash& propHash = res.properties();
+ const QList<QUrl> keys = propHash.uniqueKeys();
+ foreach( const QUrl& prop, keys ) {
+ QList<QVariant> values = propHash.values( prop );
+
+ QUrl graph = fetchGraph( uri, prop );
+ if( graph.isEmpty() )
+ graph = lastGraph;
+
+ // This might leave some orphan graphs
+ model->removeAllStatements( uri, prop, QUrl() );
+ foreach( const QVariant& var, values ) {
+ if( var.isNull() ) {
+ continue;
+ }
+ Soprano::Statement st( uri, prop, variantToNode(var), graph );
+ kDebug() << st;
+ model->addStatement( st );
+ }
+
+ lastGraph = graph;
+ }
+ }
+}
+
diff --git a/kpeople/nepomuk-feeder/nepomukfeeder.h b/kpeople/nepomuk-feeder/nepomukfeeder.h
new file mode 100644
index 0000000..d52728b
--- /dev/null
+++ b/kpeople/nepomuk-feeder/nepomukfeeder.h
@@ -0,0 +1,37 @@
+/*
+ <one line to give the library's name and an idea of what it does.>
+ Copyright (C) 2012 Vishesh Handa <me at vhanda.in>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef NEPOMUKFEEDER_H
+#define NEPOMUKFEEDER_H
+
+#include <Nepomuk2/SimpleResource>
+#include <Nepomuk2/SimpleResourceGraph>
+
+class NepomukFeeder
+{
+public:
+ void setGraph( const Nepomuk2::SimpleResourceGraph& graph );
+ void push();
+
+private:
+ Nepomuk2::SimpleResourceGraph m_graph;
+};
+
+#endif // NEPOMUKFEEDER_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list