28 #include <xqservicerequest.h> |
28 #include <xqservicerequest.h> |
29 #include <cnthistorymodel.h> |
29 #include <cnthistorymodel.h> |
30 #include <hbparameterlengthlimiter.h> |
30 #include <hbparameterlengthlimiter.h> |
31 #include <hbmainwindow.h> |
31 #include <hbmainwindow.h> |
32 #include <hbframebackground.h> |
32 #include <hbframebackground.h> |
|
33 #include <QTimer> |
|
34 #include <qtcontacts.h> |
33 |
35 |
34 #include "cnthistoryviewitem.h" |
36 #include "cnthistoryviewitem.h" |
35 #include "cntglobal.h" |
37 #include "cntglobal.h" |
|
38 #include "cntdebug.h" |
36 |
39 |
37 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml"; |
40 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml"; |
38 |
41 |
39 /*! |
42 /*! |
40 Constructor, initialize member variables. |
43 Constructor, initialize member variables. |
97 /*! |
100 /*! |
98 * Deactivate the view |
101 * Deactivate the view |
99 */ |
102 */ |
100 void CntHistoryView::deactivate() |
103 void CntHistoryView::deactivate() |
101 { |
104 { |
|
105 QContactManager* cm = mViewMgr->contactManager(SYMBIAN_BACKEND); |
|
106 disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
|
107 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
102 } |
108 } |
103 |
109 |
104 /** |
110 /** |
105 * Activate the view |
111 * Activate the view |
106 */ |
112 */ |
107 void CntHistoryView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
113 void CntHistoryView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
108 { |
114 { |
109 mViewMgr = aMgr; |
115 mViewMgr = aMgr; |
110 mArgs = aArgs; |
116 mArgs = aArgs; |
|
117 |
|
118 QContactManager* cm = mViewMgr->contactManager(SYMBIAN_BACKEND); |
111 mContact = new QContact(mArgs.value(ESelectedContact).value<QContact>()); |
119 mContact = new QContact(mArgs.value(ESelectedContact).value<QContact>()); |
112 |
120 |
113 // Set history view heading |
121 // Set history view heading |
114 HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox"))); |
122 HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox"))); |
115 groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(mContact->displayLabel())); |
123 QString name = mContact->displayLabel(); |
|
124 if (name.isEmpty()) |
|
125 { |
|
126 name = hbTrId("txt_phob_list_unnamed"); |
|
127 } |
|
128 groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(name)); |
116 |
129 |
117 //construct listview |
130 //construct listview |
118 mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView"))); |
131 mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView"))); |
119 mHistoryListView->setLayoutName("history"); |
132 mHistoryListView->setLayoutName("history"); |
120 CntHistoryViewItem *item = new CntHistoryViewItem; |
133 CntHistoryViewItem *item = new CntHistoryViewItem; |
123 mHistoryListView->setItemPrototype(item); //ownership is taken |
136 mHistoryListView->setItemPrototype(item); //ownership is taken |
124 |
137 |
125 // Connect listview items to respective slots |
138 // Connect listview items to respective slots |
126 connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)), |
139 connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)), |
127 this, SLOT(itemActivated(const QModelIndex &))); |
140 this, SLOT(itemActivated(const QModelIndex &))); |
128 mHistoryModel = new CntHistoryModel(mContact->localId(), |
141 mHistoryModel = new CntHistoryModel(mContact->localId(), cm); |
129 mViewMgr->contactManager(SYMBIAN_BACKEND)); |
|
130 mHistoryListView->setModel(mHistoryModel); //ownership is not taken |
142 mHistoryListView->setModel(mHistoryModel); //ownership is not taken |
131 |
143 |
132 //start listening to the events amount changing in the model |
144 //start listening to the events amount changing in the model |
133 connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), |
145 connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), |
134 this, SLOT(updateScrollingPosition())); |
146 this, SLOT(updateScrollingPosition())); |
148 showClearHistoryMenu(); |
160 showClearHistoryMenu(); |
149 |
161 |
150 HbMainWindow* mainWindow = mView->mainWindow(); |
162 HbMainWindow* mainWindow = mView->mainWindow(); |
151 connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
163 connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
152 this, SLOT(updateScrollingPosition())); |
164 this, SLOT(updateScrollingPosition())); |
|
165 |
|
166 connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
|
167 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
153 } |
168 } |
154 |
169 |
155 /*! |
170 /*! |
156 Called after new items are added to or removed from comm history view |
171 Called after new items are added to or removed from comm history view |
157 */ |
172 */ |
169 */ |
184 */ |
170 void CntHistoryView::clearHistory() |
185 void CntHistoryView::clearHistory() |
171 { |
186 { |
172 // Ask the use if they want to clear the history |
187 // Ask the use if they want to clear the history |
173 QString name = mContact->displayLabel(); |
188 QString name = mContact->displayLabel(); |
|
189 if (name.isEmpty()) |
|
190 { |
|
191 name = hbTrId("txt_phob_list_unnamed"); |
|
192 } |
174 |
193 |
175 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_clear_communications_history_with_1")).arg(name), this, |
194 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_clear_communications_history_with_1")).arg(name), this, |
176 SLOT(handleClearHistory(HbAction*)), hbTrId("txt_common_button_delete"), hbTrId("txt_common_button_cancel")); |
195 SLOT(handleClearHistory(int)), HbMessageBox::Delete | HbMessageBox::Cancel); |
177 } |
196 } |
178 |
197 |
179 /* |
198 /* |
180 Handle the selected action for clearing history |
199 Handle the selected action for clearing history |
181 */ |
200 */ |
182 void CntHistoryView::handleClearHistory(HbAction *action) |
201 void CntHistoryView::handleClearHistory(int action) |
183 { |
202 { |
184 HbMessageBox *note = static_cast<HbMessageBox*>(sender()); |
203 if (action == HbMessageBox::Delete) |
185 |
|
186 if (note && action == note->actions().first()) |
|
187 { |
204 { |
188 mHistoryModel->clearHistory(); |
205 mHistoryModel->clearHistory(); |
189 } |
206 } |
190 } |
207 } |
191 |
208 |
211 if ( number.isValid() ) { |
228 if ( number.isValid() ) { |
212 interface = "com.nokia.symbian.ICallDial"; |
229 interface = "com.nokia.symbian.ICallDial"; |
213 operation = "dial(QString)"; |
230 operation = "dial(QString)"; |
214 args << number; |
231 args << number; |
215 createRequest = true; |
232 createRequest = true; |
|
233 |
|
234 // TODO: Using XQApplicationManager is not working with calls |
|
235 // The factory method cannot create a request. Find out why |
|
236 createRequest = false; |
|
237 QString service("com.nokia.symbian.ICallDial"); |
|
238 QString type("dial(QString,int)"); |
|
239 XQServiceRequest snd(interface, operation, false); |
|
240 snd << number.toString() << mContact->localId(); |
|
241 snd.send(); |
216 } |
242 } |
217 |
|
218 // TODO: Using XQApplicationManager is not working with calls |
|
219 // The factory method cannot create a request. Find out why |
|
220 createRequest = false; |
|
221 QString service("com.nokia.symbian.ICallDial"); |
|
222 QString type("dial(QString)"); |
|
223 XQServiceRequest snd(interface, operation, false); |
|
224 snd << number.toString(); |
|
225 snd.send(); |
|
226 |
243 |
227 } else if ( flags & CntMessage ) { |
244 } else if ( flags & CntMessage ) { |
228 // Open conversation view |
245 // Open conversation view |
229 QVariant id = index.data(CntConverstaionIdRole); |
246 QVariant id = index.data(CntConverstaionIdRole); |
230 |
247 |
260 mArgs.insert(ESelectedContact, var); |
277 mArgs.insert(ESelectedContact, var); |
261 mViewMgr->back( mArgs ); |
278 mViewMgr->back( mArgs ); |
262 } |
279 } |
263 |
280 |
264 /*! |
281 /*! |
|
282 Go back to the root view |
|
283 */ |
|
284 void CntHistoryView::showRootView() |
|
285 { |
|
286 mViewMgr->back( mArgs, true ); |
|
287 } |
|
288 |
|
289 |
|
290 void CntHistoryView::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds) |
|
291 { |
|
292 CNT_ENTRY |
|
293 if ( contactIds.contains(mContact->localId()) ) |
|
294 { |
|
295 // Do not switch to the previous view immediately. List views are |
|
296 // not updated properly if this is not done in the event loop |
|
297 QTimer::singleShot(0, this, SLOT(showRootView())); |
|
298 } |
|
299 CNT_EXIT |
|
300 } |
|
301 |
|
302 /*! |
265 Show or hide the clear history menu |
303 Show or hide the clear history menu |
266 */ |
304 */ |
267 void CntHistoryView::showClearHistoryMenu() |
305 void CntHistoryView::showClearHistoryMenu() |
268 { |
306 { |
269 if (mHistoryModel->rowCount() > 0) { |
307 if (mHistoryModel->rowCount() > 0) { |