emailservices/nmutilities/src/emailmailboxinfo_p.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2  * Copyright (c) 2007-2010 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:  mailbox branding object
       
    15  *
       
    16  */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 
       
    20 #include "emailmailboxinfo_p.h"
       
    21 #include "nmutilitiescommonheaders.h"
       
    22 #include "nmcenrepkeys.h"
       
    23 #include <QRegExp>
       
    24 #include <QStringList>
       
    25 
       
    26 const unsigned long int partialKey = 0x0;
       
    27 const unsigned long int bitMask = 0x0F000000;
       
    28 
       
    29 EmailMailboxInfoPrivate* EmailMailboxInfoPrivate::mSelf = NULL;
       
    30 qint32 EmailMailboxInfoPrivate::mReferenceCount = 0;
       
    31 
       
    32 const QString KBrandNameGmail("Gmail");
       
    33 const QString KBrandNameGoogleMail("Google Mail");
       
    34 
       
    35 const QString KMCCGermany("262");
       
    36 const QString KMCCUK1("234");
       
    37 const QString KMCCUK2("235");
       
    38 
       
    39 const quint8 KGermanyTzId = 36;
       
    40 const quint8 KUKTzId = 104;
       
    41 
       
    42 using namespace NmBrandingApi;
       
    43 using namespace QtMobility;
       
    44 
       
    45 /*!
       
    46      private constructor
       
    47  */
       
    48 EmailMailboxInfoPrivate::EmailMailboxInfoPrivate() :
       
    49     QObject(NULL)
       
    50 {
       
    51     NM_FUNCTION;
       
    52     
       
    53     XQSettingsManager manager;
       
    54     XQCentralRepositorySettingsKey rccKey(EMAIL_CENREP, RCC_PATH);
       
    55 
       
    56     XQCentralRepositorySettingsKey wlbKey(EMAIL_CENREP, WLB_BRAND_NAME);
       
    57 
       
    58     mWlbDomainName = manager.readItemValue(wlbKey, XQSettingsManager::TypeString).value<QString> ();    
       
    59 }
       
    60 /*!
       
    61      private destructor
       
    62  */
       
    63 EmailMailboxInfoPrivate::~EmailMailboxInfoPrivate()
       
    64 {
       
    65     NM_FUNCTION;
       
    66 }
       
    67 
       
    68 /*!
       
    69     gets instance of EmailMailboxInfoPrivate
       
    70     \return instance of EmailMailboxInfoPrivate
       
    71  */
       
    72 EmailMailboxInfoPrivate* EmailMailboxInfoPrivate::getInstance()
       
    73 {
       
    74     NM_FUNCTION;
       
    75     
       
    76     if (!mSelf) {
       
    77         mSelf = new EmailMailboxInfoPrivate();
       
    78     }
       
    79     mReferenceCount++;
       
    80     return mSelf;
       
    81 }
       
    82 
       
    83 /*!
       
    84     releases pointer to instance of EmailMailboxInfoPrivate
       
    85     \param pointer to instance of EmailMailboxInfoPrivate object
       
    86  */
       
    87 void EmailMailboxInfoPrivate::releaseInstance(EmailMailboxInfoPrivate *&instance)
       
    88 {
       
    89     NM_FUNCTION;
       
    90     
       
    91     if (instance) {
       
    92         mReferenceCount--;
       
    93         instance = NULL;
       
    94     }
       
    95     if (mReferenceCount < 1) {
       
    96         delete mSelf;
       
    97         mSelf = NULL;
       
    98     }
       
    99 }
       
   100 
       
   101 /*!
       
   102     returns branding name of given domain
       
   103     \param branding identifier
       
   104     \return branding name
       
   105  */
       
   106 QString EmailMailboxInfoPrivate::name(const QVariant &identifier)
       
   107 {
       
   108     NM_FUNCTION;
       
   109     
       
   110     QString returnValue = "";
       
   111     QString domainName = "";
       
   112     if (identifier.canConvert<QString> ()) {
       
   113         domainName = identifier.value<QString> ();
       
   114     }
       
   115 
       
   116     if (domainName.length() > 0) {
       
   117         processCenRepRecords(domainName);
       
   118         returnValue = mTempName;
       
   119     }
       
   120 
       
   121     verifyMailAccountName(returnValue);
       
   122 
       
   123     return returnValue;
       
   124 }
       
   125 
       
   126 /*!
       
   127     returns branding icon of given domain
       
   128     \param branding identifier
       
   129     \return branding icon
       
   130  */
       
   131 QString EmailMailboxInfoPrivate::icon(const QVariant &identifier)
       
   132 {
       
   133     NM_FUNCTION;
       
   134     
       
   135     QString returnValue = "";
       
   136     QString domainName = "";
       
   137     if (identifier.canConvert<QString> ()) {
       
   138         domainName = identifier.value<QString> ();
       
   139         int delimIndex = domainName.lastIndexOf('@');
       
   140         if(delimIndex >= 0) {
       
   141             domainName = domainName.mid(delimIndex + 1);
       
   142         }
       
   143     }
       
   144 
       
   145     if (domainName.length() > 0){
       
   146         processCenRepRecords(domainName);
       
   147         returnValue = mTempIcon;
       
   148     }
       
   149 
       
   150     return returnValue;
       
   151 }
       
   152 
       
   153 /*!
       
   154     goes through cenrep to find matching branding details
       
   155     \param brandingId (i.e. domain name)
       
   156  */
       
   157 void EmailMailboxInfoPrivate::processCenRepRecords(const QString &brandingId)
       
   158 {
       
   159     NM_FUNCTION;
       
   160     
       
   161     bool found = false;
       
   162     QString name;
       
   163     QString icon;
       
   164 
       
   165     XQSettingsManager cenRepManager;
       
   166 
       
   167     if (brandingId == mWlbDomainName) {
       
   168         found = true;
       
   169         XQCentralRepositorySettingsKey wlbNameKey(EMAIL_CENREP, WLB_MAILBOX_NAME);
       
   170         XQCentralRepositorySettingsKey wlbIconKey(EMAIL_CENREP, WLB_ICON_PATH);
       
   171 
       
   172         icon = cenRepManager.readItemValue(wlbIconKey, XQSettingsManager::TypeString).value<QString> ();
       
   173         name = cenRepManager.readItemValue(wlbNameKey, XQSettingsManager::TypeString).value<QString> ();
       
   174     }
       
   175     else {
       
   176         XQCentralRepositorySearchCriteria sCriteria(EMAIL_CENREP, partialKey, bitMask);
       
   177         XQCentralRepositoryUtils cenrepUtils(cenRepManager);
       
   178         QList<XQCentralRepositorySettingsKey> foundKeys = cenrepUtils.findKeys(sCriteria);
       
   179 
       
   180         foreach(XQCentralRepositorySettingsKey key, foundKeys)
       
   181         {
       
   182             QString dataRow = "";
       
   183             if (mBrandingDataMap.contains(key.key())) {
       
   184                 dataRow = mBrandingDataMap.value(key.key());
       
   185             }
       
   186             //first we put every spotted data row to map
       
   187             else {
       
   188                 QVariant brandingDataRaw = cenRepManager.readItemValue(key,
       
   189 					XQSettingsManager::TypeString);
       
   190                 if (brandingDataRaw.canConvert<QString>()) {
       
   191                     dataRow = brandingDataRaw.value<QString>();
       
   192                     mBrandingDataMap.insert(key.key(), dataRow);
       
   193                 }
       
   194             }
       
   195 
       
   196             // then we check if this row contains matching data
       
   197             QStringList cenRepRecord = dataRow.split(";");
       
   198 
       
   199             if (cenRepRecord.size() < 4) {
       
   200                 continue;
       
   201             }
       
   202 
       
   203             if (!brandingId.contains(cenRepRecord.at(0), Qt::CaseInsensitive)) {
       
   204                 continue;
       
   205             }
       
   206 
       
   207             QRegExp regExp(cenRepRecord.at(1));
       
   208             regExp.setCaseSensitivity(Qt::CaseInsensitive);
       
   209 
       
   210             if (regExp.exactMatch(brandingId)) { //match
       
   211                 found = true;
       
   212                 icon = "z:/resource/apps/" + cenRepRecord.at(3) + ".svg";
       
   213                 name = cenRepRecord.at(2);
       
   214                 break;
       
   215             }
       
   216         }
       
   217     }
       
   218     if (!found ) { 
       
   219         //get default icon and name
       
   220         icon = "qtg_large_email";
       
   221         QStringList domain = brandingId.split(".");
       
   222         if (domain.size() > 0) {
       
   223             name = domain.at(0);
       
   224         }
       
   225     }
       
   226     mTempIcon = icon;
       
   227     mTempName = name;
       
   228 }
       
   229 
       
   230 /*!
       
   231     gets current country code
       
   232     \return current country id
       
   233  */
       
   234 quint8 EmailMailboxInfoPrivate::getCurrentCountryL() const
       
   235 {
       
   236     NM_FUNCTION;
       
   237     
       
   238     CTzLocalizer* localizer = CTzLocalizer::NewLC();
       
   239 
       
   240     CTzLocalizedCity* city = localizer->GetFrequentlyUsedZoneCityL(
       
   241         CTzLocalizedTimeZone::ECurrentZone);
       
   242     CleanupStack::PushL(city);
       
   243 
       
   244     CTzLocalizedCityGroup* cityGroup = localizer->GetCityGroupL(city->GroupId());
       
   245 
       
   246     TUint8 countryId = cityGroup->Id();
       
   247 
       
   248     delete cityGroup;
       
   249     cityGroup = NULL;
       
   250 
       
   251     CleanupStack::PopAndDestroy(2, localizer);
       
   252 
       
   253     return countryId;
       
   254 }
       
   255 
       
   256 /*!
       
   257     verifies if timezone is set for Germany or UK
       
   258     \return true if timezone is UK or Germany, false otherwise
       
   259  */
       
   260 bool EmailMailboxInfoPrivate::verifyTimeZone() const
       
   261 {
       
   262     NM_FUNCTION;
       
   263     
       
   264     quint8 timeZone = 0;
       
   265     bool retVal = false;
       
   266     TRAPD(err, timeZone = getCurrentCountryL());
       
   267 
       
   268     if (err == KErrNone && (timeZone == KGermanyTzId || timeZone == KUKTzId)) {
       
   269         retVal = true;
       
   270     }
       
   271     return retVal;
       
   272 }
       
   273 
       
   274 /*!
       
   275     modifies branding name "Gmail" according to UK and Germany law rules
       
   276     \param brandingName name of branding
       
   277  */
       
   278 void EmailMailboxInfoPrivate::verifyMailAccountName(QString &brandingName) const
       
   279 {
       
   280     NM_FUNCTION;
       
   281     
       
   282     QSystemNetworkInfo *networkInfo = new QSystemNetworkInfo();
       
   283     QString currentMCC = networkInfo->currentMobileCountryCode();
       
   284 
       
   285     if (brandingName == KBrandNameGmail) {
       
   286         if (currentMCC.size() > 0) {
       
   287             if ((currentMCC == KMCCGermany) || (currentMCC == KMCCUK1) || (currentMCC == KMCCUK2)) {
       
   288                 brandingName = KBrandNameGoogleMail;
       
   289             }
       
   290         }
       
   291         else { //if there is information (no sim)
       
   292             if (verifyTimeZone()) {
       
   293                 brandingName = KBrandNameGoogleMail;
       
   294             }
       
   295         }
       
   296     }
       
   297 }
       
   298