|
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 "cntactionmenubuilder.h" |
|
18 #include <qcontact.h> |
|
19 #include "cntstringmapper.h" |
|
20 #include <hbaction.h> |
|
21 #include "cntactionpopup.h" |
|
22 |
|
23 CntActionMenuBuilder::CntActionMenuBuilder( QContactLocalId aMyCardId ) : |
|
24 QObject(), |
|
25 iMyCardId( aMyCardId ), |
|
26 mContact( 0 ), |
|
27 mMap( 0 ) |
|
28 { |
|
29 mMap = new CntStringMapper(); |
|
30 } |
|
31 |
|
32 CntActionMenuBuilder::~CntActionMenuBuilder() |
|
33 { |
|
34 delete mMap; |
|
35 mMap = 0; |
|
36 |
|
37 delete mContact; |
|
38 mContact = 0; |
|
39 } |
|
40 |
|
41 HbMenu* CntActionMenuBuilder::buildActionMenu( QContact& aContact ) |
|
42 { |
|
43 HbMenu* menu = new HbMenu(); |
|
44 |
|
45 // Regular contact, NOT MyCard |
|
46 if ( aContact.localId() != iMyCardId ) |
|
47 { |
|
48 QList<QContactActionDescriptor> actionDescriptors = aContact.availableActions(); |
|
49 QStringList actions; |
|
50 foreach ( QContactActionDescriptor d, aContact.availableActions() ) |
|
51 { |
|
52 actions << d.actionName(); |
|
53 } |
|
54 |
|
55 if ( actions.contains("call", Qt::CaseInsensitive) && isSupportedDetails("call", aContact)) |
|
56 { |
|
57 createCallAction( *menu, aContact ); |
|
58 } |
|
59 |
|
60 if ( actions.contains("message", Qt::CaseInsensitive) && isSupportedDetails("message", aContact) ) |
|
61 { |
|
62 createMessageAction( *menu, aContact ); |
|
63 } |
|
64 |
|
65 if ( actions.contains("email", Qt::CaseInsensitive) ) |
|
66 { |
|
67 createEmailAction( *menu, aContact ); |
|
68 } |
|
69 |
|
70 if ( menu->actions().size() > 0 ) |
|
71 menu->addSeparator(); |
|
72 } |
|
73 |
|
74 // If contact is NOT MyCard OR MyCard is not empty (detail count is more than 4) |
|
75 if ( aContact.localId() != iMyCardId || aContact.details().size() > 4 ) |
|
76 { |
|
77 menu->addAction(hbTrId("txt_common_menu_open"), this, SLOT(emitOpenContact()) ); |
|
78 menu->addAction(hbTrId("txt_common_menu_edit"), this, SLOT(emitEditContact()) ); |
|
79 menu->addAction(hbTrId("txt_phob_menu_delete_contact"), this, SLOT(emitDeleteContact())); |
|
80 } |
|
81 return menu; |
|
82 } |
|
83 |
|
84 HbMenu* CntActionMenuBuilder::actionMenu( QContact& aContact, QContactLocalId myCardId) |
|
85 { |
|
86 iMyCardId = myCardId; |
|
87 mContact = new QContact( aContact ); |
|
88 return buildActionMenu( aContact ); |
|
89 } |
|
90 |
|
91 void CntActionMenuBuilder::emitOpenContact() |
|
92 { |
|
93 emit openContact( *mContact ); |
|
94 } |
|
95 |
|
96 void CntActionMenuBuilder::emitEditContact() |
|
97 { |
|
98 emit editContact( *mContact ); |
|
99 } |
|
100 |
|
101 void CntActionMenuBuilder::emitDeleteContact() |
|
102 { |
|
103 emit deleteContact( *mContact ); |
|
104 } |
|
105 |
|
106 void CntActionMenuBuilder::emitCallContact() |
|
107 { |
|
108 QContactDetail detail = mContact->preferredDetail("call"); |
|
109 if (!detail.isEmpty()) |
|
110 { |
|
111 emit performContactAction( *mContact, detail, "call" ); |
|
112 } |
|
113 else if (mContact->details<QContactPhoneNumber>().count() == 1 ) |
|
114 { |
|
115 mContact->setPreferredDetail("call", mContact->details<QContactPhoneNumber>().first()); |
|
116 emit performContactAction(*mContact, mContact->details<QContactPhoneNumber>().first(), "call"); |
|
117 } |
|
118 else |
|
119 { |
|
120 CntActionPopup *actionPopup = new CntActionPopup(mContact); |
|
121 actionPopup->showActionPopup("call"); |
|
122 connect( actionPopup, SIGNAL(executeContactAction(QContact&, QContactDetail, QString)), this, |
|
123 SLOT(emitContactaction(QContact&,QContactDetail, QString))); |
|
124 } |
|
125 } |
|
126 |
|
127 void CntActionMenuBuilder::emitSmsContact() |
|
128 { |
|
129 QContactDetail detail = mContact->preferredDetail("message"); |
|
130 if (!detail.isEmpty()) |
|
131 { |
|
132 emit performContactAction( *mContact, detail, "message" ); |
|
133 } |
|
134 else if (mContact->details<QContactPhoneNumber>().count() == 1 ) |
|
135 { |
|
136 mContact->setPreferredDetail("message", mContact->details<QContactPhoneNumber>().first()); |
|
137 emit performContactAction(*mContact, mContact->details<QContactPhoneNumber>().first(), "message"); |
|
138 } |
|
139 else |
|
140 { |
|
141 CntActionPopup *actionPopup = new CntActionPopup(mContact); |
|
142 actionPopup->showActionPopup("message"); |
|
143 connect( actionPopup, SIGNAL(executeContactAction(QContact&, QContactDetail, QString)), this, |
|
144 SLOT(emitContactaction(QContact&,QContactDetail, QString))); |
|
145 } |
|
146 } |
|
147 |
|
148 void CntActionMenuBuilder::emitMailContact() |
|
149 { |
|
150 QContactDetail detail = mContact->preferredDetail("email"); |
|
151 if (!detail.isEmpty()) |
|
152 { |
|
153 emit performContactAction( *mContact,detail, "email" ); |
|
154 } |
|
155 else if (mContact->details<QContactEmailAddress>().count() == 1 ) |
|
156 { |
|
157 mContact->setPreferredDetail("email", mContact->details<QContactEmailAddress>().first()); |
|
158 emit performContactAction(*mContact, mContact->details<QContactEmailAddress>().first(), "email"); |
|
159 } |
|
160 else |
|
161 { |
|
162 CntActionPopup *actionPopup = new CntActionPopup(mContact); |
|
163 actionPopup->showActionPopup("email"); |
|
164 connect( actionPopup, SIGNAL(executeContactAction(QContact&, QContactDetail, QString)), this, |
|
165 SLOT(emitContactaction(QContact&,QContactDetail, QString))); |
|
166 } |
|
167 } |
|
168 |
|
169 void CntActionMenuBuilder::emitContactaction(QContact& aContact,QContactDetail contactDetail, QString aAction) |
|
170 { |
|
171 emit performContactAction( aContact,contactDetail, aAction); |
|
172 } |
|
173 |
|
174 void CntActionMenuBuilder::createCallAction( HbMenu& aMenu, QContact& aContact ) |
|
175 { |
|
176 // Create call action |
|
177 QContactDetail detail = aContact.preferredDetail("call"); |
|
178 QContactPhoneNumber number = detail.isEmpty() ? aContact.detail<QContactPhoneNumber>() : detail; |
|
179 QString context = number.contexts().isEmpty() ? QString() : number.contexts().first(); |
|
180 QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first(); |
|
181 |
|
182 aMenu.addAction( mMap->getItemSpecificMenuLocString( subtype, context ), this, SLOT(emitCallContact()) ); |
|
183 } |
|
184 |
|
185 void CntActionMenuBuilder::createEmailAction( HbMenu& aMenu, QContact& aContact ) |
|
186 { |
|
187 // Create email action |
|
188 QContactDetail detail = aContact.preferredDetail("email"); |
|
189 QContactEmailAddress email = detail.isEmpty() ? aContact.detail<QContactEmailAddress>() : detail; |
|
190 QString context = email.contexts().isEmpty() ? QString() : email.contexts().first(); |
|
191 |
|
192 aMenu.addAction( mMap->getItemSpecificMenuLocString( email.definitionName(), context), this, SLOT(emitMailContact()) ); |
|
193 } |
|
194 |
|
195 void CntActionMenuBuilder::createMessageAction( HbMenu& aMenu, QContact& aContact ) |
|
196 { |
|
197 Q_UNUSED( aContact ); |
|
198 |
|
199 aMenu.addAction(hbTrId("txt_phob_menu_send_message"), this, SLOT(emitSmsContact())); |
|
200 } |
|
201 |
|
202 bool CntActionMenuBuilder::isSupportedDetails( const QString &actionName, const QContact &contact ) |
|
203 { |
|
204 QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(actionName, "symbian"); |
|
205 if (actionDescriptors.isEmpty()) |
|
206 { |
|
207 return false; |
|
208 } |
|
209 |
|
210 QContactAction* contactAction = QContactAction::action(actionDescriptors.first()); |
|
211 QList<QContactDetail> details = contactAction->supportedDetails(contact); |
|
212 |
|
213 delete contactAction; |
|
214 |
|
215 for (int i = 0; i < details.count(); i++) |
|
216 { |
|
217 if (contact.details().contains(details[i])) |
|
218 { |
|
219 return true; |
|
220 } |
|
221 } |
|
222 |
|
223 return false; |
|
224 } |
|
225 |
|
226 // End of File |