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