|         |      1 /* | 
|         |      2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|         |      3  * All rights reserved. | 
|         |      4  * This component and the accompanying materials are made available | 
|         |      5  * under the terms of "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  * Nokia Corporation - initial contribution. | 
|         |     11  * | 
|         |     12  * Contributors: | 
|         |     13  * | 
|         |     14  * Description: | 
|         |     15  * | 
|         |     16  */ | 
|         |     17  | 
|         |     18 #ifndef CONVERSATIONS_ENGINE_H | 
|         |     19 #define CONVERSATIONS_ENGINE_H | 
|         |     20  | 
|         |     21 // INCLUDES | 
|         |     22 #include <QObject> | 
|         |     23 #include <QStandardItemModel> | 
|         |     24 #include <sqldb.h> | 
|         |     25  | 
|         |     26 #ifdef BUILD_DLL | 
|         |     27 #define CONVERSATIONS_ENGINE_API_EXPORT Q_DECL_EXPORT | 
|         |     28 #else | 
|         |     29 #define CONVERSATIONS_ENGINE_API_EXPORT Q_DECL_IMPORT | 
|         |     30 #endif | 
|         |     31  | 
|         |     32 class ConversationsSummaryModel; | 
|         |     33 class ConversationsModel; | 
|         |     34 class DraftsModel; | 
|         |     35 class ConversationMsgStoreHandler; | 
|         |     36 class ConversationsEnginePrivate; | 
|         |     37  | 
|         |     38 /** | 
|         |     39  * This is a singleton class which | 
|         |     40  * implements the models for the model/view framework. | 
|         |     41  * The models hold data for the conversations fetched from the | 
|         |     42  * server. | 
|         |     43  * | 
|         |     44  */ | 
|         |     45  | 
|         |     46 class CONVERSATIONS_ENGINE_API_EXPORT ConversationsEngine : public QObject | 
|         |     47 { | 
|         |     48     Q_OBJECT | 
|         |     49  | 
|         |     50 public: | 
|         |     51  | 
|         |     52     /** | 
|         |     53      * Returns pointer to sole instance. | 
|         |     54      * @return ConversationEngine object | 
|         |     55      */ | 
|         |     56     static ConversationsEngine* instance(); | 
|         |     57  | 
|         |     58     /** | 
|         |     59      * Destructor | 
|         |     60      */ | 
|         |     61     virtual ~ConversationsEngine(); | 
|         |     62  | 
|         |     63 public: | 
|         |     64  | 
|         |     65     /** | 
|         |     66      * Returns Conversations Summary Model instance | 
|         |     67      */ | 
|         |     68     QStandardItemModel* getConversationsSummaryModel(); | 
|         |     69  | 
|         |     70     /** | 
|         |     71      * Returns Conversations Model instance | 
|         |     72      */ | 
|         |     73     QStandardItemModel* getConversationsModel(); | 
|         |     74  | 
|         |     75     /** | 
|         |     76      * Returns drafts Model instance | 
|         |     77      */ | 
|         |     78     QStandardItemModel* getDraftsModel(); | 
|         |     79  | 
|         |     80     /** | 
|         |     81      * Get all conversations. | 
|         |     82      * @param conversationId, conversationId | 
|         |     83      * @return returns true if call is successful | 
|         |     84      */ | 
|         |     85     bool getConversations(qint64 conversationId); | 
|         |     86 	 | 
|         |     87     /** | 
|         |     88      * Deregisters the current conversationId and clears the model | 
|         |     89      * @return returns true if call is successful | 
|         |     90      */ | 
|         |     91     bool clearConversations(); | 
|         |     92  | 
|         |     93     /** | 
|         |     94      * Delete all conversations. | 
|         |     95      * @param conversationId, conversationId | 
|         |     96      * @return returns true if call is successful | 
|         |     97      */     | 
|         |     98     bool deleteConversations(qint64 conversationId); | 
|         |     99  | 
|         |    100     /** | 
|         |    101      * Delete all messages. | 
|         |    102      * @param msgIdList, message list. | 
|         |    103      */   | 
|         |    104     void deleteMessages(QList<int>& msgIdList); | 
|         |    105  | 
|         |    106     /** | 
|         |    107      * Delete all draft messages. | 
|         |    108      */ | 
|         |    109     void deleteAllDraftMessages(); | 
|         |    110  | 
|         |    111     /** | 
|         |    112      * Marks all the unread conversations to read | 
|         |    113      * @param conversationId, conversationId | 
|         |    114      * @return returns true if call is successful | 
|         |    115      */         | 
|         |    116     bool markConversationRead(qint64 conversationId); | 
|         |    117      | 
|         |    118     /** | 
|         |    119      * Mark messages as read. | 
|         |    120      * @param msgIdList, message list. | 
|         |    121      * @return returns true if call is successful | 
|         |    122      */       | 
|         |    123     bool markMessagesRead(QList<int>& msgIdList); | 
|         |    124      | 
|         |    125     /** | 
|         |    126      * Get Contact details name. | 
|         |    127      * @param conversationId, conversationId | 
|         |    128      * @param displayName, Name | 
|         |    129      */   | 
|         |    130     void getContactDetails(qint64 conversationId, | 
|         |    131         QString& displayName, | 
|         |    132         QString& address); | 
|         |    133  | 
|         |    134     /** | 
|         |    135      * Get conversationId for a given address. | 
|         |    136      * @param address, Phone number | 
|         |    137      * @return conversation id | 
|         |    138      */   | 
|         |    139     qint64 getConversationIdFromAddress(QString address); | 
|         |    140  | 
|         |    141     /** | 
|         |    142      * Get current conversation id. | 
|         |    143      */   | 
|         |    144     qint64 getCurrentConversationId(); | 
|         |    145  | 
|         |    146     /** | 
|         |    147      * Get conversationId for a given contactId. | 
|         |    148      * @param contactId, Contact Id | 
|         |    149      * @return conversation id | 
|         |    150      */  | 
|         |    151     qint64 getConversationIdFromContactId(qint32 contactId); | 
|         |    152  | 
|         |    153     /** | 
|         |    154      * Emits conversationModelPopulated signal | 
|         |    155      */  | 
|         |    156     void emitConversationModelPopulated(); | 
|         |    157      | 
|         |    158     /** | 
|         |    159      * Emits conversationModelUpdated signal | 
|         |    160      */  | 
|         |    161     void emitConversationModelUpdated(); | 
|         |    162      | 
|         |    163     /** | 
|         |    164      * Updates the new conversation id for list view | 
|         |    165      */ | 
|         |    166     void emitOpenConversationViewIdUpdate(int newConversationId); | 
|         |    167      | 
|         |    168     void disableRegisterationForCVEvents(); | 
|         |    169      | 
|         |    170     /** | 
|         |    171      * Emits conversationListModelPopulated signal | 
|         |    172      */  | 
|         |    173     void emitConversationListModelPopulated(); | 
|         |    174  | 
|         |    175     /** | 
|         |    176      * Emits conversationListModelEntryDeleted | 
|         |    177      */ | 
|         |    178     void emitConversationListModelEntryDeleted( int conversationId ); | 
|         |    179      | 
|         |    180     /** | 
|         |    181      *  Starts fetching remaing conversations | 
|         |    182      */ | 
|         |    183     void fetchMoreConversations(); | 
|         |    184  | 
|         |    185     /** | 
|         |    186      *  Resend a failed message | 
|         |    187 	 *@param  messageId qint32 the Id of the message to be sent | 
|         |    188 	 *@return bool true if succeeded | 
|         |    189      */ | 
|         |    190     bool resendMessage(qint32 messageId); | 
|         |    191  | 
|         |    192     /** | 
|         |    193      * Download a specified message | 
|         |    194      * @param messageId qint32 the Id of the message  | 
|         |    195      * @return KErrNone if Download request is successful,  | 
|         |    196      *         KErrNotFound if settings are not available, | 
|         |    197      *         KErrGeneral for other cases | 
|         |    198      */ | 
|         |    199     int downloadMessage(qint32 messageId);   | 
|         |    200  | 
|         |    201     /** | 
|         |    202      * Query if the download operation be performed for | 
|         |    203      * a message notification entry | 
|         |    204      * @param aId, message notification id | 
|         |    205      * @return true if download operation is possible | 
|         |    206      */ | 
|         |    207     bool downloadOperationSupported(qint32 messageId); | 
|         |    208 	 | 
|         |    209     /** | 
|         |    210      * Mark message as read and get the message type | 
|         |    211      * @param messageId  message Id  | 
|         |    212      * @param msgType message type is written to this. | 
|         |    213      * @param msgType message sub type is written to this. | 
|         |    214      */ | 
|         |    215     void markAsReadAndGetType( qint32 messageId, | 
|         |    216                                int& msgType, | 
|         |    217                                int& msgSubType); | 
|         |    218      | 
|         |    219     /* | 
|         |    220      * Get SQL DB handle | 
|         |    221      * @param isOpen, set to true if open, check this before using the handle | 
|         |    222      */ | 
|         |    223     RSqlDatabase& getDBHandle(TBool& isOpen); | 
|         |    224      | 
|         |    225     /** | 
|         |    226      * Get the biotype of a message | 
|         |    227      * @param messageId | 
|         |    228      */ | 
|         |    229     int getMsgSubType(int messageId); | 
|         |    230      | 
|         |    231 private: | 
|         |    232  | 
|         |    233     /** | 
|         |    234      * Constructor | 
|         |    235      */ | 
|         |    236     explicit ConversationsEngine(QObject* parent = 0);     | 
|         |    237      | 
|         |    238 signals: | 
|         |    239  | 
|         |    240     /** | 
|         |    241      * ConversationListModelPopulated signal indicating  | 
|         |    242      * that the model is ready to be displayed | 
|         |    243      */  | 
|         |    244     void conversationModelPopulated(); | 
|         |    245      | 
|         |    246     /** | 
|         |    247      * ConversationModelUpdated signal indicating dynamic  | 
|         |    248      * updates in the model | 
|         |    249      */  | 
|         |    250     void conversationModelUpdated(); | 
|         |    251      | 
|         |    252     /** | 
|         |    253      * ConversationListModelPopulated signal indicating  | 
|         |    254      * that the model is ready to be displayed | 
|         |    255      */ | 
|         |    256     void conversationListModelPopulated(); | 
|         |    257      | 
|         |    258 	/**  | 
|         |    259 	 * Signal to indicate the completion of conversation delete | 
|         |    260 	 * operation. | 
|         |    261 	 */ | 
|         |    262      void conversationListEntryDeleted( int conversationId ); | 
|         |    263 	  | 
|         |    264     /** | 
|         |    265      * Signal to specify the CV model empty now | 
|         |    266      */ | 
|         |    267     void conversationViewEmpty(); | 
|         |    268      | 
|         |    269 private: | 
|         |    270  | 
|         |    271     /** | 
|         |    272      * Conversations Summary Model | 
|         |    273      * Own | 
|         |    274      */         | 
|         |    275     ConversationsSummaryModel* mConversationsSummaryModel; | 
|         |    276  | 
|         |    277     /** | 
|         |    278      * Conversations Model | 
|         |    279      * Own | 
|         |    280      */     | 
|         |    281     ConversationsModel* mConversationsModel; | 
|         |    282  | 
|         |    283     /** | 
|         |    284      * Drafts Model | 
|         |    285      * Own | 
|         |    286      */     | 
|         |    287     DraftsModel* mDraftsModel; | 
|         |    288  | 
|         |    289     /** | 
|         |    290      * MsgStoreHandler | 
|         |    291      * Own | 
|         |    292      */     | 
|         |    293     ConversationMsgStoreHandler* mConversationMsgStoreHandler; | 
|         |    294      | 
|         |    295     /** | 
|         |    296      * ConversationsEnginePrivate | 
|         |    297      * Own | 
|         |    298      */ | 
|         |    299     ConversationsEnginePrivate* d_ptr; | 
|         |    300  | 
|         |    301 }; | 
|         |    302  | 
|         |    303 #endif // CONVERSATIONS_ENGINE_H |