messagingapp/msgui/unifiedviewer/src/univiewerfeeder_p.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: Feeder Private class for unified viewer. Fetches data from the
       
    15  *              message store for the given message id.
       
    16  *
       
    17  */
       
    18 #include "univiewerfeeder_p.h"
       
    19 // SYSTEM INCLUDES
       
    20 #include <mtclreg.h>
       
    21 #include <mtclbase.h>
       
    22 #include <msvstd.h>
       
    23 #include <txtetext.h>
       
    24 #include <txtrich.h>
       
    25 #include <s60qconversions.h>
       
    26 #include <msvids.h>
       
    27 #include <qtcontactsglobal.h>
       
    28 #include "qtcontacts.h"
       
    29 #include "qcontactdetailfilter.h"
       
    30 
       
    31 // USER INCLUDES
       
    32 #include "nativemessageconsts.h"
       
    33 #include "univiewerfeeder.h"
       
    34 #include "unidatamodelloader.h"
       
    35 #include "debugtraces.h"
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // UniViewerFeederPrivate::UniViewerFeederPrivate
       
    39 // @see header file
       
    40 // ---------------------------------------------------------------------------
       
    41 UniViewerFeederPrivate::UniViewerFeederPrivate(qint32 msgId,
       
    42                                                UniViewerFeeder* feeder) :
       
    43     q_ptr(feeder), mSlideCount(0), mSession(NULL)
       
    44 {
       
    45     TRAP_IGNORE(initL(msgId));
       
    46 }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // UniViewerFeederPrivate::~UniViewerFeederPrivate
       
    50 // @see header file
       
    51 // ---------------------------------------------------------------------------
       
    52 UniViewerFeederPrivate::~UniViewerFeederPrivate()
       
    53 {
       
    54     q_ptr = NULL;
       
    55     clearContent();
       
    56     if(pluginLoader)
       
    57     {
       
    58         delete pluginLoader;
       
    59         pluginLoader = NULL;
       
    60     }
       
    61 }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // UniViewerFeederPrivate::initL
       
    65 // Symbian specific constructions
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void UniViewerFeederPrivate::initL(qint32 msgId)
       
    69 {
       
    70     QDEBUG_WRITE("UniViewerFeederPrivate::initL start");
       
    71     TMsvId serviceId = KMsvNullIndexEntryId;
       
    72     pluginInterface = NULL;
       
    73     mMsgId = msgId;
       
    74     pluginLoader = new UniDataModelLoader();
       
    75     pluginLoader->loadPlugins();
       
    76     pluginInterface = pluginLoader->getDataModelPlugin("sms");
       
    77 
       
    78     mSession = pluginInterface->session();
       
    79     mSession->GetEntry(msgId, serviceId, mEntry);
       
    80     QDEBUG_WRITE("UniViewerFeederPrivate::initL end");
       
    81 }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // UniViewerFeederPrivate::fetchDetails
       
    85 // Fetches message details from the store
       
    86 // ---------------------------------------------------------------------------
       
    87 void UniViewerFeederPrivate::fetchDetails()
       
    88 {
       
    89     TRAP_IGNORE(fetchDetailsL());
       
    90 }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // UniViewerFeederPrivate::msgType
       
    94 // Returns the message type.
       
    95 // ---------------------------------------------------------------------------
       
    96 qint32 UniViewerFeederPrivate::msgType()
       
    97 {
       
    98     return mEntry.iMtm.iUid;
       
    99 }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // UniViewerFeederPrivate::isIncoming
       
   103 // Returns if it is a incoming message.
       
   104 // ---------------------------------------------------------------------------
       
   105 bool UniViewerFeederPrivate::isIncoming()
       
   106 {
       
   107     if (mEntry.Parent() == KMsvGlobalInBoxIndexEntryId)
       
   108     {
       
   109         return true;
       
   110     }
       
   111     return false;
       
   112 }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // UniViewerFeederPrivate::priority
       
   116 // Returns the message priority.
       
   117 // ---------------------------------------------------------------------------
       
   118 int UniViewerFeederPrivate::priority()
       
   119 {
       
   120     if (mEntry.Priority() == EMsvHighPriority)
       
   121     {
       
   122         return ConvergedMessage::High;
       
   123     }
       
   124     else if (mEntry.Priority() == EMsvLowPriority)
       
   125     {
       
   126         return ConvergedMessage::Low;
       
   127     }
       
   128     return ConvergedMessage::Normal;
       
   129 }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // UniViewerFeederPrivate::subject
       
   133 // Returns the message subject.
       
   134 // ---------------------------------------------------------------------------
       
   135 QString UniViewerFeederPrivate::subject()
       
   136 {
       
   137     return pluginInterface->subject();
       
   138 }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // UniViewerFeederPrivate::timeStamp
       
   142 // Returns the time stamp
       
   143 // ---------------------------------------------------------------------------
       
   144 QDateTime UniViewerFeederPrivate::timeStamp()
       
   145 {
       
   146 
       
   147     return pluginInterface->timeStamp();
       
   148 }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // UniViewerFeederPrivate::fetchDetailsL
       
   152 // Fetches message details from the store.
       
   153 // ---------------------------------------------------------------------------
       
   154 void UniViewerFeederPrivate::fetchDetailsL()
       
   155 {
       
   156     QDEBUG_WRITE("UniViewerFeederPrivate fetchDetailsL : SMS start");
       
   157 
       
   158     if (msgType() == KSenduiMtmSmsUidValue)
       
   159     {
       
   160         QString body;
       
   161         pluginInterface->body(body);
       
   162         q_ptr->emitMsgBody(body);
       
   163     }
       
   164 
       
   165     QDEBUG_WRITE("UniViewerFeederPrivate fetchDetailsL : SMS END");
       
   166 }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // UniViewerFeederPrivate::hasAttachments
       
   170 // @see header file
       
   171 // ---------------------------------------------------------------------------
       
   172 bool UniViewerFeederPrivate::hasAttachments()
       
   173 {
       
   174     return pluginInterface->hasAttachment();
       
   175 }
       
   176 // ---------------------------------------------------------------------------
       
   177 // UniViewerFeederPrivate::attachmentsList
       
   178 // @see header file
       
   179 // ---------------------------------------------------------------------------
       
   180 UniMessageInfoList UniViewerFeederPrivate::attachmentsList()
       
   181 {
       
   182     return pluginInterface->attachmentList();
       
   183 }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // UniViewerFeederPrivate::attachmentCount
       
   187 // @see header file
       
   188 // ---------------------------------------------------------------------------
       
   189 int UniViewerFeederPrivate::attachmentCount()
       
   190 {
       
   191     return pluginInterface->attachmentCount();
       
   192 }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // UniViewerFeederPrivate::objectsList
       
   196 // @see header file
       
   197 // ---------------------------------------------------------------------------
       
   198 UniMessageInfoList UniViewerFeederPrivate::objectsList()
       
   199 {
       
   200     return pluginInterface->objectList();
       
   201 }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // UniViewerFeederPrivate::objectCount
       
   205 // @see header file
       
   206 // ---------------------------------------------------------------------------
       
   207 int UniViewerFeederPrivate::objectCount()
       
   208 {
       
   209     return pluginInterface->objectCount();
       
   210 }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // UniViewerFeederPrivate::slideCount
       
   214 // @see header file
       
   215 // ---------------------------------------------------------------------------
       
   216 int UniViewerFeederPrivate::slideCount()
       
   217 {
       
   218     return mSlideCount;
       
   219 }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // UniViewerFeederPrivate::slideContent
       
   223 // @see header file
       
   224 // ---------------------------------------------------------------------------
       
   225 UniMessageInfoList UniViewerFeederPrivate::slideContent(int slidenum)
       
   226 {
       
   227     return pluginInterface->slideContent(slidenum);
       
   228 }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // UniViewerFeederPrivate::updateContent
       
   232 // @see header file
       
   233 // ---------------------------------------------------------------------------
       
   234 void UniViewerFeederPrivate::updateContent(qint32 msgId)
       
   235 {
       
   236   
       
   237     if (msgId != mMsgId)
       
   238     {
       
   239         mMsgId = msgId;
       
   240         TMsvId serviceId = KMsvNullIndexEntryId;
       
   241         mSession->GetEntry(msgId, serviceId, mEntry);
       
   242         clearContent();
       
   243     }
       
   244 
       
   245     if (msgType() == KSenduiMtmSmsUidValue)
       
   246     {
       
   247         pluginInterface = pluginLoader->getDataModelPlugin("sms");
       
   248         pluginInterface->setMessageId(msgId);
       
   249     }
       
   250 
       
   251     if (msgType() == KSenduiMtmMmsUidValue)
       
   252     {
       
   253         pluginInterface = pluginLoader->getDataModelPlugin("mms");
       
   254         pluginInterface->setMessageId(msgId);
       
   255         mSlideCount = pluginInterface->slideCount();
       
   256     }
       
   257     pluginInterface->toRecipientList(mToAddressList);
       
   258     pluginInterface->ccRecipientList(mCcAddressList);
       
   259 }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // UniViewerFeederPrivate::toAddressList
       
   263 // @see header file
       
   264 // ---------------------------------------------------------------------------
       
   265 ConvergedMessageAddressList UniViewerFeederPrivate::toAddressList()
       
   266 {
       
   267     for (int i = 0; i < mToAddressList.count(); ++i)
       
   268     {
       
   269         if (mToAddressList.at(i)->alias().isEmpty())
       
   270         {
       
   271             QString alias = QString();
       
   272             GetNameFromContacts(mToAddressList.at(i)->address(), alias);
       
   273             mToAddressList.at(i)->setAlias(alias);
       
   274             alias.clear();
       
   275         }
       
   276     }
       
   277     return mToAddressList;
       
   278 }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // UniViewerFeederPrivate::ccAddressList
       
   282 // @see header file
       
   283 // ---------------------------------------------------------------------------
       
   284 ConvergedMessageAddressList UniViewerFeederPrivate::ccAddressList()
       
   285 {
       
   286     for (int i = 0; i < mCcAddressList.count(); ++i)
       
   287     {
       
   288         if (mCcAddressList.at(i)->alias().isEmpty())
       
   289         {
       
   290             QString alias = QString();
       
   291             GetNameFromContacts(mCcAddressList.at(i)->address(), alias);
       
   292             mCcAddressList.at(i)->setAlias(alias);
       
   293             alias.clear();
       
   294         }
       
   295     }
       
   296     return mCcAddressList;
       
   297 }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // UniViewerFeederPrivate::messageSize
       
   301 // @see header file
       
   302 // ---------------------------------------------------------------------------
       
   303 int UniViewerFeederPrivate::messageSize()
       
   304 {
       
   305     return pluginInterface->messageSize();
       
   306 }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // UniViewerFeederPrivate::fromAddressAndAlias
       
   310 // @see header file
       
   311 // ---------------------------------------------------------------------------
       
   312 void UniViewerFeederPrivate::fromAddressAndAlias(QString& from, QString& alias)
       
   313 {
       
   314     pluginInterface->fromAddress(from);
       
   315     GetNameFromContacts(from, alias);
       
   316 }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // UniViewerFeederPrivate::clearContent
       
   320 // @see header file
       
   321 // ---------------------------------------------------------------------------
       
   322 void UniViewerFeederPrivate::clearContent()
       
   323 {
       
   324     for (int i = 0; i < mToAddressList.count(); ++i)
       
   325     {
       
   326         delete mToAddressList.at(i);
       
   327     }
       
   328     mToAddressList.clear();
       
   329 
       
   330     for (int i = 0; i < mCcAddressList.count(); ++i)
       
   331     {
       
   332         delete mCcAddressList.at(i);
       
   333     }
       
   334 
       
   335     mCcAddressList.clear();
       
   336 }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // UniViewerFeederPrivate::GetNameFromContacts
       
   340 // @see header file
       
   341 //----------------------------------------------------------------------------
       
   342 int UniViewerFeederPrivate::GetNameFromContacts(const QString& address,
       
   343                                                 QString& alias)
       
   344 {
       
   345     QContactManager contactManager("symbian");
       
   346     //set filter
       
   347     QContactDetailFilter phoneFilter;
       
   348     phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName,
       
   349                                         QContactPhoneNumber::FieldNumber);
       
   350     phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
       
   351 
       
   352     phoneFilter.setValue(address); // this is the phone number to be resolved
       
   353 
       
   354     QList<QContactLocalId> matchingContacts =
       
   355             contactManager.contacts(phoneFilter);
       
   356     int count = 0;
       
   357     if (matchingContacts.count() > 0)
       
   358     {
       
   359         QContact match = contactManager.contact(matchingContacts.at(0));
       
   360         
       
   361         QContactName name = match.detail(QContactName::DefinitionName);
       
   362         QString nickName(match.detail<QContactNickname> ().nickname());
       
   363         
       
   364         QString displayLabel = match.displayLabel();
       
   365           
       
   366         QList<QContactPhoneNumber> numbers =
       
   367                 match.details<QContactPhoneNumber> ();
       
   368         count = numbers.count();
       
   369         if(displayLabel != "Unnamed")
       
   370         {
       
   371             alias.append(displayLabel);
       
   372         }
       
   373         else if(!nickName.isEmpty())
       
   374         {
       
   375             alias.append(nickName);
       
   376         }
       
   377             
       
   378     }
       
   379     return count;
       
   380 }
       
   381 
       
   382 // EOF