|
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( false ), |
|
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::deckButtonPressed() |
|
114 { |
|
115 if ( sender() == mTaggedSongsButton ) { |
|
116 loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_FAVORITE_MODE ); |
|
117 } else { |
|
118 loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE ); |
|
119 } |
|
120 |
|
121 const bool showTagged = mTaggedSongsButton->isChecked(); |
|
122 historyModel().setShowTagged( showTagged ); |
|
123 |
|
124 updateVisibilities(); |
|
125 } |
|
126 |
|
127 /*! |
|
128 * Private slot |
|
129 * |
|
130 */ |
|
131 void RadioHistoryView::clearList() |
|
132 { |
|
133 const bool showingTagged = mTaggedSongsButton->isChecked(); |
|
134 askQuestion( hbTrId( showingTagged ? "txt_rad_info_clear_tagged_songs_list" : |
|
135 "txt_rad_info_clear_recently_played_songs_list" ) ); |
|
136 } |
|
137 |
|
138 /*! |
|
139 * Private slot |
|
140 * |
|
141 */ |
|
142 void RadioHistoryView::updateVisibilities() |
|
143 { |
|
144 const int itemCount = mMainWindow->uiEngine().historyModel().rowCount(); |
|
145 loadSection( DOCML::FILE_HISTORYVIEW, itemCount ? DOCML::HV_SECTION_SHOW_LIST : DOCML::HV_SECTION_HIDE_LIST ); |
|
146 } |
|
147 |
|
148 /*! |
|
149 * Private slot |
|
150 * |
|
151 */ |
|
152 void RadioHistoryView::showContextMenu( const QModelIndex& index ) |
|
153 { |
|
154 *mSelectedItem = historyModel().itemAtIndex( index ); |
|
155 mCurrentRow = index.row(); |
|
156 |
|
157 HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::HV_NAME_CONTEXT_MENU ); |
|
158 |
|
159 if ( HbAction* tagAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_TAG ) ) { |
|
160 if ( mSelectedItem->isTagged() ) { |
|
161 tagAction->setText( hbTrId( "txt_rad_menu_remove_tag" ) ); |
|
162 } else { |
|
163 tagAction->setText( hbTrId( "txt_rad_menu_tag_song" ) ); |
|
164 } |
|
165 } |
|
166 |
|
167 if ( HbAction* searchAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_SEARCH ) ) { |
|
168 //TODO: Check if "search from other store" should be available |
|
169 searchAction->setVisible( false ); |
|
170 } |
|
171 |
|
172 HbAbstractViewItem* item = mHistoryList->itemByIndex( index ); |
|
173 QPointF coords = item->pos(); |
|
174 coords.setY( mHistoryList->contentWidget()->pos().y() + coords.y() ); |
|
175 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() + menu->size().height() / 2 ) ); |
|
176 |
|
177 menu->show(); |
|
178 } |
|
179 |
|
180 /*! |
|
181 * Private slot |
|
182 * |
|
183 */ |
|
184 void RadioHistoryView::toggleTagging() |
|
185 { |
|
186 historyModel().toggleTagging( *mSelectedItem, mCurrentRow ); |
|
187 mSelectedItem->reset(); |
|
188 mCurrentRow = -1; |
|
189 } |
|
190 |
|
191 /*! |
|
192 * Private slot |
|
193 * |
|
194 */ |
|
195 void RadioHistoryView::openOviStore() |
|
196 { |
|
197 QString msg = "To be implemented: Open ovi store. Artist: %1, Title: %2"; |
|
198 HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) ); |
|
199 mMainWindow->uiEngine().openMusicStore( *mSelectedItem ); |
|
200 } |
|
201 |
|
202 /*! |
|
203 * Private slot |
|
204 * |
|
205 */ |
|
206 void RadioHistoryView::openOtherStore() |
|
207 { |
|
208 QString msg = "To be implemented: Open other store. Artist: %1, Title: %2"; |
|
209 HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) ); |
|
210 mMainWindow->uiEngine().openMusicStore( *mSelectedItem, RadioUiEngine::OtherStore ); |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Private slot |
|
215 * TEMPORARY TEST CODE |
|
216 */ |
|
217 void RadioHistoryView::addSongs() |
|
218 { |
|
219 for ( int i = 0; i < KSongsCount; ++i ) { |
|
220 QTimer::singleShot( 1000 + i * 1500, this, SLOT(addOneSong()) ); |
|
221 } |
|
222 } |
|
223 |
|
224 /*! |
|
225 * Private slot |
|
226 * TEMPORARY TEST CODE |
|
227 */ |
|
228 void RadioHistoryView::addOneSong() |
|
229 { |
|
230 Song song = KRecognizedSongs[mSongIndex++]; |
|
231 mSongIndex %= KSongsCount; |
|
232 |
|
233 RadioStation station = mMainWindow->uiEngine().stationModel().currentStation(); |
|
234 mMainWindow->uiEngine().historyModel().addItem( song.mArtist, song.mTitle, station ); |
|
235 } |
|
236 |
|
237 /*! |
|
238 * \reimp |
|
239 * |
|
240 */ |
|
241 void RadioHistoryView::init() |
|
242 { |
|
243 LOG_METHOD; |
|
244 mInitialized = true; |
|
245 |
|
246 RadioHistoryModel* historyModel = &mMainWindow->uiEngine().historyModel(); |
|
247 historyModel->setShowDetails( mOrientation == Qt::Horizontal ); |
|
248 |
|
249 if ( !mNonTaggedIcon.isNull() && !mTaggedIcon.isNull() ) { |
|
250 historyModel->setIcons( mNonTaggedIcon.qicon(), mTaggedIcon.qicon() ); |
|
251 } |
|
252 |
|
253 mHistoryList = mUiLoader->findObject<HbListView>( DOCML::HV_NAME_HISTORY_LIST ); |
|
254 mHistoryList->setScrollingStyle( HbListView::PanOrFlick ); |
|
255 mHistoryList->setModel( historyModel ); |
|
256 mHistoryList->setSelectionMode( HbListView::NoSelection ); |
|
257 mHistoryList->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
|
258 |
|
259 mAllSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_ALL_SONGS_BUTTON ); |
|
260 mTaggedSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_TAGGED_SONGS_BUTTON ); |
|
261 |
|
262 if ( HbAction* clearListAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CLEAR_LIST_ACTION ) ) { |
|
263 connectAndTest( clearListAction, SIGNAL(triggered()), |
|
264 this, SLOT(clearList()) ); |
|
265 } |
|
266 |
|
267 connectAndTest( mTaggedSongsButton, SIGNAL(triggered() ), |
|
268 this, SLOT(deckButtonPressed() ) ); |
|
269 connectAndTest( mAllSongsButton, SIGNAL(triggered() ), |
|
270 this, SLOT(deckButtonPressed() ) ); |
|
271 connectAndTest( historyModel, SIGNAL(itemAdded() ), |
|
272 this, SLOT(updateVisibilities() ) ); |
|
273 |
|
274 loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE ); |
|
275 updateVisibilities(); |
|
276 |
|
277 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
|
278 |
|
279 initBackAction(); |
|
280 |
|
281 // BEGIN TEMPORARY TEST CODE |
|
282 if ( HbAction* addSongsAction = mUiLoader->findObject<HbAction>( "hv:add_songs_action" ) ) { |
|
283 connectAndTest( addSongsAction, SIGNAL(triggered()), |
|
284 this, SLOT(addSongs()) ); |
|
285 } |
|
286 // END TEMPORARY TEST CODE |
|
287 } |
|
288 |
|
289 /*! |
|
290 * \reimp |
|
291 * |
|
292 */ |
|
293 void RadioHistoryView::setOrientation() |
|
294 { |
|
295 RadioHistoryModel& model = mMainWindow->uiEngine().historyModel(); |
|
296 model.setShowDetails( mOrientation == Qt::Horizontal ); |
|
297 } |
|
298 |
|
299 /*! |
|
300 * \reimp |
|
301 * |
|
302 */ |
|
303 void RadioHistoryView::userAccepted() |
|
304 { |
|
305 mMainWindow->uiEngine().historyModel().removeAll(); |
|
306 updateVisibilities(); |
|
307 } |
|
308 |
|
309 /*! |
|
310 * |
|
311 */ |
|
312 RadioHistoryModel& RadioHistoryView::historyModel() const |
|
313 { |
|
314 return *static_cast<RadioHistoryModel*>( mHistoryList->model() ); |
|
315 } |