emailuis/uicomponents/src/fssmileydictionary.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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: This file implements class CFsSmileyDictionary.
       
    15 *
       
    16 */
       
    17 #include "emailtrace.h"
       
    18 #include "fssmileydictionary.h"
       
    19 
       
    20 EXPORT_C CFsSmileyDictionary* CFsSmileyDictionary::NewL()
       
    21     {
       
    22     FUNC_LOG;
       
    23     CFsSmileyDictionary* self = new(ELeave)CFsSmileyDictionary();
       
    24     CleanupStack::PushL(self);
       
    25     self->ConstructL();
       
    26     CleanupStack::Pop(self);
       
    27     return self;
       
    28     }
       
    29     
       
    30 EXPORT_C CFsSmileyDictionary::~CFsSmileyDictionary()
       
    31     {
       
    32     FUNC_LOG;
       
    33     for(int i = 0 ; i < iSmileysDictionary.Count() ; ++i)
       
    34         {
       
    35         TSmiley *smiley = iSmileysDictionary[i];
       
    36         delete smiley;
       
    37         }
       
    38       
       
    39     delete []iResults;
       
    40     iSmileysDictionary.Close();    
       
    41     }
       
    42 
       
    43 void CFsSmileyDictionary::AddNewSmileyL(TSmiley* aSmiley)
       
    44     {
       
    45     FUNC_LOG;
       
    46     iSmileysDictionary.AppendL(aSmiley);
       
    47     if(aSmiley->iText->Length() > iLongestSmiley)
       
    48         {
       
    49         iLongestSmiley = aSmiley->iText->Length();
       
    50         }
       
    51         
       
    52     iEndIndex = iSmileysDictionary.Count();
       
    53     }   
       
    54     
       
    55 EXPORT_C void CFsSmileyDictionary::AddNewSmileyL(
       
    56         const TDesC& aText, 
       
    57         TFileName aFileName)
       
    58     {
       
    59     FUNC_LOG;
       
    60     TSmiley* smiley = new(ELeave)TSmiley;
       
    61     
       
    62     smiley->iText = aText.AllocL();
       
    63     smiley->iFileName = aFileName;
       
    64     
       
    65     iSmileysDictionary.AppendL(smiley);
       
    66     if(smiley->iText->Length() > iLongestSmiley)
       
    67         {
       
    68         iLongestSmiley = smiley->iText->Length();
       
    69         }
       
    70         
       
    71     iEndIndex = iSmileysDictionary.Count();
       
    72     }
       
    73 
       
    74 TBool CFsSmileyDictionary::CheckDictionaryL(TBuf<1> someCharacter) 
       
    75     {
       
    76     FUNC_LOG;
       
    77     TBool retVal = ETrue;
       
    78     TInt newEndPosition = 0;
       
    79     
       
    80     //poprzednia litera nie byla smileyem
       
    81     if( -1 == iPositionOfCheckingLetter )
       
    82         {
       
    83         ResetL();
       
    84         iPositionOfCheckingLetter = 0;
       
    85         }
       
    86     
       
    87     for(int i = 0 ; i < iEndIndex ; ++i)
       
    88         {
       
    89         TSmiley* smiley = iSmileysDictionary[iResults[i]];
       
    90         
       
    91         if(smiley->iText->Length() > iPositionOfCheckingLetter 
       
    92                 && 0 == someCharacter.Mid(0, 1)
       
    93                   .Compare(smiley->iText->Mid(iPositionOfCheckingLetter, 1)))
       
    94             {
       
    95             iResults[newEndPosition++] = iResults[i];
       
    96             }
       
    97         }
       
    98     
       
    99     if(0 == newEndPosition)
       
   100         {
       
   101         retVal = EFalse;
       
   102         
       
   103         //sprawdzic co sie dzialo
       
   104         if(0 == iPositionOfCheckingLetter)
       
   105             {
       
   106             //ani jedna literka nie przeszla
       
   107             }
       
   108         else
       
   109             {
       
   110             //jakies literki przeszly  
       
   111             for(int i = 0 ; i < iEndIndex ; ++i)
       
   112                 {
       
   113                 TSmiley* smiley = iSmileysDictionary[iResults[i]];
       
   114                 
       
   115                 if(smiley->iText->Length() == iPositionOfCheckingLetter)
       
   116                     {
       
   117                     iSmileyFound = ETrue;
       
   118                     iSmileyIndex = iResults[i];
       
   119                     }
       
   120                 }  
       
   121             }
       
   122         iPositionOfCheckingLetter = -1;
       
   123         }
       
   124     else
       
   125         {
       
   126         iEndIndex = newEndPosition; 
       
   127         ++iPositionOfCheckingLetter; 
       
   128         }
       
   129     
       
   130     return retVal;
       
   131     }
       
   132 
       
   133 TInt CFsSmileyDictionary::GetSmileyLength(TInt aSmileyIndex)
       
   134     {
       
   135     FUNC_LOG;
       
   136     return iSmileysDictionary[aSmileyIndex]->iText->Length();
       
   137     }
       
   138     
       
   139 TFileName CFsSmileyDictionary::GetSmileyFileName(TInt aSmileyIndex)
       
   140     {
       
   141     FUNC_LOG;
       
   142     TFileName retVal;
       
   143     if ( aSmileyIndex >= 0 && aSmileyIndex < iSmileysDictionary.Count() )
       
   144         {
       
   145         retVal = iSmileysDictionary[aSmileyIndex]->iFileName;
       
   146         }
       
   147     return retVal; 
       
   148     }
       
   149 
       
   150 TInt CFsSmileyDictionary::GetSmileyIndex()
       
   151     {
       
   152     FUNC_LOG;
       
   153     return iSmileyIndex;
       
   154     }
       
   155 
       
   156 TBool CFsSmileyDictionary::IsSmiley()
       
   157     {
       
   158     FUNC_LOG;
       
   159     return iSmileyFound;
       
   160     }
       
   161     
       
   162 void CFsSmileyDictionary::ResetL()
       
   163     {
       
   164     FUNC_LOG;
       
   165     if(0 != iSmileysDictionary.Count() && 
       
   166        (!iResults || 
       
   167        iSizeOfResultsTable != iSmileysDictionary.Count()))
       
   168         {
       
   169         delete []iResults;
       
   170         
       
   171         iSizeOfResultsTable = iSmileysDictionary.Count();
       
   172         
       
   173         iResults = new(ELeave)TInt[iSizeOfResultsTable];
       
   174         }
       
   175         
       
   176     for(TInt i = 0 ; i < iSizeOfResultsTable ; ++i)
       
   177         {
       
   178         iResults[i] = i;
       
   179         }
       
   180             
       
   181     iEndIndex = iSizeOfResultsTable;
       
   182     iSmileyFound = EFalse;
       
   183     }
       
   184     
       
   185 void CFsSmileyDictionary::ConstructL()
       
   186     {
       
   187     FUNC_LOG;
       
   188     
       
   189     }
       
   190         
       
   191 CFsSmileyDictionary::CFsSmileyDictionary():iPositionOfCheckingLetter(-1)
       
   192     {
       
   193     FUNC_LOG;
       
   194         
       
   195     }
       
   196 
       
   197