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