messagingapp/msgui/appengine/inc/conversationsengine.h
changeset 31 ebfee66fde93
child 34 84197e66a4bd
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     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      * Emits conversationListModelPopulated signal
       
   165      */ 
       
   166     void emitConversationListModelPopulated();
       
   167 
       
   168     /**
       
   169      *  Starts fetching remaing conversations
       
   170      */
       
   171     void fetchMoreConversations();
       
   172 
       
   173     /**
       
   174      *  Resend a failed message
       
   175 	 *@param  messageId qint32 the Id of the message to be sent
       
   176 	 *@return bool true if succeeded
       
   177      */
       
   178     bool resendMessage(qint32 messageId);
       
   179 
       
   180     /**
       
   181      * Download a specified message
       
   182      * @param messageId qint32 the Id of the message 
       
   183      * @return KErrNone if Download request is successful, 
       
   184      *         KErrNotFound if settings are not available,
       
   185      *         KErrGeneral for other cases
       
   186      */
       
   187     int downloadMessage(qint32 messageId);  
       
   188 
       
   189     /**
       
   190      * Query if the download operation be performed for
       
   191      * a message notification entry
       
   192      * @param aId, message notification id
       
   193      * @return true if download operation is possible
       
   194      */
       
   195     bool downloadOperationSupported(qint32 messageId);
       
   196 	
       
   197     /**
       
   198      * Mark message as read and get the message type
       
   199      * @param messageId  message Id 
       
   200      * @param msgType message type is written to this.
       
   201      * @param msgType message sub type is written to this.
       
   202      */
       
   203     void markAsReadAndGetType( qint32 messageId,
       
   204                                int& msgType,
       
   205                                int& msgSubType);
       
   206     
       
   207     /*
       
   208      * Get SQL DB handle
       
   209      * @param isOpen, set to true if open, check this before using the handle
       
   210      */
       
   211     RSqlDatabase& getDBHandle(TBool& isOpen);
       
   212     
       
   213 private:
       
   214 
       
   215     /**
       
   216      * Constructor
       
   217      */
       
   218     explicit ConversationsEngine(QObject* parent = 0);    
       
   219     
       
   220 signals:
       
   221 
       
   222     /**
       
   223      * ConversationListModelPopulated signal indicating 
       
   224      * that the model is ready to be displayed
       
   225      */ 
       
   226     void conversationModelPopulated();
       
   227     
       
   228     /**
       
   229      * ConversationModelUpdated signal indicating dynamic 
       
   230      * updates in the model
       
   231      */ 
       
   232     void conversationModelUpdated();
       
   233     
       
   234     /**
       
   235      * ConversationListModelPopulated signal indicating 
       
   236      * that the model is ready to be displayed
       
   237      */
       
   238     void conversationListModelPopulated();
       
   239     
       
   240 private:
       
   241 
       
   242     /**
       
   243      * Conversations Summary Model
       
   244      * Own
       
   245      */        
       
   246     ConversationsSummaryModel* mConversationsSummaryModel;
       
   247 
       
   248     /**
       
   249      * Conversations Model
       
   250      * Own
       
   251      */    
       
   252     ConversationsModel* mConversationsModel;
       
   253 
       
   254     /**
       
   255      * Drafts Model
       
   256      * Own
       
   257      */    
       
   258     DraftsModel* mDraftsModel;
       
   259 
       
   260     /**
       
   261      * MsgStoreHandler
       
   262      * Own
       
   263      */    
       
   264     ConversationMsgStoreHandler* mConversationMsgStoreHandler;
       
   265     
       
   266     /**
       
   267      * ConversationsEnginePrivate
       
   268      * Own
       
   269      */
       
   270     ConversationsEnginePrivate* d_ptr;
       
   271 
       
   272 };
       
   273 
       
   274 #endif // CONVERSATIONS_ENGINE_H