15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "cnthistoryview.h" |
18 #include "cnthistoryview.h" |
19 |
19 |
|
20 #include "cnthistoryviewitem.h" |
|
21 #include "cntglobal.h" |
|
22 #include "cntdebug.h" |
|
23 |
20 #include <hblistview.h> |
24 #include <hblistview.h> |
21 #include <hbgroupbox.h> |
25 #include <hbgroupbox.h> |
22 #include <hbdocumentloader.h> |
26 #include <hbdocumentloader.h> |
23 #include <hbmenu.h> |
27 #include <hbmenu.h> |
24 #include <hbview.h> |
28 #include <hbview.h> |
25 #include <hbmessagebox.h> |
29 #include <hbmessagebox.h> |
26 #include <hbaction.h> |
30 #include <hbaction.h> |
27 #include <xqappmgr.h> |
|
28 #include <xqservicerequest.h> |
|
29 #include <cnthistorymodel.h> |
|
30 #include <hbparameterlengthlimiter.h> |
31 #include <hbparameterlengthlimiter.h> |
31 #include <hbmainwindow.h> |
32 #include <hbmainwindow.h> |
32 #include <hbframebackground.h> |
33 #include <hbframebackground.h> |
33 #include <hbabstractviewitem.h> |
34 #include <hbabstractviewitem.h> |
|
35 #include <xqappmgr.h> |
|
36 #include <xqservicerequest.h> |
|
37 #include <cnthistorymodel.h> |
34 #include <QTimer> |
38 #include <QTimer> |
35 #include <qtcontacts.h> |
|
36 |
|
37 #include "cnthistoryviewitem.h" |
|
38 #include "cntglobal.h" |
|
39 #include "cntdebug.h" |
|
40 |
39 |
41 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml"; |
40 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml"; |
42 |
41 |
43 /*! |
42 /*! |
44 Constructor, initialize member variables. |
43 Constructor, initialize member variables. |
79 */ |
78 */ |
80 CntHistoryView::~CntHistoryView() |
79 CntHistoryView::~CntHistoryView() |
81 { |
80 { |
82 mView->deleteLater(); |
81 mView->deleteLater(); |
83 |
82 |
84 if (mDocumentLoader) { |
83 delete mDocumentLoader; |
85 delete mDocumentLoader; |
84 delete mHistoryModel; |
86 mDocumentLoader = NULL; |
85 delete mContact; |
87 } |
|
88 if (mHistoryModel) { |
|
89 delete mHistoryModel; |
|
90 mHistoryModel = NULL; |
|
91 } |
|
92 if (mContact) { |
|
93 delete mContact; |
|
94 mContact = NULL; |
|
95 } |
|
96 |
|
97 delete mRequest; |
86 delete mRequest; |
98 mRequest = NULL; |
|
99 } |
|
100 |
|
101 /*! |
|
102 * Deactivate the view |
|
103 */ |
|
104 void CntHistoryView::deactivate() |
|
105 { |
|
106 QContactManager* cm = &mEngine->contactManager(SYMBIAN_BACKEND); |
|
107 disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
|
108 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
|
109 } |
87 } |
110 |
88 |
111 /** |
89 /** |
112 * Activate the view |
90 * Activate the view |
113 */ |
91 */ |
124 QString name = mContact->displayLabel(); |
102 QString name = mContact->displayLabel(); |
125 if (name.isEmpty()) |
103 if (name.isEmpty()) |
126 { |
104 { |
127 name = hbTrId("txt_phob_list_unnamed"); |
105 name = hbTrId("txt_phob_list_unnamed"); |
128 } |
106 } |
129 groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(name)); |
107 groupBox->setHeading(HbParameterLengthLimiter("txt_phob_subtitle_history_with_1").arg(name)); |
130 |
108 |
131 //construct listview |
109 //construct listview |
132 mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView"))); |
110 mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView"))); |
133 mHistoryListView->setLayoutName("history"); |
|
134 CntHistoryViewItem *item = new CntHistoryViewItem; |
111 CntHistoryViewItem *item = new CntHistoryViewItem; |
135 item->setSecondaryTextRowCount(1, 3); |
|
136 item->setGraphicsSize(HbListViewItem::SmallIcon); |
|
137 mHistoryListView->setItemPrototype(item); //ownership is taken |
112 mHistoryListView->setItemPrototype(item); //ownership is taken |
138 |
113 |
139 // Connect listview items to respective slots |
114 // Connect listview items to respective slots |
140 connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)), |
115 connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)), |
141 this, SLOT(itemActivated(const QModelIndex &))); |
116 this, SLOT(itemActivated(const QModelIndex &))); |
142 connect( mHistoryListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), |
117 |
143 this, SLOT(onLongPressed(HbAbstractViewItem*,const QPointF&)) ); |
118 // To make LongPress act like shortpress. After this only activated signal comes |
144 |
119 mHistoryListView->setLongPressEnabled(false); |
145 |
120 |
146 |
|
147 mHistoryModel = new CntHistoryModel(mContact->localId(), cm); |
121 mHistoryModel = new CntHistoryModel(mContact->localId(), cm); |
148 mHistoryListView->setModel(mHistoryModel); //ownership is not taken |
122 mHistoryListView->setModel(mHistoryModel); //ownership is not taken |
149 |
123 |
150 //start listening to the events amount changing in the model |
124 //start listening to the events amount changing in the model |
151 connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), |
125 connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), |
172 connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
146 connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
173 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
147 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
174 } |
148 } |
175 |
149 |
176 /*! |
150 /*! |
|
151 * Deactivate the view |
|
152 */ |
|
153 void CntHistoryView::deactivate() |
|
154 { |
|
155 QContactManager* cm = &mEngine->contactManager(SYMBIAN_BACKEND); |
|
156 disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
|
157 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
|
158 } |
|
159 |
|
160 /*! |
177 Called after new items are added to or removed from comm history view |
161 Called after new items are added to or removed from comm history view |
178 */ |
162 */ |
179 void CntHistoryView::updateScrollingPosition() |
163 void CntHistoryView::updateScrollingPosition() |
180 { |
164 { |
181 int rowCnt = mHistoryModel->rowCount(); |
165 int rowCnt = mHistoryModel->rowCount(); |
195 if (name.isEmpty()) |
179 if (name.isEmpty()) |
196 { |
180 { |
197 name = hbTrId("txt_phob_list_unnamed"); |
181 name = hbTrId("txt_phob_list_unnamed"); |
198 } |
182 } |
199 |
183 |
200 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_clear_communications_history_with_1")).arg(name), this, |
184 HbMessageBox::question(HbParameterLengthLimiter("txt_phob_info_clear_communications_history_with_1").arg(name), this, |
201 SLOT(handleClearHistory(int)), HbMessageBox::Delete | HbMessageBox::Cancel); |
185 SLOT(handleClearHistory(int)), HbMessageBox::Delete | HbMessageBox::Cancel); |
202 } |
186 } |
203 |
187 |
204 /* |
188 /* |
205 Handle the selected action for clearing history |
189 Handle the selected action for clearing history |
207 void CntHistoryView::handleClearHistory(int action) |
191 void CntHistoryView::handleClearHistory(int action) |
208 { |
192 { |
209 if (action == HbMessageBox::Delete) |
193 if (action == HbMessageBox::Delete) |
210 { |
194 { |
211 mHistoryModel->clearHistory(); |
195 mHistoryModel->clearHistory(); |
212 } |
|
213 } |
|
214 |
|
215 void CntHistoryView::onLongPressed(HbAbstractViewItem *item, const QPointF &coords) |
|
216 { |
|
217 Q_UNUSED(coords); |
|
218 QModelIndex index = item->modelIndex(); |
|
219 if (index.isValid()) |
|
220 { |
|
221 itemActivated(index); |
|
222 } |
196 } |
223 } |
197 } |
224 |
198 |
225 /*! |
199 /*! |
226 Once list item is pressed on the list view this slot handles the |
200 Once list item is pressed on the list view this slot handles the |
235 QString interface; |
209 QString interface; |
236 QString operation; |
210 QString operation; |
237 QVariantList args; |
211 QVariantList args; |
238 |
212 |
239 // If the list item is a call log a call is made to that item |
213 // If the list item is a call log a call is made to that item |
240 if ( flags & CntCallLog ) { |
214 if ( flags & CntCallLog ) |
|
215 { |
241 // Make a call |
216 // Make a call |
242 QVariant number = index.data(CntPhoneNumberRole); |
217 QVariant number = index.data(CntPhoneNumberRole); |
243 |
218 |
244 if ( number.isValid() ) { |
219 if ( number.isValid() ) |
|
220 { |
245 interface = "com.nokia.symbian.ICallDial"; |
221 interface = "com.nokia.symbian.ICallDial"; |
246 operation = "dial(QString)"; |
222 operation = "dial(QString)"; |
247 args << number; |
223 args << number; |
248 createRequest = true; |
224 createRequest = true; |
249 |
225 |
255 XQServiceRequest snd(interface, operation, false); |
231 XQServiceRequest snd(interface, operation, false); |
256 snd << number.toString() << mContact->localId(); |
232 snd << number.toString() << mContact->localId(); |
257 snd.send(); |
233 snd.send(); |
258 } |
234 } |
259 |
235 |
260 } else if ( flags & CntMessage ) { |
236 } |
|
237 else if ( flags & CntMessage ) |
|
238 { |
261 // Open conversation view |
239 // Open conversation view |
262 QVariant id = index.data(CntConverstaionIdRole); |
240 QVariant id = index.data(CntConverstaionIdRole); |
263 |
241 |
264 if ( id.isValid() ) { |
242 if ( id.isValid() ) |
|
243 { |
265 interface = "com.nokia.symbian.IMessageView"; |
244 interface = "com.nokia.symbian.IMessageView"; |
266 operation = "view(int)"; |
245 operation = "view(int)"; |
267 args << id; |
246 args << id; |
268 createRequest = true; |
247 createRequest = true; |
269 } |
248 } |
270 } |
249 } |
271 |
250 |
272 if ( createRequest ) { |
251 if ( createRequest ) |
|
252 { |
273 XQApplicationManager appMng; |
253 XQApplicationManager appMng; |
274 |
254 |
275 delete mRequest; |
255 delete mRequest; |
276 mRequest = NULL; |
256 mRequest = NULL; |
277 mRequest = appMng.create(interface, operation, true); // embedded |
257 mRequest = appMng.create(interface, operation, true); // embedded |
278 |
258 |
279 if ( mRequest ) { |
259 if ( mRequest ) |
|
260 { |
280 mRequest->setArguments(args); |
261 mRequest->setArguments(args); |
281 mRequest->send(); |
262 mRequest->send(); |
282 } |
263 } |
283 } |
264 } |
284 } |
265 } |
300 void CntHistoryView::showRootView() |
281 void CntHistoryView::showRootView() |
301 { |
282 { |
302 mViewMgr->back( mArgs, true ); |
283 mViewMgr->back( mArgs, true ); |
303 } |
284 } |
304 |
285 |
305 |
286 /*! |
|
287 Show or hide the clear history menu |
|
288 */ |
|
289 void CntHistoryView::showClearHistoryMenu() |
|
290 { |
|
291 if (mHistoryModel->rowCount() > 0) |
|
292 { |
|
293 mClearHistory->setEnabled(true); |
|
294 } |
|
295 else |
|
296 { |
|
297 mClearHistory->setEnabled(false); |
|
298 } |
|
299 } |
|
300 |
|
301 /*! |
|
302 Handle the situation where this contact is deleted from another source |
|
303 */ |
306 void CntHistoryView::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds) |
304 void CntHistoryView::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds) |
307 { |
305 { |
308 CNT_ENTRY |
306 CNT_ENTRY |
|
307 |
309 if ( contactIds.contains(mContact->localId()) ) |
308 if ( contactIds.contains(mContact->localId()) ) |
310 { |
309 { |
311 // Do not switch to the previous view immediately. List views are |
310 // Do not switch to the previous view immediately. List views are |
312 // not updated properly if this is not done in the event loop |
311 // not updated properly if this is not done in the event loop |
313 QTimer::singleShot(0, this, SLOT(showRootView())); |
312 QTimer::singleShot(0, this, SLOT(showRootView())); |
314 } |
313 } |
|
314 |
315 CNT_EXIT |
315 CNT_EXIT |
316 } |
316 } |
317 |
317 |
318 /*! |
318 /*! |
319 Show or hide the clear history menu |
319 Document loader |
320 */ |
320 */ |
321 void CntHistoryView::showClearHistoryMenu() |
|
322 { |
|
323 if (mHistoryModel->rowCount() > 0) { |
|
324 mClearHistory->setEnabled(true); |
|
325 } else { |
|
326 mClearHistory->setEnabled(false); |
|
327 } |
|
328 } |
|
329 |
|
330 /*! |
|
331 * Document loader |
|
332 */ |
|
333 HbDocumentLoader* CntHistoryView::docLoader() |
321 HbDocumentLoader* CntHistoryView::docLoader() |
334 { |
322 { |
335 if (!mDocumentLoader) { |
323 if (!mDocumentLoader) |
|
324 { |
336 mDocumentLoader = new HbDocumentLoader(); |
325 mDocumentLoader = new HbDocumentLoader(); |
337 } |
326 } |
|
327 |
338 return mDocumentLoader; |
328 return mDocumentLoader; |
339 } |
329 } |
340 |
330 |
341 // end of file |
331 // end of file |