diff -r 427125ac6cb8 -r 7eb70891911c telutils/keysequencerecognitionservice/src/keysequencerecognitionprovider.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/telutils/keysequencerecognitionservice/src/keysequencerecognitionprovider.cpp Fri Jun 11 14:07:16 2010 +0300 @@ -0,0 +1,156 @@ +/*! +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Implements Qt Highway provider for key sequence handling. +* +*/ + +#include +#include +#include +#include +#include "keysequencerecognitionprovider.h" +#include "manufacturerkeysequencehandler.h" +#include "imeikeysequencehandler.h" +#include "lifetimerkeysequencehandler.h" +#include "keysequencerecognitionservicelog.h" + +/*! + KeySequenceRecognitionProvider::KeySequenceRecognitionProvider. + */ +KeySequenceRecognitionProvider::KeySequenceRecognitionProvider( + QObject* parent) + : + XQServiceProvider(QLatin1String( + "keysequencerecognitionservice.com.nokia.symbian.IKeySequenceRecognition"), + parent), + m_keySequenceValidator("") +{ + DPRINT_METHODENTRYEXIT; + + publishAll(); + + setupLocalization(); + + // One should not call anything exception generating after handlers are + // created because memory for handlers will be leaked on an exception + // while being in c++ constructor. + constructKeySequenceHandlers(); +} + + +/*! + KeySequenceRecognitionProvider::~KeySequenceRecognitionProvider. + */ +KeySequenceRecognitionProvider::~KeySequenceRecognitionProvider() +{ + DPRINT_METHODENTRYEXIT; +} + + +/*! + KeySequenceRecognitionProvider::keySequenceValidator. + */ +QString KeySequenceRecognitionProvider::keySequenceValidator() +{ + DPRINT_METHODENTRYEXIT; + + if (m_keySequenceValidator.isEmpty()) { + constructKeySequenceValidator(); + } + + return m_keySequenceValidator; +} + + +/*! + KeySequenceRecognitionProvider::executeKeySequence. + */ +bool KeySequenceRecognitionProvider::executeKeySequence( + const QString &keySequence) +{ + DPRINT_METHODENTRYEXIT; + + bool handled = false; + + QList::const_iterator it = m_handlers.constBegin(); + for (;(it != m_handlers.constEnd()) && (!handled); ++it) { + handled = (*it)->executeKeySequence(keySequence); + } + + return handled; +} + + +/*! + KeySequenceRecognitionProvider::setupLocalization. + */ +void KeySequenceRecognitionProvider::setupLocalization() +{ + DPRINT_METHODENTRYEXIT; + + QScopedPointer translator(new QTranslator(this)); + + QString locale = QLocale::system().name(); + QString path = QString("z:/resource/qt/translations/"); + bool translatorLoaded = + translator->load(QString(path + "telephone_" + locale)); + + if (translatorLoaded) { + qApp->installTranslator(translator.data()); + translator.take(); + } +} + + +/*! + KeySequenceRecognitionProvider::constructKeySequenceHandlers. + */ +void KeySequenceRecognitionProvider::constructKeySequenceHandlers() +{ + DPRINT_METHODENTRYEXIT; + + QScopedPointer manufacturerHandler( + new ManufacturerKeySequenceHandler(this)); + m_handlers.append(manufacturerHandler.data()); + manufacturerHandler.take(); + + QScopedPointer imeiHandler( + new ImeiKeySequenceHandler(this)); + m_handlers.append(imeiHandler.data()); + imeiHandler.take(); + + QScopedPointer lifeTimerHandler( + new LifeTimerKeySequenceHandler(this)); + m_handlers.append(lifeTimerHandler.data()); + lifeTimerHandler.take(); +} + + +/*! + KeySequenceRecognitionProvider::constructKeySequenceValidator. + */ +void KeySequenceRecognitionProvider::constructKeySequenceValidator() +{ + DPRINT_METHODENTRYEXIT; + + QList::const_iterator it = m_handlers.constBegin(); + for (;it != m_handlers.constEnd(); ++it) { + if (!m_keySequenceValidator.isEmpty()) { + m_keySequenceValidator.append("|"); + } + + QString validator = (*it)->keySequenceValidator(); + m_keySequenceValidator.append(validator); + } +}