logsui/logscntfinder/src/logspredictive12keytranslator.cpp
changeset 2 7119b73b84d6
child 4 e52d42f9500c
equal deleted inserted replaced
0:4a5361db8937 2:7119b73b84d6
       
     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:
       
    15 *
       
    16 */
       
    17 #include <QObject>
       
    18 #include <QLocale>
       
    19 #include <QHash>
       
    20 #include <hbinputkeymapfactory.h>
       
    21 #include <hbinputkeymap.h>
       
    22 #include <hbinputsettingproxy.h>
       
    23 
       
    24 #include "logspredictive12keytranslator.h"
       
    25 #include "logslogger.h"
       
    26 
       
    27 const QChar ZeroSepar('0');
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // LogsPredictive12KeyTranslator::LogsPredictive12KeyTranslator()
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 LogsPredictive12KeyTranslator::LogsPredictive12KeyTranslator() 
       
    35     : LogsPredictiveTranslator()
       
    36 {
       
    37     LOGS_QDEBUG( "logs [FINDER] -> LogsPredictive12KeyTranslator::\
       
    38 LogsPredictive12KeyTranslator()" )
       
    39     LOGS_QDEBUG( "logs [FINDER] <- LogsPredictive12KeyTranslator::\
       
    40 LogsPredictive12KeyTranslator()" )
       
    41 
       
    42 }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // LogsPredictive12KeyTranslator::~LogsPredictive12KeyTranslator()
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 LogsPredictive12KeyTranslator::~LogsPredictive12KeyTranslator()
       
    49 {
       
    50     LOGS_QDEBUG( "logs [FINDER] -> LogsPredictive12KeyTranslator::\
       
    51 ~LogsPredictive12KeyTranslator()" )
       
    52     LOGS_QDEBUG( "logs [FINDER] <- LogsPredictive12KeyTranslator::\
       
    53 ~LogsPredictive12KeyTranslator()" )
       
    54     
       
    55 }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // LogsPredictive12KeyTranslator::LogsPredictive12KeyTranslator()
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 QStringList LogsPredictive12KeyTranslator::patternTokens( const QString& pattern ) const
       
    62 {
       
    63     QStringList target = pattern.split( ZeroSepar, QString::SkipEmptyParts );
       
    64     if ( target.length() > 1 ) {
       
    65         QString& first = target[0];
       
    66         QString& last = target[target.length()-1];
       
    67         padWithZeros( first, pattern, 0 );
       
    68         padWithZeros( last, pattern, last.length() );
       
    69     } else if ( target.length() == 0 ) {
       
    70         target.append( ZeroSepar );
       
    71     }
       
    72     return target;
       
    73 }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // LogsPredictive12KeyTranslator::hasPatternSeparators()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 int LogsPredictive12KeyTranslator::hasPatternSeparators( 
       
    80         const QString& pattern ) const
       
    81 {
       
    82     return pattern.count( ZeroSepar );
       
    83 
       
    84 }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // LogsPredictive12KeyTranslator::translateChar()
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 const QChar LogsPredictive12KeyTranslator::translateChar( 
       
    91         const QChar character ) const
       
    92 {
       
    93     const HbMappedKey* mappedKey = 
       
    94             mKeyMap->keyForCharacter( HbKeyboardVirtual12Key, character );
       
    95     return mappedKey ? mappedKey->keycode : QChar();
       
    96 }
       
    97 
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // LogsPredictive12KeyTranslator::padWithLeadingZeros()
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void LogsPredictive12KeyTranslator::padWithZeros( QString& token, 
       
   105                                      const QString& source, int padIndex ) const
       
   106 {
       
   107     const QChar* content = source.data();
       
   108     int index = !padIndex ? 0 : source.length()-1;
       
   109             
       
   110     while( index >= 0 && index < source.length() ) {
       
   111         if ( content[ index ] == ZeroSepar ) {
       
   112             token.insert( padIndex, ZeroSepar );
       
   113             index = !padIndex ? index+1 : index-1;
       
   114         } else {
       
   115             index = -1;
       
   116         }
       
   117     }
       
   118 }
       
   119