phonesettings/cpphonesettingsplugins/cptelephonyutils/src/cpplugincommon.cpp
changeset 37 ba76fc04e6c2
child 45 6b911d05207e
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     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 
       
    18 
       
    19 #include <etelmm.h>
       
    20 #include <xqsysinfo.h>
       
    21 #include <xqsettingsmanager.h>
       
    22 #include <xqsettingskey.h>
       
    23 #include <e32base.h>
       
    24 #include <etelmm.h>
       
    25 #include <exterror.h>               
       
    26 #include <gsmerror.h>
       
    27 #include <settingsinternalcrkeys.h>
       
    28 #include <LogsDomainCRKeys.h>
       
    29 #include <BTSapDomainPSKeys.h>
       
    30 #include <NumberGroupingCRKeys.h>
       
    31 #include <hbglobal.h>
       
    32 #include <CoreApplicationUIsSDKCRKeys.h>
       
    33 #include "cptelephonyutilsdefs.h"
       
    34 #include "cpplugincommon.h"
       
    35 #include "cppluginlogging.h"
       
    36 
       
    37 const int CenrepKeyValueOff = 0;
       
    38 const int CenrepKeyValueOn = 1;
       
    39 
       
    40 const int SoftRejectTextDefault = 0; 
       
    41 const int SoftRejectTextUserDefined = 1; 
       
    42 
       
    43 /*!
       
    44   Tools::voipSupported
       
    45 */
       
    46 bool Tools::voipSupported()
       
    47 {
       
    48     return XQSysInfo::isSupported(KFeatureIdCommonVoip);
       
    49 }
       
    50 
       
    51 /*!
       
    52   Tools::videoSupported
       
    53 */
       
    54 bool Tools::videoSupported()
       
    55 {
       
    56     return XQSysInfo::isSupported(KFeatureIdCsVideoTelephony);
       
    57 }
       
    58 
       
    59 /*!
       
    60   Tools::errorCodeTextMapping.
       
    61  */
       
    62 bool Tools::errorCodeTextMapping(const int errorcode, QString &errorText)
       
    63 {
       
    64     DPRINT;
       
    65     errorText.clear();
       
    66     bool errorTextFound(true);
       
    67 
       
    68     switch(errorcode){
       
    69         case KErrGsmSSSubscriptionViolation:
       
    70             errorText = hbTrId("txt_phone_info_barring_operation_not_successful");
       
    71             break;
       
    72         case KErrGsmSSUnknownSubscriber:
       
    73         case KErrGsmSSAbsentSubscriber:
       
    74         case KErrGsmSSIllegalOperation:
       
    75         case KErrGsmSSIllegalSubscriber:
       
    76         case KErrGsmSSIllegalEquipment:
       
    77         case KErrGsmSSCallBarred:
       
    78         case KErrGsmSSDataMissing:
       
    79             errorText = hbTrId("txt_phone_info_not_allowed");
       
    80             break;
       
    81         case KErrGsmSSIncompatibility:
       
    82             errorText = hbTrId("Services in conflict");
       
    83             break;
       
    84         case KErrGsmSSSystemFailure:
       
    85             errorText = hbTrId("txt_phone_info_result_unknown");
       
    86             break;
       
    87         case KErrGsmSSUnexpectedDataValue:
       
    88         case KErrGsmSSResourcesUnavailable:
       
    89             errorText = hbTrId("txt_phone_info_request_rejected");
       
    90             break;
       
    91         case KErrGsmSSNegativePasswordCheck:
       
    92         case KErrGsmSSPasswordRegistrationFailure:
       
    93             errorText = hbTrId("Password error");
       
    94             break;
       
    95         case KErrGsmSSPasswordAttemptsViolation:
       
    96             errorText = hbTrId("txt_phone_info_barring_password_blocked");
       
    97             break;
       
    98         case KErrGsmSMSNoNetworkService:
       
    99         case KErrGsmNoService:
       
   100             errorText = hbTrId("No network coverage");
       
   101             break;
       
   102         case KErrSsActivationDataLost:
       
   103             errorText = hbTrId("Check network services");
       
   104             break;
       
   105         case KErrGsmOfflineOpNotAllowed:
       
   106             if(XQSysInfo::isSupported(KFeatureIdOfflineMode)){
       
   107                 XQSettingsManager *xqsettingsManager = new XQSettingsManager();
       
   108                 XQSettingsKey key(XQSettingsKey::TargetPublishAndSubscribe,
       
   109                         KPSUidBluetoothSapConnectionState.iUid,
       
   110                         KBTSapConnectionState);
       
   111                 QVariant startupValue = xqsettingsManager->readItemValue(key);
       
   112                 int value = startupValue.toInt();
       
   113                 delete xqsettingsManager;
       
   114                 xqsettingsManager = NULL;
       
   115                 if (value == EBTSapConnected){
       
   116                     errorText = hbTrId("Operation not possible in SIM access profile mode");
       
   117                 } else {
       
   118                     errorText = hbTrId("Operation not possible in Off-line mode");
       
   119                 }
       
   120             } else {
       
   121                 errorText = hbTrId("txt_phone_info_request_not_completed");
       
   122             }
       
   123             break;
       
   124         case KErrGsmSSUnknownAlphabet:
       
   125             errorText = hbTrId("txt_phone_info_invalid_phone_number");
       
   126             break;
       
   127         default:
       
   128             errorText = hbTrId("txt_phone_info_request_not_completed");
       
   129             break;
       
   130     }
       
   131 
       
   132     return errorTextFound;
       
   133 }
       
   134 
       
   135 CpSettingsWrapper::CpSettingsWrapper(QObject *parent): 
       
   136     QObject(parent)
       
   137 {
       
   138     m_Settings = new XQSettingsManager();
       
   139 }
       
   140 
       
   141 CpSettingsWrapper::~CpSettingsWrapper()
       
   142 {
       
   143     delete m_Settings;
       
   144 }
       
   145 
       
   146 bool CpSettingsWrapper::showCallDuration()
       
   147 {
       
   148     bool showDuration; 
       
   149     if (CenrepKeyValueOn == readCenrepValue(KCRUidLogs.iUid, KLogsShowCallDuration).toInt()) {
       
   150         showDuration = true; 
       
   151     } else {
       
   152         showDuration = false;
       
   153     }
       
   154     
       
   155     DPRINT << "show call duration:" << showDuration;
       
   156     return showDuration;
       
   157 }
       
   158 
       
   159 int CpSettingsWrapper::setShowCallDuration(bool value)
       
   160 {
       
   161     int cenrepValue; 
       
   162     DPRINT << "show call duration:" << value;
       
   163 
       
   164     if (value) {
       
   165         cenrepValue = CenrepKeyValueOn;
       
   166     } else {
       
   167         cenrepValue = CenrepKeyValueOff; 
       
   168     }
       
   169     return writeCenrepValue(KCRUidLogs.iUid, KLogsShowCallDuration, cenrepValue );
       
   170 }
       
   171 
       
   172 void CpSettingsWrapper::readSoftRejectText(QString &text, bool &userDefined )
       
   173 {
       
   174     if (SoftRejectTextDefault ==
       
   175         readCenrepValue(KCRUidTelephonySettings.iUid, KSettingsSoftRejectDefaultInUse ).toInt()) {
       
   176         userDefined = false; 
       
   177     } else {
       
   178         userDefined = true; 
       
   179     }
       
   180         
       
   181     text = readCenrepString(KCRUidTelephonySettings.iUid, KSettingsSoftRejectText);
       
   182     DPRINT << "text:" << text << " ,userDefined:" << userDefined;
       
   183 }
       
   184 
       
   185 int CpSettingsWrapper::writeSoftRejectText(const QString &text, bool userDefined )
       
   186 {
       
   187     int err = writeCenrepValue(KCRUidTelephonySettings.iUid, KSettingsSoftRejectText, text);
       
   188     int cenrepValue; 
       
   189     if (userDefined) {
       
   190         cenrepValue = SoftRejectTextUserDefined; 
       
   191     } else {
       
   192         cenrepValue = SoftRejectTextDefault; 
       
   193     }
       
   194     err |= writeCenrepValue(KCRUidTelephonySettings.iUid, KSettingsSoftRejectDefaultInUse, cenrepValue);
       
   195     DPRINT << "text:" << text << " ,userDefined:" << userDefined << " , err:" << err;
       
   196     return err;
       
   197 }
       
   198 
       
   199  bool CpSettingsWrapper::numberGroupingSupported() const
       
   200  {
       
   201      return readCenrepValue(KCRUidNumberGrouping.iUid, KNumberGrouping).toBool();
       
   202  }
       
   203 
       
   204 QVariant CpSettingsWrapper::readCenrepValue(
       
   205     const long int uid, const unsigned long int key) const
       
   206 {
       
   207     XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, uid, key);
       
   208     QVariant ret = m_Settings->readItemValue(settingsKey);
       
   209     DPRINT << "ret: " << ret;
       
   210     return ret;
       
   211 }
       
   212 
       
   213 QString CpSettingsWrapper::readCenrepString(
       
   214     const long int uid, const unsigned long int key) const
       
   215 {
       
   216     XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, uid, key);
       
   217     QString text = m_Settings->readItemValue(settingsKey, XQSettingsManager::TypeString).toString();
       
   218     DPRINT << "text: " << text;
       
   219     return text;
       
   220 }
       
   221 
       
   222 int CpSettingsWrapper::writeCenrepValue(
       
   223     const long int uid, const unsigned long int key, const QVariant &settingsKeyValue ) const
       
   224 {
       
   225     DPRINT << "uid:" << uid << ", key:" << key << ", settingsKeyValue:" << settingsKeyValue;
       
   226     XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, uid, key);
       
   227     int err = m_Settings->writeItemValue(settingsKey, settingsKeyValue );
       
   228     DPRINT << "err: " << err;
       
   229     return err;
       
   230 }
       
   231 
       
   232 bool CpSettingsWrapper::isFeatureCallWaitingDistiquishNotProvisionedEnabled()
       
   233 {
       
   234     bool enabled = readCenrepValue(KCRUidPhoneSettings.iUid, KPSetCallWaiting).toBool();
       
   235     DPRINT << "enabled: " << enabled;
       
   236     return enabled;
       
   237 }
       
   238 
       
   239 bool CpSettingsWrapper::isPhoneOffline() const
       
   240 {
       
   241     bool offLinesupport(false);
       
   242     if (XQSysInfo::isSupported(KFeatureIdOfflineMode)) {
       
   243         offLinesupport = !readCenrepValue(
       
   244                 KCRUidCoreApplicationUIs.iUid, 
       
   245                 KCoreAppUIsNetworkConnectionAllowed).toBool();
       
   246     }
       
   247     return offLinesupport;
       
   248 }