|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 create new group command object. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPguCreateNewGroupCmd.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPguGroupNameQueryDlg.h" |
|
23 #include "Pbk2GroupConsts.h" |
|
24 #include <CPbk2InputAbsorber.h> |
|
25 #include <Pbk2GroupUIRes.rsg> |
|
26 #include <Pbk2UIControls.rsg> |
|
27 #include <MPbk2CommandObserver.h> |
|
28 #include <MPbk2ContactUiControl.h> |
|
29 #include <CPbk2StoreConfiguration.h> |
|
30 #include <MPbk2AppUi.h> |
|
31 #include <MPbk2ApplicationServices.h> |
|
32 #include <MPbk2ContactViewSupplier.h> |
|
33 |
|
34 // Virtual Phonebook |
|
35 #include <CVPbkContactManager.h> |
|
36 #include <TVPbkContactStoreUriPtr.h> |
|
37 #include <MVPbkContactStoreList.h> |
|
38 #include <MVPbkContactGroup.h> |
|
39 #include <MVPbkContactStore.h> |
|
40 #include <MVPbkContactStoreProperties.h> |
|
41 #include <VPbkContactStoreUris.h> |
|
42 |
|
43 // System includes |
|
44 #include <StringLoader.h> |
|
45 |
|
46 // Debugging headers |
|
47 #include <Pbk2Debug.h> |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CPguCreateNewGroupCmd::CPguCreateNewGroupCmd |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 CPguCreateNewGroupCmd::CPguCreateNewGroupCmd |
|
54 ( MPbk2ContactUiControl& aUiControl ) : |
|
55 iUiControl( &aUiControl ) |
|
56 { |
|
57 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
58 ("CPguCreateNewGroupCmd::CPguCreateNewGroupCmd(0x%x)"),this); |
|
59 } |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CPguCreateNewGroupCmd::~CPguCreateNewGroupCmd |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 CPguCreateNewGroupCmd::~CPguCreateNewGroupCmd() |
|
66 { |
|
67 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
68 (" CPguCreateNewGroupCmd::~CPguCreateNewGroupCmd(0x%x)"), this ); |
|
69 |
|
70 delete iNewGroup; |
|
71 delete iInputAbsorber; |
|
72 } |
|
73 |
|
74 // -------------------------------------------------------------------------- |
|
75 // CPguCreateNewGroupCmd::NewL |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 CPguCreateNewGroupCmd* CPguCreateNewGroupCmd::NewL |
|
79 ( MPbk2ContactUiControl& aUiControl ) |
|
80 { |
|
81 CPguCreateNewGroupCmd* self = |
|
82 new ( ELeave ) CPguCreateNewGroupCmd( aUiControl ); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPguCreateNewGroupCmd::ConstructL |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 inline void CPguCreateNewGroupCmd::ConstructL() |
|
94 { |
|
95 CPbk2StoreConfiguration* storeConfig = CPbk2StoreConfiguration::NewL(); |
|
96 CleanupStack::PushL( storeConfig ); |
|
97 iTargetStore = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
98 ContactManager().ContactStoresL(). |
|
99 Find( storeConfig->DefaultSavingStoreL() ); |
|
100 CleanupStack::PopAndDestroy( storeConfig ); |
|
101 } |
|
102 |
|
103 // -------------------------------------------------------------------------- |
|
104 // CPguCreateNewGroupCmd::ExecuteLD |
|
105 // -------------------------------------------------------------------------- |
|
106 // |
|
107 void CPguCreateNewGroupCmd::ExecuteLD() |
|
108 { |
|
109 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
110 ("CPguCreateNewGroupCmd::ExecuteLD(0x%x)"), this); |
|
111 CleanupStack::PushL( this ); |
|
112 |
|
113 CheckDefaultSavingStorageL(); |
|
114 |
|
115 CleanupStack::Pop( this ); |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // CPguCreateNewGroupCmd::AddObserver |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 void CPguCreateNewGroupCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
123 { |
|
124 iCommandObserver = &aObserver; |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // CPguCreateNewGroupCmd::ResetUiControl |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 void CPguCreateNewGroupCmd::ResetUiControl( |
|
132 MPbk2ContactUiControl& aUiControl) |
|
133 { |
|
134 if (iUiControl == &aUiControl) |
|
135 { |
|
136 iUiControl = NULL; |
|
137 } |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPguCreateNewGroupCmd::ContactOperationCompleted |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 void CPguCreateNewGroupCmd::ContactOperationCompleted |
|
145 ( TContactOpResult /*aResult*/ ) |
|
146 { |
|
147 // Will finish the command even if errors occur |
|
148 TRAP_IGNORE( FinishCommandL() ); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CPguCreateNewGroupCmd::ContactOperationFailed |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 void CPguCreateNewGroupCmd::ContactOperationFailed |
|
156 ( TContactOp /*aOpCode*/, TInt /*aErrorCode*/, |
|
157 TBool /*aErrorNotified*/ ) |
|
158 { |
|
159 // Will finish the command even if errors occur |
|
160 TRAP_IGNORE( FinishCommandL() ); |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // CPguCreateNewGroupCmd::AddNewGroupL |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 void CPguCreateNewGroupCmd::AddNewGroupL() |
|
168 { |
|
169 HBufC* textBuf = HBufC::NewLC( KGroupLabelLength ); |
|
170 TPtr text = textBuf->Des(); |
|
171 |
|
172 MVPbkContactViewBase* groupsView = |
|
173 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
174 ViewSupplier().AllGroupsViewL(); |
|
175 |
|
176 CPguGroupNameQueryDlg* dlg = |
|
177 CPguGroupNameQueryDlg::NewL( |
|
178 text, |
|
179 *groupsView, |
|
180 Phonebook2::Pbk2AppUi()->ApplicationServices().NameFormatter(), |
|
181 ETrue ); |
|
182 dlg->SetMaxLength( KGroupLabelLength ); |
|
183 |
|
184 if ( dlg->ExecuteLD( R_PHONEBOOK2_GROUPLIST_NEWGROUP_QUERY ) ) |
|
185 { |
|
186 // Insert new group into database |
|
187 iNewGroup = iTargetStore->CreateNewContactGroupLC(); |
|
188 CleanupStack::Pop(); // iNewGroup |
|
189 iNewGroup->SetGroupLabelL( text ); |
|
190 iNewGroup->CommitL( *this ); |
|
191 CleanupStack::PopAndDestroy( textBuf ); |
|
192 |
|
193 // Use input absorber to block key events until |
|
194 // FinishCommandL is executed |
|
195 delete iInputAbsorber; |
|
196 iInputAbsorber = NULL; |
|
197 iInputAbsorber = CPbk2InputAbsorber::NewL( R_AVKON_SOFTKEYS_OPTIONS_EXIT ); |
|
198 iInputAbsorber->Wait(); |
|
199 } |
|
200 else |
|
201 { |
|
202 CleanupStack::PopAndDestroy( textBuf ); |
|
203 FinishCommandL(); |
|
204 } |
|
205 } |
|
206 |
|
207 // -------------------------------------------------------------------------- |
|
208 // CPguCreateNewGroupCmd::CheckDefaultSavingStorageL |
|
209 // -------------------------------------------------------------------------- |
|
210 // |
|
211 void CPguCreateNewGroupCmd::CheckDefaultSavingStorageL() |
|
212 { |
|
213 TVPbkContactStoreUriPtr defaultSavingStore = |
|
214 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
215 StoreConfiguration().DefaultSavingStoreL(); |
|
216 MVPbkContactStoreList& stores = |
|
217 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
218 ContactManager().ContactStoresL(); |
|
219 |
|
220 MVPbkContactStore* store = stores.Find( defaultSavingStore.UriDes() ); |
|
221 if ( store && store->StoreProperties().SupportsContactGroups() ) |
|
222 { |
|
223 AddNewGroupL(); |
|
224 } |
|
225 else |
|
226 { |
|
227 MVPbkContactStoreList& stores = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
228 ContactManager().ContactStoresL(); |
|
229 |
|
230 // Change target store to Contacts Model |
|
231 TVPbkContactStoreUriPtr ptr |
|
232 ( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
233 iTargetStore = stores.Find( ptr ); |
|
234 |
|
235 AddNewGroupL(); |
|
236 } |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // CPguCreateNewGroupCmd::FinishCommandL |
|
241 // -------------------------------------------------------------------------- |
|
242 // |
|
243 void CPguCreateNewGroupCmd::FinishCommandL() |
|
244 { |
|
245 if ( iCommandObserver ) |
|
246 { |
|
247 iCommandObserver->CommandFinished( *this ); |
|
248 } |
|
249 |
|
250 if (iUiControl) |
|
251 { |
|
252 // Control focuses created group by reacting to contact view event, |
|
253 // do not set focus to created group here |
|
254 iUiControl->ResetFindL(); |
|
255 iUiControl->UpdateAfterCommandExecution(); |
|
256 } |
|
257 |
|
258 if ( iInputAbsorber ) |
|
259 { |
|
260 iInputAbsorber->StopWait(); |
|
261 } |
|
262 } |
|
263 |
|
264 // End of File |