radiohswidget/src/radiohswidgetprofilereader.cpp
branchRCL_3
changeset 19 cce62ebc198e
equal deleted inserted replaced
18:1a6714c53019 19:cce62ebc198e
       
     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: FM Radio widget process handler
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QDateTime>
       
    20 #include "xqsettingsmanager.h"
       
    21 #include "xqsettingskey.h"
       
    22 #include "xqpublishandsubscribeutils.h"
       
    23 
       
    24 // User includes
       
    25 #include "radiohswidgetprofilereader.h"
       
    26 #include "radiohswidget.h"
       
    27 #include "radioservicedef.h"
       
    28 #include "radio_global.h"
       
    29 #include "radiologger.h"
       
    30 
       
    31 // Constants
       
    32 /** Constant for radio running undefined status. */
       
    33 const int RADIO_RUNNING_STATUS_UNDEFINED(-1);
       
    34 
       
    35 /*!
       
    36     \class RadioHsWidgetProfileReader
       
    37     \brief Implementation of P&S key reader and monitor.
       
    38 
       
    39     RadioHsWidgetProfileReader implements reader and monitor for P&S keys.
       
    40 */
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 /*!
       
    45     Constructs a profile reader which is a child of \a parent.
       
    46     
       
    47     Creates XQSettingsManager for monitoring and accessing the P&S keys.
       
    48     Connects to the signals of XQSettingsManager.
       
    49 */
       
    50 RadioHsWidgetProfileReader::RadioHsWidgetProfileReader(
       
    51     RadioHsWidget *parent) :
       
    52     QObject(parent),
       
    53     mParent(*parent),
       
    54     mSettingsManager(new XQSettingsManager(this)),
       
    55     mRadioStatus(RADIO_RUNNING_STATUS_UNDEFINED)
       
    56 {
       
    57     LOG_METHOD;
       
    58     Radio::connect(mSettingsManager, SIGNAL(itemDeleted(XQSettingsKey)), this,
       
    59         SLOT(handleDeletedItem(XQSettingsKey)));
       
    60     Radio::connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
       
    61         this, SLOT(handleChanges(XQSettingsKey, QVariant)));
       
    62 }
       
    63 
       
    64 /*!
       
    65     Destructor 
       
    66  */
       
    67 RadioHsWidgetProfileReader::~RadioHsWidgetProfileReader()
       
    68 {
       
    69     LOG_METHOD;
       
    70     XQSettingsKey radioRunningKey(XQSettingsKey::TargetPublishAndSubscribe,
       
    71         KRadioPSUid, KRadioStartupKey);
       
    72     mSettingsManager->stopMonitoring(radioRunningKey);
       
    73 }
       
    74 
       
    75 /*!
       
    76     Start monitoring of radio P&S key. Read also the initial value.
       
    77  */
       
    78 void RadioHsWidgetProfileReader::startMonitoringRadioRunningStatus()
       
    79 {
       
    80     LOG_METHOD;
       
    81     XQSettingsKey radioRunningKey(XQSettingsKey::TargetPublishAndSubscribe,
       
    82         KRadioPSUid, KRadioStartupKey);
       
    83     // Start monitoring.
       
    84     mSettingsManager->startMonitoring(radioRunningKey);
       
    85     // Read current value.
       
    86     radioRunningStatus(
       
    87         mSettingsManager->readItemValue(radioRunningKey));
       
    88 }
       
    89 
       
    90 /*!
       
    91     Checks if device is in offline mode and \returns \c true if it is
       
    92     and \c false if not.
       
    93  */
       
    94 bool RadioHsWidgetProfileReader::isInOfflineMode()
       
    95 {
       
    96     LOG_METHOD_RET("%d");
       
    97     XQSettingsKey connectionKey( XQSettingsKey::TargetCentralRepository,
       
    98             CENREP_CORE_APPLICATION_UIS, ID_NETWORK_CONNECTION_ALLOWED );
       
    99 
       
   100     // Read current value.
       
   101     const QVariant connectionAllowed = mSettingsManager->readItemValue( connectionKey );
       
   102     if ( connectionAllowed.canConvert( QVariant::Int ) && connectionAllowed.toInt() == NetworkNotAllowed ) {
       
   103         return true;
       
   104     }
       
   105 
       
   106     return false;
       
   107 }
       
   108 
       
   109 /*!
       
   110     Handling of deletion of listened keys.
       
   111  
       
   112     \param key Deleted key.
       
   113  */
       
   114 void RadioHsWidgetProfileReader::handleDeletedItem(const XQSettingsKey &key)
       
   115 {
       
   116     LOG_METHOD_ENTER;
       
   117     if (key.uid() == KRadioPSUid && key.key() == KRadioStartupKey) {
       
   118         LOG("KRadioStartupKey deleted");
       
   119         startMonitoringRadioRunningStatus();
       
   120     }
       
   121 }
       
   122 
       
   123 /*!
       
   124     Notifications from settings manager are handled and routed to appropriate
       
   125     private slots.
       
   126 
       
   127     \param key Changed key.
       
   128     \param value Value of changed key.
       
   129  */
       
   130 void RadioHsWidgetProfileReader::handleChanges(const XQSettingsKey &key,
       
   131     const QVariant& value)
       
   132 {
       
   133     LOG_SLOT_CALLER;
       
   134 
       
   135     if (key.uid() == KRadioPSUid && key.key()
       
   136         == KRadioStartupKey) {
       
   137         LOG("KRadioStartupKey changed");
       
   138         radioRunningStatus(value);
       
   139     }
       
   140 }
       
   141 
       
   142 /*!
       
   143     Handling changes in radio running P&S key.
       
   144  
       
   145     \param value is int representation of time in seconds when radio was
       
   146     started.
       
   147  */
       
   148 void RadioHsWidgetProfileReader::radioRunningStatus(
       
   149     const QVariant &value)
       
   150 {
       
   151     LOG_METHOD_ENTER;
       
   152     if (value.canConvert(QVariant::Int)) {
       
   153         mRadioStatus = value.toInt();
       
   154         // Notify the observer that radio is running.
       
   155         mParent.handleRadioStateChange(FmRadio::StateRunning);
       
   156     } else {
       
   157         mRadioStatus = RADIO_RUNNING_STATUS_UNDEFINED;
       
   158         // Notify the observer that radio is not running.
       
   159         mParent.handleRadioStateChange(FmRadio::StateNotRunning);
       
   160     }
       
   161 }