20 #include <HbTextItem> |
20 #include <HbTextItem> |
21 #include <HbPushButton> |
21 #include <HbPushButton> |
22 #include <HbAction> |
22 #include <HbAction> |
23 #include <hbinputeditorinterface.h> |
23 #include <hbinputeditorinterface.h> |
24 #include <cntservicescontact.h> |
24 #include <cntservicescontact.h> |
|
25 #include <xqaiwrequest.h> |
|
26 #include <xqappmgr.h> |
|
27 #include <telconfigcrkeys.h> // KCRUidTelephonyConfiguration |
|
28 #include <centralrepository.h> |
25 |
29 |
26 // USER INCLUDES |
30 // USER INCLUDES |
27 #include "msgunieditoraddress.h" |
31 #include "msgunieditoraddress.h" |
28 #include "msgunifiededitorlineedit.h" |
32 #include "msgunifiededitorlineedit.h" |
29 #include "msguiutilsmanager.h" |
33 |
30 #include "matchphnumberutil.h" |
34 const QString PBK_ICON("qtg_mono_contacts"); |
31 |
35 const QString SEND_ICON("qtg_mono_send"); |
32 const QString PBK_ICON(":/qtg_mono_contacts.svg"); |
|
33 const QString SEND_ICON(":/qtg_mono_send.svg"); |
|
34 |
36 |
35 // Constants |
37 // Constants |
|
38 const int KDefaultGsmNumberMatchLength = 7; //matching unique ph numbers |
36 |
39 |
37 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label, |
40 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label, |
38 const QString& pluginPath, |
41 const QString& pluginPath, |
39 QGraphicsItem *parent ) : |
42 QGraphicsItem *parent ) : |
40 HbWidget(parent), |
43 HbWidget(parent), |
41 mPluginPath(pluginPath), |
44 mPluginPath(pluginPath) |
42 mUtilsManager(0) |
|
43 { |
45 { |
44 #ifdef _DEBUG_TRACES_ |
46 #ifdef _DEBUG_TRACES_ |
45 qDebug() << "MsgUnifiedEditorAddress calling HbStyle::registerPlugin"; |
47 qDebug() << "MsgUnifiedEditorAddress calling HbStyle::registerPlugin"; |
46 #endif |
48 #endif |
47 |
49 |
|
50 this->setContentsMargins(0,0,0,0); |
48 setPluginBaseId(style()->registerPlugin(mPluginPath)); |
51 setPluginBaseId(style()->registerPlugin(mPluginPath)); |
49 mUtilsManager = new MsgUiUtilsManager(this); |
52 |
50 |
|
51 mLaunchBtn = new HbPushButton(this); |
53 mLaunchBtn = new HbPushButton(this); |
52 HbStyle::setItemName(mLaunchBtn,"launchBtn"); |
54 HbStyle::setItemName(mLaunchBtn,"launchBtn"); |
53 connect(mLaunchBtn,SIGNAL(clicked()),mUtilsManager,SLOT(fetchContacts())); |
55 connect(mLaunchBtn,SIGNAL(clicked()),this,SLOT(fetchContacts())); |
54 |
56 |
55 mLaunchBtn->setIcon(HbIcon(PBK_ICON)); |
57 mLaunchBtn->setIcon(HbIcon(PBK_ICON)); |
56 |
58 |
57 mAddressEdit = new MsgUnifiedEditorLineEdit(label,this); |
59 mAddressEdit = new MsgUnifiedEditorLineEdit(label,this); |
58 HbStyle::setItemName(mAddressEdit,"addressField"); |
60 HbStyle::setItemName(mAddressEdit,"addressField"); |
59 |
61 |
60 mAddressEdit->setMaxRows(40); |
62 mAddressEdit->setMaxRows(40); |
61 connect(mAddressEdit, SIGNAL(addressTextChanged(const QString&)), |
63 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
62 this, SLOT(onTextChanged(const QString&))); |
64 this, SLOT(onContentsAdded(const QString&))); |
63 |
65 |
64 // add "Send" action in VKB |
66 // add "Send" action in VKB |
65 HbEditorInterface editorInterface(mAddressEdit); |
67 HbEditorInterface editorInterface(mAddressEdit); |
|
68 mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
66 HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this); |
69 HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this); |
67 connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage())); |
70 connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage())); |
68 editorInterface.addAction(sendAction); |
71 editorInterface.addAction(sendAction); |
69 |
72 |
70 connect(mUtilsManager, SIGNAL(contactsFetched(const QVariant&)), |
|
71 this, SLOT(contactsFetched(const QVariant&))); |
|
72 } |
73 } |
73 |
74 |
74 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress() |
75 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress() |
75 { |
76 { |
76 style()->unregisterPlugin(mPluginPath); |
77 style()->unregisterPlugin(mPluginPath); |
77 } |
78 } |
78 |
79 |
79 void MsgUnifiedEditorAddress::contactsFetched(const QVariant& value) |
80 void MsgUnifiedEditorAddress::fetchContacts() |
|
81 { |
|
82 QList<QVariant> args; |
|
83 QString serviceName("com.nokia.services.phonebookservices"); |
|
84 QString operation("fetch(QString,QString,QString)"); |
|
85 XQAiwRequest* request; |
|
86 XQApplicationManager appManager; |
|
87 request = appManager.create(serviceName, "Fetch", operation, true); // embedded |
|
88 if ( request == NULL ) |
|
89 { |
|
90 return; |
|
91 } |
|
92 |
|
93 // Result handlers |
|
94 connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
95 connect (request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
96 |
|
97 args << QString(tr("Phonebook")); |
|
98 args << KCntActionAll; |
|
99 args << KCntFilterDisplayAll; |
|
100 |
|
101 request->setArguments(args); |
|
102 request->send(); |
|
103 delete request; |
|
104 } |
|
105 |
|
106 void MsgUnifiedEditorAddress::handleOk(const QVariant& value) |
80 { |
107 { |
81 CntServicesContactList contactList; |
108 CntServicesContactList contactList; |
82 contactList = qVariantValue<CntServicesContactList>(value); |
109 contactList = qVariantValue<CntServicesContactList>(value); |
83 |
110 |
84 for(int i = 0; i < contactList.count(); i++ ) |
111 for(int i = 0; i < contactList.count(); i++ ) |
144 mAddressEdit->setText(addrlist[i]->address()); |
177 mAddressEdit->setText(addrlist[i]->address()); |
145 } |
178 } |
146 } |
179 } |
147 } |
180 } |
148 |
181 |
149 void MsgUnifiedEditorAddress::onTextChanged(const QString& text) |
182 int MsgUnifiedEditorAddress::contactMatchDigits() |
|
183 { |
|
184 // Read the amount of digits to be used in contact matching |
|
185 // The key is owned by PhoneApp |
|
186 CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration); |
|
187 int matchDigitCount = 0; |
|
188 if ( repository->Get(KTelMatchDigits, matchDigitCount) == KErrNone ) |
|
189 { |
|
190 // Min is 7 |
|
191 matchDigitCount = Max(matchDigitCount, KDefaultGsmNumberMatchLength); |
|
192 } |
|
193 CleanupStack::PopAndDestroy(); // repository |
|
194 |
|
195 return matchDigitCount; |
|
196 |
|
197 } |
|
198 |
|
199 void MsgUnifiedEditorAddress::onContentsAdded(const QString& text) |
150 { |
200 { |
151 if(!text.isEmpty()) |
201 if(!text.isEmpty()) |
152 { |
202 { |
153 disconnect(mAddressEdit, SIGNAL(addressTextChanged(const QString&)), |
203 disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
154 this, SLOT(onTextChanged(const QString&))); |
204 this, SLOT(onContentsAdded(const QString&))); |
155 emit mmContentAdded(true); |
205 emit contentChanged(); |
156 connect(mAddressEdit, SIGNAL(addressTextChanged(const QString&)), |
206 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
157 this, SLOT(onTextRemoved(const QString&))); |
207 this, SLOT(onContentsRemoved(const QString&))); |
158 } |
208 } |
159 } |
209 } |
160 |
210 |
161 void MsgUnifiedEditorAddress::onTextRemoved(const QString& text) |
211 void MsgUnifiedEditorAddress::onContentsRemoved(const QString& text) |
162 { |
212 { |
163 if(text.isEmpty()) |
213 if(text.isEmpty()) |
164 { |
214 { |
165 disconnect(mAddressEdit, SIGNAL(addressTextChanged(const QString&)), |
215 disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
166 this, SLOT(onTextRemoved(const QString&))); |
216 this, SLOT(onContentsRemoved(const QString&))); |
167 emit mmContentAdded(false); |
217 emit contentChanged(); |
168 connect(mAddressEdit, SIGNAL(addressTextChanged(const QString&)), |
218 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
169 this, SLOT(onTextChanged(const QString&))); |
219 this, SLOT(onContentsAdded(const QString&))); |
170 } |
220 } |
171 } |
221 } |
172 |
222 |
173 void MsgUnifiedEditorAddress::syncDeletionsToMap() |
223 void MsgUnifiedEditorAddress::syncDeletionsToMap() |
174 { |
224 { |