|
1 /* |
|
2 * Copyright (c) 2002-2007 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: A command for clipboard copy |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CPbk2CopyAddressToClipboardCmd.h" |
|
21 |
|
22 #include <MVPbkStoreContact.h> |
|
23 #include <MVPbkContactOperationBase.h> |
|
24 #include <CVPbkContactManager.h> |
|
25 #include <MVPbkContactFieldTextData.h> |
|
26 #include <CPbk2ApplicationServices.h> |
|
27 #include <MPbk2AppUi.h> |
|
28 #include <MPbk2ContactUiControl.h> |
|
29 #include <MPbk2CommandObserver.h> |
|
30 #include <CPbk2PresentationContact.h> |
|
31 #include <CPbk2FieldPropertyArray.h> |
|
32 #include <CPbk2PresentationContactFieldCollection.h> |
|
33 #include <Pbk2Commands.rsg> |
|
34 #include <Pbk2CmdExtRes.rsg> |
|
35 #include <MVPbkContactFieldUriData.h> |
|
36 |
|
37 #include <txtetext.h> // CPlainText |
|
38 #include <baclipb.h> // CClipboard |
|
39 #include <StringLoader.h> |
|
40 #include <aknnotewrappers.h> // CAknInformationNote |
|
41 |
|
42 |
|
43 // -------------------------------------------------------------------------- |
|
44 // CPbk2CopyAddressToClipboardCmd::NewL |
|
45 // -------------------------------------------------------------------------- |
|
46 // |
|
47 CPbk2CopyAddressToClipboardCmd* CPbk2CopyAddressToClipboardCmd::NewL( |
|
48 MPbk2ContactUiControl& aUiControl ) |
|
49 { |
|
50 CPbk2CopyAddressToClipboardCmd* self = |
|
51 new ( ELeave ) CPbk2CopyAddressToClipboardCmd( aUiControl ); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CPbk2CopyAddressToClipboardCmd::CPbk2CopyAddressToClipboardCmd |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CPbk2CopyAddressToClipboardCmd::CPbk2CopyAddressToClipboardCmd( |
|
63 MPbk2ContactUiControl& aUiControl) : |
|
64 iUiControl(&aUiControl) |
|
65 { |
|
66 // do nothing |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CPbk2CopyAddressToClipboardCmd::~CPbk2CopyAddressToClipboardCmd |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 CPbk2CopyAddressToClipboardCmd::~CPbk2CopyAddressToClipboardCmd() |
|
74 { |
|
75 delete iStoreContact; |
|
76 delete iRetrieveOperation; |
|
77 Release( iAppServices ); |
|
78 } |
|
79 |
|
80 // -------------------------------------------------------------------------- |
|
81 // CPbk2CopyAddressToClipboardCmd::ConstructL |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 inline void CPbk2CopyAddressToClipboardCmd::ConstructL() |
|
85 { |
|
86 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2CopyAddressToClipboardCmd::ExecuteLD |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 void CPbk2CopyAddressToClipboardCmd::ExecuteLD() |
|
94 { |
|
95 CleanupStack::PushL(this); |
|
96 |
|
97 if (iUiControl) |
|
98 { |
|
99 MVPbkContactLink* link = iUiControl->FocusedContactL()->CreateLinkLC(); |
|
100 iRetrieveOperation = |
|
101 iAppServices->ContactManager().RetrieveContactL(*link, *this); |
|
102 CleanupStack::PopAndDestroy(); // link |
|
103 } |
|
104 else |
|
105 { |
|
106 iObserver->CommandFinished(*this); |
|
107 } |
|
108 CleanupStack::Pop(this); |
|
109 } |
|
110 |
|
111 // -------------------------------------------------------------------------- |
|
112 // CPbk2CopyAddressToClipboardCmd::AddObserver |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 void CPbk2CopyAddressToClipboardCmd::AddObserver(MPbk2CommandObserver& aObserver) |
|
116 { |
|
117 iObserver = &aObserver; |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CPbk2CopyAddressToClipboardCmd::ResetUiControl |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 void CPbk2CopyAddressToClipboardCmd::ResetUiControl( |
|
125 MPbk2ContactUiControl& aUiControl) |
|
126 { |
|
127 if (iUiControl == &aUiControl) |
|
128 { |
|
129 iUiControl = NULL; |
|
130 } |
|
131 } |
|
132 |
|
133 // -------------------------------------------------------------------------- |
|
134 // CPbk2CopyAddressToClipboardCmd::VPbkSingleContactOperationComplete |
|
135 // -------------------------------------------------------------------------- |
|
136 // |
|
137 void CPbk2CopyAddressToClipboardCmd::VPbkSingleContactOperationComplete( |
|
138 MVPbkContactOperationBase& aOperation, |
|
139 MVPbkStoreContact* aContact) |
|
140 { |
|
141 if (&aOperation == iRetrieveOperation) |
|
142 { |
|
143 delete iRetrieveOperation; |
|
144 iRetrieveOperation = NULL; |
|
145 |
|
146 delete iStoreContact; |
|
147 iStoreContact = aContact; |
|
148 |
|
149 TRAP_IGNORE(CopyAddressToClipboardL()); |
|
150 |
|
151 if (iUiControl) |
|
152 { |
|
153 iUiControl->UpdateAfterCommandExecution(); |
|
154 } |
|
155 iObserver->CommandFinished(*this); |
|
156 } |
|
157 } |
|
158 |
|
159 // -------------------------------------------------------------------------- |
|
160 // CPbk2CopyAddressToClipboardCmd::VPbkSingleContactOperationFailed |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 void CPbk2CopyAddressToClipboardCmd::VPbkSingleContactOperationFailed( |
|
164 MVPbkContactOperationBase& aOperation, |
|
165 TInt /*aError*/) |
|
166 { |
|
167 if (&aOperation == iRetrieveOperation) |
|
168 { |
|
169 delete iRetrieveOperation; |
|
170 iRetrieveOperation = NULL; |
|
171 |
|
172 if (iUiControl) |
|
173 { |
|
174 iUiControl->UpdateAfterCommandExecution(); |
|
175 } |
|
176 iObserver->CommandFinished(*this); |
|
177 } |
|
178 } |
|
179 |
|
180 // -------------------------------------------------------------------------- |
|
181 // CPbk2CopyAddressToClipboardCmd::CopyAddressToClipboardL |
|
182 // -------------------------------------------------------------------------- |
|
183 // |
|
184 void CPbk2CopyAddressToClipboardCmd::CopyAddressToClipboardL() |
|
185 { |
|
186 // Construct a plain text from the number |
|
187 const TInt KBeginning = 0; |
|
188 |
|
189 MVPbkStoreContactField* field = FocusedFieldLC( *iStoreContact ); |
|
190 TPtrC address; |
|
191 TVPbkFieldStorageType fieldType = field->FieldData().DataType(); |
|
192 |
|
193 switch(fieldType) |
|
194 { |
|
195 case EVPbkFieldStorageTypeText: |
|
196 { |
|
197 address.Set(MVPbkContactFieldTextData::Cast(field->FieldData()).Text()); |
|
198 break; |
|
199 } |
|
200 case EVPbkFieldStorageTypeUri: |
|
201 { |
|
202 address.Set(MVPbkContactFieldUriData::Cast(field->FieldData()).Text()); |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 CleanupStack::PopAndDestroy(); // field |
|
208 CPlainText* plainText = CPlainText::NewL(); |
|
209 CleanupStack::PushL(plainText); |
|
210 plainText->InsertL(KBeginning, address); |
|
211 |
|
212 // Copy to clipboard |
|
213 CClipboard* cb = CClipboard::NewForWritingLC( |
|
214 iAppServices->ContactManager().FsSession()); |
|
215 plainText->CopyToStoreL(cb->Store(), cb->StreamDictionary(), |
|
216 KBeginning, plainText->DocumentLength()); |
|
217 cb->CommitL(); |
|
218 |
|
219 CleanupStack::PopAndDestroy(2); // cb, plainText |
|
220 |
|
221 |
|
222 // Show a note |
|
223 HBufC* prompt = StringLoader::LoadLC( R_QTN_CCA_INFO_NOTE_ADDRESS_COPIED_TO_CLIPBOARD ); |
|
224 CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue); |
|
225 dlg->ExecuteLD(*prompt); |
|
226 CleanupStack::PopAndDestroy(prompt); |
|
227 } |
|
228 |
|
229 MVPbkStoreContactField* CPbk2CopyAddressToClipboardCmd::FocusedFieldLC |
|
230 ( MVPbkStoreContact& aStoreContact ) |
|
231 { |
|
232 TInt index = KErrNotFound; |
|
233 CPbk2PresentationContact* presentationContact = |
|
234 CPbk2PresentationContact::NewL( aStoreContact, |
|
235 iAppServices->FieldProperties() ); |
|
236 CleanupStack::PushL( presentationContact ); |
|
237 |
|
238 if (iUiControl) |
|
239 { |
|
240 index = presentationContact->PresentationFields().StoreIndexOfField( |
|
241 iUiControl->FocusedFieldIndex() ); |
|
242 } |
|
243 CleanupStack::PopAndDestroy( presentationContact ); |
|
244 |
|
245 if ( index != KErrNotFound ) |
|
246 { |
|
247 // Use FieldAtLC to avoid the unvalidity of the field after new |
|
248 // FieldAt call. |
|
249 return aStoreContact.Fields().FieldAtLC( index ); |
|
250 } |
|
251 return NULL; |
|
252 } |
|
253 |
|
254 // End of File |