src/hbcore/utils/hbfeaturemanager.cpp
changeset 6 c3690ec91ef8
child 21 4633027730f5
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbfeaturemanager_r.h"
       
    27 
       
    28 #include <QString>
       
    29 
       
    30 #if defined(Q_WS_S60)
       
    31 #include <centralrepository.h>
       
    32 #else
       
    33 #include <QSettings>
       
    34 #endif // Q_WS_S60
       
    35 
       
    36 /*!
       
    37     @alpha
       
    38     @hbcore
       
    39     \class HbFeatureManager
       
    40     \brief HbFeatureManager is used to control hb internal features.
       
    41 */
       
    42 
       
    43 /*!
       
    44     \enum HbFeatureManager::Feature
       
    45 
       
    46     This enum defines the hb internal features.
       
    47 */
       
    48 
       
    49 /*!
       
    50     \var HbFeatureManager::TextMeasurement
       
    51 
       
    52     Runtime variation flag for text measurement feature.
       
    53 
       
    54     This needs to be enabled if you want to get the localization layout
       
    55     metrics from your application.
       
    56 
       
    57     Zero means disabled, non-zero means enabled.
       
    58 */
       
    59 
       
    60 /*!
       
    61     \var HbFeatureManager::TheTestUtility
       
    62 
       
    63     Runtime variation flag for "the test utility"
       
    64 
       
    65     This needs to be enabled if you want to utilize "the test utility"
       
    66     (the four floating buttons) in your application. 
       
    67 
       
    68     Zero means disabled, non-zero means enabled.
       
    69 */
       
    70 
       
    71 /*!
       
    72     \var HbFeatureManager::LanguageSwitch
       
    73 */
       
    74 
       
    75 
       
    76 #if defined(Q_WS_S60)
       
    77 const TUid HBFM_CREPO_ID  = {0x2002C304};
       
    78 #endif
       
    79 
       
    80 
       
    81 class HbFeatureManagerPrivate
       
    82 {
       
    83 public:
       
    84     HbFeatureManagerPrivate();
       
    85     virtual ~HbFeatureManagerPrivate();
       
    86 
       
    87     QString toString( HbFeatureManager::Feature feature );
       
    88 
       
    89 #if defined(Q_WS_S60)
       
    90     CRepository *mRepo;
       
    91 #else
       
    92     QSettings *mSettings;
       
    93 #endif // Q_WS_S60
       
    94 };
       
    95 
       
    96 /*!
       
    97 \internal
       
    98 */
       
    99 HbFeatureManagerPrivate::HbFeatureManagerPrivate()
       
   100 {
       
   101 #if defined(Q_WS_S60)
       
   102     TRAPD( err, mRepo = CRepository::NewL( HBFM_CREPO_ID ) );
       
   103     if( err ) {
       
   104         qWarning( "HbFeatureManager construction fails, error code = %d", err );
       
   105     }
       
   106     // Default values defined in cenrep file.
       
   107 #else
       
   108     mSettings = new QSettings( "Nokia", "Hb feature manager" );
       
   109     // Set default values:
       
   110     if( !mSettings->contains( toString( HbFeatureManager::TextMeasurement ) ) ) {
       
   111         mSettings->setValue( toString( HbFeatureManager::TextMeasurement ), 0 );
       
   112     }
       
   113     if( !mSettings->contains( toString( HbFeatureManager::TheTestUtility ) ) ) {
       
   114         mSettings->setValue( toString( HbFeatureManager::TheTestUtility ), 0 );
       
   115     }
       
   116 #endif // Q_WS_S60
       
   117 }
       
   118 
       
   119 /*!
       
   120 \internal
       
   121 */
       
   122 HbFeatureManagerPrivate::~HbFeatureManagerPrivate()
       
   123 {
       
   124 #if defined(Q_WS_S60)
       
   125     delete mRepo;
       
   126 #else
       
   127     delete mSettings;
       
   128 #endif // Q_WS_S60
       
   129 }
       
   130 
       
   131 /*!
       
   132 \internal
       
   133 */
       
   134 QString HbFeatureManagerPrivate::toString( HbFeatureManager::Feature feature )
       
   135 {
       
   136     return QString( "HbFeature_" ) + QString::number( ( int )feature );
       
   137 }
       
   138 
       
   139 /*!
       
   140     Default constructor.
       
   141 */
       
   142 HbFeatureManager::HbFeatureManager() :
       
   143     d(new HbFeatureManagerPrivate)
       
   144 {
       
   145 }
       
   146 
       
   147 /*!
       
   148     Returns singleton instance
       
   149 */
       
   150 HbFeatureManager *HbFeatureManager::instance()
       
   151 {
       
   152     static HbFeatureManager theManager;
       
   153     return &theManager;
       
   154 }
       
   155 
       
   156 /*!
       
   157     Destructor
       
   158 */
       
   159 HbFeatureManager::~HbFeatureManager()
       
   160 {
       
   161     delete d;
       
   162 }
       
   163 
       
   164 /*!
       
   165     Returns the status of requested feature.
       
   166 */
       
   167 int HbFeatureManager::featureStatus( Feature feature )
       
   168 {
       
   169 #if defined(Q_WS_S60)
       
   170     if (!d->mRepo) {
       
   171         return 0;
       
   172     }
       
   173     TUint32 key = (TUint32)feature;
       
   174     TInt value = 0;
       
   175     TInt error = d->mRepo->Get( key, value );
       
   176     if( error != KErrNone ) {
       
   177         qWarning( "HbFeatureManager getting the feature fails, error code = %d", error );
       
   178     } else {
       
   179         return (int)value;
       
   180     }
       
   181 
       
   182 #else
       
   183     if( d->mSettings->contains( d->toString( feature ) ) ) {
       
   184         return d->mSettings->value( d->toString( feature ) ).toInt();
       
   185     }
       
   186 #endif
       
   187     return 0;
       
   188 }
       
   189 
       
   190 
       
   191 /*!
       
   192     Sets the status of requested feature to given value.
       
   193 */
       
   194 void HbFeatureManager::setFeatureStatus( Feature feature, int status )
       
   195 {
       
   196 #if defined(Q_WS_S60)
       
   197     if (!d->mRepo) {
       
   198         return;
       
   199     }
       
   200     TUint32 key = (TUint32)feature;
       
   201     TInt value = (TInt)status;
       
   202     TInt error = d->mRepo->Set( key, value );
       
   203     if( error != KErrNone ) {
       
   204         qWarning( "HbFeatureManager setting the feature fails, error code = %d", error );
       
   205     }
       
   206 
       
   207 #else
       
   208     d->mSettings->setValue( d->toString( feature ), status );
       
   209 #endif
       
   210 }
       
   211