|
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 } |
|
75 |
|
76 /*! |
|
77 Start monitoring of radio P&S key. Read also the initial value. |
|
78 */ |
|
79 void RadioHsWidgetProfileReader::startMonitoringRadioRunningStatus() |
|
80 { |
|
81 LOG_METHOD; |
|
82 XQSettingsKey radioRunningKey(XQSettingsKey::TargetPublishAndSubscribe, |
|
83 KRadioPSUid, KRadioStartupKey); |
|
84 // Start monitoring. |
|
85 mSettingsManager->startMonitoring(radioRunningKey); |
|
86 // Read current value. |
|
87 radioRunningStatus( |
|
88 mSettingsManager->readItemValue(radioRunningKey)); |
|
89 } |
|
90 |
|
91 /*! |
|
92 Reads the current profile of the device and \returns \c true if the |
|
93 current profile is offline, \c false otherwise. |
|
94 */ |
|
95 bool RadioHsWidgetProfileReader::isCurrentProfileOffline() |
|
96 { |
|
97 LOG_METHOD; |
|
98 XQSettingsKey profileKey(XQSettingsKey::TargetCentralRepository, |
|
99 KCRUidProfileEngine.iUid, KProEngActiveProfile); |
|
100 // Read current value. |
|
101 QVariant profile(mSettingsManager->readItemValue(profileKey)); |
|
102 if (profile.canConvert(QVariant::Int) && profile.toInt() == OFFLINE_PROFILE) { |
|
103 return true; |
|
104 } |
|
105 return false; |
|
106 } |
|
107 |
|
108 /*! |
|
109 Handling of deletion of listened keys. |
|
110 |
|
111 \param key Deleted key. |
|
112 */ |
|
113 void RadioHsWidgetProfileReader::handleDeletedItem(const XQSettingsKey &key) |
|
114 { |
|
115 LOG_METHOD; |
|
116 // Profile information will be used for offline query. |
|
117 /* |
|
118 if (key.uid() == KCRUidProfileEngine.iUid && key.key() |
|
119 == KProEngActiveProfile) { |
|
120 } |
|
121 */ |
|
122 if (key.uid() == KRadioPSUid && key.key() == KRadioStartupKey) { |
|
123 LOG("KRadioStartupKey deleted"); |
|
124 startMonitoringRadioRunningStatus(); |
|
125 } |
|
126 } |
|
127 |
|
128 /*! |
|
129 Notifications from settings manager are handled and routed to appropriate |
|
130 private slots. |
|
131 |
|
132 \param key Changed key. |
|
133 \param value Value of changed key. |
|
134 */ |
|
135 void RadioHsWidgetProfileReader::handleChanges(const XQSettingsKey &key, |
|
136 const QVariant& value) |
|
137 { |
|
138 LOG_SLOT_CALLER; |
|
139 |
|
140 // Profile information will be used for offline query. |
|
141 /* |
|
142 if (key.uid() == KCRUidProfileEngine.iUid && key.key() |
|
143 == KProEngActiveProfile) { |
|
144 currentProfileStatus(value); |
|
145 } |
|
146 */ |
|
147 |
|
148 if (key.uid() == KRadioPSUid && key.key() |
|
149 == KRadioStartupKey) { |
|
150 LOG("KRadioStartupKey changed"); |
|
151 radioRunningStatus(value); |
|
152 } |
|
153 } |
|
154 |
|
155 /* |
|
156 Handling changes in profile information. |
|
157 |
|
158 \param value |
|
159 */ |
|
160 /* |
|
161 void RadioHsWidgetProfileReader::currentProfileStatus(QVariant value) |
|
162 { |
|
163 if (value.canConvert(QVariant::Int)) { |
|
164 emit profileChanged(value.toInt()); |
|
165 } |
|
166 } |
|
167 */ |
|
168 |
|
169 /*! |
|
170 Handling changes in radio running P&S key. |
|
171 |
|
172 \param value is int representation of time in seconds when radio was |
|
173 started. |
|
174 */ |
|
175 void RadioHsWidgetProfileReader::radioRunningStatus( |
|
176 const QVariant &value) |
|
177 { |
|
178 LOG_METHOD; |
|
179 if (value.canConvert(QVariant::Int)) { |
|
180 mRadioStatus = value.toInt(); |
|
181 // Notify the observer that radio is running. |
|
182 mParent.handleRadioStateChange(FmRadio::StateRunning); |
|
183 } else { |
|
184 mRadioStatus = RADIO_RUNNING_STATUS_UNDEFINED; |
|
185 // Notify the observer that radio is not running. |
|
186 mParent.handleRadioStateChange(FmRadio::StateNotRunning); |
|
187 } |
|
188 } |