63
|
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 |
// INCLUDES
|
|
19 |
#include "CPbk2CopyDetailToClipboardCmd.h"
|
|
20 |
|
|
21 |
#include <MVPbkStoreContact.h>
|
|
22 |
#include <MVPbkContactOperationBase.h>
|
|
23 |
#include <CVPbkContactManager.h>
|
|
24 |
#include <MVPbkContactFieldTextData.h>
|
|
25 |
#include <MVPbkContactFieldDateTimeData.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 |
#include <Pbk2AddressTools.h>
|
|
37 |
|
|
38 |
#include <txtetext.h> // CPlainText
|
|
39 |
#include <baclipb.h> // CClipboard
|
|
40 |
#include <StringLoader.h>
|
|
41 |
#include <aknnotewrappers.h> // CAknInformationNote
|
|
42 |
|
|
43 |
|
|
44 |
// --------------------------------------------------------------------------
|
|
45 |
// CPbk2CopyDetailToClipboardCmd::NewL
|
|
46 |
// --------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
CPbk2CopyDetailToClipboardCmd* CPbk2CopyDetailToClipboardCmd::NewL(
|
|
49 |
MPbk2ContactUiControl& aUiControl )
|
|
50 |
{
|
|
51 |
CPbk2CopyDetailToClipboardCmd* self =
|
|
52 |
new ( ELeave ) CPbk2CopyDetailToClipboardCmd( aUiControl );
|
|
53 |
CleanupStack::PushL( self );
|
|
54 |
self->ConstructL();
|
|
55 |
CleanupStack::Pop( self );
|
|
56 |
return self;
|
|
57 |
}
|
|
58 |
|
|
59 |
// --------------------------------------------------------------------------
|
|
60 |
// CPbk2CopyDetailToClipboardCmd::CPbk2CopyDetailToClipboardCmd
|
|
61 |
// --------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
CPbk2CopyDetailToClipboardCmd::CPbk2CopyDetailToClipboardCmd(
|
|
64 |
MPbk2ContactUiControl& aUiControl) :
|
|
65 |
iUiControl(&aUiControl)
|
|
66 |
{
|
|
67 |
// do nothing
|
|
68 |
}
|
|
69 |
|
|
70 |
// --------------------------------------------------------------------------
|
|
71 |
// CPbk2CopyDetailToClipboardCmd::~CPbk2CopyDetailToClipboardCmd
|
|
72 |
// --------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CPbk2CopyDetailToClipboardCmd::~CPbk2CopyDetailToClipboardCmd()
|
|
75 |
{
|
|
76 |
delete iStoreContact;
|
|
77 |
delete iRetrieveOperation;
|
|
78 |
Release( iAppServices );
|
|
79 |
}
|
|
80 |
|
|
81 |
// --------------------------------------------------------------------------
|
|
82 |
// CPbk2CopyDetailToClipboardCmd::ConstructL
|
|
83 |
// --------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
inline void CPbk2CopyDetailToClipboardCmd::ConstructL()
|
|
86 |
{
|
|
87 |
iAppServices = CPbk2ApplicationServices::InstanceL();
|
|
88 |
}
|
|
89 |
|
|
90 |
// --------------------------------------------------------------------------
|
|
91 |
// CPbk2CopyDetailToClipboardCmd::ExecuteLD
|
|
92 |
// --------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
void CPbk2CopyDetailToClipboardCmd::ExecuteLD()
|
|
95 |
{
|
|
96 |
CleanupStack::PushL(this);
|
|
97 |
|
|
98 |
if (iUiControl)
|
|
99 |
{
|
|
100 |
MVPbkContactLink* link = iUiControl->FocusedContactL()->CreateLinkLC();
|
|
101 |
iRetrieveOperation =
|
|
102 |
iAppServices->ContactManager().RetrieveContactL(*link, *this);
|
|
103 |
CleanupStack::PopAndDestroy(); // link
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
iObserver->CommandFinished(*this);
|
|
108 |
}
|
|
109 |
CleanupStack::Pop(this);
|
|
110 |
}
|
|
111 |
|
|
112 |
// --------------------------------------------------------------------------
|
|
113 |
// CPbk2CopyDetailToClipboardCmd::AddObserver
|
|
114 |
// --------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CPbk2CopyDetailToClipboardCmd::AddObserver(MPbk2CommandObserver& aObserver)
|
|
117 |
{
|
|
118 |
iObserver = &aObserver;
|
|
119 |
}
|
|
120 |
|
|
121 |
// --------------------------------------------------------------------------
|
|
122 |
// CPbk2CopyDetailToClipboardCmd::ResetUiControl
|
|
123 |
// --------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CPbk2CopyDetailToClipboardCmd::ResetUiControl(
|
|
126 |
MPbk2ContactUiControl& aUiControl)
|
|
127 |
{
|
|
128 |
if (iUiControl == &aUiControl)
|
|
129 |
{
|
|
130 |
iUiControl = NULL;
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
// --------------------------------------------------------------------------
|
|
135 |
// CPbk2CopyDetailToClipboardCmd::VPbkSingleContactOperationComplete
|
|
136 |
// --------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
void CPbk2CopyDetailToClipboardCmd::VPbkSingleContactOperationComplete(
|
|
139 |
MVPbkContactOperationBase& aOperation,
|
|
140 |
MVPbkStoreContact* aContact)
|
|
141 |
{
|
|
142 |
if (&aOperation == iRetrieveOperation)
|
|
143 |
{
|
|
144 |
delete iRetrieveOperation;
|
|
145 |
iRetrieveOperation = NULL;
|
|
146 |
|
|
147 |
delete iStoreContact;
|
|
148 |
iStoreContact = aContact;
|
|
149 |
// should not execute copyDetail command when
|
|
150 |
// there is no UI Control
|
|
151 |
if ( iUiControl )
|
|
152 |
{
|
|
153 |
TRAP_IGNORE(CopyDetailToClipboardL());
|
|
154 |
iUiControl->UpdateAfterCommandExecution();
|
|
155 |
}
|
|
156 |
iObserver->CommandFinished(*this);
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
// --------------------------------------------------------------------------
|
|
161 |
// CPbk2CopyDetailToClipboardCmd::VPbkSingleContactOperationFailed
|
|
162 |
// --------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
void CPbk2CopyDetailToClipboardCmd::VPbkSingleContactOperationFailed(
|
|
165 |
MVPbkContactOperationBase& aOperation,
|
|
166 |
TInt /*aError*/)
|
|
167 |
{
|
|
168 |
if (&aOperation == iRetrieveOperation)
|
|
169 |
{
|
|
170 |
delete iRetrieveOperation;
|
|
171 |
iRetrieveOperation = NULL;
|
|
172 |
|
|
173 |
if (iUiControl)
|
|
174 |
{
|
|
175 |
iUiControl->UpdateAfterCommandExecution();
|
|
176 |
}
|
|
177 |
iObserver->CommandFinished(*this);
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
// --------------------------------------------------------------------------
|
|
182 |
// CPbk2CopyDetailToClipboardCmd::CopyDetailToClipboardL
|
|
183 |
// --------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
void CPbk2CopyDetailToClipboardCmd::CopyDetailToClipboardL()
|
|
186 |
{
|
|
187 |
// Construct a plain text from the detail
|
|
188 |
const TInt KBeginning = 0;
|
|
189 |
// Fetch field from current UI control
|
|
190 |
const MVPbkBaseContactField* field = iUiControl->FocusedField();
|
|
191 |
TPtrC detail;
|
|
192 |
RBuf addText;
|
|
193 |
TVPbkFieldStorageType fieldType = field->FieldData().DataType();
|
|
194 |
|
|
195 |
switch(fieldType)
|
|
196 |
{
|
|
197 |
case EVPbkFieldStorageTypeText:
|
|
198 |
{
|
|
199 |
const MVPbkFieldType* vPbkFieldType = field->BestMatchingFieldType();
|
|
200 |
TPbk2FieldGroupId groupId = Pbk2AddressTools::MapVPbkFieldTypeToAddressGroupId( vPbkFieldType );
|
|
201 |
if( groupId == EPbk2FieldGroupIdHomeAddress ||
|
|
202 |
groupId == EPbk2FieldGroupIdCompanyAddress ||
|
|
203 |
groupId == EPbk2FieldGroupIdPostalAddress ) //the focused field belongs to Address
|
|
204 |
{
|
|
205 |
MVPbkStoreContact* vPbkStoreContact = const_cast<MVPbkStoreContact*>( iUiControl->FocusedStoreContact() );
|
|
206 |
//address view is empty
|
|
207 |
if( Pbk2AddressTools::IsAddressPreviewEmptyL(*vPbkStoreContact, groupId) )
|
|
208 |
{
|
|
209 |
detail.Set( KNullDesC() ); //KNullDesC will be copied to clipboard
|
|
210 |
}
|
|
211 |
else //address view is not empty
|
|
212 |
{
|
|
213 |
Pbk2AddressTools::GetAddressPreviewLC(*vPbkStoreContact, groupId, addText);
|
|
214 |
detail.Set( addText );
|
|
215 |
}
|
|
216 |
}
|
|
217 |
else //the focused field doesn't belong to Address
|
|
218 |
{
|
|
219 |
detail.Set(MVPbkContactFieldTextData::Cast(field->FieldData()).Text());
|
|
220 |
}
|
|
221 |
break;
|
|
222 |
}
|
|
223 |
case EVPbkFieldStorageTypeDateTime:
|
|
224 |
{
|
|
225 |
TLocale locale;
|
|
226 |
TBuf<64> dateBuffer;
|
|
227 |
|
|
228 |
const MVPbkContactFieldDateTimeData& date =
|
|
229 |
MVPbkContactFieldDateTimeData::Cast(field->FieldData());
|
|
230 |
|
|
231 |
TTime time(date.DateTime());
|
|
232 |
|
|
233 |
HBufC* dateFormat = CCoeEnv::Static()->AllocReadResourceLC
|
|
234 |
(R_QTN_DATE_USUAL_WITH_ZERO); // in avkon.rsg
|
|
235 |
|
|
236 |
time.FormatL(dateBuffer, *dateFormat, locale);
|
|
237 |
CleanupStack::PopAndDestroy(dateFormat);
|
|
238 |
|
|
239 |
detail.Set(dateBuffer);
|
|
240 |
break;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
CPlainText* plainText = CPlainText::NewL();
|
|
245 |
CleanupStack::PushL(plainText);
|
|
246 |
plainText->InsertL(KBeginning, detail);
|
|
247 |
|
|
248 |
// Copy to clipboard
|
|
249 |
CClipboard* cb = CClipboard::NewForWritingLC(
|
|
250 |
iAppServices->ContactManager().FsSession());
|
|
251 |
plainText->CopyToStoreL(cb->Store(), cb->StreamDictionary(),
|
|
252 |
KBeginning, plainText->DocumentLength());
|
|
253 |
cb->CommitL();
|
|
254 |
|
|
255 |
CleanupStack::PopAndDestroy(2); // cb, plainText
|
|
256 |
if( addText.Length() )
|
|
257 |
{
|
|
258 |
CleanupStack::PopAndDestroy(&addText);
|
|
259 |
}
|
|
260 |
|
|
261 |
// Show a note
|
|
262 |
HBufC* prompt = StringLoader::LoadLC(R_QTN_CCA_INFO_NOTE_COPIED_TO_CLIPBOARD);
|
|
263 |
CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue);
|
|
264 |
dlg->ExecuteLD(*prompt);
|
|
265 |
CleanupStack::PopAndDestroy(prompt);
|
|
266 |
}
|
|
267 |
|
|
268 |
// End of File
|