smf/smfservermodule/smfcommon/smfactions.h
changeset 18 013a02bf2bb0
equal deleted inserted replaced
17:106a4bfcb866 18:013a02bf2bb0
       
     1 /**
       
     2  * Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the "Eclipse Public License v1.0"
       
     6  * which accompanies  this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html"
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
       
    11  *
       
    12  * Contributors:
       
    13  * Manasij Roy, Nalina Hariharan
       
    14  *
       
    15  * Description:
       
    16  * Represents activities in terms similar to standard activity stream http://activitystrea.ms/
       
    17  */
       
    18 
       
    19 #ifndef SMFACTIONS_H_
       
    20 #define SMFACTIONS_H_
       
    21 
       
    22 #include <QList>
       
    23 #include <QImage>
       
    24 #include <QDateTime>
       
    25 #include <QStringList>
       
    26 #include <QUrl>
       
    27 #include <qdatastream.h>
       
    28 #include <QSharedData>
       
    29 #include <QMetaType>
       
    30 
       
    31 #include "smfclientglobal.h"
       
    32 #include "smfpost.h"
       
    33 #include "smfcontact.h"
       
    34 
       
    35 /**
       
    36  * Implementation const
       
    37  */
       
    38 const int MaxSmfActivityEntrySize = 5000;
       
    39 
       
    40 /**
       
    41  * The actions in the activity based on Atom Activity Base Schema
       
    42  * see http://activitystrea.ms/schema/1.0/activity-schema-01.html
       
    43  */
       
    44 enum SmfActivityVerb
       
    45 	{
       
    46 	SmfActivityMarkAsFavorite,
       
    47 	SmfActivityStartFollowing,
       
    48 	SmfActivityMarkLiked,
       
    49 	SmfActivityMakeFriend,
       
    50 	SmfActivityJoin,
       
    51 	SmfActivityPlay,
       
    52 	SmfActivityPost,
       
    53 	SmfActivitySave,
       
    54 	SmfActivityShare,
       
    55 	SmfActivityTag,
       
    56 	SmfActivityUpdate
       
    57 	};
       
    58 
       
    59 /**
       
    60  * The type of the object on which the activity is performed - as per Atom Activity Base Schema
       
    61  * see http://activitystrea.ms/schema/1.0/activity-schema-01.html
       
    62  */
       
    63 enum SmfActivityObjectType
       
    64 	{
       
    65 	SmfActivityObjTypeArticle,
       
    66 	SmfActivityObjTypeAudio,
       
    67 	SmfActivityObjTypeBookmark,
       
    68 	SmfActivityObjTypeComment,
       
    69 	SmfActivityObjTypeFile,
       
    70 	SmfActivityObjTypeFolder,
       
    71 	SmfActivityObjTypeGroup,
       
    72 	SmfActivityObjTypeList,
       
    73 	SmfActivityObjTypeNote,
       
    74 	SmfActivityObjTypePerson,
       
    75 	SmfActivityObjTypePhoto,
       
    76 	SmfActivityObjTypePhotoAlbum,
       
    77 	SmfActivityObjTypePlace,
       
    78 	SmfActivityObjTypePlaylist,
       
    79 	SmfActivityObjTypeProduct,
       
    80 	SmfActivityObjTypeReview,
       
    81 	SmfActivityObjTypeService,
       
    82 	SmfActivityObjTypeStatus,
       
    83 	SmfActivityObjTypeVideo,
       
    84 	SmfActivityObjTypeMusic,
       
    85 	SmfActivityObjTypeEvent,
       
    86 	SmfActivityObjTypeAdvanced
       
    87 	};
       
    88 
       
    89 enum SmfActivityFor
       
    90 	{
       
    91 		SmfActivitySelf,
       
    92 		SmfActivityFriend,
       
    93 		SmfActivityOthers
       
    94 	};
       
    95 
       
    96 class SmfActivityObjectPrivate;
       
    97 //class SmfActivityEntryPrivate;
       
    98 
       
    99 /**
       
   100  * @ingroup smf_common_group
       
   101  * The object class represents an object in an activity (e.g.a picture or a music track on which somebody commented)
       
   102  */
       
   103 class SMFCOMMON_EXPORT SmfActivityObject 
       
   104 	{
       
   105 public:
       
   106 	/**
       
   107 	 * Constructor
       
   108 	 */
       
   109 	SmfActivityObject();
       
   110 
       
   111 	/**
       
   112 	 * Copy Constructor
       
   113 	 */
       
   114 	SmfActivityObject(const SmfActivityObject& aOther);
       
   115 	
       
   116 	/**
       
   117 	 * Overloaded = operator
       
   118 	 * @param aOther The reference object
       
   119 	 * @return The target reference value
       
   120 	 */
       
   121 	SmfActivityObject& operator=( const SmfActivityObject &aOther );
       
   122 	
       
   123 	/**
       
   124 	 * Destructor
       
   125 	 */
       
   126 	~SmfActivityObject();
       
   127 
       
   128 	/**
       
   129 	 * @return returns service specific Id of this object in the entry 
       
   130 	 */
       
   131 	QString id() const;
       
   132 	
       
   133 	/**
       
   134 	 * @return returns thumbnail if availabel for this object in the entry
       
   135 	 */
       
   136 	QImage thumbnail() const;
       
   137 	
       
   138 	/**
       
   139 	 * @return Captions for this object
       
   140 	 */
       
   141 	QString caption() const;
       
   142 	
       
   143 	/**
       
   144 	 * @return retruns the type of this object
       
   145 	 */
       
   146 	SmfActivityObjectType type( ) const;
       
   147 	
       
   148 	/**
       
   149 	 * @return returns data of the object - see type() for casting
       
   150 	 */
       
   151 	QVariant objData() const;
       
   152 	
       
   153 	/**
       
   154 	 * @return url of this object, e.g. url of the image on which somebody commented
       
   155 	 */
       
   156 	QString link() const;
       
   157 	
       
   158 	/**
       
   159 	 * @return Time of creation of this object
       
   160 	 */
       
   161 	QDateTime time() const;
       
   162 	
       
   163 	/**
       
   164 	 * @return Description of the content of this object
       
   165 	 */
       
   166 	QString content() const;
       
   167 
       
   168 	/**
       
   169 	 * Sets service specific id for this object
       
   170 	 * @param aId The id to be set
       
   171 	 */
       
   172 	void setId(const QString& aId);
       
   173 	
       
   174 	/**
       
   175 	 * Sets thumbnail for this object , not mandatory
       
   176 	 * @param aIcon The thumbnail image
       
   177 	 */
       
   178 	void setThumbnail(const QImage& aIcon);
       
   179 	
       
   180 	/**
       
   181 	 * Sets caption for this object
       
   182 	 * @param aCaption The caption to be set
       
   183 	 */
       
   184 	void setCaption(const QString& aCap);
       
   185 	
       
   186 	/**
       
   187 	 * Sets type of this object - ObjData should be set next accordingly
       
   188 	 * @param aObjType The activity type to be set
       
   189 	 */
       
   190 	void setType(const SmfActivityObjectType& aObjType);
       
   191 	
       
   192 	/**
       
   193 	 * Sets object data e,g, SmfImage, SmfComment, SmfMusic, SmfEvent etc
       
   194 	 * setType() with suitable type should have been called before  
       
   195 	 * @param aData The object data to be set  
       
   196 	 */
       
   197 	void setObjData( const QVariant& aData);
       
   198 	
       
   199 	/**
       
   200 	 * Sets the url for the object
       
   201 	 * @param aLink The Link to be set
       
   202 	 */
       
   203 	void setLink( const QString& aLink);
       
   204 	
       
   205 	/**
       
   206 	 * Sets the time of creation/last modification of the object
       
   207 	 * @param aTime The time to be set
       
   208 	 */
       
   209 	void setTime( const QDateTime& aTime);
       
   210 	
       
   211 	/**
       
   212 	 * Sets the description of the content of this object
       
   213 	 * @param aText The content to be set
       
   214 	 */
       
   215 	void setContent( const QString& aText) ;
       
   216 	
       
   217 private:
       
   218 	QSharedDataPointer<SmfActivityObjectPrivate> d;
       
   219 	
       
   220 	friend QDataStream& operator >> ( QDataStream &aOut, SmfActivityObject& aData);
       
   221 	friend QDataStream& operator << ( QDataStream &aIn, const SmfActivityObject& aData);	
       
   222 	};
       
   223 
       
   224 SMFCOMMON_EXPORT QDataStream& operator >> ( QDataStream &aOut, SmfActivityObject& aData);
       
   225 SMFCOMMON_EXPORT QDataStream& operator << ( QDataStream &aIn, const SmfActivityObject& aData);	
       
   226 
       
   227 typedef QList<SmfActivityObject> SmfActivityObjectList;
       
   228 
       
   229 // Make the class SmfActivityObject known to QMetaType, so that as to register it.
       
   230 Q_DECLARE_METATYPE(SmfActivityObject)
       
   231 Q_DECLARE_METATYPE(QList<SmfActivityObject>)
       
   232 
       
   233 
       
   234 class SmfActivityEntryPrivate: public QSharedData
       
   235 	{
       
   236 public:
       
   237 	SmfActivityEntryPrivate( ) {
       
   238 		m_id.clear();
       
   239 	}
       
   240 	
       
   241 	SmfActivityEntryPrivate( const SmfActivityEntryPrivate& aOther ) :
       
   242 		QSharedData (aOther),
       
   243 		m_id (aOther.m_id),
       
   244 		m_title (aOther.m_title),
       
   245 		m_details (aOther.m_details),
       
   246 		m_author (aOther.m_author),
       
   247 		m_actionName (aOther.m_actionName),
       
   248 		m_activities (aOther.m_activities),
       
   249 		m_targetObj (aOther.m_targetObj)  { }
       
   250 
       
   251 	~SmfActivityEntryPrivate( ) { }
       
   252 	
       
   253 	/**
       
   254 	 * Data members
       
   255 	 */
       
   256 	QString m_id;
       
   257 	SmfPost m_title;
       
   258 	SmfPost m_details;
       
   259 	SmfContact m_author;
       
   260 	SmfActivityVerb m_actionName;
       
   261 	QList<SmfActivityObject> m_activities;
       
   262 	SmfActivityObject m_targetObj;
       
   263 	};
       
   264 
       
   265 /**
       
   266  * @ingroup smf_common_group
       
   267  * The object class represents an entry in the list of activities 
       
   268  */
       
   269 class SMFCOMMON_EXPORT SmfActivityEntry
       
   270 	{
       
   271 
       
   272 public:
       
   273 	
       
   274 	SmfActivityEntry();
       
   275 	SmfActivityEntry(const SmfActivityEntry& aOther);
       
   276 	~SmfActivityEntry();
       
   277 	
       
   278 	/**
       
   279 	 * @return Returns service specific id of the of entry 
       
   280 	 */
       
   281 	QString id() const;
       
   282 	/**
       
   283 	 * @return Returns the title of the entry - mostly be a string 
       
   284 	 */
       
   285 	SmfPost title() const;
       
   286 
       
   287 	/**
       
   288 	 * @return Returns detail descriptiopn of this entry in the activity list. might be absent if title is sufficient
       
   289 	 */
       
   290 	SmfPost details() const;
       
   291 	
       
   292 	/**
       
   293 	 * @return Returns the author of the activity - the name and the uri field are most commonly used
       
   294 	 * Other information fields might be empty
       
   295 	 */
       
   296 	SmfContact author() const;
       
   297 	
       
   298 	/**
       
   299 	 * @return Returns the verb of the activity ,e.g. Robin "marked" Joseph as a friend   
       
   300 	 */
       
   301 	SmfActivityVerb actionName() const;
       
   302 
       
   303 	/**
       
   304 	 * There can be multiple objects in a single activity entry, though this may be rare - only for few verbs.
       
   305 	 * @return list of activity objects (mostly one object)
       
   306 	 */
       
   307 	QList<SmfActivityObject> activities() const;
       
   308 	
       
   309 	/**
       
   310 	 * @return Returns information about the target of the activity, for verbs that support a target.
       
   311 	 * For example, a target is a photo album to which photos were added
       
   312 	 */
       
   313 	SmfActivityObject targetObj() const;
       
   314 
       
   315 	/**
       
   316 	 * Sets service specific id of the of entry 
       
   317 	 * @param aId The id to be set
       
   318 	 */
       
   319 	bool setId( const QString& aId);
       
   320 	
       
   321 	/**
       
   322 	 * Sets the title of the entry - mostly be a string
       
   323 	 * @param aTitle The title to be set 
       
   324 	 */
       
   325 	bool setTitle(const SmfPost& aTitle);
       
   326 
       
   327 	/**
       
   328 	 * Sets detail description of this entry in the activity list. might be absent if title is sufficient
       
   329 	 * @param aDetails The details to be set
       
   330 	 */
       
   331 	bool setDetails(const SmfPost& aDetails);
       
   332 	
       
   333 	/**
       
   334 	 * Sets the author of the activity - the name and the uri field are most commonly used
       
   335 	 * Oher information fields might be empty
       
   336 	 * @param aContact The author to be set
       
   337 	 */
       
   338 	bool setAuthor(const SmfContact& aContact);
       
   339 	
       
   340 	/**
       
   341 	 * Sets the verb of the activity ,e.g. Robin "marked" Joseph as a friend
       
   342 	 * @param aVerb The action name to be set   
       
   343 	 */
       
   344 	void setActionName(SmfActivityVerb  aVerb);
       
   345 
       
   346 	/**
       
   347 	 * Sets single or multiple objects in a single activity entry, though multiple may be rare - only for few verbs.
       
   348 	 * @param list of activity objects (mostly one object)
       
   349 	 */
       
   350 	bool setActivities(QList<SmfActivityObject>& aList);
       
   351 	
       
   352 	/**
       
   353 	 * Returns information about the target of the activity, for verbs that support a target.
       
   354 	 * For example, a target is a photo album to which photos were added
       
   355 	 * @param aTarget The activity object to be set
       
   356 	 */
       
   357 	bool setTargetObj(const SmfActivityObject& aTarget);
       
   358 	
       
   359 private:
       
   360 	QSharedDataPointer<SmfActivityEntryPrivate> d;
       
   361 	
       
   362 	friend QDataStream& operator >> ( QDataStream &aOut, SmfActivityEntry& aData);
       
   363 	friend QDataStream& operator << ( QDataStream &aIn, const SmfActivityEntry& aData);	
       
   364 	};
       
   365 
       
   366 SMFCOMMON_EXPORT QDataStream& operator >> ( QDataStream &aOut, SmfActivityEntry& aData);
       
   367 SMFCOMMON_EXPORT QDataStream& operator << ( QDataStream &aIn, const SmfActivityEntry& aData);	
       
   368 
       
   369 typedef QList<SmfActivityEntry> SmfActivityEntryList;
       
   370 
       
   371 // Make the class SmfActivityEntry known to QMetaType, so that as to register it.
       
   372 Q_DECLARE_METATYPE(SmfActivityEntry)
       
   373 Q_DECLARE_METATYPE(QList<SmfActivityEntry>)
       
   374 
       
   375 #endif /* SMFACTIONS_H_ */