Commit e601f866 authored by Christian Mollekopf's avatar Christian Mollekopf

Akonadi::Tag support.

This patch introduces all the necessary client API for akonadi tags and
ports all existing functionality from Nepomuk to Akonadi.
All dependencies to nepomuk are hereby removed.

Thanks to Daniel Vratil for his share of the work.

Squashed commit from the akonadi-tags branch.
parent f62cbaec
......@@ -116,6 +116,7 @@ set( akonadikde_LIB_SRC
entitytreemodel.cpp
entitytreemodel_p.cpp
entitytreeview.cpp
entityannotationsattribute.cpp
erroroverlay.cpp
etmviewstatesaver.cpp
exception.cpp
......@@ -185,6 +186,16 @@ set( akonadikde_LIB_SRC
transactionsequence.cpp
transportresourcebase.cpp
typepluginloader.cpp
attributeentity.cpp
tag.cpp
tagmodel.cpp
tagmodel_p.cpp
tagattribute.cpp
tagcreatejob.cpp
tagmodifyjob.cpp
tagfetchscope.cpp
tagfetchjob.cpp
tagdeletejob.cpp
unlinkjob.cpp
# Temporary until ported to Qt-plugin framework
pluginloader.cpp
......@@ -210,11 +221,11 @@ endif()
# DBus interfaces and adaptors
set(akonadi_xml ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.NotificationManager.xml)
set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessagev2_p.h" )
set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessagev3_p.h" )
qt4_add_dbus_interface( akonadikde_LIB_SRC ${akonadi_xml} notificationmanagerinterface )
set(akonadi_xml ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.NotificationSource.xml)
set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessagev2_p.h" )
set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessagev3_p.h" )
qt4_add_dbus_interface( akonadikde_LIB_SRC ${akonadi_xml} notificationsourceinterface )
qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.AgentManager.xml )
......@@ -306,6 +317,7 @@ install( FILES
agenttypedialog.h
attribute.h
attributefactory.h
attributeentity.h
cachepolicy.h
cachepolicypage.h
changerecorder.h
......@@ -349,6 +361,7 @@ install( FILES
entitytreeview.h
entitytreeviewstatesaver.h
etmviewstatesaver.h
entityannotationsattribute.h
exception.h
favoritecollectionsmodel.h
gid/gidextractorinterface.h
......@@ -390,6 +403,14 @@ install( FILES
specialcollectionsdiscoveryjob.h
standardactionmanager.h
statisticsproxymodel.h
tagattribute.h
tag.h
tagmodel.h
tagmodifyjob.h
tagcreatejob.h
tagfetchjob.h
tagfetchscope.h
tagdeletejob.h
trashjob.h
trashrestorejob.h
trashsettings.h
......
/*
Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attributeentity.h"
#include <QHash>
#include <QSet>
using namespace Akonadi;
struct Akonadi::AttributeEntity::Private
{
Private()
{}
~Private()
{
qDeleteAll( mAttributes );
}
Private(const Private &other)
{
Q_FOREACH (Attribute *attr, other.mAttributes) {
mAttributes.insert(attr->type(), attr->clone());
}
mDeletedAttributes = other.mDeletedAttributes;
}
QHash<QByteArray, Attribute*> mAttributes;
QSet<QByteArray> mDeletedAttributes;
};
AttributeEntity::AttributeEntity()
:d_ptr(new Private)
{
}
AttributeEntity::AttributeEntity(const AttributeEntity &other)
:d_ptr(new Private)
{
operator=(other);
}
AttributeEntity::~AttributeEntity()
{
}
Akonadi::AttributeEntity& Akonadi::AttributeEntity::operator=(const Akonadi::AttributeEntity &other)
{
QHash<QByteArray, Attribute*>::const_iterator it = other.d_ptr->mAttributes.constBegin();
for (; it != other.d_ptr->mAttributes.constEnd(); it++) {
d_ptr->mAttributes.insert(it.key(), it.value()->clone());
}
d_ptr->mDeletedAttributes = other.d_ptr->mDeletedAttributes;
return *this;
}
void AttributeEntity::addAttribute(Attribute * attr)
{
if (d_ptr->mAttributes.contains(attr->type())) {
Attribute *existing = d_ptr->mAttributes.value(attr->type());
if (attr == existing) {
return;
}
d_ptr->mAttributes.remove(attr->type());
delete existing;
}
d_ptr->mAttributes.insert(attr->type(), attr);
d_ptr->mDeletedAttributes.remove(attr->type());
}
void AttributeEntity::removeAttribute(const QByteArray &type)
{
d_ptr->mDeletedAttributes.insert(type);
delete d_ptr->mAttributes.take(type);
}
bool AttributeEntity::hasAttribute(const QByteArray & type) const
{
return d_ptr->mAttributes.contains(type);
}
Attribute::List AttributeEntity::attributes() const
{
return d_ptr->mAttributes.values();
}
void Akonadi::AttributeEntity::clearAttributes()
{
Q_FOREACH ( Attribute *attr, d_ptr->mAttributes ) {
d_ptr->mDeletedAttributes.insert( attr->type() );
delete attr;
}
d_ptr->mAttributes.clear();
}
Attribute *AttributeEntity::attribute(const QByteArray & type) const
{
if (d_ptr->mAttributes.contains(type)) {
return d_ptr->mAttributes.value(type);
}
return 0;
}
QSet<QByteArray>& AttributeEntity::removedAttributes() const
{
return d_ptr->mDeletedAttributes;
}
/*
Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef AKONADI_ATTRIBUTEENTITY_H
#define AKONADI_ATTRIBUTEENTITY_H
#include <akonadi/job.h>
#include <QVector>
#include <qsharedpointer.h>
#include "attribute.h"
#include <kdebug.h>
namespace Akonadi {
/**
* Parent class for entities that can have attributes.
* This is supposed to eventually share the code between Akonadi::Tag and Akonadi::Entity.
*
* In the current form using this in Akonadi::Entity would break the implicit sharing of it's private class,
* so AttributeEntity::Private would need to become a parent class of EntityPrivate and use the same clone()
* calls etc.
* An even better solution is probably ot make AttributeEntity a private member of Entity, with all Attribute related member functions forwarding to this class.
*/
class AKONADI_EXPORT AttributeEntity {
public:
AttributeEntity();
AttributeEntity(const AttributeEntity &);
virtual ~AttributeEntity();
//Each subclass must override this to avoid slicing
virtual AttributeEntity &operator=(const AttributeEntity &);
/**
* Adds an attribute to the entity.
*
* If an attribute of the same type name already exists, it is deleted and
* replaced with the new one.
*
* @param attribute The new attribute.
*
* @note The entity takes the ownership of the attribute.
*/
void addAttribute( Attribute *attribute );
/**
* Removes and deletes the attribute of the given type @p name.
*/
void removeAttribute( const QByteArray &name );
/**
* Returns @c true if the entity has an attribute of the given type @p name,
* false otherwise.
*/
bool hasAttribute( const QByteArray &name ) const;
/**
* Returns a list of all attributes of the entity.
*/
Attribute::List attributes() const;
/**
* Removes and deletes all attributes of the entity.
*/
void clearAttributes();
/**
* Returns the attribute of the given type @p name if available, 0 otherwise.
*/
Attribute* attribute( const QByteArray &name ) const;
/**
* Describes the options that can be passed to access attributes.
*/
enum CreateOption {
AddIfMissing ///< Creates the attribute if it is missing
};
/**
* Returns the attribute of the requested type.
* If the entity has no attribute of that type yet, a new one
* is created and added to the entity.
*
* @param option The create options.
*/
template <typename T> inline T* attribute( CreateOption option )
{
Q_UNUSED( option );
const T dummy;
if ( hasAttribute( dummy.type() ) ) {
T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
if ( attr ) {
return attr;
}
kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
<< ". Did you forget to call AttributeFactory::registerAttribute()?";
}
T* attr = new T();
addAttribute( attr );
return attr;
}
/**
* Returns the attribute of the requested type or 0 if it is not available.
*/
template <typename T> inline T* attribute() const
{
const T dummy;
if ( hasAttribute( dummy.type() ) ) {
T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
if ( attr )
return attr;
kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
<< ". Did you forget to call AttributeFactory::registerAttribute()?";
}
return 0;
}
/**
* Removes and deletes the attribute of the requested type.
*/
template <typename T> inline void removeAttribute()
{
const T dummy;
removeAttribute( dummy.type() );
}
/**
* Returns whether the entity has an attribute of the requested type.
*/
template <typename T> inline bool hasAttribute() const
{
const T dummy;
return hasAttribute( dummy.type() );
}
private:
friend class TagModifyJob;
QSet<QByteArray> &removedAttributes() const;
class Private;
QSharedPointer<Private> d_ptr;
};
}
#endif
\ No newline at end of file
......@@ -26,6 +26,8 @@
#include "indexpolicyattribute.h"
#include "persistentsearchattribute.h"
#include "entitydeletedattribute.h"
#include "tagattribute.h"
#include "entityannotationsattribute.h"
#include <KGlobal>
......@@ -81,6 +83,8 @@ class StaticAttributeFactory : public AttributeFactory
AttributeFactory::registerAttribute<IndexPolicyAttribute>();
AttributeFactory::registerAttribute<PersistentSearchAttribute>();
AttributeFactory::registerAttribute<EntityDeletedAttribute>();
AttributeFactory::registerAttribute<EntityAnnotationsAttribute>();
AttributeFactory::registerAttribute<TagAttribute>();
}
bool initialized;
};
......
......@@ -95,3 +95,8 @@ ItemListCache* ChangeNotificationDependenciesFactory::createItemListCache(int ma
{
return new ItemListCache( maxCapacity, session );
}
TagListCache* ChangeNotificationDependenciesFactory::createTagListCache( int maxCapacity, Session *session )
{
return new TagListCache( maxCapacity, session );
}
......@@ -42,6 +42,7 @@ public:
virtual Akonadi::CollectionCache* createCollectionCache(int maxCapacity, Session *session);
virtual Akonadi::ItemCache* createItemCache(int maxCapacity, Session *session);
virtual Akonadi::ItemListCache* createItemListCache(int maxCapacity, Session *session);
virtual Akonadi::TagListCache* createTagListCache(int maxCapacity, Session *session);
};
}
......
......@@ -61,7 +61,7 @@ void ChangeRecorder::replayNext()
return;
if ( !d->pendingNotifications.isEmpty() ) {
const NotificationMessageV2 msg = d->pendingNotifications.head();
const NotificationMessageV3 msg = d->pendingNotifications.head();
if ( d->ensureDataAvailable( msg ) ) {
if ( !d->emitNotification( msg ) ) {
//If no signal was emitted (e.g. because noone was connected to it), noone is going to call changeProcessed, so we help ourselves
......
......@@ -44,7 +44,7 @@ int ChangeRecorderPrivate::pipelineSize() const
return MonitorPrivate::pipelineSize();
}
void ChangeRecorderPrivate::slotNotify(const Akonadi::NotificationMessageV2::List &msgs)
void ChangeRecorderPrivate::slotNotify(const Akonadi::NotificationMessageV3::List &msgs)
{
Q_Q( ChangeRecorder );
const int oldChanges = pendingNotifications.size();
......@@ -83,7 +83,7 @@ void ChangeRecorderPrivate::loadNotifications()
for ( int i = 0; i < size; ++i ) {
settings->setArrayIndex( i );
NotificationMessageV2 msg;
NotificationMessageV3 msg;
msg.setSessionId( settings->value( QLatin1String( "sessionId" ) ).toByteArray() );
msg.setType( (NotificationMessageV2::Type)settings->value( QLatin1String( "type" ) ).toInt() );
msg.setOperation( (NotificationMessageV2::Operation)settings->value( QLatin1String( "op" ) ).toInt() );
......@@ -124,11 +124,11 @@ void ChangeRecorderPrivate::loadNotifications()
notificationsLoaded();
}
static const quint64 s_currentVersion = Q_UINT64_C(0x000200000000);
static const quint64 s_currentVersion = Q_UINT64_C(0x000300000000);
static const quint64 s_versionMask = Q_UINT64_C(0xFFFF00000000);
static const quint64 s_sizeMask = Q_UINT64_C(0x0000FFFFFFFF);
QQueue<NotificationMessageV2> ChangeRecorderPrivate::loadFrom(QIODevice *device)
QQueue<NotificationMessageV3> ChangeRecorderPrivate::loadFrom(QIODevice *device)
{
QDataStream stream( device );
stream.setVersion( QDataStream::Qt_4_6 );
......@@ -138,8 +138,9 @@ QQueue<NotificationMessageV2> ChangeRecorderPrivate::loadFrom(QIODevice *device)
quint64 uid, parentCollection, parentDestCollection;
QString remoteId, mimeType, remoteRevision;
QSet<QByteArray> itemParts, addedFlags, removedFlags;
QSet<qint64> addedTags, removedTags;
QQueue<NotificationMessageV2> list;
QQueue<NotificationMessageV3> list;
quint64 sizeAndVersion;
stream >> sizeAndVersion;
......@@ -183,9 +184,9 @@ QQueue<NotificationMessageV2> ChangeRecorderPrivate::loadFrom(QIODevice *device)
msg.setParentDestCollection( parentDestCollection );
msg.setItemParts( itemParts );
} else if ( version == 2 ) {
} else if ( version == 2 || version == 3 ) {
NotificationMessageV2 msg;
NotificationMessageV3 msg;
stream >> sessionId;
stream >> type;
......@@ -205,6 +206,10 @@ QQueue<NotificationMessageV2> ChangeRecorderPrivate::loadFrom(QIODevice *device)
stream >> itemParts;
stream >> addedFlags;
stream >> removedFlags;
if ( version == 3 ) {
stream >> addedTags;
stream >> removedTags;
}
if ( i < startOffset )
continue;
......@@ -219,6 +224,8 @@ QQueue<NotificationMessageV2> ChangeRecorderPrivate::loadFrom(QIODevice *device)
msg.setItemParts( itemParts );
msg.setAddedFlags( addedFlags );
msg.setRemovedFlags( removedFlags );
msg.setAddedTags( addedTags );
msg.setRemovedTags( removedTags );
list << msg;
}
......@@ -245,6 +252,7 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
quint64 parentCollection, parentDestCollection;
QString remoteId, remoteRevision, mimeType;
QSet<QByteArray> itemParts, addedFlags, removedFlags;
QSet<qint64> addedTags, removedTags;
QVariantList items;
QStringList list;
......@@ -280,6 +288,10 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
stream >> itemParts;
stream >> addedFlags;
stream >> removedFlags;
if ( version == 3 ) {
stream >> addedTags;
stream >> removedTags;
}
if ( i < startOffset )
continue;
......@@ -292,6 +304,9 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
case NotificationMessageV2::Items:
typeString = QLatin1String( "Items" );
break;
case NotificationMessageV2::Tags:
typeString = QLatin1String( "Tags" );
break;
default:
typeString = QLatin1String( "InvalidType" );
break;
......@@ -308,6 +323,9 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
case NotificationMessageV2::ModifyFlags:
operationString = QLatin1String( "ModifyFlags" );
break;
case NotificationMessageV2::ModifyTags:
operationString = QLatin1String( "ModifyTags" );
break;
case NotificationMessageV2::Move:
operationString = QLatin1String( "Move" );
break;
......@@ -331,15 +349,19 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
break;
};
QStringList itemPartsList, addedFlagsList, removedFlagsList;
QStringList itemPartsList, addedFlagsList, removedFlagsList, addedTagsList, removedTagsList;
foreach( const QByteArray &b, itemParts )
itemPartsList.push_back( QString::fromLatin1(b) );
foreach( const QByteArray &b, addedFlags )
addedFlagsList.push_back( QString::fromLatin1(b) );
foreach( const QByteArray &b, removedFlags )
removedFlagsList.push_back( QString::fromLatin1(b) );
foreach( qint64 id, addedTags )
addedTagsList.push_back( QString::number( id ) );
foreach( qint64 id, removedTags )
removedTagsList.push_back( QString::number( id ) ) ;
const QString entry = QString::fromLatin1("session=%1 type=%2 operation=%3 items=%4 resource=%5 destResource=%6 parentCollection=%7 parentDestCollection=%8 itemParts=%9 addedFlags=%10 removedFlags=%11")
const QString entry = QString::fromLatin1("session=%1 type=%2 operation=%3 items=%4 resource=%5 destResource=%6 parentCollection=%7 parentDestCollection=%8 itemParts=%9 addedFlags=%10 removedFlags=%11 addedTags=%12 removedTags=%13")
.arg( QString::fromLatin1( sessionId ) )
.arg( typeString )
.arg( operationString )
......@@ -350,7 +372,9 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
.arg( parentDestCollection )
.arg( itemPartsList.join(QLatin1String(", " )) )
.arg( addedFlagsList.join(QLatin1String( ", " )) )
.arg( removedFlagsList.join(QLatin1String( ", " )) );
.arg( removedFlagsList.join(QLatin1String( ", " )) )
.arg( addedTagsList.join(QLatin1String(", ")) )
.arg( removedTagsList.join(QLatin1String(", ")) );
result += entry + QLatin1Char('\n');
}
......@@ -358,7 +382,7 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
return result;
}
void ChangeRecorderPrivate::addToStream(QDataStream &stream, const NotificationMessageV2 &msg)
void ChangeRecorderPrivate::addToStream(QDataStream &stream, const NotificationMessageV3 &msg)
{
stream << msg.sessionId();
stream << int(msg.type());
......@@ -377,6 +401,8 @@ void ChangeRecorderPrivate::addToStream(QDataStream &stream, const NotificationM
stream << msg.itemParts();
stream << msg.addedFlags();
stream << msg.removedFlags();
stream << msg.addedTags();
stream << msg.removedTags();
}
void ChangeRecorderPrivate::writeStartOffset()
......@@ -438,7 +464,7 @@ void ChangeRecorderPrivate::saveTo(QIODevice *device)
//kDebug() << "Saving" << pendingNotifications.count() << "notifications (full save)";
for ( int i = 0; i < pendingNotifications.count(); ++i ) {
const NotificationMessageV2 msg = pendingNotifications.at( i );
const NotificationMessageV3 msg = pendingNotifications.at( i );
addToStream( stream, msg );
}
}
......
......@@ -42,14 +42,14 @@ class AKONADI_TESTS_EXPORT ChangeRecorderPrivate : public Akonadi::MonitorPrivat
virtual void notificationsEnqueued( int count );
virtual void notificationsErased();
virtual void slotNotify( const NotificationMessageV2::List &msgs );
virtual void slotNotify( const NotificationMessageV3::List &msgs );
QString notificationsFileName() const;
void loadNotifications();
QQueue<NotificationMessageV2> loadFrom( QIODevice *device );
QQueue<NotificationMessageV3> loadFrom( QIODevice *device );
QString dumpNotificationListToString() const;
void addToStream( QDataStream &stream, const NotificationMessageV2 &msg );
void addToStream( QDataStream &stream, const NotificationMessageV3 &msg );
void saveNotifications();
void saveTo( QIODevice *device );
private:
......
......@@ -5,15 +5,8 @@ include_directories(
${Boost_INCLUDE_DIR}
${CMAKE_BINARY_DIR}/kabc
${CMAKE_SOURCE_DIR}/kabc
${NEPOMUK_CORE_INCLUDE_DIR}
)
if (Soprano_FOUND)
include_directories(
${SOPRANO_INCLUDE_DIR}
)
endif()
find_package(Prison QUIET)
set_package_properties(Prison PROPERTIES DESCRIPTION "Prison" URL "http://projects.kde.org/prison" TYPE OPTIONAL PURPOSE "Needed to show mobile barcodes of your contacts")
if (PRISON_FOUND)
......@@ -168,7 +161,6 @@ target_link_libraries(akonadi-contact akonadi-kde
kpimutils
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
${NEPOMUK_CORE_LIBRARY}