messagingapp/msgutils/unieditorutils/unieditorplugins/unieditormmsplugin/src/unieditormmsplugin_p.cpp
changeset 56 f42d9a78f435
parent 46 b1f0785c289d
equal deleted inserted replaced
55:5b3b2fa8c3ec 56:f42d9a78f435
    44 #include "unidatamodelloader.h"
    44 #include "unidatamodelloader.h"
    45 #include "unidatamodelplugininterface.h"
    45 #include "unidatamodelplugininterface.h"
    46 #include "msgcontacthandler.h"
    46 #include "msgcontacthandler.h"
    47 #include <xqconversions.h>
    47 #include <xqconversions.h>
    48 #include "debugtraces.h"
    48 #include "debugtraces.h"
    49 #include "UniEditorGenUtils.h"
       
    50 
    49 
    51 // Possible values for mms validity period in seconds
    50 // Possible values for mms validity period in seconds
    52 const TInt32 KUniMmsValidityPeriod1h = 3600;
    51 const TInt32 KUniMmsValidityPeriod1h = 3600;
    53 const TInt32 KUniMmsValidityPeriod6h = 21600;
    52 const TInt32 KUniMmsValidityPeriod6h = 21600;
    54 const TInt32 KUniMmsValidityPeriod24h = 86400;
    53 const TInt32 KUniMmsValidityPeriod24h = 86400;
   101 
   100 
   102     if(iSession)
   101     if(iSession)
   103     {
   102     {
   104         delete iSession;
   103         delete iSession;
   105     }
   104     }
       
   105     delete iGenUtils;
   106 }
   106 }
   107 
   107 
   108 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
   109 // C++ default constructor
   109 // C++ default constructor
   110 // @see Header
   110 // @see Header
   111 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
   112 //
   112 //
   113 CUniEditorMmsPluginPrivate::CUniEditorMmsPluginPrivate( )
   113 CUniEditorMmsPluginPrivate::CUniEditorMmsPluginPrivate( )
   114 {
   114 {
   115     TRAP_IGNORE(iSession = CMsvSession::OpenSyncL(*this));
   115     TRAP_IGNORE(iSession = CMsvSession::OpenSyncL(*this));
       
   116     iGenUtils = new UniEditorGenUtils();
   116 }
   117 }
   117 
   118 
   118 // -----------------------------------------------------------------------------
   119 // -----------------------------------------------------------------------------
   119 // convertFromL
   120 // convertFromL
   120 // @see Header
   121 // @see Header
   662             stringToAdd.Set( addressPtr );
   663             stringToAdd.Set( addressPtr );
   663 
   664 
   664             // Internal data structures always holds the address data in western format.
   665             // Internal data structures always holds the address data in western format.
   665             // UI is responsible of doing language specific conversions.    
   666             // UI is responsible of doing language specific conversions.    
   666             //MuiuTextUtils::ConvertDigitsTo( addressPtr, EDigitTypeWestern );
   667             //MuiuTextUtils::ConvertDigitsTo( addressPtr, EDigitTypeWestern );
   667             UniEditorGenUtils* genUtils = new UniEditorGenUtils();
   668             iGenUtils->ConvertDigitsTo( addressPtr, EDigitTypeWestern );
   668             genUtils->ConvertDigitsTo( addressPtr, EDigitTypeWestern );
       
   669             delete genUtils;
       
   670         }
   669         }
   671 
   670 
   672         if ( ( aDetails.Length() != 0 ) &&   // Not a first address
   671         if ( ( aDetails.Length() != 0 ) &&   // Not a first address
   673                 ( aDetails.Length() + KAddressSeparator().Length() < KMaxDetailsLength ) )
   672                 ( aDetails.Length() + KAddressSeparator().Length() < KMaxDetailsLength ) )
   674         {
   673         {
  1030         // resolve contact if alias is empty
  1029         // resolve contact if alias is empty
  1031         if(addr->alias().isEmpty())
  1030         if(addr->alias().isEmpty())
  1032             {
  1031             {
  1033             QString alias;
  1032             QString alias;
  1034             int count;
  1033             int count;
  1035             int localId =
  1034             if(-1 != MsgContactHandler::resolveContactDisplayName(
  1036                     MsgContactHandler::resolveContactDisplayName(
  1035                             addr->address(), alias, count))
  1037                             addr->address(), alias, count);
  1036                 {
  1038             addr->setAlias(alias);
  1037                 addr->setAlias(alias);
       
  1038                 }
  1039             }
  1039             }
  1040         }
  1040         }
  1041     }
  1041     }
  1042 
  1042 
  1043 // -----------------------------------------------------------------------------
  1043 // -----------------------------------------------------------------------------
  1046 // -----------------------------------------------------------------------------
  1046 // -----------------------------------------------------------------------------
  1047 //
  1047 //
  1048 void CUniEditorMmsPluginPrivate::convertFromReplyAllHandlerL(
  1048 void CUniEditorMmsPluginPrivate::convertFromReplyAllHandlerL(
  1049         ConvergedMessage* aMessage)
  1049         ConvergedMessage* aMessage)
  1050     {
  1050     {
       
  1051     ConvergedMessage* tempmsg = new ConvergedMessage();
  1051     // populate all recipients (and sender for received mms)
  1052     // populate all recipients (and sender for received mms)
  1052     TMsvEntry entry = MmsMtmL()->Entry().Entry();
  1053     TMsvEntry entry = MmsMtmL()->Entry().Entry();
  1053     if( entry.Parent() == KMsvGlobalInBoxIndexEntryIdValue )
  1054     if( entry.Parent() == KMsvGlobalInBoxIndexEntryIdValue )
  1054         {
  1055         {
  1055         populateSenderL(*aMessage);
  1056         populateSenderL(*tempmsg);
  1056         }
  1057         }
  1057     populateRecipientsL(*aMessage);
  1058     populateRecipientsL(*tempmsg);
  1058     
  1059     removeOwnNumberForReplyAll(tempmsg, aMessage);
  1059     // resolve to-field contacts
  1060     delete tempmsg;
  1060     ConvergedMessageAddressList addrList = aMessage->toAddressList();
       
  1061     int addrCount = addrList.count();
       
  1062     for(int i=0; i<addrCount; i++)
       
  1063         {
       
  1064         ConvergedMessageAddress* addr = addrList.at(i);
       
  1065         // resolve contact if alias is empty
       
  1066         if(addr->alias().isEmpty())
       
  1067             {
       
  1068             QString alias;
       
  1069             int count;
       
  1070             int localId =
       
  1071                     MsgContactHandler::resolveContactDisplayName(
       
  1072                             addr->address(), alias, count);
       
  1073             addr->setAlias(alias);
       
  1074             }
       
  1075         }
       
  1076 
       
  1077     // resolve cc-field contacts
       
  1078     addrList = aMessage->ccAddressList();
       
  1079     addrCount = addrList.count();
       
  1080     for(int i=0; i<addrCount; i++)
       
  1081         {
       
  1082         ConvergedMessageAddress* addr = addrList.at(i);
       
  1083         // resolve contact if alias is empty
       
  1084         if(addr->alias().isEmpty())
       
  1085             {
       
  1086             QString alias;
       
  1087             int count;
       
  1088             int localId =
       
  1089                     MsgContactHandler::resolveContactDisplayName(
       
  1090                             addr->address(), alias, count);
       
  1091             addr->setAlias(alias);
       
  1092             }
       
  1093         }
       
  1094 
       
  1095     // resolve bcc-field contacts
       
  1096     addrList = aMessage->bccAddressList();
       
  1097     addrCount = addrList.count();
       
  1098     for(int i=0; i<addrCount; i++)
       
  1099         {
       
  1100         ConvergedMessageAddress* addr = addrList.at(i);
       
  1101         // resolve contact if alias is empty
       
  1102         if(addr->alias().isEmpty())
       
  1103             {
       
  1104             QString alias;
       
  1105             int count;
       
  1106             int localId =
       
  1107                     MsgContactHandler::resolveContactDisplayName(
       
  1108                             addr->address(), alias, count);
       
  1109             addr->setAlias(alias);
       
  1110             }
       
  1111         }
       
  1112 
  1061 
  1113     // populate the subject field
  1062     // populate the subject field
  1114     QString subject = XQConversions::s60DescToQString(
  1063     QString subject = XQConversions::s60DescToQString(
  1115             MmsMtmL()->SubjectL());
  1064             MmsMtmL()->SubjectL());
  1116     if(!subject.startsWith(LOC_RE, Qt::CaseInsensitive))
  1065     if(!subject.startsWith(LOC_RE, Qt::CaseInsensitive))
  1174     //The region info inside slides is not maintained
  1123     //The region info inside slides is not maintained
  1175     populateMessageBodyL(*aMessage);
  1124     populateMessageBodyL(*aMessage);
  1176     
  1125     
  1177     QDEBUG_WRITE("Exit convertFromDefaultHandlerL");
  1126     QDEBUG_WRITE("Exit convertFromDefaultHandlerL");
  1178 }
  1127 }
       
  1128 
       
  1129 // -----------------------------------------------------------------------------
       
  1130 // removeOwnNumberForReplyAll
       
  1131 // @see Header
       
  1132 // -----------------------------------------------------------------------------
       
  1133 void CUniEditorMmsPluginPrivate::removeOwnNumberForReplyAll(
       
  1134         ConvergedMessage* sourcemsg, 
       
  1135         ConvergedMessage* targetmsg)
       
  1136 {
       
  1137     // allocate new memory for trimming the address list
       
  1138     // why do we need it? Because ConvergedMessageAddressList is implicitely
       
  1139     // shared, and Implicit sharing automatically detaches the object from
       
  1140     // a shared block if the object is about to change and the reference count
       
  1141     // is greater than one. This is called copy-on-write or value semantics.
       
  1142     ConvergedMessageAddressList toAddrList = 
       
  1143             copyAddrList(sourcemsg->toAddressList());
       
  1144     ConvergedMessageAddressList ccAddrList = 
       
  1145             copyAddrList(sourcemsg->ccAddressList());
       
  1146     ConvergedMessageAddressList bccAddrList = 
       
  1147             copyAddrList(sourcemsg->bccAddressList());
       
  1148 
       
  1149     // start self-address check/remove process. Stop if there's only one
       
  1150     // address left in the address-list (to+cc+bcc)
       
  1151     QStringList selfAddrs = MsgContactHandler::selfAddresses();
       
  1152     int remainingAddr = 
       
  1153             toAddrList.count() + ccAddrList.count() + bccAddrList.count();
       
  1154     bool runOwnAddrCheck =(remainingAddr>1)?true:false;
       
  1155     if(runOwnAddrCheck)
       
  1156     {
       
  1157         foreach(ConvergedMessageAddress *bccAddress,bccAddrList)
       
  1158         {
       
  1159             if(isSelfAddress(bccAddress->address(), selfAddrs))
       
  1160             {
       
  1161                 bccAddrList.removeOne(bccAddress);
       
  1162                 --remainingAddr;
       
  1163                 if(remainingAddr == 1)
       
  1164                 {
       
  1165                     runOwnAddrCheck = false;
       
  1166                     break;
       
  1167                 }
       
  1168             }
       
  1169         }
       
  1170     }
       
  1171 
       
  1172     if(runOwnAddrCheck)
       
  1173     {
       
  1174         foreach(ConvergedMessageAddress *ccAddress,ccAddrList)
       
  1175         {
       
  1176             if(isSelfAddress(ccAddress->address(), selfAddrs))
       
  1177             {
       
  1178                 ccAddrList.removeOne(ccAddress);
       
  1179                 --remainingAddr;
       
  1180                 if(remainingAddr == 1)
       
  1181                 {
       
  1182                     runOwnAddrCheck = false;
       
  1183                     break;
       
  1184                 }
       
  1185             }
       
  1186         }
       
  1187     }
       
  1188 
       
  1189     if(runOwnAddrCheck)
       
  1190     {
       
  1191         foreach(ConvergedMessageAddress *toAddress,toAddrList)
       
  1192         {
       
  1193             if(isSelfAddress(toAddress->address(), selfAddrs))
       
  1194             {
       
  1195                 toAddrList.removeOne(toAddress);
       
  1196                 --remainingAddr;
       
  1197                 if(remainingAddr == 1)
       
  1198                 {
       
  1199                     runOwnAddrCheck = false;
       
  1200                     break;
       
  1201                 }
       
  1202             }
       
  1203         }
       
  1204     }
       
  1205 
       
  1206     // Run contact-resolution on address list now. This is needed
       
  1207     // because we by-pass server and directly feed data in UI
       
  1208     resolveContacts(toAddrList);
       
  1209     resolveContacts(ccAddrList);
       
  1210     resolveContacts(bccAddrList);
       
  1211 
       
  1212     // restore addresses to aMessage
       
  1213     targetmsg->addToRecipients(toAddrList);
       
  1214     targetmsg->addCcRecipients(ccAddrList);
       
  1215     targetmsg->addBccRecipients((bccAddrList));
       
  1216 }
       
  1217 
       
  1218 // -----------------------------------------------------------------------------
       
  1219 // copyAddrList
       
  1220 // @see Header
       
  1221 // -----------------------------------------------------------------------------
       
  1222 ConvergedMessageAddressList CUniEditorMmsPluginPrivate::copyAddrList(
       
  1223         ConvergedMessageAddressList addrList)
       
  1224 {
       
  1225     ConvergedMessageAddressList copyAddrList;
       
  1226     int count = addrList.count();
       
  1227     for(int i=0; i<count; i++)
       
  1228     {
       
  1229         ConvergedMessageAddress* addr = new ConvergedMessageAddress;
       
  1230         addr->setAddress(addrList.at(i)->address());
       
  1231         addr->setAlias(addrList.at(i)->alias());
       
  1232         copyAddrList << addr;
       
  1233     }
       
  1234     return copyAddrList;
       
  1235 }
       
  1236 
       
  1237 // -----------------------------------------------------------------------------
       
  1238 // resolveContacts
       
  1239 // @see Header
       
  1240 // -----------------------------------------------------------------------------
       
  1241 void CUniEditorMmsPluginPrivate::resolveContacts(
       
  1242         ConvergedMessageAddressList addrList)
       
  1243 {
       
  1244     int count = addrList.count();
       
  1245     for(int i=0; i<count; i++)
       
  1246     {
       
  1247         ConvergedMessageAddress* addr = addrList.at(i);
       
  1248         // resolve contact if alias is empty
       
  1249         if(addr->alias().isEmpty())
       
  1250         {
       
  1251             QString alias;
       
  1252             int count;
       
  1253             if(-1 != MsgContactHandler::resolveContactDisplayName(
       
  1254                             addr->address(), alias, count))
       
  1255             {
       
  1256                 addr->setAlias(alias);
       
  1257             }
       
  1258         }
       
  1259     }
       
  1260 }
       
  1261 
       
  1262 // -----------------------------------------------------------------------------
       
  1263 // isSelfAddress
       
  1264 // @see Header
       
  1265 // -----------------------------------------------------------------------------
       
  1266 bool CUniEditorMmsPluginPrivate::isSelfAddress(
       
  1267         QString address,
       
  1268         QStringList selfAddrList)
       
  1269 {
       
  1270     bool ifSelfAddr = false;
       
  1271     
       
  1272     TRAP_IGNORE(
       
  1273     // check if the given address is an email-address
       
  1274     HBufC* addr = XQConversions::qStringToS60Desc(address);
       
  1275     CleanupStack::PushL(addr);
       
  1276 
       
  1277     if( iGenUtils->IsValidEmailAddress(*addr) )
       
  1278     {
       
  1279         ifSelfAddr = selfAddrList.contains(address, Qt::CaseInsensitive);
       
  1280     }
       
  1281     else // address is a phonenumber, use contact matching
       
  1282     {
       
  1283         foreach(QString selfaddress, selfAddrList)
       
  1284         {
       
  1285             bool ret = false;
       
  1286             HBufC* selfAddr = XQConversions::qStringToS60Desc(selfaddress);
       
  1287             CleanupStack::PushL(selfAddr);
       
  1288             ret = iGenUtils->MatchPhoneNumberL(*addr,*selfAddr);
       
  1289             CleanupStack::PopAndDestroy(selfAddr);
       
  1290             if(ret)
       
  1291             {
       
  1292                 ifSelfAddr = true;
       
  1293                 break;
       
  1294             }
       
  1295         }
       
  1296     }
       
  1297     CleanupStack::PopAndDestroy(addr);
       
  1298     );
       
  1299     return ifSelfAddr;
       
  1300 }
       
  1301 
  1179 //  End of File
  1302 //  End of File