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 |
#include "cntactionpopup_p.h"
|
|
18 |
#include <qcontact.h>
|
|
19 |
#include <qcontactdetail.h>
|
|
20 |
#include <qcontactphonenumber.h>
|
|
21 |
#include <hbaction.h>
|
|
22 |
#include <QDebug>
|
|
23 |
#include "cntstringmapper.h"
|
|
24 |
#include <hblistview.h>
|
|
25 |
#include <hblistviewitem.h>
|
|
26 |
#include <QStandardItemModel>
|
|
27 |
|
|
28 |
CntActionPopupPrivate::CntActionPopupPrivate( QContact* aContact, QGraphicsItem *parent ) :
|
|
29 |
HbSelectionDialog(parent),
|
|
30 |
mContact( NULL ),
|
|
31 |
mListModel(NULL),
|
|
32 |
mListView(NULL),
|
|
33 |
mCancelAction(NULL)
|
|
34 |
{
|
|
35 |
mContact = new QContact( *aContact );
|
|
36 |
mListView = new HbListView(this);
|
|
37 |
mListModel = new QStandardItemModel(this);
|
|
38 |
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
39 |
mDataItemList.clear();
|
|
40 |
}
|
|
41 |
|
|
42 |
CntActionPopupPrivate::~CntActionPopupPrivate()
|
|
43 |
{
|
|
44 |
delete mContact;
|
|
45 |
mContact = NULL;
|
|
46 |
}
|
|
47 |
|
|
48 |
void CntActionPopupPrivate::buildCallActionPopup()
|
|
49 |
{
|
|
50 |
// Create call action
|
|
51 |
QList<QContactPhoneNumber> details = mContact->details<QContactPhoneNumber>();
|
|
52 |
CntStringMapper map;
|
|
53 |
for (int index = 0; index < details.count(); index++)
|
|
54 |
{
|
|
55 |
if(supportsDetail("call", details[index]))
|
|
56 |
{
|
|
57 |
QString context = details[index].contexts().isEmpty() ? QString() : details[index].contexts().first();
|
|
58 |
QString subtype = details[index].subTypes().isEmpty() ? details[index].definitionName() : details[index].subTypes().first();
|
|
59 |
|
|
60 |
int position = getPosition(subtype, context);
|
|
61 |
|
|
62 |
QString titleText = map.getContactCardListLocString(subtype , context);
|
|
63 |
QString valueText = details[index].number();
|
|
64 |
|
|
65 |
QStandardItem *labelItem = new QStandardItem();
|
|
66 |
QStringList textList;
|
|
67 |
textList << titleText << valueText;
|
|
68 |
labelItem->setData(textList, Qt::DisplayRole);
|
|
69 |
labelItem->setData(HbIcon(map.getContactCardIconString(subtype, context)), Qt::DecorationRole);
|
|
70 |
labelItem->setData(index, Qt::UserRole);
|
|
71 |
labelItem->setData("call", Qt::UserRole+1);
|
|
72 |
labelItem->setData(position, Qt::UserRole+2);
|
|
73 |
mDataItemList.append(labelItem);
|
|
74 |
}
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
void CntActionPopupPrivate::buildEmailActionPopup()
|
|
79 |
{
|
|
80 |
// Create email action
|
|
81 |
QList<QContactEmailAddress> details = mContact->details<QContactEmailAddress>();
|
|
82 |
CntStringMapper map;
|
|
83 |
for (int index = 0; index < details.count(); index++)
|
|
84 |
{
|
|
85 |
if(supportsDetail("email", details[index]))
|
|
86 |
{
|
|
87 |
QString context = details[index].contexts().isEmpty() ? QString() : details[index].contexts().first();
|
|
88 |
int position = getPosition(details[index].definitionName(), context);
|
|
89 |
|
|
90 |
QString titleText = map.getContactCardListLocString(details[index].definitionName() , context);
|
|
91 |
QString valueText = details[index].emailAddress();
|
|
92 |
|
|
93 |
QStandardItem *labelItem = new QStandardItem();
|
|
94 |
QStringList textList;
|
|
95 |
textList << titleText << valueText;
|
|
96 |
labelItem->setData(textList, Qt::DisplayRole);
|
|
97 |
labelItem->setData(HbIcon(map.getContactEditorIconString(details[index].definitionName(), context)), Qt::DecorationRole);
|
|
98 |
labelItem->setData(index, Qt::UserRole);
|
|
99 |
labelItem->setData("email", Qt::UserRole+1);
|
|
100 |
labelItem->setData(position, Qt::UserRole+2);
|
|
101 |
mDataItemList.append(labelItem);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
void CntActionPopupPrivate::buildMessageActionPopup()
|
|
107 |
{
|
|
108 |
// Create message action
|
|
109 |
QList<QContactPhoneNumber> details = mContact->details<QContactPhoneNumber>();
|
|
110 |
CntStringMapper map;
|
|
111 |
for (int index = 0; index < details.count(); index++)
|
|
112 |
{
|
|
113 |
if(supportsDetail("message", details[index]))
|
|
114 |
{
|
|
115 |
// Todo : Use loc string for this dialog
|
|
116 |
QString context = details[index].contexts().isEmpty() ? QString() : details[index].contexts().first();
|
|
117 |
QString subtype = details[index].subTypes().isEmpty() ? details[index].definitionName() : details[index].subTypes().first();
|
|
118 |
|
|
119 |
int position = getPosition(subtype, context);
|
|
120 |
|
|
121 |
QString icon;
|
|
122 |
if (details[index].contexts().isEmpty())
|
|
123 |
{
|
|
124 |
icon = "qtg_large_message";
|
|
125 |
}
|
|
126 |
else if (details[index].contexts().first() == QContactDetail::ContextHome)
|
|
127 |
{
|
|
128 |
icon = "qtg_large_message_home";
|
|
129 |
}
|
|
130 |
else if (details[index].contexts().first() == QContactDetail::ContextWork)
|
|
131 |
{
|
|
132 |
icon = "qtg_large_message_work";
|
|
133 |
}
|
|
134 |
else
|
|
135 |
{
|
|
136 |
icon = "qtg_large_message";
|
|
137 |
}
|
|
138 |
|
|
139 |
QString titleText( hbTrId("txt_phob_dblist_send_message"));
|
|
140 |
QString valueText = details[index].number();
|
|
141 |
|
|
142 |
QStandardItem *labelItem = new QStandardItem();
|
|
143 |
QStringList textList;
|
|
144 |
textList << titleText << valueText;
|
|
145 |
labelItem->setData(textList, Qt::DisplayRole);
|
|
146 |
labelItem->setData(HbIcon(icon), Qt::DecorationRole);
|
|
147 |
labelItem->setData(index, Qt::UserRole);
|
|
148 |
labelItem->setData("message", Qt::UserRole+1);
|
|
149 |
labelItem->setData(position, Qt::UserRole+2);
|
|
150 |
mDataItemList.append(labelItem);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
bool CntActionPopupPrivate::showActionPopup(QString action)
|
|
156 |
{
|
|
157 |
if (action.compare("call", Qt::CaseInsensitive) == 0 )
|
|
158 |
{
|
|
159 |
buildCallActionPopup();
|
|
160 |
}
|
|
161 |
else if( action.compare("message", Qt::CaseInsensitive) == 0 )
|
|
162 |
{
|
|
163 |
buildMessageActionPopup();
|
|
164 |
}
|
|
165 |
else if (action.compare("email", Qt::CaseInsensitive) == 0 )
|
|
166 |
{
|
|
167 |
buildEmailActionPopup();
|
|
168 |
}
|
|
169 |
|
|
170 |
if(mDataItemList.count())
|
|
171 |
{
|
|
172 |
showPopup();
|
|
173 |
return true;
|
|
174 |
}
|
|
175 |
return false;
|
|
176 |
|
|
177 |
}
|
|
178 |
|
|
179 |
void CntActionPopupPrivate::showPopup()
|
|
180 |
{
|
|
181 |
for (int i= 0 ;i< mDataItemList.count() ;i++)
|
|
182 |
{
|
|
183 |
mListModel->appendRow(mDataItemList.at(i));
|
|
184 |
}
|
|
185 |
mListModel->setSortRole(Qt::UserRole+2);
|
|
186 |
mListModel->sort(0, Qt::AscendingOrder);
|
|
187 |
|
|
188 |
clearActions();
|
|
189 |
mListView->setModel(mListModel);
|
|
190 |
mListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
|
|
191 |
mListView->setFrictionEnabled(true);
|
|
192 |
mListView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Maximum );
|
81
|
193 |
mListView->setLongPressEnabled(false);//This is to make longpress act like shortpress when no tap menu
|
72
|
194 |
|
|
195 |
QString contactName = mContact->displayLabel();
|
|
196 |
if (contactName.isEmpty())
|
|
197 |
{
|
|
198 |
contactName = hbTrId("txt_phob_list_unnamed");
|
|
199 |
}
|
|
200 |
|
81
|
201 |
setHeadingText(contactName);
|
72
|
202 |
setContentWidget(mListView);
|
|
203 |
|
|
204 |
mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"), this);
|
|
205 |
addAction(mCancelAction);
|
|
206 |
setTimeout(HbDialog::NoTimeout);
|
|
207 |
setDismissPolicy(HbDialog::NoDismiss);
|
|
208 |
setModal(true);
|
|
209 |
|
81
|
210 |
connect(mListView, SIGNAL(activated (const QModelIndex &)),
|
|
211 |
this, SLOT(listItemSelected(QModelIndex)) );
|
72
|
212 |
|
|
213 |
//launch dialog asyncronously
|
|
214 |
open(this, SLOT(handleUserResponse(HbAction*)));
|
|
215 |
|
|
216 |
}
|
|
217 |
|
|
218 |
void CntActionPopupPrivate::handleUserResponse(HbAction* action)
|
|
219 |
{
|
|
220 |
if (action == mCancelAction )
|
|
221 |
{
|
|
222 |
emit actionPopupCancelPressed();
|
|
223 |
}
|
|
224 |
mCancelAction = 0;
|
|
225 |
|
|
226 |
}
|
|
227 |
|
|
228 |
void CntActionPopupPrivate::listItemSelected( QModelIndex index )
|
|
229 |
{
|
|
230 |
if (index.isValid())
|
|
231 |
{
|
|
232 |
int selectedDetail = mListModel->item(index.row())->data(Qt::UserRole).toInt();
|
|
233 |
QString actionName = mListModel->item(index.row())->data(Qt::UserRole+1).toString();
|
|
234 |
if (actionName.compare("call", Qt::CaseInsensitive) == 0
|
|
235 |
|| actionName.compare("message", Qt::CaseInsensitive) == 0 )
|
|
236 |
{
|
|
237 |
QList<QContactPhoneNumber> details = mContact->details<QContactPhoneNumber>();
|
|
238 |
emit executeContactAction( *mContact, details[selectedDetail], actionName);
|
|
239 |
}
|
|
240 |
else if (actionName.compare("email", Qt::CaseInsensitive) == 0 )
|
|
241 |
{
|
|
242 |
QList<QContactEmailAddress> details = mContact->details<QContactEmailAddress>();
|
|
243 |
emit executeContactAction( *mContact, details[selectedDetail], actionName);
|
|
244 |
}
|
|
245 |
}
|
|
246 |
close();
|
|
247 |
}
|
|
248 |
|
|
249 |
/*!
|
|
250 |
Returns position of specific item
|
|
251 |
*/
|
|
252 |
int CntActionPopupPrivate::getPosition(const QString& aId, const QString& aContext)
|
|
253 |
{
|
|
254 |
int position = CntActionPopupPrivate::ENotSupported;
|
|
255 |
if (aId == QContactPhoneNumber::SubTypeAssistant && aContext.isEmpty() )
|
|
256 |
{
|
|
257 |
position = CntActionPopupPrivate::ECallAssistant;
|
|
258 |
}
|
|
259 |
else if (aId == QContactPhoneNumber::SubTypeCar && aContext.isEmpty() )
|
|
260 |
{
|
|
261 |
position = CntActionPopupPrivate::ECallCar;
|
|
262 |
}
|
|
263 |
else if (aId == QContactPhoneNumber::SubTypeMobile && aContext.isEmpty() )
|
|
264 |
{
|
|
265 |
position = CntActionPopupPrivate::ECallMobile;
|
|
266 |
}
|
|
267 |
else if (aId == QContactPhoneNumber::SubTypeMobile && aContext == QContactDetail::ContextHome )
|
|
268 |
{
|
|
269 |
position = CntActionPopupPrivate::ECallMobileHome;
|
|
270 |
}
|
|
271 |
else if (aId == QContactPhoneNumber::SubTypeMobile && aContext == QContactDetail::ContextWork )
|
|
272 |
{
|
|
273 |
position = CntActionPopupPrivate::ECallMobileWork;
|
|
274 |
}
|
|
275 |
else if (aId == QContactPhoneNumber::SubTypeLandline && aContext.isEmpty() )
|
|
276 |
{
|
|
277 |
position = CntActionPopupPrivate::ECallPhone;
|
|
278 |
}
|
|
279 |
else if (aId == QContactPhoneNumber::SubTypeLandline && aContext == QContactDetail::ContextHome )
|
|
280 |
{
|
|
281 |
position = CntActionPopupPrivate::ECallPhoneHome;
|
|
282 |
}
|
|
283 |
else if (aId == QContactPhoneNumber::SubTypeLandline && aContext == QContactDetail::ContextWork )
|
|
284 |
{
|
|
285 |
position = CntActionPopupPrivate::ECallPhoneWork;
|
|
286 |
}
|
|
287 |
else if (aId == QContactPhoneNumber::SubTypeFax && aContext.isEmpty() )
|
|
288 |
{
|
|
289 |
position = CntActionPopupPrivate::ECallFax;
|
|
290 |
}
|
|
291 |
else if (aId == QContactPhoneNumber::SubTypeFax && aContext == QContactDetail::ContextHome )
|
|
292 |
{
|
|
293 |
position = CntActionPopupPrivate::ECallFaxHome;
|
|
294 |
}
|
|
295 |
else if (aId == QContactPhoneNumber::SubTypeFax && aContext == QContactDetail::ContextWork )
|
|
296 |
{
|
|
297 |
position = CntActionPopupPrivate::ECallFaxWork;
|
|
298 |
}
|
|
299 |
else if (aId == QContactPhoneNumber::SubTypePager && aContext.isEmpty() )
|
|
300 |
{
|
|
301 |
position = CntActionPopupPrivate::ECallPager;
|
|
302 |
}
|
|
303 |
else if (aId == QContactEmailAddress::DefinitionName && aContext.isEmpty())
|
|
304 |
{
|
|
305 |
position = CntActionPopupPrivate::EEmail;
|
|
306 |
}
|
|
307 |
else if (aId == QContactEmailAddress::DefinitionName && aContext == QContactDetail::ContextHome)
|
|
308 |
{
|
|
309 |
position = CntActionPopupPrivate::EEmailHome;
|
|
310 |
}
|
|
311 |
else if (aId == QContactEmailAddress::DefinitionName && aContext == QContactDetail::ContextWork)
|
|
312 |
{
|
|
313 |
position = CntActionPopupPrivate::EEmailWork;
|
|
314 |
}
|
|
315 |
else
|
|
316 |
{
|
|
317 |
position = CntActionPopupPrivate::ENotSupported;
|
|
318 |
}
|
|
319 |
|
|
320 |
return position;
|
|
321 |
}
|
|
322 |
|
|
323 |
/*!
|
|
324 |
Returns true if contactDetails contains spesific action.
|
|
325 |
*/
|
|
326 |
bool CntActionPopupPrivate::supportsDetail(const QString &actionName, const QContactDetail &contactDetail)
|
|
327 |
{
|
|
328 |
QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(actionName, "symbian");
|
|
329 |
if (actionDescriptors.isEmpty())
|
|
330 |
{
|
|
331 |
return false;
|
|
332 |
}
|
|
333 |
|
|
334 |
QContactAction* contactAction = QContactAction::action(actionDescriptors.first());
|
|
335 |
bool isSupportDetail = contactAction->isDetailSupported(contactDetail);
|
|
336 |
|
|
337 |
delete contactAction;
|
|
338 |
|
|
339 |
return isSupportDetail;
|
|
340 |
}
|
|
341 |
|
|
342 |
// End of File
|