|
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 <hbprogressdialog.h> |
|
20 |
|
21 // User includes |
|
22 #include "radiofrequencyscanner.h" |
|
23 #include "radiolocalization.h" |
|
24 #include "radiouiengine.h" |
|
25 #include "radiologger.h" |
|
26 #include "radiostationmodel.h" |
|
27 |
|
28 // Constants |
|
29 const int KExtraRoomToMaxValue = 100000; |
|
30 |
|
31 /*! |
|
32 * |
|
33 */ |
|
34 RadioFrequencyScanner::RadioFrequencyScanner( RadioUiEngine& uiEngine, QObject* parent ) : |
|
35 QObject( parent ), |
|
36 mUiEngine( uiEngine ), |
|
37 mScanningProgressNote( new HbProgressDialog( HbProgressDialog::ProgressDialog ) ), |
|
38 mChannelCount( 0 ), |
|
39 mMinFrequency( 0 ) |
|
40 { |
|
41 mScanningProgressNote->setModal( true ); |
|
42 mScanningProgressNote->setAutoClose( true ); |
|
43 |
|
44 mMinFrequency = mUiEngine.minFrequency(); |
|
45 |
|
46 // Add some extra to the maximum value to allow room for the station at the low band edge |
|
47 mScanningProgressNote->setRange( mMinFrequency, mUiEngine.maxFrequency() + KExtraRoomToMaxValue ); |
|
48 mScanningProgressNote->setProgressValue( mMinFrequency ); |
|
49 mScanningProgressNote->setText( TRANSLATE( KProgressTitleScanStations ) ); |
|
50 |
|
51 RadioStationModel* stationModel = &mUiEngine.model(); |
|
52 connectAndTest( stationModel, SIGNAL(stationAdded(RadioStation)), |
|
53 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
|
54 |
|
55 connectAndTest( &mUiEngine, SIGNAL(scanAndSaveFinished()), |
|
56 this, SLOT(scanAndSavePresetsFinished()) ); |
|
57 |
|
58 connectAndTest( mScanningProgressNote, SIGNAL(cancelled()), |
|
59 this, SLOT(scanAndSavePresetsCancelled()) ); |
|
60 } |
|
61 |
|
62 /*! |
|
63 * |
|
64 */ |
|
65 void RadioFrequencyScanner::startScanning() |
|
66 { |
|
67 mUiEngine.scanFrequencyBand(); |
|
68 mScanningProgressNote->show(); |
|
69 } |
|
70 |
|
71 /*! |
|
72 * Private slot |
|
73 * |
|
74 */ |
|
75 void RadioFrequencyScanner::updateScanAndSaveProgress( const RadioStation& station ) |
|
76 { |
|
77 const uint frequency = station.frequency(); |
|
78 LOG_FORMAT( "RadioFrequencyScanner::updateScanAndSaveProgress frequency: %d", frequency ); |
|
79 |
|
80 // Check for special case that can happen during scanning. |
|
81 // If there is a valid radio station at the low frequency band edge it will be reported last after |
|
82 // all of the higher frequencies. We don't update the progress value here because the value would |
|
83 // be lower than the previous one. The progress value is set to maximum when the scanner finishes. |
|
84 if ( frequency != mMinFrequency ) { |
|
85 mScanningProgressNote->setProgressValue( frequency ); |
|
86 } |
|
87 |
|
88 ++mChannelCount; |
|
89 mScanningProgressNote->setText( QString( TRANSLATE( KProgressTitleStationsFound ) ).arg( mChannelCount ) ); |
|
90 } |
|
91 |
|
92 /*! |
|
93 * Private slot |
|
94 * |
|
95 */ |
|
96 void RadioFrequencyScanner::scanAndSavePresetsFinished() |
|
97 { |
|
98 mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() ); |
|
99 |
|
100 disconnect( &mUiEngine.model(), SIGNAL(stationAdded(RadioStation)), |
|
101 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
|
102 disconnect( &mUiEngine, SIGNAL(scanAndSaveFinished()), |
|
103 this, SLOT(scanAndSavePresetsFinished()) ); |
|
104 |
|
105 emit frequencyScannerFinished(); |
|
106 mScanningProgressNote->deleteLater(); |
|
107 deleteLater(); |
|
108 } |
|
109 |
|
110 /*! |
|
111 * Private slot |
|
112 * |
|
113 */ |
|
114 void RadioFrequencyScanner::scanAndSavePresetsCancelled() |
|
115 { |
|
116 mUiEngine.cancelScanFrequencyBand(); |
|
117 scanAndSavePresetsFinished(); |
|
118 mScanningProgressNote = 0; |
|
119 mChannelCount = 0; |
|
120 } |