10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: video collection view plugin's ui utils class |
14 * Description: video collection view plugin's ui utils class |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 // Version : %version: 37 % |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <hbglobal.h> |
18 #include <hblistview.h> |
22 #include <hblistview.h> |
19 #include <hbscrollbar.h> |
23 #include <hbscrollbar.h> |
20 #include <hblistviewitem.h> |
24 #include <hblistviewitem.h> |
21 #include <hbdialog.h> |
25 #include <hbdialog.h> |
22 #include <hbmessagebox.h> |
26 #include <hbmessagebox.h> |
|
27 #include <hbnotificationdialog.h> |
23 #include <centralrepository.h> |
28 #include <centralrepository.h> |
24 |
29 |
25 #include "videocollectioncommon.h" |
30 #include "videocollectioncommon.h" |
26 #include "videocollectionviewutils.h" |
31 #include "videocollectionviewutils.h" |
27 #include "videosortfilterproxymodel.h" |
32 #include "videosortfilterproxymodel.h" |
|
33 #include "videocollectiontrace.h" |
28 |
34 |
29 const int KVideoCollectionViewCenrepUid(0x2002BC63); |
35 const int KVideoCollectionViewCenrepUid(0x2002BC63); |
30 const int KVideoCollectionViewCenrepServiceIconKey(0x2); |
36 const int KVideoCollectionViewCenrepServiceIconKey(0x2); |
31 const int KVideoCollectionViewCenrepServiceIconPressedKey(0x3); |
37 const int KVideoCollectionViewCenrepServiceIconPressedKey(0x3); |
32 const int KVideoCollectionViewCenrepServiceUriKey(0x4); |
38 const int KVideoCollectionViewCenrepVideoSortingRoleKey(0x5); |
33 const int KVideoCollectionViewCenrepSortingRoleKey(0x5); |
39 const int KVideoCollectionViewCenrepVideoSortingOrderKey(0x6); |
34 const int KVideoCollectionViewCenrepSortingOrderKey(0x6); |
40 const int KVideoCollectionViewCenrepCollectionsSortingRoleKey(0x7); |
|
41 const int KVideoCollectionViewCenrepCollectionsSortingOrderKey(0x8); |
35 |
42 |
36 // --------------------------------------------------------------------------- |
43 // --------------------------------------------------------------------------- |
37 // instance |
44 // instance |
38 // --------------------------------------------------------------------------- |
45 // --------------------------------------------------------------------------- |
39 // |
46 // |
40 VideoCollectionViewUtils& VideoCollectionViewUtils::instance() |
47 VideoCollectionViewUtils& VideoCollectionViewUtils::instance() |
41 { |
48 { |
|
49 FUNC_LOG; |
42 static VideoCollectionViewUtils _popupInstance; |
50 static VideoCollectionViewUtils _popupInstance; |
43 return _popupInstance; |
51 return _popupInstance; |
44 } |
52 } |
45 |
53 |
46 // --------------------------------------------------------------------------- |
54 // --------------------------------------------------------------------------- |
47 // VideoCollectionViewUtils |
55 // VideoCollectionViewUtils |
48 // --------------------------------------------------------------------------- |
56 // --------------------------------------------------------------------------- |
49 // |
57 // |
50 VideoCollectionViewUtils::VideoCollectionViewUtils(): |
58 VideoCollectionViewUtils::VideoCollectionViewUtils(): |
51 mSortRole(-1), |
59 mVideosSortRole(-1), |
52 mSortOrder(Qt::AscendingOrder) |
60 mCollectionsSortRole(-1), |
53 { |
61 mVideosSortOrder(Qt::AscendingOrder), |
54 |
62 mCollectionsSortOrder(Qt::AscendingOrder) |
|
63 { |
|
64 FUNC_LOG; |
|
65 |
55 } |
66 } |
56 |
67 |
57 // --------------------------------------------------------------------------- |
68 // --------------------------------------------------------------------------- |
58 // ~VideoCollectionViewUtils |
69 // ~VideoCollectionViewUtils |
59 // --------------------------------------------------------------------------- |
70 // --------------------------------------------------------------------------- |
60 // |
71 // |
61 VideoCollectionViewUtils::~VideoCollectionViewUtils() |
72 VideoCollectionViewUtils::~VideoCollectionViewUtils() |
62 { |
73 { |
|
74 FUNC_LOG; |
63 |
75 |
64 } |
76 } |
65 |
77 |
66 // --------------------------------------------------------------------------- |
78 // --------------------------------------------------------------------------- |
67 // saveSortingValues |
79 // saveSortingValues |
68 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
69 // |
81 // |
70 int VideoCollectionViewUtils::saveSortingValues(int role, Qt::SortOrder order) |
82 int VideoCollectionViewUtils::saveSortingValues(int role, Qt::SortOrder order, VideoCollectionCommon::TCollectionLevels target) |
71 { |
83 { |
|
84 FUNC_LOG; |
|
85 INFO_3("VideoCollectionViewUtils::saveSortingValues() saving: role: %d, order: %d, target: %d", role, order, target); |
|
86 |
|
87 int status = -1; |
|
88 if (target != VideoCollectionCommon::ELevelInvalid) |
|
89 { |
|
90 CRepository *cenRep = 0; |
|
91 TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
|
92 |
|
93 int *rolePtr = &mVideosSortRole; |
|
94 Qt::SortOrder *orderPtr = &mVideosSortOrder; |
|
95 |
|
96 int roleKey(KVideoCollectionViewCenrepVideoSortingRoleKey); |
|
97 int orderKey(KVideoCollectionViewCenrepVideoSortingOrderKey); |
|
98 |
|
99 if(target == VideoCollectionCommon::ELevelCategory) |
|
100 { |
|
101 rolePtr = &mCollectionsSortRole; |
|
102 orderPtr = &mCollectionsSortOrder; |
|
103 |
|
104 roleKey = KVideoCollectionViewCenrepCollectionsSortingRoleKey; |
|
105 orderKey = KVideoCollectionViewCenrepCollectionsSortingOrderKey; |
|
106 } |
|
107 |
|
108 if(cenRep) |
|
109 { |
|
110 status = cenRep->Set(roleKey, static_cast<TInt>(role)); |
|
111 if(status == KErrNone) |
|
112 { |
|
113 status = cenRep->Set(orderKey, static_cast<TInt>(order)); |
|
114 } |
|
115 delete cenRep; |
|
116 } |
|
117 |
|
118 *rolePtr = role; |
|
119 *orderPtr = order; |
|
120 } |
|
121 return status; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // loadSortingValues |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 int VideoCollectionViewUtils::loadSortingValues(int &role, Qt::SortOrder &order, VideoCollectionCommon::TCollectionLevels target) |
|
129 { |
|
130 FUNC_LOG; |
|
131 int err(0); |
|
132 |
|
133 if ((target > VideoCollectionCommon::ELevelCategory) && |
|
134 (mVideosSortRole != -1)) |
|
135 { |
|
136 role = mVideosSortRole; |
|
137 order = mVideosSortOrder; |
|
138 } |
|
139 else if ((target == VideoCollectionCommon::ELevelCategory) && |
|
140 (mCollectionsSortRole != -1)) |
|
141 { |
|
142 role = mCollectionsSortRole; |
|
143 order = mCollectionsSortOrder; |
|
144 } |
|
145 else if (target != VideoCollectionCommon::ELevelInvalid) |
|
146 { |
|
147 int *rolePtr = &mVideosSortRole; |
|
148 Qt::SortOrder *orderPtr = &mVideosSortOrder; |
|
149 int roleKey(KVideoCollectionViewCenrepVideoSortingRoleKey); |
|
150 int orderKey(KVideoCollectionViewCenrepVideoSortingOrderKey); |
|
151 |
|
152 if(target == VideoCollectionCommon::ELevelCategory) |
|
153 { |
|
154 roleKey = KVideoCollectionViewCenrepCollectionsSortingRoleKey; |
|
155 orderKey = KVideoCollectionViewCenrepCollectionsSortingOrderKey; |
|
156 rolePtr = &mCollectionsSortRole; |
|
157 orderPtr = &mCollectionsSortOrder; |
|
158 } |
|
159 |
|
160 CRepository *cenRep = 0; |
|
161 TRAP(err, cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
|
162 if(cenRep) |
|
163 { |
|
164 int sortRole(-1); |
|
165 int sortOrder(-1); |
|
166 err = cenRep->Get(roleKey, sortRole); |
|
167 if(err == KErrNone) |
|
168 { |
|
169 err = cenRep->Get(orderKey, sortOrder); |
|
170 if(err == KErrNone) |
|
171 { |
|
172 *orderPtr = static_cast<Qt::SortOrder>(sortOrder); |
|
173 *rolePtr = sortRole; |
|
174 } |
|
175 } |
|
176 delete cenRep; |
|
177 } |
|
178 |
|
179 role = *rolePtr; |
|
180 order = *orderPtr; |
|
181 } |
|
182 INFO_3("VideoCollectionViewUtils::loadSortingValues() loaded: role: %d, order: %d, target: %d", role, order, target); |
|
183 return err; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // getServiceIconStrings |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 int VideoCollectionViewUtils::getServiceIconStrings(QString& icon, |
|
191 QString& iconPressed) |
|
192 { |
|
193 FUNC_LOG; |
72 int status = -1; |
194 int status = -1; |
73 CRepository *cenRep = 0; |
195 CRepository *cenRep = 0; |
74 TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
196 TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
75 if(cenRep) |
197 if(cenRep) |
76 { |
198 { |
77 status = cenRep->Set(KVideoCollectionViewCenrepSortingRoleKey, static_cast<TInt>(role)); |
|
78 if(status == KErrNone) |
|
79 { |
|
80 status = cenRep->Set(KVideoCollectionViewCenrepSortingOrderKey, static_cast<TInt>(order)); |
|
81 } |
|
82 delete cenRep; |
|
83 } |
|
84 |
|
85 mSortRole = role; |
|
86 mSortOrder = order; |
|
87 |
|
88 return status; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // loadSortingValues |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 int VideoCollectionViewUtils::loadSortingValues(int &role, Qt::SortOrder &order) |
|
96 { |
|
97 int err(0); |
|
98 |
|
99 if (mSortRole == -1) |
|
100 { |
|
101 CRepository *cenRep = 0; |
|
102 TRAP(err, cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
|
103 if(cenRep) |
|
104 { |
|
105 int sortRole(-1); |
|
106 int sortOrder(-1); |
|
107 err = cenRep->Get(KVideoCollectionViewCenrepSortingRoleKey, sortRole); |
|
108 if(err == KErrNone) |
|
109 { |
|
110 mSortRole = sortRole; |
|
111 err = cenRep->Get(KVideoCollectionViewCenrepSortingOrderKey, sortOrder); |
|
112 if(err == KErrNone) |
|
113 { |
|
114 mSortOrder = static_cast<Qt::SortOrder>(sortOrder); |
|
115 } |
|
116 } |
|
117 delete cenRep; |
|
118 } |
|
119 } |
|
120 |
|
121 role = mSortRole; |
|
122 order = mSortOrder; |
|
123 |
|
124 return err; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // getServiceIconStrings |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 int VideoCollectionViewUtils::getServiceIconStrings(QString& icon, |
|
132 QString& iconPressed) |
|
133 { |
|
134 int status = -1; |
|
135 CRepository *cenRep = 0; |
|
136 TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
|
137 if(cenRep) |
|
138 { |
|
139 TBuf<255> iconValue; |
199 TBuf<255> iconValue; |
140 TBuf<255> pressedValue; |
200 TBuf<255> pressedValue; |
141 status = cenRep->Get(KVideoCollectionViewCenrepServiceIconKey, iconValue); |
201 status = cenRep->Get(KVideoCollectionViewCenrepServiceIconKey, iconValue); |
142 if(status == KErrNone) |
202 if(status == KErrNone) |
143 { |
203 { |
144 status = cenRep->Get(KVideoCollectionViewCenrepServiceIconPressedKey, pressedValue); |
204 status = cenRep->Get(KVideoCollectionViewCenrepServiceIconPressedKey, pressedValue); |
145 if(status == KErrNone) |
205 if(status == KErrNone) |
146 { |
206 { |
147 QString iconTemp((QChar*)iconValue.Ptr(),iconValue.Length()); |
207 QString iconTemp((QChar*)iconValue.Ptr(),iconValue.Length()); |
148 QString pressedTemp((QChar*)pressedValue.Ptr(),pressedValue.Length()); |
208 QString pressedTemp((QChar*)pressedValue.Ptr(),pressedValue.Length()); |
149 |
209 |
150 icon = iconTemp; |
210 icon = iconTemp; |
151 iconPressed = pressedTemp; |
211 iconPressed = pressedTemp; |
152 } |
212 } |
153 } |
213 } |
154 delete cenRep; |
214 delete cenRep; |
155 } |
215 } |
156 return status; |
216 return status; |
157 } |
217 } |
158 |
218 |
159 // --------------------------------------------------------------------------- |
219 // --------------------------------------------------------------------------- |
160 // getServiceUriString |
220 // getServiceUriString |
161 // --------------------------------------------------------------------------- |
221 // --------------------------------------------------------------------------- |
162 // |
222 // |
163 QString VideoCollectionViewUtils::getServiceUriString() |
223 QString VideoCollectionViewUtils::getServiceUriString() |
164 { |
224 { |
|
225 FUNC_LOG; |
165 QString uri; |
226 QString uri; |
166 CRepository *cenRep = 0; |
227 CRepository *cenRep = 0; |
167 TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
228 TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid))); |
168 if(cenRep) |
229 if(cenRep) |
169 { |
230 { |
212 // sortModel |
274 // sortModel |
213 // --------------------------------------------------------------------------- |
275 // --------------------------------------------------------------------------- |
214 // |
276 // |
215 void VideoCollectionViewUtils::sortModel( |
277 void VideoCollectionViewUtils::sortModel( |
216 VideoSortFilterProxyModel *model, |
278 VideoSortFilterProxyModel *model, |
217 bool async) |
279 bool async, |
218 { |
280 VideoCollectionCommon::TCollectionLevels target) |
|
281 { |
|
282 FUNC_LOG; |
219 if (model) |
283 if (model) |
220 { |
284 { |
221 // setup sorting order for model |
285 // setup sorting order for model |
222 int sortRole(VideoCollectionCommon::KeyDateTime); |
286 int sortRole(VideoCollectionCommon::KeyDateTime); |
|
287 |
|
288 // default for categories |
|
289 if(target == VideoCollectionCommon::ELevelCategory) |
|
290 { |
|
291 sortRole = VideoCollectionCommon::KeyTitle; |
|
292 } |
|
293 |
223 Qt::SortOrder sortOrder(Qt::AscendingOrder); |
294 Qt::SortOrder sortOrder(Qt::AscendingOrder); |
224 |
295 |
225 // return value ignored, as in case of error the sortRole and sortOrder variables |
296 // return value ignored, as in case of error the sortRole and sortOrder variables |
226 // stay at their predefined values, and in error cases those are the sorting values |
297 // stay at their predefined values, and in error cases those are the sorting values |
227 // that are used. |
298 // that are used. |
228 VideoCollectionViewUtils &self = VideoCollectionViewUtils::instance(); |
299 VideoCollectionViewUtils &self = VideoCollectionViewUtils::instance(); |
229 self.loadSortingValues(sortRole, sortOrder); |
300 self.loadSortingValues(sortRole, sortOrder, target); |
|
301 |
230 model->doSorting(sortRole, sortOrder, async); |
302 model->doSorting(sortRole, sortOrder, async); |
231 } |
303 } |
232 } |
304 } |
233 |
305 |
234 // --------------------------------------------------------------------------- |
306 // --------------------------------------------------------------------------- |
235 // showStatusMsgSlot |
307 // showStatusMsgSlot |
236 // --------------------------------------------------------------------------- |
308 // --------------------------------------------------------------------------- |
237 // |
309 // |
238 void VideoCollectionViewUtils::showStatusMsgSlot(int statusCode, QVariant &additional) |
310 void VideoCollectionViewUtils::showStatusMsgSlot(int statusCode, QVariant &additional) |
239 { |
311 { |
|
312 FUNC_LOG; |
240 QString msg(""); |
313 QString msg(""); |
241 QString format(""); |
314 QString format(""); |
242 bool error(true); |
315 bool error(true); |
243 switch(statusCode) |
316 switch(statusCode) |
244 { |
317 { |
251 break; |
324 break; |
252 case VideoCollectionCommon::statusMultipleDeleteFail: |
325 case VideoCollectionCommon::statusMultipleDeleteFail: |
253 msg = hbTrId("txt_videos_info_unable_to_delete_some_items_which"); |
326 msg = hbTrId("txt_videos_info_unable_to_delete_some_items_which"); |
254 break; |
327 break; |
255 case VideoCollectionCommon::statusSingleRemoveFail: |
328 case VideoCollectionCommon::statusSingleRemoveFail: |
256 format = tr("Unable to remove collection %1."); //localisation |
329 format = hbTrId("txt_videos_info_unable_to_remove_collection_1"); |
257 if(additional.isValid()) |
330 if(additional.isValid()) |
258 { |
331 { |
259 msg = format.arg(additional.toString()); |
332 msg = format.arg(additional.toString()); |
260 } |
333 } |
261 break; |
334 break; |
262 case VideoCollectionCommon::statusMultiRemoveFail: |
335 case VideoCollectionCommon::statusMultiRemoveFail: |
263 msg = tr("Unable to remove some collections."); //localisation |
336 msg = hbTrId("txt_videos_info_unable_to_remove_some_collections"); |
264 break; |
337 break; |
265 case VideoCollectionCommon::statusVideosAddedToCollection: |
338 case VideoCollectionCommon::statusVideosAddedToCollection: |
266 format = hbTrId("txt_videos_dpopinfo_videos_added_to_1"); |
339 format = hbTrId("txt_videos_dpopinfo_videos_added_to_1"); |
267 if(additional.isValid()) |
340 if(additional.isValid()) |
268 { |
341 { |
269 msg = format.arg(additional.toString()); |
342 msg = format.arg(additional.toString()); |
270 } |
343 } |
271 error = false; |
344 error = false; |
272 break; |
345 break; |
273 case VideoCollectionCommon::statusAllVideosAlreadyInCollection: |
346 case VideoCollectionCommon::statusAllVideosAlreadyInCollection: |
274 msg = tr("All videos already added to this collection."); //localisation |
347 msg = hbTrId("txt_videos_info_all_videos_already_added_to_this_c"); |
275 break; |
348 break; |
276 case VideoCollectionCommon::statusDeleteInProgress: |
349 case VideoCollectionCommon::statusDeleteInProgress: |
277 format = hbTrId("txt_videos_dpopinfo_ln_videos_are_being_deleted"); |
350 format = hbTrId("txt_videos_dpopinfo_ln_videos_are_being_deleted"); |
278 if(additional.isValid()) |
351 if(additional.isValid()) |
279 { |
352 { |
280 msg = format.arg(additional.toString()); |
353 msg = format.arg(additional.toString()); |
281 } |
354 } |
282 error = false; |
355 error = false; |
283 break; |
356 break; |
284 default: // no msg to show |
357 default: // no msg to show |
285 return; |
358 return; |
286 } |
359 } |
287 |
360 |
288 if(msg.count() > 0) |
361 if(msg.count() > 0) |
289 { |
362 { |
290 if(error) |
363 if(error) |
291 { |
364 { |
292 HbMessageBox::warning(msg); |
365 HbMessageBox::warning(msg); |
293 } |
366 } |
294 else |
367 else |
295 { |
368 { |
296 HbMessageBox::information(msg); |
369 HbNotificationDialog *infoNote = new HbNotificationDialog(); |
297 } |
370 infoNote->setAttribute(Qt::WA_DeleteOnClose); |
298 |
371 // only title can be two rows for HbNotificationDialog |
299 } |
372 infoNote->setTitleTextWrapping(Hb::TextWordWrap); |
300 } |
373 infoNote->setTitle(msg); |
301 |
374 infoNote->show(); |
|
375 } |
|
376 } |
|
377 } |
|
378 |