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