messagingapp/msgui/appengine/src/conversationsengine.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 #include "conversationsengine.h"
       
    18 
       
    19 #include "conversationsenginedefines.h"
       
    20 #include "convergedmessage.h"
       
    21 #include "conversationmsgstorehandler.h"
       
    22 #include "conversationssummarymodel.h"
       
    23 #include "conversationsmodel.h"
       
    24 #include "draftsmodel.h"
       
    25 #include "conversationsengine_p.h"
       
    26 #include "debugtraces.h"
       
    27 #include "s60qconversions.h"
       
    28 
       
    29 //---------------------------------------------------------------
       
    30 // ConversationsEngine::instance
       
    31 // @see header
       
    32 //---------------------------------------------------------------
       
    33 ConversationsEngine* ConversationsEngine::instance()
       
    34 {
       
    35     static ConversationsEngine* conversationsEngine =
       
    36         new ConversationsEngine();
       
    37     return conversationsEngine;
       
    38 }
       
    39 
       
    40 //---------------------------------------------------------------
       
    41 // ConversationsEngine::ConversationsEngine
       
    42 // @see header
       
    43 //---------------------------------------------------------------
       
    44 ConversationsEngine::ConversationsEngine(QObject* parent):
       
    45     QObject(parent), mDraftsModel(NULL)
       
    46 {
       
    47     mConversationMsgStoreHandler = new ConversationMsgStoreHandler;
       
    48     mConversationsSummaryModel = new ConversationsSummaryModel(this);    
       
    49     mConversationsModel = new ConversationsModel(mConversationMsgStoreHandler,
       
    50         this);   
       
    51 
       
    52     d_ptr = new ConversationsEnginePrivate(mConversationMsgStoreHandler,
       
    53         mConversationsSummaryModel,
       
    54         mConversationsModel);
       
    55 }
       
    56 
       
    57 //---------------------------------------------------------------
       
    58 // ConversationsEngine::~ConversationsEngine
       
    59 // @see header
       
    60 //---------------------------------------------------------------
       
    61 ConversationsEngine::~ConversationsEngine()
       
    62 {
       
    63     if(mConversationMsgStoreHandler)
       
    64     {
       
    65         delete mConversationMsgStoreHandler;
       
    66         mConversationMsgStoreHandler = NULL;
       
    67     }
       
    68     if(d_ptr)
       
    69     {
       
    70         delete d_ptr;
       
    71         d_ptr = NULL;
       
    72     }
       
    73 }
       
    74 
       
    75 //---------------------------------------------------------------
       
    76 // ConversationsEngine::getConversationsSummaryModel
       
    77 // @see header
       
    78 //---------------------------------------------------------------
       
    79 QStandardItemModel* ConversationsEngine::getConversationsSummaryModel()
       
    80 {
       
    81     return mConversationsSummaryModel;
       
    82 }
       
    83 
       
    84 //---------------------------------------------------------------
       
    85 // ConversationsEngine::getConversationsModel
       
    86 // @see header
       
    87 //---------------------------------------------------------------
       
    88 QStandardItemModel* ConversationsEngine::getConversationsModel()
       
    89 {
       
    90     return mConversationsModel;
       
    91 }
       
    92 
       
    93 //---------------------------------------------------------------
       
    94 // ConversationsEngine::getDraftsModel
       
    95 // @see header
       
    96 //---------------------------------------------------------------
       
    97 QStandardItemModel* ConversationsEngine::getDraftsModel()
       
    98     {
       
    99     if(!mDraftsModel)
       
   100         {
       
   101         mDraftsModel = new DraftsModel(this);
       
   102         mConversationMsgStoreHandler->FetchDraftMessages(mDraftsModel);
       
   103         }
       
   104     return mDraftsModel;
       
   105     }
       
   106 //---------------------------------------------------------------
       
   107 // ConversationsEngine::getConversations
       
   108 // @see header
       
   109 //---------------------------------------------------------------
       
   110 bool ConversationsEngine::getConversations(qint64 conversationId)
       
   111 {
       
   112     int error;
       
   113     TRAP(error,d_ptr->getConversationsL(conversationId));
       
   114     return (error!=KErrNone) ? false : true; 
       
   115 }
       
   116 
       
   117 //---------------------------------------------------------------
       
   118 // ConversationsEngine::clearConversations
       
   119 // @see header
       
   120 //---------------------------------------------------------------
       
   121 bool ConversationsEngine::clearConversations()
       
   122 {
       
   123     int error;
       
   124     TRAP(error,d_ptr->clearConversationsL());
       
   125     return (error!=KErrNone) ? false : true; 
       
   126 }
       
   127 
       
   128 //---------------------------------------------------------------
       
   129 // ConversationsEngine::deleteConversations
       
   130 // @see header
       
   131 //---------------------------------------------------------------
       
   132 bool ConversationsEngine::deleteConversations(qint64 conversationId)
       
   133 {
       
   134     int error;
       
   135     TRAP(error,d_ptr->deleteConversationL(conversationId));
       
   136     return (error!=KErrNone) ? false : true; 
       
   137 }
       
   138 
       
   139 //---------------------------------------------------------------
       
   140 // ConversationsEngine::deleteMessages
       
   141 // @see header
       
   142 //---------------------------------------------------------------
       
   143 void ConversationsEngine::deleteMessages(QList<int>& msgIdList)
       
   144 {
       
   145     RArray<TInt> idArray;
       
   146     for(int i=0; i < msgIdList.count(); ++i)
       
   147     {
       
   148         idArray.Append(msgIdList[i]);
       
   149     }
       
   150     if(msgIdList.count()>0)
       
   151     {
       
   152         d_ptr->deleteMessages(idArray);
       
   153     }
       
   154 }
       
   155 
       
   156 //---------------------------------------------------------------
       
   157 // ConversationsEngine::markConversationRead
       
   158 // @see header
       
   159 //---------------------------------------------------------------
       
   160 bool ConversationsEngine::markConversationRead(qint64 conversationId)
       
   161 {
       
   162     int error;
       
   163     TRAP(error,d_ptr->markConversationReadL(conversationId));
       
   164     return (error!=KErrNone) ? false : true; 
       
   165 }
       
   166 
       
   167 //---------------------------------------------------------------
       
   168 // ConversationsEngine::markMessagesRead
       
   169 // @see header
       
   170 //---------------------------------------------------------------
       
   171 bool ConversationsEngine::markMessagesRead(QList<int>& msgIdList)
       
   172 {
       
   173     RArray<TInt> idArray;
       
   174     int error;
       
   175     for(int i=0; i < msgIdList.count(); ++i)
       
   176     {
       
   177         idArray.Append(msgIdList[i]);
       
   178     }
       
   179     if(msgIdList.count()>0)
       
   180     {
       
   181         TRAP(error,d_ptr->markMessagesReadL(idArray));
       
   182     }
       
   183     return (error!=KErrNone) ? false : true; 
       
   184 }
       
   185 
       
   186 //---------------------------------------------------------------
       
   187 // ConversationsEngine::getContactDetails
       
   188 // @see header
       
   189 //---------------------------------------------------------------
       
   190 void ConversationsEngine::getContactDetails(qint64 conversationId,
       
   191     QString& firstName,
       
   192     QString& lastName,
       
   193     QString& address)
       
   194 {
       
   195     QModelIndexList indexList = mConversationsSummaryModel->match(
       
   196             mConversationsSummaryModel->index(0, 0), 
       
   197             ConversationId, 
       
   198             conversationId, 
       
   199             1, // One match 
       
   200             Qt::MatchExactly);
       
   201 
       
   202     if(indexList.count() > 0)
       
   203     {
       
   204         firstName = indexList[0].data(FirstName).toString();
       
   205         lastName = indexList[0].data(LastName).toString();
       
   206         address = indexList[0].data(ConversationAddress).toString();
       
   207     }         
       
   208 }
       
   209 
       
   210 //---------------------------------------------------------------
       
   211 // ConversationsEngine::getConversationIdFromAddress
       
   212 // @see header
       
   213 //---------------------------------------------------------------
       
   214 qint64 ConversationsEngine::getConversationIdFromAddress(QString address)
       
   215 {
       
   216     qint64 conversationId = -1;
       
   217 
       
   218     int error;
       
   219     HBufC* number = S60QConversions::qStringToS60Desc(address);
       
   220     TRAP(error,conversationId = 
       
   221         d_ptr->getConversationIdFromAddressL(*number));
       
   222 
       
   223     delete number;
       
   224     
       
   225     return conversationId;
       
   226 }
       
   227 
       
   228 //---------------------------------------------------------------
       
   229 // ConversationsEngine::getCurrentConversationId
       
   230 // @see header
       
   231 //---------------------------------------------------------------
       
   232 qint64 ConversationsEngine::getCurrentConversationId()
       
   233 {
       
   234     return d_ptr->getConversationCurrentId();   
       
   235 }
       
   236 
       
   237 //---------------------------------------------------------------
       
   238 // ConversationsEngine::getConversationIdFromContactId
       
   239 // @see header
       
   240 //---------------------------------------------------------------
       
   241 qint64 ConversationsEngine::getConversationIdFromContactId(qint32 contactId)
       
   242 {  
       
   243     qint64 conversationId = -1;
       
   244     int error;
       
   245     TRAP(error,conversationId = 
       
   246         d_ptr->getConversationIdFromContactIdL(contactId));
       
   247     
       
   248     return conversationId;    
       
   249 }
       
   250 
       
   251 //---------------------------------------------------------------
       
   252 // ConversationsEngine::emitConversationModelPopulated
       
   253 // @see header
       
   254 //---------------------------------------------------------------
       
   255 void ConversationsEngine::emitConversationModelPopulated()
       
   256 {
       
   257     emit conversationModelPopulated();
       
   258 }
       
   259 
       
   260 //---------------------------------------------------------------
       
   261 // ConversationsEngine::emitConversationModelUpdated
       
   262 // @see header
       
   263 //---------------------------------------------------------------
       
   264 void ConversationsEngine::emitConversationModelUpdated()
       
   265 {
       
   266     emit conversationModelUpdated();
       
   267 }
       
   268 
       
   269 //---------------------------------------------------------------
       
   270 // ConversationsEngine::emitConversationListModelPopulated
       
   271 // @see header
       
   272 //---------------------------------------------------------------
       
   273 void ConversationsEngine::emitConversationListModelPopulated()
       
   274 {
       
   275     emit conversationListModelPopulated();
       
   276 }
       
   277 
       
   278 //---------------------------------------------------------------
       
   279 // ConversationsEngine::fetchMoreConversations
       
   280 // @see header
       
   281 //---------------------------------------------------------------
       
   282 void ConversationsEngine::fetchMoreConversations()
       
   283 {
       
   284     d_ptr->fetchMoreConversations();
       
   285 }
       
   286 
       
   287 //EOF
       
   288