telutils/keysequencerecognitionservice/src/keysequencerecognitionprovider.cpp
branchRCL_3
changeset 19 7d48bed6ce0c
equal deleted inserted replaced
18:594d59766373 19:7d48bed6ce0c
       
     1 /*!
       
     2 * Copyright (c) 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: Implements Qt Highway provider for key sequence handling.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QCoreApplication>
       
    19 #include <QTimer>
       
    20 #include <QTranslator>
       
    21 #include <QLocale>
       
    22 #include <tstasksettings.h>
       
    23 #include "keysequencerecognitionprovider.h"
       
    24 #include "manufacturerkeysequencehandler.h"
       
    25 #include "imeikeysequencehandler.h"
       
    26 #include "lifetimerkeysequencehandler.h"
       
    27 #include "simcontrolkeysequencehandler.h"
       
    28 #include "keysequencerecognitionservicelog.h"
       
    29 
       
    30 /*!
       
    31   KeySequenceRecognitionProvider::KeySequenceRecognitionProvider.
       
    32  */
       
    33 KeySequenceRecognitionProvider::KeySequenceRecognitionProvider(
       
    34     QObject* parent)
       
    35     : 
       
    36     XQServiceProvider(QLatin1String(
       
    37         "keysequencerecognitionservice.com.nokia.symbian.IKeySequenceRecognition"),
       
    38         parent),
       
    39     m_keySequenceValidator("")
       
    40 {
       
    41     DPRINT_METHODENTRYEXIT;
       
    42     
       
    43     publishAll();
       
    44     
       
    45     setupLocalization();
       
    46     
       
    47     // One should not call anything exception generating after handlers are
       
    48     // created because memory for handlers will be leaked on an exception 
       
    49     // while being in c++ constructor.
       
    50     constructKeySequenceHandlers();
       
    51 
       
    52     // Keysequencerecognitionprovider to be invisible in taskswitcher 
       
    53     TsTaskSettings taskSettings;
       
    54     taskSettings.setVisibility(false);
       
    55 }
       
    56 
       
    57 
       
    58 /*!
       
    59   KeySequenceRecognitionProvider::~KeySequenceRecognitionProvider.
       
    60  */
       
    61 KeySequenceRecognitionProvider::~KeySequenceRecognitionProvider()
       
    62 {
       
    63     DPRINT_METHODENTRYEXIT;
       
    64 }
       
    65 
       
    66 
       
    67 /*!
       
    68   KeySequenceRecognitionProvider::keySequenceValidator.
       
    69  */
       
    70 QString KeySequenceRecognitionProvider::keySequenceValidator()
       
    71 {
       
    72     DPRINT_METHODENTRYEXIT;
       
    73     
       
    74     if (m_keySequenceValidator.isEmpty()) {
       
    75         constructKeySequenceValidator();
       
    76     }
       
    77     
       
    78     return m_keySequenceValidator;
       
    79 }
       
    80 
       
    81 
       
    82 /*!
       
    83   KeySequenceRecognitionProvider::executeKeySequence.
       
    84  */
       
    85 bool KeySequenceRecognitionProvider::executeKeySequence(
       
    86     const QString &keySequence)
       
    87 {
       
    88     DPRINT_METHODENTRYEXIT;
       
    89     
       
    90     bool handled = false;
       
    91     
       
    92     QList<KeySequenceHandler*>::const_iterator it = m_handlers.constBegin();
       
    93     for (;(it != m_handlers.constEnd()) && (!handled); ++it) {
       
    94         handled = (*it)->executeKeySequence(keySequence);
       
    95     }
       
    96     
       
    97     return handled;
       
    98 }
       
    99 
       
   100 
       
   101 /*!
       
   102   KeySequenceRecognitionProvider::setupLocalization.
       
   103  */
       
   104 void KeySequenceRecognitionProvider::setupLocalization()
       
   105 {
       
   106     DPRINT_METHODENTRYEXIT;
       
   107     
       
   108     QScopedPointer<QTranslator> translator(new QTranslator(this));
       
   109     
       
   110     QString locale = QLocale::system().name();
       
   111     QString path = QString("z:/resource/qt/translations/");
       
   112     bool translatorLoaded = 
       
   113         translator->load(QString(path + "telephone_" + locale));
       
   114     
       
   115     if (translatorLoaded) {
       
   116         qApp->installTranslator(translator.data());
       
   117         translator.take();
       
   118     }
       
   119 }
       
   120 
       
   121 
       
   122 /*!
       
   123   KeySequenceRecognitionProvider::constructKeySequenceHandlers.
       
   124  */
       
   125 void KeySequenceRecognitionProvider::constructKeySequenceHandlers()
       
   126 {
       
   127     DPRINT_METHODENTRYEXIT;
       
   128     
       
   129     QScopedPointer<KeySequenceHandler> manufacturerHandler( 
       
   130         new ManufacturerKeySequenceHandler(this));
       
   131     m_handlers.append(manufacturerHandler.data());
       
   132     manufacturerHandler.take();
       
   133     
       
   134     QScopedPointer<KeySequenceHandler> imeiHandler( 
       
   135         new ImeiKeySequenceHandler(this));
       
   136     m_handlers.append(imeiHandler.data());
       
   137     imeiHandler.take();
       
   138 
       
   139     QScopedPointer<KeySequenceHandler> lifeTimerHandler( 
       
   140         new LifeTimerKeySequenceHandler(this));
       
   141     m_handlers.append(lifeTimerHandler.data());
       
   142     lifeTimerHandler.take();
       
   143     
       
   144     QScopedPointer<KeySequenceHandler> simControlHandler( 
       
   145         new SimControlKeySequenceHandler(this));
       
   146     m_handlers.append(simControlHandler.data());
       
   147     simControlHandler.take();
       
   148 }
       
   149 
       
   150 
       
   151 /*!
       
   152   KeySequenceRecognitionProvider::constructKeySequenceValidator.
       
   153  */
       
   154 void KeySequenceRecognitionProvider::constructKeySequenceValidator()
       
   155 {
       
   156     DPRINT_METHODENTRYEXIT;
       
   157     
       
   158     QList<KeySequenceHandler*>::const_iterator it = m_handlers.constBegin();
       
   159     for (;it != m_handlers.constEnd(); ++it) {
       
   160         if (!m_keySequenceValidator.isEmpty()) {
       
   161             m_keySequenceValidator.append("|");
       
   162         }
       
   163         
       
   164         QString validator = (*it)->keySequenceValidator();
       
   165         m_keySequenceValidator.append(validator);
       
   166     }
       
   167 }