logsui/logsengine/src/logscommondata.cpp
changeset 17 90fe74753f71
parent 15 76d2cf7a585e
child 21 2f0af9ba7665
--- a/logsui/logsengine/src/logscommondata.cpp	Mon Aug 23 18:14:51 2010 +0300
+++ b/logsui/logsengine/src/logscommondata.cpp	Fri Sep 03 14:26:05 2010 +0300
@@ -22,18 +22,34 @@
 #include "logsengdefs.h"
 
 //SYSTEM
+#include <xqsettingsmanager.h>
 #include <qcontactmanager.h>
-
+#include <LogsDomainCRKeys.h>
 
 static LogsCommonData* mLogsCommonInstance = 0;
- 
+
+// CONSTANTS
+
+// Telephony Configuration API
+// Keys under this category are used in defining telephony configuration.
+const TUid logsTelConfigurationCRUid = {0x102828B8};
+
+// Amount of digits to be used in contact matching.
+// This allows a customer to variate the amount of digits to be matched.
+const TUint32 logsTelMatchDigits = 0x00000001;
+
+const int logsNotInitialized = -1;
+
 // -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
 //
 LogsCommonData::LogsCommonData() : 
     mContactManager(0), mMaxReadSize(-1), 
-    mMaxReadSizeDir(LogsEvent::DirUndefined), mMatchLen(logsDefaultMatchLength)
+    mMaxReadSizeDir(LogsEvent::DirUndefined), 
+    mSettingsManager(new XQSettingsManager()),
+    mMatchLen(logsDefaultMatchLength),
+    mPredictiveSearchStatus(logsNotInitialized)
 {
     LOGS_QDEBUG( "logs [ENG] <-> LogsCommonData::LogsCommonData()" )
 }
@@ -46,6 +62,7 @@
 {
     LOGS_QDEBUG( "logs [ENG] -> LogsCommonData::~LogsCommonData()" )
     delete mContactManager;
+    delete mSettingsManager;
     LOGS_QDEBUG( "logs [ENG] <- LogsCommonData::~LogsCommonData()" )
 }
 
@@ -136,18 +153,110 @@
 //
 // -----------------------------------------------------------------------------
 //
-void LogsCommonData::setTelNumMatchLen(int matchLen)
+int LogsCommonData::telNumMatchLen() const
 {
-    mMatchLen = matchLen;
+    return mMatchLen;
+}
+
+
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+int LogsCommonData::predictiveSearchStatus()
+{
+    if (mPredictiveSearchStatus == logsNotInitialized) {
+        mPredictiveSearchStatus = getPredictiveSearchStatus();
+    }
+    return mPredictiveSearchStatus;
 }
 
 // -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
 //
-int LogsCommonData::telNumMatchLen() const
+int LogsCommonData::getPredictiveSearchStatus()
+{
+    int status(logsNotInitialized);
+    LOGS_QDEBUG( "logs [ENG] -> LogsCommonData::getPredictiveSearchStatus()" )
+    XQSettingsKey key(XQSettingsKey::TargetCentralRepository, 
+                      KCRUidLogs.iUid, 
+                      KLogsPredictiveSearch);
+    QVariant value = mSettingsManager->readItemValue(key, 
+                                                     XQSettingsManager::TypeInt);
+    if (!value.isNull()) {
+        status = value.toInt();
+    }
+    LOGS_QDEBUG_2( "logs [ENG] <- LogsCommonData::getPredictiveSearchStatus(), status: ", status )
+    return status;
+}
+
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+int LogsCommonData::setPredictiveSearch(bool enabled)
 {
-    return mMatchLen;
+    int err(-1);
+    LOGS_QDEBUG_2( "logs [ENG] -> LogsCommonData::setPredictiveSearch(), enabled: ", enabled )
+    if (predictiveSearchStatus() != 0) {
+        XQSettingsKey key(XQSettingsKey::TargetCentralRepository, 
+                          KCRUidLogs.iUid, 
+                          KLogsPredictiveSearch);
+        int value = enabled ? 1 : 2;
+        if (mSettingsManager->writeItemValue(key, QVariant(value))) {
+            err = 0;
+            mPredictiveSearchStatus = value;
+        }
+    }
+    LOGS_QDEBUG_2( "logs [ENG] <- LogsCommonData::setPredictiveSearch(), err: ", err )
+    return err;
+}
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+int LogsCommonData::clearMissedCallsCounter()
+{
+    int err(-1);
+    XQSettingsKey key(XQSettingsKey::TargetCentralRepository, 
+                      KCRUidLogs.iUid, 
+                      KLogsNewMissedCalls);
+    QVariant value = mSettingsManager->readItemValue(
+                            key, XQSettingsManager::TypeInt);
+    if (!value.isNull()) {
+        err = 0;
+        if (value.toInt() > 0) {
+            err = mSettingsManager->writeItemValue(key, 0) ? 0 : -1;
+        }
+    }
+    return err;    
+}
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+bool LogsCommonData::getTelNumMatchLen(int& matchLen)
+{
+    bool ok(false);
+    //use local manager, since normally this function is called only once, 
+    //after that we can clean related cenrep handler resources
+    XQSettingsManager manager;
+    XQSettingsKey key(XQSettingsKey::TargetCentralRepository, 
+                      logsTelConfigurationCRUid.iUid, 
+                      logsTelMatchDigits);
+    QVariant value = manager.readItemValue(
+                             key, XQSettingsManager::TypeInt);
+    if (!value.isNull()) {
+        matchLen = value.toInt();
+        mMatchLen = matchLen;
+        ok = true;
+    }
+    return ok;
 }
 
 // End of file