|
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 <hbstyleloader.h> |
|
20 #include <hbpushbutton.h> |
|
21 #include <hbmessagebox.h> |
|
22 #include <hbanchorlayout.h> |
|
23 |
|
24 // User includes |
|
25 #include "radiostationcontrolwidget.h" |
|
26 #include "radiolocalization.h" |
|
27 #include "radioxmluiloader.h" |
|
28 #include "radiomainwindow.h" |
|
29 #include "radiologger.h" |
|
30 #include "radiostation.h" |
|
31 #include "radiouiengine.h" |
|
32 #include "radiostationmodel.h" |
|
33 #include "radioplaylogmodel.h" |
|
34 |
|
35 |
|
36 #ifdef USE_LAYOUT_FROM_E_DRIVE |
|
37 const QString KBlinkEffectFile = "e:/radiotest/effects/blink_in_out_in.fxml"; |
|
38 #else |
|
39 const QString KBlinkEffectFile = ":/effects/blink_in_out_in.fxml"; |
|
40 #endif |
|
41 const QString KBlinkEffect = "blink_in_out_in"; |
|
42 |
|
43 static const QString FILE_PATH_WIDGETML = ":/layout/radiostationcontrolwidget.widgetml"; |
|
44 static const QString FILE_PATH_CSS = ":/layout/radiostationcontrolwidget.css"; |
|
45 |
|
46 /*! |
|
47 * |
|
48 */ |
|
49 RadioStationControlWidget::RadioStationControlWidget( RadioUiEngine& uiEngine, QGraphicsItem* parent ) : |
|
50 HbWidget( parent ), |
|
51 mUiEngine( uiEngine ), |
|
52 mTagSongButton( new HbPushButton( this ) ), |
|
53 mStationsViewButton( new HbPushButton( this ) ), |
|
54 mRecognizeButton( new HbPushButton( this ) ), |
|
55 mMainWindow( 0 ) |
|
56 { |
|
57 bool registered = HbStyleLoader::registerFilePath( FILE_PATH_WIDGETML ); |
|
58 LOG_FORMAT( "registered: %d", registered ); |
|
59 registered = HbStyleLoader::registerFilePath( FILE_PATH_CSS ); |
|
60 LOG_FORMAT( "registered: %d", registered ); |
|
61 |
|
62 HbStyle::setItemName( mTagSongButton, "tag_song_button" ); |
|
63 HbStyle::setItemName( mRecognizeButton, "recognize_button" ); |
|
64 HbStyle::setItemName( mStationsViewButton, "stations_button" ); |
|
65 } |
|
66 |
|
67 /*! |
|
68 * |
|
69 */ |
|
70 RadioStationControlWidget::~RadioStationControlWidget() |
|
71 { |
|
72 HbStyleLoader::unregisterFilePath( FILE_PATH_WIDGETML ); |
|
73 HbStyleLoader::unregisterFilePath( FILE_PATH_CSS ); |
|
74 } |
|
75 |
|
76 /*! |
|
77 * Property |
|
78 * |
|
79 */ |
|
80 void RadioStationControlWidget::setBackground( const HbIcon& background ) |
|
81 { |
|
82 mBackground = background; |
|
83 } |
|
84 |
|
85 /*! |
|
86 * Property |
|
87 */ |
|
88 HbIcon RadioStationControlWidget::background() const |
|
89 { |
|
90 return mBackground; |
|
91 } |
|
92 |
|
93 /*! |
|
94 * Property |
|
95 */ |
|
96 void RadioStationControlWidget::setTagBtnText( const QString& text ) |
|
97 { |
|
98 mTagSongButton->setText( text ); |
|
99 } |
|
100 |
|
101 /*! |
|
102 * Property |
|
103 */ |
|
104 QString RadioStationControlWidget::tagBtnText() const |
|
105 { |
|
106 return mTagSongButton->text(); |
|
107 } |
|
108 |
|
109 /*! |
|
110 * Property |
|
111 */ |
|
112 void RadioStationControlWidget::setRecognizeBtnText( const QString& text ) |
|
113 { |
|
114 mRecognizeButton->setText( text ); |
|
115 } |
|
116 |
|
117 /*! |
|
118 * Property |
|
119 */ |
|
120 QString RadioStationControlWidget::recognizeBtnText() const |
|
121 { |
|
122 return mRecognizeButton->text(); |
|
123 } |
|
124 |
|
125 /*! |
|
126 * Property |
|
127 */ |
|
128 void RadioStationControlWidget::setStationsBtnText( const QString& text ) |
|
129 { |
|
130 mStationsViewButton->setText( text ); |
|
131 } |
|
132 |
|
133 /*! |
|
134 * Property |
|
135 */ |
|
136 QString RadioStationControlWidget::stationsBtnText() const |
|
137 { |
|
138 return mStationsViewButton->text(); |
|
139 } |
|
140 |
|
141 /*! |
|
142 * |
|
143 */ |
|
144 void RadioStationControlWidget::init( RadioMainWindow* aMainWindow ) |
|
145 { |
|
146 mMainWindow = aMainWindow; |
|
147 |
|
148 mTagSongButton->setBackground( HbIcon( " " ) ); |
|
149 mRecognizeButton->setBackground( HbIcon( " " ) ); |
|
150 mStationsViewButton->setBackground( HbIcon( " " ) ); |
|
151 |
|
152 mTagSongButton->setIcon( HbIcon( ":/images/tagsongbuttonicon.png" ) ); |
|
153 mRecognizeButton->setIcon( HbIcon( ":/images/identifysongbuttonicon.png" ) ); |
|
154 mStationsViewButton->setIcon( HbIcon( ":/images/stationsbuttonicon.png" ) ); |
|
155 |
|
156 RadioPlayLogModel* playLogModel = &mUiEngine.playLogModel(); |
|
157 if ( !playLogModel->isCurrentSongRecognized() ) { |
|
158 disableTagButton(); |
|
159 } else { |
|
160 enableTagButton(); |
|
161 } |
|
162 |
|
163 connectAndTest( playLogModel, SIGNAL(currentSongReset()), |
|
164 this, SLOT(disableTagButton()) ); |
|
165 connectAndTest( playLogModel, SIGNAL(itemAdded()), |
|
166 this, SLOT(enableTagButton()) ); |
|
167 |
|
168 // if ( RadioUiUtilities::uiEngine().isSongRecognitionAppAvailable() ) { |
|
169 connectAndTest( mRecognizeButton, SIGNAL(clicked()), |
|
170 this, SLOT(recognizePressed()) ); |
|
171 // } else { |
|
172 // mRecognizeButton->setOpacity( 0.4 ); |
|
173 // } |
|
174 |
|
175 connectAndTest( mStationsViewButton, SIGNAL(clicked()), |
|
176 this, SLOT(updateStationsButton()) ); |
|
177 |
|
178 HbEffect::add( mTagSongButton, KBlinkEffectFile, KBlinkEffect ); |
|
179 HbEffect::add( mRecognizeButton, KBlinkEffectFile, KBlinkEffect ); |
|
180 HbEffect::add( mStationsViewButton, KBlinkEffectFile, KBlinkEffect ); |
|
181 } |
|
182 |
|
183 /*! |
|
184 * Private slot |
|
185 * |
|
186 */ |
|
187 void RadioStationControlWidget::updateStationsButton() |
|
188 { |
|
189 HbEffect::start( mStationsViewButton, KBlinkEffect, this, "effectFinished" ); |
|
190 } |
|
191 |
|
192 /*! |
|
193 * Private slot |
|
194 * |
|
195 */ |
|
196 void RadioStationControlWidget::recognizePressed() |
|
197 { |
|
198 LOG_METHOD; |
|
199 HbEffect::start( mRecognizeButton, KBlinkEffect ); |
|
200 mUiEngine.launchSongRecognition(); |
|
201 } |
|
202 |
|
203 /*! |
|
204 * Private slot |
|
205 * |
|
206 */ |
|
207 void RadioStationControlWidget::effectFinished( HbEffect::EffectStatus status ) |
|
208 { |
|
209 Q_UNUSED( status ); |
|
210 mMainWindow->activateStationsView(); |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Private slot |
|
215 * |
|
216 */ |
|
217 void RadioStationControlWidget::disableTagButton() |
|
218 { |
|
219 mTagSongButton->setOpacity( 0.5 ); |
|
220 disconnect( mTagSongButton, SIGNAL(clicked()) ); |
|
221 } |
|
222 |
|
223 /*! |
|
224 * Private slot |
|
225 * |
|
226 */ |
|
227 void RadioStationControlWidget::enableTagButton() |
|
228 { |
|
229 mTagSongButton->setOpacity( 1 ); |
|
230 RadioPlayLogModel* playLogModel = &mUiEngine.playLogModel(); |
|
231 connectAndTest( mTagSongButton, SIGNAL(clicked()), |
|
232 playLogModel, SLOT(setFavorite()) ); |
|
233 } |
|
234 |
|
235 /*! |
|
236 * \reimp |
|
237 * |
|
238 */ |
|
239 void RadioStationControlWidget::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) |
|
240 { |
|
241 HbWidget::paint( painter, option, widget ); |
|
242 mBackground.paint( painter, QRectF( QPoint( 0, 0 ), size() ), Qt::IgnoreAspectRatio ); |
|
243 } |