|
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 FILES |
|
19 #include "CntModelTesterSetToneToContacts.h" |
|
20 #include <cntdef.h> |
|
21 #include <cntitem.h> |
|
22 #include <cntdb.h> |
|
23 #include <cntview.h> |
|
24 #include <cntfldst.h> |
|
25 |
|
26 |
|
27 // LOCAL CONSTANTS AND MACROS |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 inline TBool CCntModelTesterSetToneToContacts ::MoreContactsToSet() const |
|
35 { |
|
36 return (iContacts && iContacts->Count() > 0); |
|
37 } |
|
38 |
|
39 inline void CCntModelTesterSetToneToContacts ::Cancel() |
|
40 { |
|
41 delete iContacts; |
|
42 iContacts = NULL; |
|
43 } |
|
44 |
|
45 inline CCntModelTesterSetToneToContacts ::CCntModelTesterSetToneToContacts () |
|
46 { |
|
47 } |
|
48 |
|
49 inline void CCntModelTesterSetToneToContacts ::ConstructL |
|
50 (const CContactIdArray& aContacts, |
|
51 const TDesC& aRingingToneName) |
|
52 { |
|
53 iRingingToneFile = aRingingToneName.AllocL(); |
|
54 iTotalContactsToSet = aContacts.Count(); |
|
55 iSetCount=0; |
|
56 iContacts = CContactIdArray::NewL(&aContacts); |
|
57 iContacts->ReverseOrder(); |
|
58 iDb= CContactDatabase::OpenL(KDbFileName); |
|
59 } |
|
60 inline TInt CCntModelTesterSetToneToContacts::GetCount() |
|
61 { |
|
62 return iSetCount; |
|
63 } |
|
64 |
|
65 EXPORT_C CCntModelTesterSetToneToContacts * CCntModelTesterSetToneToContacts ::NewL |
|
66 ( const CContactIdArray& aContacts, |
|
67 const TDesC& aRingingToneName) |
|
68 { |
|
69 CCntModelTesterSetToneToContacts * self = new(ELeave) CCntModelTesterSetToneToContacts (); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(aContacts, aRingingToneName); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 CCntModelTesterSetToneToContacts ::~CCntModelTesterSetToneToContacts () |
|
77 { |
|
78 delete iDb; |
|
79 delete iContacts; |
|
80 delete iRingingToneFile; |
|
81 } |
|
82 |
|
83 void CCntModelTesterSetToneToContacts ::StepL() |
|
84 { |
|
85 if (MoreContactsToSet()) |
|
86 { |
|
87 const TInt index = iContacts->Count() - 1; |
|
88 const TContactItemId id = (*iContacts)[index]; |
|
89 |
|
90 CContactItem* item = iDb->OpenContactLX(id); |
|
91 CleanupStack::PushL(item); |
|
92 |
|
93 SetRingingToneL(*item); |
|
94 |
|
95 iDb->CommitContactL(*item); |
|
96 CleanupStack::PopAndDestroy(2); // item, lock |
|
97 |
|
98 iContacts->Remove(index); |
|
99 ++iSetCount; |
|
100 } |
|
101 } |
|
102 |
|
103 TInt CCntModelTesterSetToneToContacts ::TotalNumberOfSteps() |
|
104 { |
|
105 return iTotalContactsToSet; |
|
106 } |
|
107 |
|
108 TBool CCntModelTesterSetToneToContacts ::IsProcessDone() const |
|
109 { |
|
110 return !MoreContactsToSet(); |
|
111 } |
|
112 |
|
113 void CCntModelTesterSetToneToContacts ::ProcessFinished() |
|
114 { |
|
115 Cancel(); |
|
116 } |
|
117 |
|
118 TInt CCntModelTesterSetToneToContacts ::HandleStepError(TInt aError) |
|
119 { |
|
120 if (aError != KErrNone) |
|
121 { |
|
122 Cancel(); |
|
123 } |
|
124 |
|
125 return aError; |
|
126 } |
|
127 |
|
128 void CCntModelTesterSetToneToContacts ::ProcessCanceled() |
|
129 { |
|
130 Cancel(); |
|
131 } |
|
132 |
|
133 void CCntModelTesterSetToneToContacts ::SetRingingToneL |
|
134 (CContactItem &aContact) |
|
135 { |
|
136 TInt index = aContact.CardFields().Find(KUidContactFieldRingTone); |
|
137 |
|
138 CContactItemField* field = NULL; |
|
139 |
|
140 if (index != KErrNotFound) |
|
141 { |
|
142 field = &aContact.CardFields()[index]; |
|
143 } |
|
144 |
|
145 if (iRingingToneFile->Compare(KNullDesC) == 0) |
|
146 { |
|
147 // remove ringing tone field |
|
148 if (field) |
|
149 { |
|
150 aContact.RemoveField(index); |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 // ringing tone selected |
|
156 if (field) |
|
157 { |
|
158 field->TextStorage()->SetTextL(*iRingingToneFile); |
|
159 } |
|
160 else |
|
161 { |
|
162 field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldRingTone); |
|
163 field->SetMapping(KUidContactFieldVCardMapUnknown); |
|
164 field->TextStorage()->SetTextL(*iRingingToneFile); |
|
165 aContact.AddFieldL(*field); |
|
166 CleanupStack::Pop(); |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 // End of File |