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 <HbListView> |
|
20 #include <HbAction> |
|
21 #include <HbAbstractViewItem> |
|
22 #include <HbMenu> |
|
23 #include <HbMessageBox> |
|
24 |
|
25 // User includes |
|
26 #include "radiohistoryview.h" |
|
27 #include "radiowindow.h" |
|
28 #include "radiologger.h" |
|
29 #include "radiouiloader.h" |
|
30 #include "radiouiengine.h" |
|
31 #include "radiohistorymodel.h" |
|
32 #include "radiohistoryitem.h" |
|
33 |
|
34 // BEGIN TEMPORARY TEST CODE CODE |
|
35 #include <QTimer> |
|
36 #include "radiostationmodel.h" |
|
37 |
|
38 struct Song |
|
39 { |
|
40 const char* mArtist; |
|
41 const char* mTitle; |
|
42 }; |
|
43 const Song KRecognizedSongs[] = { |
|
44 { "Red Hot Chili Peppers", "Under The Bridge" }, |
|
45 { "Queens Of The Stone Age", "No One Knows" }, |
|
46 { "The Presidents of the United States of America", "Dune Buggy" }, |
|
47 { "System of a Down", "Aerials" }, |
|
48 { "The White Stripes", "Seven Nation Army" }, |
|
49 { "Alice In Chains", "When The Sun Rose Again" }, |
|
50 { "Bullet For My Valentine", "Tears Don't Fall" } |
|
51 }; |
|
52 const int KSongsCount = sizeof( KRecognizedSongs ) / sizeof( KRecognizedSongs[0] ); |
|
53 // END TEMPORARY TEST CODE CODE |
|
54 |
|
55 /*! |
|
56 * |
|
57 */ |
|
58 RadioHistoryView::RadioHistoryView() : |
|
59 RadioViewBase(), |
|
60 mHistoryList( 0 ), |
|
61 mAllSongsButton( 0 ), |
|
62 mTaggedSongsButton( 0 ), |
|
63 mSelectedItem( new RadioHistoryItem() ), |
|
64 mCurrentRow( -1 ), |
|
65 mSongIndex( 0 ) |
|
66 { |
|
67 } |
|
68 |
|
69 /*! |
|
70 * |
|
71 */ |
|
72 RadioHistoryView::~RadioHistoryView() |
|
73 { |
|
74 } |
|
75 |
|
76 /*! |
|
77 * |
|
78 */ |
|
79 void RadioHistoryView::setNonTaggedIcon( const HbIcon& nonTaggedIcon ) |
|
80 { |
|
81 mNonTaggedIcon = nonTaggedIcon; |
|
82 mNonTaggedIcon.setColor( Qt::white ); |
|
83 } |
|
84 |
|
85 /*! |
|
86 * |
|
87 */ |
|
88 HbIcon RadioHistoryView::nonTaggedIcon() const |
|
89 { |
|
90 return mNonTaggedIcon; |
|
91 } |
|
92 |
|
93 /*! |
|
94 * |
|
95 */ |
|
96 void RadioHistoryView::setTaggedIcon( const HbIcon& taggedIcon ) |
|
97 { |
|
98 mTaggedIcon = taggedIcon; |
|
99 } |
|
100 |
|
101 /*! |
|
102 * |
|
103 */ |
|
104 HbIcon RadioHistoryView::taggedIcon() const |
|
105 { |
|
106 return mTaggedIcon; |
|
107 } |
|
108 |
|
109 /*! |
|
110 * Private slot |
|
111 * |
|
112 */ |
|
113 void RadioHistoryView::updateViewMode() |
|
114 { |
|
115 QString section = DOCML::HV_SECTION_HISTORY_MODE; |
|
116 bool showTagged = false; |
|
117 |
|
118 if ( sender() == mTaggedSongsButton ) { |
|
119 section = DOCML::HV_SECTION_FAVORITE_MODE; |
|
120 showTagged = true; |
|
121 } |
|
122 |
|
123 loadSection( DOCML::FILE_HISTORYVIEW, section ); |
|
124 historyModel().setShowTagged( showTagged ); |
|
125 |
|
126 updateVisibilities(); |
|
127 } |
|
128 |
|
129 /*! |
|
130 * Private slot |
|
131 * |
|
132 */ |
|
133 void RadioHistoryView::clearList() |
|
134 { |
|
135 const bool showingTagged = mTaggedSongsButton->isChecked(); |
|
136 askQuestion( hbTrId( showingTagged ? "txt_rad_info_clear_tagged_songs_list" : |
|
137 "txt_rad_info_clear_recently_played_songs_list" ) ); |
|
138 } |
|
139 |
|
140 /*! |
|
141 * Private slot |
|
142 * |
|
143 */ |
|
144 void RadioHistoryView::updateVisibilities() |
|
145 { |
|
146 const int itemCount = mUiEngine->historyModel().rowCount(); |
|
147 loadSection( DOCML::FILE_HISTORYVIEW, itemCount ? DOCML::HV_SECTION_SHOW_LIST : DOCML::HV_SECTION_HIDE_LIST ); |
|
148 } |
|
149 |
|
150 /*! |
|
151 * Private slot |
|
152 * |
|
153 */ |
|
154 void RadioHistoryView::showContextMenu( const QModelIndex& index ) |
|
155 { |
|
156 *mSelectedItem = historyModel().itemAtIndex( index ); |
|
157 mCurrentRow = index.row(); |
|
158 |
|
159 HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::HV_NAME_CONTEXT_MENU ); |
|
160 |
|
161 if ( HbAction* tagAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_TAG ) ) { |
|
162 if ( mSelectedItem->isTagged() ) { |
|
163 tagAction->setText( hbTrId( "txt_rad_menu_remove_tag" ) ); |
|
164 } else { |
|
165 tagAction->setText( hbTrId( "txt_rad_menu_tag_song" ) ); |
|
166 } |
|
167 } |
|
168 |
|
169 if ( HbAction* searchAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_SEARCH ) ) { |
|
170 //TODO: Add support for other music store |
|
171 searchAction->setVisible( false ); |
|
172 } |
|
173 |
|
174 HbAbstractViewItem* item = mHistoryList->itemByIndex( index ); |
|
175 QPointF coords = item->pos(); |
|
176 coords.setY( mHistoryList->contentWidget()->pos().y() + coords.y() ); |
|
177 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() + menu->size().height() / 2 ) ); |
|
178 |
|
179 menu->show(); |
|
180 } |
|
181 |
|
182 /*! |
|
183 * Private slot |
|
184 * |
|
185 */ |
|
186 void RadioHistoryView::handleLongPress( HbAbstractViewItem* item ) |
|
187 { |
|
188 showContextMenu( item->modelIndex() ); |
|
189 } |
|
190 |
|
191 /*! |
|
192 * Private slot |
|
193 * |
|
194 */ |
|
195 void RadioHistoryView::toggleTagging() |
|
196 { |
|
197 historyModel().toggleTagging( *mSelectedItem, mCurrentRow ); |
|
198 mSelectedItem->reset(); |
|
199 mCurrentRow = -1; |
|
200 updateVisibilities(); |
|
201 } |
|
202 |
|
203 /*! |
|
204 * Private slot |
|
205 * |
|
206 */ |
|
207 void RadioHistoryView::openOviStore() |
|
208 { |
|
209 QString msg = "To be implemented: Open ovi store. Artist: %1, Title: %2"; |
|
210 HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) ); |
|
211 mUiEngine->openMusicStore( *mSelectedItem ); |
|
212 } |
|
213 |
|
214 /*! |
|
215 * Private slot |
|
216 * |
|
217 */ |
|
218 void RadioHistoryView::openOtherStore() |
|
219 { |
|
220 mUiEngine->openMusicStore( *mSelectedItem, RadioUiEngine::OtherStore ); |
|
221 } |
|
222 |
|
223 /*! |
|
224 * Private slot |
|
225 * TEMPORARY TEST CODE |
|
226 */ |
|
227 void RadioHistoryView::addSongs() |
|
228 { |
|
229 for ( int i = 0; i < KSongsCount; ++i ) { |
|
230 QTimer::singleShot( 1000 + i * 1500, this, SLOT(addOneSong()) ); |
|
231 } |
|
232 } |
|
233 |
|
234 /*! |
|
235 * Private slot |
|
236 * TEMPORARY TEST CODE |
|
237 */ |
|
238 void RadioHistoryView::addOneSong() |
|
239 { |
|
240 Song song = KRecognizedSongs[mSongIndex++]; |
|
241 mSongIndex %= KSongsCount; |
|
242 |
|
243 RadioStation station = mUiEngine->stationModel().currentStation(); |
|
244 mUiEngine->historyModel().addItem( song.mArtist, song.mTitle, station ); |
|
245 } |
|
246 |
|
247 /*! |
|
248 * \reimp |
|
249 * |
|
250 */ |
|
251 void RadioHistoryView::init() |
|
252 { |
|
253 LOG_METHOD; |
|
254 loadSection( DOCML::FILE_HISTORYVIEW, DOCML::SECTION_LAZY_LOAD ); |
|
255 |
|
256 RadioHistoryModel* historyModel = &mUiEngine->historyModel(); |
|
257 historyModel->setShowDetails( mOrientation == Qt::Horizontal ); |
|
258 |
|
259 if ( !mNonTaggedIcon.isNull() && !mTaggedIcon.isNull() ) { |
|
260 historyModel->setIcons( mNonTaggedIcon.qicon(), mTaggedIcon.qicon() ); |
|
261 } |
|
262 |
|
263 mHistoryList = mUiLoader->findObject<HbListView>( DOCML::HV_NAME_HISTORY_LIST ); |
|
264 mHistoryList->setScrollingStyle( HbListView::PanOrFlick ); |
|
265 mHistoryList->setModel( historyModel ); |
|
266 mHistoryList->setSelectionMode( HbListView::NoSelection ); |
|
267 mHistoryList->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
|
268 //TODO: Uncomment after MCL wk28 release to improve scrolling FPS rate |
|
269 //mHistoryList->setItemPixmapCacheEnabled( true ); |
|
270 |
|
271 mAllSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_ALL_SONGS_BUTTON ); |
|
272 mTaggedSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_TAGGED_SONGS_BUTTON ); |
|
273 |
|
274 if ( HbAction* clearListAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CLEAR_LIST_ACTION ) ) { |
|
275 Radio::connect( clearListAction, SIGNAL(triggered()), |
|
276 this, SLOT(clearList()) ); |
|
277 } |
|
278 |
|
279 Radio::connect( mTaggedSongsButton, SIGNAL(triggered()), |
|
280 this, SLOT(updateViewMode()) ); |
|
281 Radio::connect( mAllSongsButton, SIGNAL(triggered()), |
|
282 this, SLOT(updateViewMode()) ); |
|
283 Radio::connect( historyModel, SIGNAL(itemAdded()), |
|
284 this, SLOT(updateVisibilities()) ); |
|
285 Radio::connect( mHistoryList, SIGNAL(activated(QModelIndex)), |
|
286 this, SLOT(showContextMenu(QModelIndex)) ); |
|
287 Radio::connect( mHistoryList, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), |
|
288 this, SLOT(handleLongPress(HbAbstractViewItem*)) ); |
|
289 |
|
290 connectCommonMenuItem( MenuItem::Exit ); |
|
291 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
|
292 |
|
293 // Context menu actions |
|
294 connectXmlElement( DOCML::HV_NAME_TOGGLE_TAG_ACTION, SIGNAL(triggered()), |
|
295 this, SLOT(toggleTagging()) ); |
|
296 connectXmlElement( DOCML::HV_NAME_OVI_STORE_ACTION, SIGNAL(triggered()), |
|
297 this, SLOT(openOviStore()) ); |
|
298 connectXmlElement( DOCML::HV_NAME_OTHER_STORE_ACTION, SIGNAL(triggered()), |
|
299 this, SLOT(openOtherStore()) ); |
|
300 initBackAction(); |
|
301 |
|
302 updateViewMode(); |
|
303 |
|
304 // BEGIN TEMPORARY TEST CODE |
|
305 if ( HbAction* addSongsAction = mUiLoader->findObject<HbAction>( "hv:add_songs_action" ) ) { |
|
306 Radio::connect( addSongsAction, SIGNAL(triggered()), |
|
307 this, SLOT(addSongs()) ); |
|
308 } |
|
309 // END TEMPORARY TEST CODE |
|
310 } |
|
311 |
|
312 /*! |
|
313 * \reimp |
|
314 * |
|
315 */ |
|
316 void RadioHistoryView::setOrientation() |
|
317 { |
|
318 if ( mUiEngine ) { |
|
319 RadioHistoryModel& model = mUiEngine->historyModel(); |
|
320 model.setShowDetails( mOrientation == Qt::Horizontal ); |
|
321 } |
|
322 } |
|
323 |
|
324 /*! |
|
325 * \reimp |
|
326 * |
|
327 */ |
|
328 void RadioHistoryView::userAccepted() |
|
329 { |
|
330 const bool removeTagged = mTaggedSongsButton->isChecked(); |
|
331 mUiEngine->historyModel().removeAll( removeTagged ); |
|
332 updateVisibilities(); |
|
333 } |
|
334 |
|
335 /*! |
|
336 * |
|
337 */ |
|
338 RadioHistoryModel& RadioHistoryView::historyModel() const |
|
339 { |
|
340 return *static_cast<RadioHistoryModel*>( mHistoryList->model() ); |
|
341 } |
|