author | hgs |
Thu, 08 Jul 2010 12:44:18 +0300 | |
changeset 36 | ba22309243a1 |
parent 34 | bc10a61bd7d3 |
child 37 | 451b2e1545b2 |
child 57 | 21be958eb3ce |
permissions | -rw-r--r-- |
24 | 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 |
// System includes |
|
19 |
#include <QApplication> |
|
20 |
#include <QStringList> |
|
21 |
#include <QDateTime> |
|
22 |
#ifndef BUILD_WIN32 |
|
23 |
# include <XQSettingsManager> |
|
24 |
# include <XQPublishAndSubscribeSettingsKey> |
|
25 |
# include <XQPublishAndSubscribeUtils> |
|
26 |
#endif |
|
27 |
||
28 |
// User includes |
|
29 |
#include "radiouiengine.h" |
|
30 |
#include "radiouiengine_p.h" |
|
31 |
#include "radioenginewrapper.h" |
|
32 |
#include "radiostationmodel.h" |
|
33 |
#include "radiostationmodel_p.h" |
|
34 |
#include "radiohistorymodel.h" |
|
35 |
#include "radiopresetstorage.h" |
|
36 |
#include "radiosettings.h" |
|
37 |
#include "radiostation.h" |
|
38 |
#include "radioscannerengine.h" |
|
39 |
#include "radiostationhandlerif.h" |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
40 |
#include "radiocontrolservice.h" |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
41 |
#include "radiomonitorservice.h" |
24 | 42 |
#include "radioservicedef.h" |
43 |
#include "radiologger.h" |
|
44 |
||
45 |
/*! |
|
46 |
* |
|
47 |
*/ |
|
48 |
RadioUiEnginePrivate::RadioUiEnginePrivate( RadioUiEngine* engine ) : |
|
34 | 49 |
q_ptr( engine ), |
50 |
mPowerOffTimer( NULL ) |
|
24 | 51 |
{ |
52 |
} |
|
53 |
||
54 |
/*! |
|
55 |
* |
|
56 |
*/ |
|
57 |
RadioUiEnginePrivate::~RadioUiEnginePrivate() |
|
58 |
{ |
|
59 |
#ifndef BUILD_WIN32 |
|
60 |
XQSettingsManager settingsManager; |
|
61 |
XQPublishAndSubscribeUtils utils( settingsManager ); |
|
62 |
XQPublishAndSubscribeSettingsKey radioStartupKey( KRadioPSUid, KRadioStartupKey ); |
|
63 |
bool deleted = utils.deleteProperty( radioStartupKey ); |
|
34 | 64 |
LOG_ASSERT( deleted, LOG( "RadioUiEnginePrivate::~RadioUiEnginePrivate(). Failed to remove P&S key" ) ); |
24 | 65 |
#endif |
66 |
} |
|
67 |
||
68 |
/*! |
|
69 |
* |
|
70 |
*/ |
|
71 |
RadioUiEngine& RadioUiEnginePrivate::api() |
|
72 |
{ |
|
73 |
Q_Q( RadioUiEngine ); |
|
74 |
return *q; |
|
75 |
} |
|
76 |
||
77 |
/*! |
|
78 |
* |
|
79 |
*/ |
|
80 |
bool RadioUiEnginePrivate::init() |
|
81 |
{ |
|
82 |
mControlService.reset( new RadioControlService( *q_ptr ) ); |
|
83 |
mMonitorService.reset( new RadioMonitorService( *this ) ); |
|
84 |
mStationModel.reset( new RadioStationModel( *this ) ); |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
85 |
|
24 | 86 |
mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) ); |
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
87 |
if ( !mEngineWrapper->init() ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
88 |
return false; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
89 |
} |
24 | 90 |
mEngineWrapper->addObserver( this ); |
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
91 |
|
24 | 92 |
mPresetStorage.reset( new RadioPresetStorage() ); |
93 |
mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() ); |
|
94 |
mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) ); |
|
95 |
||
96 |
#ifndef BUILD_WIN32 |
|
97 |
// Write the startup timestamp to P&S key for the homescreen widget |
|
98 |
XQSettingsManager settingsManager; |
|
99 |
XQPublishAndSubscribeUtils utils( settingsManager ); |
|
100 |
XQPublishAndSubscribeSettingsKey radioStartupKey( KRadioPSUid, KRadioStartupKey ); |
|
101 |
bool defined = utils.defineProperty( radioStartupKey, XQSettingsManager::TypeInt ); |
|
102 |
if ( defined ) { |
|
103 |
settingsManager.writeItemValue( radioStartupKey, (int)QDateTime::currentDateTime().toTime_t() ); |
|
104 |
} |
|
105 |
#endif |
|
106 |
||
107 |
mMonitorService->init(); |
|
108 |
||
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
109 |
return true; |
24 | 110 |
} |
111 |
||
112 |
/*! |
|
113 |
* |
|
114 |
*/ |
|
115 |
void RadioUiEnginePrivate::cancelSeeking() |
|
116 |
{ |
|
117 |
mEngineWrapper->cancelSeeking(); |
|
118 |
} |
|
119 |
||
120 |
/*! |
|
121 |
* |
|
122 |
*/ |
|
123 |
RadioEngineWrapper& RadioUiEnginePrivate::wrapper() |
|
124 |
{ |
|
125 |
return *mEngineWrapper; |
|
126 |
} |
|
127 |
||
128 |
/*! |
|
129 |
* |
|
130 |
*/ |
|
131 |
void RadioUiEnginePrivate::tunedToFrequency( uint frequency, int reason ) |
|
132 |
{ |
|
133 |
Q_Q( RadioUiEngine ); |
|
134 |
q->emitTunedToFrequency( frequency, reason ); |
|
135 |
} |
|
136 |
||
137 |
/*! |
|
138 |
* |
|
139 |
*/ |
|
140 |
void RadioUiEnginePrivate::radioStatusChanged( bool radioIsOn ) |
|
141 |
{ |
|
142 |
Q_Q( RadioUiEngine ); |
|
143 |
q->emitRadioStatusChanged( radioIsOn ); |
|
144 |
} |
|
145 |
||
146 |
/*! |
|
147 |
* |
|
148 |
*/ |
|
149 |
void RadioUiEnginePrivate::rdsAvailabilityChanged( bool available ) |
|
150 |
{ |
|
151 |
Q_Q( RadioUiEngine ); |
|
152 |
q->emitRdsAvailabilityChanged( available ); |
|
153 |
} |
|
154 |
||
155 |
/*! |
|
156 |
* |
|
157 |
*/ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
158 |
void RadioUiEnginePrivate::increaseVolume() |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
159 |
{ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
160 |
Q_Q( RadioUiEngine ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
161 |
if( q->isScanning() ){ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
162 |
// volume not changed while scanning |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
163 |
} else { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
164 |
mEngineWrapper->increaseVolume(); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
165 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
166 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
167 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
168 |
/*! |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
169 |
* |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
170 |
*/ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
171 |
void RadioUiEnginePrivate::decreaseVolume() |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
172 |
{ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
173 |
Q_Q( RadioUiEngine ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
174 |
if( q->isScanning() ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
175 |
// volume not changed while scanning |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
176 |
} else { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
177 |
mEngineWrapper->decreaseVolume(); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
178 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
179 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
180 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
181 |
/*! |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
182 |
* |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
183 |
*/ |
24 | 184 |
void RadioUiEnginePrivate::volumeChanged( int volume ) |
185 |
{ |
|
186 |
Q_Q( RadioUiEngine ); |
|
187 |
q->emitVolumeChanged( volume ); |
|
188 |
} |
|
189 |
||
190 |
/*! |
|
191 |
* |
|
192 |
*/ |
|
193 |
void RadioUiEnginePrivate::muteChanged( bool muted ) |
|
194 |
{ |
|
195 |
Q_Q( RadioUiEngine ); |
|
196 |
q->emitMuteChanged( muted ); |
|
197 |
} |
|
198 |
||
199 |
/*! |
|
200 |
* |
|
201 |
*/ |
|
202 |
void RadioUiEnginePrivate::audioRouteChanged( bool loudspeaker ) |
|
203 |
{ |
|
204 |
Q_Q( RadioUiEngine ); |
|
205 |
q->emitAudioRouteChanged( loudspeaker ); |
|
206 |
} |
|
207 |
||
208 |
/*! |
|
209 |
* |
|
210 |
*/ |
|
211 |
void RadioUiEnginePrivate::antennaStatusChanged( bool connected ) |
|
212 |
{ |
|
213 |
Q_Q( RadioUiEngine ); |
|
214 |
q->emitAntennaStatusChanged( connected ); |
|
215 |
} |
|
216 |
||
217 |
/*! |
|
218 |
* |
|
219 |
*/ |
|
220 |
void RadioUiEnginePrivate::skipPrevious() |
|
221 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
222 |
skip( StationSkip::PreviousFavorite, 0, TuneReason::SkipFromEngine ); |
24 | 223 |
} |
224 |
||
225 |
/*! |
|
226 |
* |
|
227 |
*/ |
|
228 |
void RadioUiEnginePrivate::skipNext() |
|
229 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
230 |
skip( StationSkip::NextFavorite, 0, TuneReason::SkipFromEngine ); |
24 | 231 |
} |
232 |
||
233 |
/*! |
|
234 |
* Tunes to next or previous station |
|
235 |
*/ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
236 |
uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency, const int reason ) |
24 | 237 |
{ |
238 |
LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode ); |
|
239 |
if ( startFrequency == 0 ) { |
|
240 |
startFrequency = mEngineWrapper->currentFrequency(); |
|
241 |
} |
|
242 |
||
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
243 |
const int favoriteCount = mStationModel->favoriteCount(); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
244 |
if ( favoriteCount < 2 ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
245 |
if ( mode == StationSkip::NextFavorite ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
246 |
mode = StationSkip::Next; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
247 |
} else if ( mode == StationSkip::PreviousFavorite ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
248 |
mode = StationSkip::Previous; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
249 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
250 |
} |
24 | 251 |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
252 |
const RadioStation station = mStationModel->findClosest( startFrequency, mode ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
253 |
if ( station.isValid() ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
254 |
const uint newFrequency = station.frequency(); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
255 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
256 |
LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
257 |
mEngineWrapper->setFrequency( newFrequency, reason ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
258 |
return newFrequency; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
259 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
260 |
return startFrequency; |
24 | 261 |
} |
262 |