messagingapp/msgui/conversationview/src/msgcharcounter_p.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 30 6a20128ce557
child 32 f3f513612312
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
     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:Implements Symbian functionality to get message pdu details.
       
    15  *
       
    16  */
       
    17 #include "msgcharcounter_p.h"
       
    18 
       
    19 #include <smuthdr.h>
       
    20 #include <gsmuset.h>
       
    21 #include <gsmumsg.h>
       
    22 #include <txtetext.h>
       
    23 #include <txtrich.h>
       
    24 
       
    25 #include "msgcharcounter.h"
       
    26 #include "s60qconversions.h"
       
    27 
       
    28 enum MsgCharSupport
       
    29 {
       
    30     msgCharSupportFull = 0, msgCharSupportReduced
       
    31 };
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Default Constructor ( 1st phase )
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 MsgCharCounterPrivate::MsgCharCounterPrivate(MsgCharCounter *msgCharCounter) :
       
    38     q_ptr(msgCharCounter)
       
    39 {
       
    40     // No implementation required
       
    41 }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Destructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 MsgCharCounterPrivate::~MsgCharCounterPrivate()
       
    48 {
       
    49     q_ptr = NULL;
       
    50 
       
    51     if (mParaFormatLayer)
       
    52     {
       
    53         delete mParaFormatLayer;
       
    54         mParaFormatLayer = NULL;
       
    55     }
       
    56 
       
    57     if (mCharFormatLayer)
       
    58     {
       
    59         delete mCharFormatLayer;
       
    60         mCharFormatLayer = NULL;
       
    61     }
       
    62 
       
    63     if (mRichText)
       
    64     {
       
    65         delete mRichText;
       
    66         mRichText = NULL;
       
    67     }
       
    68 
       
    69     if (mSmsHeader)
       
    70     {
       
    71         delete mSmsHeader;
       
    72         mSmsHeader = NULL;
       
    73     }
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Two-phased constructor.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 MsgCharCounterPrivate* MsgCharCounterPrivate::newL(
       
    81     MsgCharCounter *msgCharCounter)
       
    82 {
       
    83     MsgCharCounterPrivate* self = new (ELeave) MsgCharCounterPrivate(
       
    84         msgCharCounter);
       
    85     CleanupStack::PushL(self);
       
    86     self->constructL();
       
    87     CleanupStack::Pop(); // self;
       
    88     return self;
       
    89 }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // EPOC default constructor for performing 2nd stage construction
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void MsgCharCounterPrivate::constructL()
       
    96 {
       
    97     mParaFormatLayer = CParaFormatLayer::NewL();
       
    98     mCharFormatLayer = CCharFormatLayer::NewL();
       
    99     mRichText = CRichText::NewL(mParaFormatLayer, mCharFormatLayer);
       
   100 
       
   101     mSmsHeader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *mRichText);
       
   102 }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // To Set encoding settings like encoding type, character support and
       
   106 // alternative encoding if any.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void MsgCharCounterPrivate::setEncodingSettings(bool unicodeMode,
       
   110     int alternativeEncodingType, int charSupportType)
       
   111 {
       
   112     TSmsUserDataSettings smsSettings;
       
   113     CSmsMessage& smsMsg = mSmsHeader->Message();
       
   114 
       
   115     mUnicodeMode = unicodeMode;
       
   116     mCharSupportType = charSupportType;
       
   117     mAlternativeEncodingType = (TSmsEncoding) alternativeEncodingType;
       
   118 
       
   119     if (mUnicodeMode)
       
   120     {
       
   121         smsSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabetUCS2);
       
   122     }
       
   123     else
       
   124     {
       
   125         smsSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   126     }
       
   127     smsSettings.SetTextCompressed(EFalse);
       
   128     smsMsg.SetUserDataSettingsL(smsSettings);
       
   129     //First try without any alternate encoding
       
   130     smsMsg.SetAlternative7bitEncoding(ESmsEncodingNone);
       
   131 }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // To get PDU Info: extracts details of number of PDUs, number of remaining
       
   135 // chars in last PDU and encoding types used.
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void MsgCharCounterPrivate::getNumPDUs(const QString &buf,
       
   139     int &numOfRemainingChars, int &numOfPDUs, bool &unicodeMode,
       
   140     int &alternativeEncodingType)
       
   141 {
       
   142     TInt numOfUnconvChars;
       
   143     TInt numOfDowngradedChars;
       
   144     TInt isAltEncSupported;
       
   145     TSmsEncoding currentAlternativeEncodingType;
       
   146 
       
   147     CSmsMessage& smsMsg = mSmsHeader->Message();
       
   148 
       
   149     // need to set the input buffer to SMS buffer through iRichText
       
   150     // (which is reference to SMS Buffer object)
       
   151     HBufC* buffer = S60QConversions::qStringToS60Desc(buf);
       
   152     CleanupStack::PushL(buffer);
       
   153     mRichText->Reset();
       
   154     mRichText->InsertL(0, *buffer);
       
   155 
       
   156     //call SMS stack API to get PDU info
       
   157     smsMsg.GetEncodingInfoL(numOfPDUs, numOfUnconvChars, numOfDowngradedChars,
       
   158         numOfRemainingChars);
       
   159 
       
   160     //Algo to switch to Unicode if required
       
   161     while ( (numOfUnconvChars || numOfDowngradedChars) && !mUnicodeMode)
       
   162     {
       
   163         currentAlternativeEncodingType = smsMsg.Alternative7bitEncoding();
       
   164         if (currentAlternativeEncodingType != mAlternativeEncodingType)
       
   165         {
       
   166             //try with this new alternative encoding type
       
   167             isAltEncSupported = smsMsg.SetAlternative7bitEncoding(
       
   168                 mAlternativeEncodingType);
       
   169             if (isAltEncSupported == KErrNotSupported)
       
   170             {
       
   171                 // if required alternative encoding plugin is not supported,
       
   172                 // retain the existing encoding mechanism.
       
   173                 mAlternativeEncodingType = currentAlternativeEncodingType;
       
   174                 continue;
       
   175             }
       
   176         }
       
   177         else if (numOfUnconvChars || (MsgCharSupport) mCharSupportType
       
   178                 == msgCharSupportFull)
       
   179         {
       
   180             //switch to Unicode
       
   181             //mUnicodeMode = ETrue;
       
   182             setEncodingSettings(ETrue, ESmsEncodingNone, mCharSupportType);
       
   183         }
       
   184         else
       
   185         {
       
   186             //Get out of while loop and return the results
       
   187             break;
       
   188         }
       
   189         //get the PDU info with new settings
       
   190         mRichText->Reset();
       
   191         mRichText->InsertL(0, *buffer);
       
   192         smsMsg.GetEncodingInfoL(numOfPDUs, numOfUnconvChars,
       
   193             numOfDowngradedChars, numOfRemainingChars);
       
   194     } // end of while
       
   195 
       
   196     CleanupStack::PopAndDestroy(buffer);
       
   197     unicodeMode = mUnicodeMode;
       
   198     alternativeEncodingType = mAlternativeEncodingType;
       
   199     if (mUnicodeMode)
       
   200     {
       
   201         // In case of Unicode mode, SMS Stack returns number of available free
       
   202         // User Data units. Need to convert them w.r.t characters.
       
   203         // Each char takse 2 UD units.
       
   204         numOfRemainingChars = numOfRemainingChars / 2;
       
   205     }
       
   206 }
       
   207 
       
   208 //EOF