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