|
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 #include <hblistview.h> |
|
18 #include <hbmenu.h> |
|
19 #include <hbaction.h> |
|
20 #include <hbicon.h> |
|
21 #include <QTimer> |
|
22 |
|
23 #include "irabstractviewmanager.h" |
|
24 #include "irapplication.h" |
|
25 #include "irplaycontroller.h" |
|
26 #include "irsonghistoryview.h" |
|
27 #include "irsonghistorymodel.h" |
|
28 #include "irqsonghistoryinfo.h" |
|
29 #include "irqenums.h" |
|
30 #include "irqmusicshop.h" |
|
31 #include "irqstatisticsreporter.h" |
|
32 #include "irqsettings.h" |
|
33 |
|
34 |
|
35 |
|
36 // public functions |
|
37 |
|
38 /* |
|
39 * Description : constructor |
|
40 */ |
|
41 IRSongHistoryView::IRSongHistoryView(IRApplication *aApplication, TIRViewId aViewId) : |
|
42 IrAbstractListViewBase(aApplication, aViewId), iClearSongHistoryAction(NULL), |
|
43 iShowPrompt(false) |
|
44 |
|
45 { |
|
46 iModel = new IRSongHistoryModel(this); |
|
47 iListView->setModel(iModel); |
|
48 iListView->setCurrentIndex(iModel->index(0)); |
|
49 |
|
50 iClearSongHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_song_history"), this); |
|
51 iMusicShop = iApplication->getMusicShop(); |
|
52 iStatisticsReporter = iApplication->getStatisticsReporter(); |
|
53 |
|
54 iStationHistoryAction = new HbAction(hbTrId("txt_irad_opt_recently_played_stations"), this); |
|
55 menu()->insertAction(iOpenWebAddressAction, iStationHistoryAction); |
|
56 connect(iStationHistoryAction, SIGNAL(triggered()), this, SLOT(gotoStationHistory())); |
|
57 |
|
58 iShowPrompt = iSettings->getSongHistoryShow(); |
|
59 if( iShowPrompt ) |
|
60 { |
|
61 iSettings->setSongHistoryShow(0); |
|
62 } |
|
63 |
|
64 connect(iClearSongHistoryAction, SIGNAL(triggered()), this, SLOT(clearHisotrySongDB())); |
|
65 connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
|
66 } |
|
67 |
|
68 /* |
|
69 * Description : destructor |
|
70 */ |
|
71 IRSongHistoryView::~IRSongHistoryView() |
|
72 { |
|
73 |
|
74 } |
|
75 |
|
76 /* |
|
77 * Description : virtual functions from base class IRBaseView. |
|
78 * handle view commands |
|
79 * |
|
80 * see also : IRBaseView::handleCommand |
|
81 */ |
|
82 TIRHandleResult IRSongHistoryView::handleCommand(TIRViewCommand aCommand, |
|
83 TIRViewCommandReason aReason) |
|
84 { |
|
85 Q_UNUSED(aReason); |
|
86 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
|
87 |
|
88 |
|
89 switch (aCommand) |
|
90 { |
|
91 case EIR_ViewCommand_ACTIVATED: |
|
92 connect(iPlayController, SIGNAL(metaDataAvailable(IRQMetaData*)), this, SLOT(newMetadataAdded(IRQMetaData*))); |
|
93 showSongHistory(); |
|
94 |
|
95 if( iShowPrompt ) |
|
96 { |
|
97 QTimer::singleShot(5, this, SLOT(showPrompt())); |
|
98 iShowPrompt = false; |
|
99 } |
|
100 ret = EIR_NoDefault; |
|
101 break; |
|
102 |
|
103 case EIR_ViewCommand_DEACTIVATE: |
|
104 disconnect(iPlayController, SIGNAL(metaDataAvailable(IRQMetaData*)), this, SLOT(newMetadataAdded(IRQMetaData*))); |
|
105 ret = EIR_NoDefault; |
|
106 break; |
|
107 |
|
108 default: |
|
109 break; |
|
110 } |
|
111 |
|
112 return ret; |
|
113 } |
|
114 |
|
115 // slots functions |
|
116 |
|
117 /* |
|
118 * Description : slot function when an item in a list is clicked. |
|
119 * issue a listen request to isds client |
|
120 * Parameters : aItem : pointer to the clicked item. |
|
121 */ |
|
122 void IRSongHistoryView::handleItemSelected() |
|
123 { |
|
124 int index = iListView->currentIndex().row(); |
|
125 IRQSongInfo *hisInfo = iModel->getSongHistoryInfo(index); |
|
126 |
|
127 |
|
128 if(NULL == iMusicShop) |
|
129 { |
|
130 popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation); |
|
131 return; |
|
132 } |
|
133 |
|
134 if( (NULL == hisInfo) || |
|
135 ( hisInfo->getSongName().isEmpty() && |
|
136 hisInfo->getArtistName().isEmpty() |
|
137 ) |
|
138 ) |
|
139 { |
|
140 popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation); |
|
141 return; |
|
142 } |
|
143 |
|
144 |
|
145 if( iMusicShop->findInMusicShop(hisInfo->getSongName(), hisInfo->getArtistName())) |
|
146 { |
|
147 if(iStatisticsReporter) |
|
148 { |
|
149 //we will add the report in future. Add the channel id in the song info db |
|
150 //iStatisticsReporter->logNmsEvents(EIRQFind,channelId); |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation); |
|
156 } |
|
157 } |
|
158 |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // IRSongHistoryView::showSongHistory() |
|
162 // gets the List which was stored earlier |
|
163 //--------------------------------------------------------------------------- |
|
164 void IRSongHistoryView::showSongHistory() |
|
165 { |
|
166 if (iModel->checkSongHistoryUpdate()) |
|
167 { |
|
168 iListView->reset(); |
|
169 iListView->setCurrentIndex(iModel->index(0)); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // IRSongHistoryView::clearAllList() |
|
175 // gets the List which was stored earlier |
|
176 //--------------------------------------------------------------------------- |
|
177 void IRSongHistoryView::clearAllList() |
|
178 { |
|
179 iModel->clearAllList(); |
|
180 iListView->reset(); |
|
181 updateView(); |
|
182 } |
|
183 |
|
184 void IRSongHistoryView::prepareMenu() |
|
185 { |
|
186 HbMenu *viewMenu = menu(); |
|
187 |
|
188 viewMenu->removeAction(iClearSongHistoryAction); |
|
189 if (iModel->rowCount() > 0) |
|
190 { |
|
191 viewMenu->insertAction(iOpenWebAddressAction, iClearSongHistoryAction); |
|
192 } |
|
193 } |
|
194 |
|
195 void IRSongHistoryView::modelChanged() |
|
196 { |
|
197 iListView->reset(); |
|
198 QString headingStr = hbTrId("txt_irad_list_recently_played_songs") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
199 setHeadingText(headingStr); |
|
200 |
|
201 //the case is that, we active the song history view with no items |
|
202 //but immediately, we get the metadata and show it on the list, |
|
203 //then we need to remove the "no content" label |
|
204 if( 1 == iListView->model()->rowCount()) |
|
205 { |
|
206 updateView(); |
|
207 } |
|
208 } |
|
209 |
|
210 void IRSongHistoryView::newMetadataAdded(IRQMetaData *aMetadata) |
|
211 { |
|
212 Q_UNUSED(aMetadata); |
|
213 iModel->checkSongHistoryUpdate(); |
|
214 |
|
215 } |
|
216 |
|
217 void IRSongHistoryView::clearHisotrySongDB() |
|
218 { |
|
219 iModel->clearHisotrySongDB(); |
|
220 updateView(); |
|
221 } |
|
222 |
|
223 void IRSongHistoryView::showPrompt() |
|
224 { |
|
225 QString str = hbTrId("txt_irad_info_click_the_song_and_find_it_in_nokia_music_shop"); |
|
226 HbMessageBox promptDialog(str, HbMessageBox::MessageTypeInformation); |
|
227 //promptDialog.setTimeout(HbPopupBase::NoTimeout); |
|
228 promptDialog.setTimeout(HbPopup::NoTimeout); // JM: changed in w47 Orbit |
|
229 promptDialog.setModal(true); |
|
230 //promptDialog.setDismissPolicy(HbPopupBase::NoDismiss); |
|
231 promptDialog.setDismissPolicy(HbPopup::NoDismiss); // JM: changed in w47 Orbit |
|
232 promptDialog.exec(); |
|
233 } |
|
234 |
|
235 void IRSongHistoryView::itemAboutToBeSelected(bool& needNetwork) |
|
236 { |
|
237 /* for in song history view, the data will retrived from the web browser*/ |
|
238 needNetwork = false; |
|
239 } |
|
240 |
|
241 void IRSongHistoryView::gotoStationHistory() |
|
242 { |
|
243 getViewManager()->activateView(EIRView_HistoryView); |
|
244 } |