smf/smfservermodule/smfclient/smfrelationmgr.h
changeset 18 013a02bf2bb0
child 25 a180113055cb
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  * Interface spefication for managing associations between various social contacts
       
    17  * 
       
    18  */
       
    19 
       
    20 #ifndef SMFRELATIONMGR_H
       
    21 #define SMFRELATIONMGR_H
       
    22 
       
    23 #include <smfprovider.h>
       
    24 #include <smfcontact.h>
       
    25 #include <smfglobal.h>
       
    26 
       
    27 // forward declaation
       
    28 class SmfRelationMgrPrivate;
       
    29 
       
    30 // implementaion constants
       
    31 const int maxSmfRelationIdSize = 500;
       
    32 const int maxSmfRelationItemSize = 1000;
       
    33 const int maxRelationItems = 1000;
       
    34 
       
    35 
       
    36 // persistent Id of a relation.
       
    37 typedef QString SmfRelationId;
       
    38 
       
    39 /**
       
    40  * One record of a contact in a relation. Index specifies their position in the relationship.
       
    41  */
       
    42 class SMFCLIENT_EXPORT SmfRelationItem : public SmfContact
       
    43 	{
       
    44 public:
       
    45 	SmfRelationItem(SmfProvider* provider=0);
       
    46 	
       
    47 public:
       
    48 	SmfProvider getProvider() const;
       
    49 	void setProvider(SmfProvider& provider);
       
    50 	
       
    51 	SmfContact getContact() const;
       
    52 	void setContact(SmfContact& contact);
       
    53 	
       
    54 	quint32	getIndex() const;
       
    55 	void setIndex(quint32 index);
       
    56 	
       
    57 private:
       
    58 	SmfProvider m_provider;
       
    59 	SmfContact  m_contact;
       
    60 	quint32		 m_index;
       
    61 	};
       
    62 
       
    63 SMFCLIENT_EXPORT QDataStream &operator<<( QDataStream &aDataStream, 
       
    64 	const SmfRelationItem &aRelnItem );
       
    65 
       
    66 SMFCLIENT_EXPORT QDataStream &operator>>( QDataStream &aDataStream, 
       
    67 		SmfRelationItem &aRelnItem);
       
    68 
       
    69 
       
    70 /**
       
    71  * All remote profiles (e.g. facebook, twitter, flicker) for a particular
       
    72  * person (or entity) constitutes a relation. Relation Manager stores
       
    73  * these relations in persistent memory.
       
    74  *
       
    75  * Relations and Items can be visualized in rows and columns.
       
    76  * Each row is identified by a RelationId.
       
    77  * Each column is identified by index of that Item in the relation
       
    78  * Each Items holds necessary information for SmfProvider and SmfContact.
       
    79  * In the diagram below C1, C2... could be local or remote contacts, which means
       
    80  * that C1, C2 .. could be contacts from device-resident phonebook. For example, for contact C1,
       
    81  * items at index 1,2,3.. in this relationship denotes C1's id in Facebook, Twitter, flickr,... .
       
    82  *
       
    83  *                                  Relation Item           Relation Item          Relation Item      Relation Item        Relation Item
       
    84  *                                        Index1                  index2                  index3                  index4                  index5
       
    85  *                             _______________________________________________________________________
       
    86  *                             |                           |                             |                            |                          |                          |
       
    87  * RelationId 1         |           C1           |        Remote        |        Remote       |         Remote    |         Remote     |
       
    88  *                             |                           |        Contact        |        Contact       |         Contact     |         Contact     |
       
    89  *                             ------------------------------------------------------------------------------------------------------------------
       
    90  *                             |                           |                             |                           |                           |                          |
       
    91  * RelationId 2         |           C2           |        Remote        |        Remote       |                          |                          |
       
    92  *                             |                           |        Contact        |        Contact       |                          |                          |
       
    93  *                             -----------------------------------------------------------------------------------------------------------------
       
    94  *                             |                           |                             |                            |                          |                          |
       
    95  * RelationId 3         |          C3            |        Remote        |                            |                          |                          |
       
    96  *                             |                           |        Contact        |                            |                          |                          |
       
    97  *                             -----------------------------------------------------------------------------------------------------------------
       
    98  *                             |                           |                             |                           |                           |                          |
       
    99  * RelationId 4         |           C4           |        Remote        |        Remote       |                          |                          |
       
   100  *                             |                           |        Contact        |        Contact       |                          |                          |
       
   101  *                             -----------------------------------------------------------------------------------------------------------------
       
   102  *                             |                           |                             |                           |                           |                          |
       
   103  * RelationId 5         |           C5           |        Remote        |                           |                           |                          |
       
   104  *                             |                           |        Contact        |                           |                           |                          |
       
   105  *                             -----------------------------------------------------------------------------------------------------------------
       
   106  *
       
   107  * Items can be added (associated) to a given relation. So this is one-to-many
       
   108  * relationship. Typically no items be present in more than one relation.
       
   109  *
       
   110  * All functions are synchronous at this moment.
       
   111  */
       
   112 class SMFCLIENT_EXPORT SmfRelationMgr : public QObject
       
   113 	{
       
   114 	Q_OBJECT
       
   115 public:
       
   116 	SmfRelationMgr(QObject* parent = 0);
       
   117 	~SmfRelationMgr();
       
   118 
       
   119 public slots:
       
   120 
       
   121 	/** create a new relation. The contact provided is the first contact in this
       
   122 	 * relation.
       
   123 	 * Please note that contact should have valid Guid @ref QtMobility::QContactGuid
       
   124 	 * (used by Smf to store the unique id of user from facebook, etc.) and valid Url
       
   125 	 * @ref QtMobility::QContactUrl
       
   126 	 *
       
   127 	 * If the contact is already stored with ContactManager (e.g. contact exists in phonebook),
       
   128 	 * then it would have QtMobility::QContactId properly filled with managerUri and localId.
       
   129 	 * These two field would also be stored in SmfRelationMgr (for easily identifying the SmfContacts).
       
   130 	 *
       
   131 	 * After successful creation, a relationId would be returned. More and more SmfContacts can
       
   132 	 * be added to this relation using this RelationId
       
   133 	 */
       
   134 	SmfRelationId create(SmfProvider *provider=NULL, SmfContact *contact=NULL);
       
   135 
       
   136 	/** assign contact to a relation */
       
   137 	SmfError associate( SmfRelationId& relation,
       
   138 						const SmfContact* contact,
       
   139 						SmfProvider* provider);
       
   140 
       
   141 	/** remove contact from a relation */
       
   142 	SmfError remove(SmfRelationId& relation,
       
   143 					const SmfContact* contact);
       
   144 
       
   145 	/** returns first relation item in the relation when exists, NULL otherwise */
       
   146 	SmfRelationItem* searchById(const SmfRelationId& relation);
       
   147 
       
   148 	/** returns relation Id for a given contacts if exists, NULL otherwise */
       
   149 	SmfRelationId searchByContact( SmfContact contact);
       
   150 
       
   151 	/** returns number of contacts in a relation*/
       
   152 	uint count(SmfRelationId relation);
       
   153 
       
   154 	/** contacts and their provider */
       
   155 	SmfRelationItem* get(SmfRelationId& relation, quint32 index);
       
   156 
       
   157 	/** list of contacts and their provider */
       
   158 	QList<SmfRelationItem> getAll(SmfRelationId& relation);
       
   159 
       
   160 	/** list of all relations */
       
   161 	QList<SmfRelationId> getAllRelations();
       
   162 
       
   163 	/** delete a particular relation*/
       
   164 	SmfError Delete(SmfRelationId& relation);
       
   165 
       
   166 private:
       
   167 	SmfRelationMgrPrivate* m_private;	//private impl wrapper
       
   168 	};
       
   169 
       
   170 #endif // SMFRELATIONMGR_H