72
|
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 |
#include "cnthistoryview.h"
|
|
19 |
|
|
20 |
#include <hblistview.h>
|
|
21 |
#include <hbgroupbox.h>
|
|
22 |
#include <hbdocumentloader.h>
|
|
23 |
#include <hbmenu.h>
|
|
24 |
#include <hbview.h>
|
|
25 |
#include <hbmessagebox.h>
|
|
26 |
#include <hbaction.h>
|
|
27 |
#include <xqappmgr.h>
|
|
28 |
#include <xqservicerequest.h>
|
|
29 |
#include <cnthistorymodel.h>
|
|
30 |
#include <hbparameterlengthlimiter.h>
|
|
31 |
#include <hbmainwindow.h>
|
|
32 |
#include <hbframebackground.h>
|
|
33 |
#include <hbabstractviewitem.h>
|
|
34 |
#include <QTimer>
|
|
35 |
#include <qtcontacts.h>
|
|
36 |
|
|
37 |
#include "cnthistoryviewitem.h"
|
|
38 |
#include "cntglobal.h"
|
|
39 |
#include "cntdebug.h"
|
|
40 |
|
|
41 |
const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
|
|
42 |
|
|
43 |
/*!
|
|
44 |
Constructor, initialize member variables.
|
|
45 |
*/
|
|
46 |
CntHistoryView::CntHistoryView() :
|
|
47 |
mHistoryListView(NULL),
|
|
48 |
mHistoryModel(NULL),
|
|
49 |
mDocumentLoader(NULL),
|
|
50 |
mViewMgr(NULL),
|
|
51 |
mContact(NULL),
|
|
52 |
mRequest(NULL)
|
|
53 |
{
|
|
54 |
bool ok = false;
|
|
55 |
|
|
56 |
docLoader()->load(CNT_HISTORYVIEW_XML, &ok);
|
|
57 |
|
|
58 |
if (ok)
|
|
59 |
{
|
|
60 |
mView = static_cast<HbView*>(docLoader()->findWidget(QString("view")));
|
|
61 |
|
|
62 |
// Create a back key action an set it as the default navigation
|
|
63 |
// action once the back key is pressed
|
|
64 |
mBackKey = new HbAction(Hb::BackNaviAction, mView);
|
|
65 |
mView->setNavigationAction(mBackKey);
|
|
66 |
connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
|
|
67 |
|
|
68 |
HbMenu* viewMenu = static_cast<HbMenu*>(docLoader()->findObject("viewMenu") );
|
|
69 |
viewMenu->setParent(mView);
|
|
70 |
}
|
|
71 |
else
|
|
72 |
{
|
|
73 |
qFatal("Unable to read :/xml/contacts_history.docml");
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
/*!
|
|
78 |
Destructor
|
|
79 |
*/
|
|
80 |
CntHistoryView::~CntHistoryView()
|
|
81 |
{
|
|
82 |
mView->deleteLater();
|
|
83 |
|
|
84 |
if (mDocumentLoader) {
|
|
85 |
delete mDocumentLoader;
|
|
86 |
mDocumentLoader = NULL;
|
|
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;
|
|
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 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Activate the view
|
|
113 |
*/
|
|
114 |
void CntHistoryView::activate( const CntViewParameters aArgs )
|
|
115 |
{
|
|
116 |
mArgs = aArgs;
|
|
117 |
mViewMgr = &mEngine->viewManager();
|
|
118 |
|
|
119 |
QContactManager* cm = &mEngine->contactManager(SYMBIAN_BACKEND);
|
|
120 |
mContact = new QContact(mArgs.value(ESelectedContact).value<QContact>());
|
|
121 |
|
|
122 |
// Set history view heading
|
|
123 |
HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox")));
|
|
124 |
QString name = mContact->displayLabel();
|
|
125 |
if (name.isEmpty())
|
|
126 |
{
|
|
127 |
name = hbTrId("txt_phob_list_unnamed");
|
|
128 |
}
|
|
129 |
groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(name));
|
|
130 |
|
|
131 |
//construct listview
|
|
132 |
mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView")));
|
|
133 |
mHistoryListView->setLayoutName("history");
|
|
134 |
CntHistoryViewItem *item = new CntHistoryViewItem;
|
|
135 |
item->setSecondaryTextRowCount(1, 3);
|
|
136 |
item->setGraphicsSize(HbListViewItem::SmallIcon);
|
|
137 |
mHistoryListView->setItemPrototype(item); //ownership is taken
|
|
138 |
|
|
139 |
// Connect listview items to respective slots
|
|
140 |
connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
|
|
141 |
this, SLOT(itemActivated(const QModelIndex &)));
|
|
142 |
connect( mHistoryListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)),
|
|
143 |
this, SLOT(onLongPressed(HbAbstractViewItem*,const QPointF&)) );
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
mHistoryModel = new CntHistoryModel(mContact->localId(), cm);
|
|
148 |
mHistoryListView->setModel(mHistoryModel); //ownership is not taken
|
|
149 |
|
|
150 |
//start listening to the events amount changing in the model
|
|
151 |
connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
|
|
152 |
this, SLOT(updateScrollingPosition()));
|
|
153 |
connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
|
|
154 |
this, SLOT(showClearHistoryMenu()));
|
|
155 |
connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
|
|
156 |
this, SLOT(updateScrollingPosition()));
|
|
157 |
connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
|
|
158 |
this, SLOT(showClearHistoryMenu()));
|
|
159 |
connect(mHistoryModel, SIGNAL(layoutChanged()),
|
|
160 |
this, SLOT(updateScrollingPosition()));
|
|
161 |
connect(mHistoryModel, SIGNAL(modelReset()),
|
|
162 |
this, SLOT(updateScrollingPosition()));
|
|
163 |
connect(mHistoryModel, SIGNAL(modelReset()),
|
|
164 |
this, SLOT(showClearHistoryMenu()));
|
|
165 |
|
|
166 |
// Connect the menu options to respective slots
|
|
167 |
mClearHistory = static_cast<HbAction*>(docLoader()->findObject("cnt:clearhistory"));
|
|
168 |
mClearHistory->setParent(mView);
|
|
169 |
connect(mClearHistory, SIGNAL(triggered()), this, SLOT(clearHistory()));
|
|
170 |
showClearHistoryMenu();
|
|
171 |
|
|
172 |
connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
173 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
174 |
}
|
|
175 |
|
|
176 |
/*!
|
|
177 |
Called after new items are added to or removed from comm history view
|
|
178 |
*/
|
|
179 |
void CntHistoryView::updateScrollingPosition()
|
|
180 |
{
|
|
181 |
int rowCnt = mHistoryModel->rowCount();
|
|
182 |
|
|
183 |
// Scroll to the last item in the list
|
|
184 |
mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0),
|
|
185 |
HbAbstractItemView::PositionAtBottom);
|
|
186 |
}
|
|
187 |
|
|
188 |
/*
|
|
189 |
Query the user for clearing communications history
|
|
190 |
*/
|
|
191 |
void CntHistoryView::clearHistory()
|
|
192 |
{
|
|
193 |
// Ask the use if they want to clear the history
|
|
194 |
QString name = mContact->displayLabel();
|
|
195 |
if (name.isEmpty())
|
|
196 |
{
|
|
197 |
name = hbTrId("txt_phob_list_unnamed");
|
|
198 |
}
|
|
199 |
|
|
200 |
HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_clear_communications_history_with_1")).arg(name), this,
|
|
201 |
SLOT(handleClearHistory(int)), HbMessageBox::Delete | HbMessageBox::Cancel);
|
|
202 |
}
|
|
203 |
|
|
204 |
/*
|
|
205 |
Handle the selected action for clearing history
|
|
206 |
*/
|
|
207 |
void CntHistoryView::handleClearHistory(int action)
|
|
208 |
{
|
|
209 |
if (action == HbMessageBox::Delete)
|
|
210 |
{
|
|
211 |
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 |
}
|
|
223 |
}
|
|
224 |
|
|
225 |
/*!
|
|
226 |
Once list item is pressed on the list view this slot handles the
|
|
227 |
emitted signal
|
|
228 |
*/
|
|
229 |
void CntHistoryView::itemActivated(const QModelIndex &index)
|
|
230 |
{
|
|
231 |
int flags = index.data(CntFlagsRole).toInt();
|
|
232 |
|
|
233 |
bool createRequest(false);
|
|
234 |
|
|
235 |
QString interface;
|
|
236 |
QString operation;
|
|
237 |
QVariantList args;
|
|
238 |
|
|
239 |
// If the list item is a call log a call is made to that item
|
|
240 |
if ( flags & CntCallLog ) {
|
|
241 |
// Make a call
|
|
242 |
QVariant number = index.data(CntPhoneNumberRole);
|
|
243 |
|
|
244 |
if ( number.isValid() ) {
|
|
245 |
interface = "com.nokia.symbian.ICallDial";
|
|
246 |
operation = "dial(QString)";
|
|
247 |
args << number;
|
|
248 |
createRequest = true;
|
|
249 |
|
|
250 |
// TODO: Using XQApplicationManager is not working with calls
|
|
251 |
// The factory method cannot create a request. Find out why
|
|
252 |
createRequest = false;
|
|
253 |
QString service("com.nokia.symbian.ICallDial");
|
|
254 |
QString type("dial(QString,int)");
|
|
255 |
XQServiceRequest snd(interface, operation, false);
|
|
256 |
snd << number.toString() << mContact->localId();
|
|
257 |
snd.send();
|
|
258 |
}
|
|
259 |
|
|
260 |
} else if ( flags & CntMessage ) {
|
|
261 |
// Open conversation view
|
|
262 |
QVariant id = index.data(CntConverstaionIdRole);
|
|
263 |
|
|
264 |
if ( id.isValid() ) {
|
|
265 |
interface = "com.nokia.symbian.IMessageView";
|
|
266 |
operation = "view(int)";
|
|
267 |
args << id;
|
|
268 |
createRequest = true;
|
|
269 |
}
|
|
270 |
}
|
|
271 |
|
|
272 |
if ( createRequest ) {
|
|
273 |
XQApplicationManager appMng;
|
|
274 |
|
|
275 |
delete mRequest;
|
|
276 |
mRequest = NULL;
|
|
277 |
mRequest = appMng.create(interface, operation, true); // embedded
|
|
278 |
|
|
279 |
if ( mRequest ) {
|
|
280 |
mRequest->setArguments(args);
|
|
281 |
mRequest->send();
|
|
282 |
}
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
/*!
|
|
287 |
Go back to previous view
|
|
288 |
*/
|
|
289 |
void CntHistoryView::showPreviousView()
|
|
290 |
{
|
|
291 |
QVariant var;
|
|
292 |
var.setValue(*mContact);
|
|
293 |
mArgs.insert(ESelectedContact, var);
|
|
294 |
mViewMgr->back( mArgs );
|
|
295 |
}
|
|
296 |
|
|
297 |
/*!
|
|
298 |
Go back to the root view
|
|
299 |
*/
|
|
300 |
void CntHistoryView::showRootView()
|
|
301 |
{
|
|
302 |
mViewMgr->back( mArgs, true );
|
|
303 |
}
|
|
304 |
|
|
305 |
|
|
306 |
void CntHistoryView::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds)
|
|
307 |
{
|
|
308 |
CNT_ENTRY
|
|
309 |
if ( contactIds.contains(mContact->localId()) )
|
|
310 |
{
|
|
311 |
// Do not switch to the previous view immediately. List views are
|
|
312 |
// not updated properly if this is not done in the event loop
|
|
313 |
QTimer::singleShot(0, this, SLOT(showRootView()));
|
|
314 |
}
|
|
315 |
CNT_EXIT
|
|
316 |
}
|
|
317 |
|
|
318 |
/*!
|
|
319 |
Show or hide the clear history menu
|
|
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()
|
|
334 |
{
|
|
335 |
if (!mDocumentLoader) {
|
|
336 |
mDocumentLoader = new HbDocumentLoader();
|
|
337 |
}
|
|
338 |
return mDocumentLoader;
|
|
339 |
}
|
|
340 |
|
|
341 |
// end of file
|