/usr/include/akonadi/entity.h is in kdepimlibs5-dev 4:4.8.5-0ubuntu0.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | /*
Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
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_ENTITY_H
#define AKONADI_ENTITY_H
#include "akonadi_export.h"
namespace Akonadi {
class Entity;
}
AKONADI_EXPORT uint qHash( const Akonadi::Entity& );
#include <akonadi/attribute.h>
#include <KDE/KDebug>
#include <QtCore/QHash>
#include <QtCore/QSharedDataPointer>
#define AKONADI_DECLARE_PRIVATE( Class ) \
Class##Private* d_func(); \
const Class##Private* d_func() const; \
friend class Class##Private;
namespace Akonadi {
class Collection;
class EntityPrivate;
/**
* @short The base class for Item and Collection.
*
* Entity is the common base class for Item and Collection that provides
* unique IDs and attributes handling.
*
* This class is not meant to be used directly, use Item or Collection instead.
*
* @author Tobias Koenig <tokoe@kde.org>
*/
class AKONADI_EXPORT Entity
{
public:
/**
* Describes the unique id type.
*/
typedef qint64 Id;
/**
* Sets the unique @p identifier of the entity.
*/
void setId( Id identifier );
/**
* Returns the unique identifier of the entity.
*/
Id id() const;
/**
* Sets the remote @p id of the entity.
*/
void setRemoteId( const QString& id );
/**
* Returns the remote id of the entity.
*/
QString remoteId() const;
/**
* Sets the remote @p revision of the entity.
*
* The remote revision can be used by resources to store some
* revision information of the backend to detect changes there.
*
* @note This method is supposed to be used by resources only.
* @since 4.5
*/
void setRemoteRevision( const QString& revision );
/**
* Returns the remote revision of the entity.
*
* @note This method is supposed to be used by resources only.
* @since 4.5
*/
QString remoteRevision() const;
/**
* Returns whether the entity is valid.
*/
bool isValid() const;
/**
* Returns whether the entity's id equals the
* id of the @p other entity.
*/
bool operator==( const Entity &other ) const;
/**
* Returns whether the entity's id does not equal the id
* of the @p other entity.
*/
bool operator!=( const Entity &other ) const;
/**
* Assigns the @p other to this entity and returns a reference to this entity.
*/
Entity& operator=( const Entity &other );
/**
* @internal For use with containers only.
*
* @since 4.8
*/
bool operator<( const Entity &other ) const;
/**
* Returns the parent collection of this object.
* @note This will of course only return a useful value if it was explictly retrieved
* from the Akonadi server.
* @since 4.4
*/
Collection parentCollection() const;
/**
* Returns a reference to the parent collection of this object.
* @note This will of course only return a useful value if it was explictly retrieved
* from the Akonadi server.
* @since 4.4
*/
Collection& parentCollection();
/**
* Set the parent collection of this object.
* @note Calling this method has no immediate effect for the object itself,
* such as being moved to another collection.
* It is mainly relevant to provide a context for RID-based operations
* inside resources.
* @param parent The parent collection.
* @since 4.4
*/
void setParentCollection( const Collection &parent );
/**
* 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() );
}
protected:
/**
* Creates an entity from an @p other entity.
*/
Entity( const Entity &other );
/**
* Destroys the entity.
*/
~Entity();
//@cond PRIVATE
Entity( EntityPrivate *dd );
QSharedDataPointer<EntityPrivate> d_ptr;
//@endcond
AKONADI_DECLARE_PRIVATE( Entity )
};
}
#endif
|