|
1 /* |
|
2 * Copyright (c) 2002 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 * Thumbnail command event handling class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkThumbnailCmd.h" |
|
22 |
|
23 #include <eikmenup.h> // CEikMenuPane |
|
24 #include <AknWaitDialog.h> |
|
25 #include <aknnotewrappers.h> |
|
26 #include <sysutil.h> |
|
27 #include <StringLoader.h> |
|
28 |
|
29 #include <PbkView.rsg> // PbkView resource symbols |
|
30 #include <PbkView.hrh> |
|
31 |
|
32 #include "CPbkThumbnailManager.h" |
|
33 #include "CPbkThumbnailPopup.h" |
|
34 #include <CPbkDrmManager.h> |
|
35 |
|
36 #include <CPbkContactItem.h> |
|
37 #include <MPbkMenuCommandObserver.h> |
|
38 |
|
39 #include <MGFetch.h> |
|
40 |
|
41 /// Unnamed namespace for local definitons |
|
42 namespace { |
|
43 |
|
44 #ifdef _DEBUG |
|
45 enum TPanicCode |
|
46 { |
|
47 EPanicPreCond_PbkThumbnailSetComplete, |
|
48 EPanicPreCond_PbkThumbnailSetFailed |
|
49 }; |
|
50 |
|
51 void Panic(TPanicCode aReason) |
|
52 { |
|
53 _LIT(KPanicText, "CPbkThumbnailCmd"); |
|
54 User::Panic(KPanicText, aReason); |
|
55 } |
|
56 #endif // _DEBUG |
|
57 |
|
58 } // namespace |
|
59 |
|
60 |
|
61 // ================= MEMBER FUNCTIONS ======================= |
|
62 |
|
63 inline CPbkThumbnailCmd::CPbkThumbnailCmd |
|
64 (CPbkContactEngine& aEngine, |
|
65 CPbkThumbnailPopup& aThumbnailPopup) : |
|
66 iEngine(aEngine), |
|
67 iThumbnailPopup(aThumbnailPopup) |
|
68 { |
|
69 } |
|
70 |
|
71 inline void CPbkThumbnailCmd::ConstructL() |
|
72 { |
|
73 iThumbnailManager = CPbkThumbnailManager::NewL(iEngine); |
|
74 iDrmManager = CPbkDrmManager::NewL(); |
|
75 } |
|
76 |
|
77 CPbkThumbnailCmd* CPbkThumbnailCmd::NewL |
|
78 (CPbkContactEngine& aEngine, |
|
79 CPbkThumbnailPopup& aThumbnailPopup) |
|
80 { |
|
81 CPbkThumbnailCmd* self = new (ELeave) |
|
82 CPbkThumbnailCmd(aEngine, aThumbnailPopup); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 CPbkThumbnailCmd::~CPbkThumbnailCmd() |
|
90 { |
|
91 if (iDestroyed && *iDestroyed==EFalse) |
|
92 { |
|
93 *iDestroyed=ETrue; |
|
94 } |
|
95 delete iDrmManager; |
|
96 delete iThumbOperation; |
|
97 delete iWaitNote; |
|
98 delete iThumbnailManager; |
|
99 } |
|
100 |
|
101 TBool CPbkThumbnailCmd::FetchThumbnailL |
|
102 (CPbkContactItem& aContactItem) |
|
103 { |
|
104 TBool result = EFalse; |
|
105 Cancel(); |
|
106 |
|
107 // fetch thumbnail from media gallery |
|
108 CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat(1); |
|
109 CleanupStack::PushL(selectedFile); |
|
110 TBool destroyed(EFalse); |
|
111 iDestroyed=&destroyed; |
|
112 TBool res = MGFetch::RunL(*selectedFile, EImageFile, EFalse, this); |
|
113 if ( *iDestroyed==EFalse && res && selectedFile->Count() > 0) |
|
114 { |
|
115 CAknWaitDialog* waitNote = |
|
116 new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>(&iWaitNote)); |
|
117 waitNote->ExecuteLD(R_QTN_GEN_NOTE_FETCHING); |
|
118 CleanupStack::PushL(waitNote); |
|
119 |
|
120 TPtrC fileName = (*selectedFile)[0]; |
|
121 iThumbOperation = |
|
122 iThumbnailManager->SetThumbnailAsyncL |
|
123 (*this, aContactItem, fileName); |
|
124 |
|
125 CleanupStack::Pop(waitNote); |
|
126 iWaitNote = waitNote; |
|
127 iContactItem = &aContactItem; |
|
128 result = ETrue; |
|
129 } |
|
130 iDestroyed = NULL; |
|
131 CleanupStack::PopAndDestroy(selectedFile); |
|
132 return result; |
|
133 } |
|
134 |
|
135 TBool CPbkThumbnailCmd::RemoveThumbnailL |
|
136 (CPbkContactItem& aContactItem) |
|
137 { |
|
138 Cancel(); |
|
139 iThumbnailManager->RemoveThumbnail(aContactItem); |
|
140 if (iThumbnailPopup.ContactId() == aContactItem.Id()) |
|
141 { |
|
142 iThumbnailPopup.CancelLoading(); |
|
143 } |
|
144 return ETrue; |
|
145 } |
|
146 |
|
147 void CPbkThumbnailCmd::DynInitMenuPaneL |
|
148 (TInt /*aResourceId*/, |
|
149 CEikMenuPane& aMenuPane, |
|
150 CPbkContactItem& aContactItem) |
|
151 { |
|
152 // if context pane not present, dim all thumbnail related items. |
|
153 if ( !iAvkonAppUi->StatusPane()-> |
|
154 PaneCapabilities(TUid::Uid(EEikStatusPaneUidContext)).IsInCurrentLayout() ) |
|
155 { |
|
156 aMenuPane.SetItemDimmed(EPbkCmdRemoveThumbnail, ETrue); |
|
157 aMenuPane.SetItemDimmed(EPbkCmdFetchThumbnail, ETrue); |
|
158 } |
|
159 |
|
160 // Filter remove thumbnail item |
|
161 else if (!iThumbnailManager->HasThumbnail(aContactItem)) |
|
162 { |
|
163 aMenuPane.SetItemDimmed(EPbkCmdRemoveThumbnail, ETrue); |
|
164 } |
|
165 } |
|
166 |
|
167 void CPbkThumbnailCmd::PbkThumbnailSetComplete |
|
168 (MPbkThumbnailOperation& |
|
169 #ifdef _DEBUG |
|
170 aOperation |
|
171 #endif |
|
172 ) |
|
173 { |
|
174 __ASSERT_DEBUG(&aOperation == iThumbOperation, |
|
175 Panic(EPanicPreCond_PbkThumbnailSetComplete)); |
|
176 |
|
177 delete iThumbOperation; |
|
178 iThumbOperation = NULL; |
|
179 |
|
180 // Display the thumbnail |
|
181 iThumbnailPopup.Load(*iContactItem, NULL ); |
|
182 |
|
183 // Dismiss the wait note |
|
184 TRAPD(err, iWaitNote->ProcessFinishedL()); |
|
185 if (err != KErrNone) |
|
186 { |
|
187 delete iWaitNote; |
|
188 iWaitNote = NULL; |
|
189 } |
|
190 } |
|
191 |
|
192 void CPbkThumbnailCmd::PbkThumbnailSetFailed |
|
193 (MPbkThumbnailOperation& |
|
194 #ifdef _DEBUG |
|
195 aOperation |
|
196 #endif |
|
197 ,TInt aError) |
|
198 { |
|
199 __ASSERT_DEBUG(&aOperation == iThumbOperation, |
|
200 Panic(EPanicPreCond_PbkThumbnailSetFailed)); |
|
201 |
|
202 delete iThumbOperation; |
|
203 iThumbOperation = NULL; |
|
204 |
|
205 // Dismiss the wait note |
|
206 TRAPD(err, iWaitNote->ProcessFinishedL()); |
|
207 if (err != KErrNone) |
|
208 { |
|
209 delete iWaitNote; |
|
210 iWaitNote = NULL; |
|
211 } |
|
212 |
|
213 // Report the failure to the user |
|
214 CCoeEnv::Static()->HandleError(aError); |
|
215 } |
|
216 |
|
217 TBool CPbkThumbnailCmd::VerifySelectionL |
|
218 (const MDesCArray* aSelectedFiles) |
|
219 { |
|
220 TBool result = EFalse; |
|
221 if (iDestroyed && *iDestroyed==EFalse && aSelectedFiles && aSelectedFiles->MdcaCount() > 0) |
|
222 { |
|
223 // DRM for phonebook thumbnail fetch |
|
224 TPtrC fileName = aSelectedFiles->MdcaPoint(0); |
|
225 if (iDrmManager->IsProtectedFile(fileName)) |
|
226 { |
|
227 // show user copyright note |
|
228 HBufC* prompt = CCoeEnv::Static()->AllocReadResourceLC(R_QTN_DRM_NOT_ALLOWED); |
|
229 CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue); |
|
230 dlg->ExecuteLD(*prompt); |
|
231 CleanupStack::PopAndDestroy(); // prompt |
|
232 } |
|
233 else |
|
234 { |
|
235 result = ETrue; |
|
236 } |
|
237 } |
|
238 return result; |
|
239 } |
|
240 |
|
241 void CPbkThumbnailCmd::Cancel() |
|
242 { |
|
243 iContactItem = NULL; |
|
244 delete iWaitNote; |
|
245 iWaitNote = NULL; |
|
246 delete iThumbOperation; |
|
247 iThumbOperation = NULL; |
|
248 } |
|
249 |
|
250 TBool CPbkThumbnailCmd::OkToExit() |
|
251 { |
|
252 TBool ret(ETrue); |
|
253 if (iDestroyed && *iDestroyed==EFalse) |
|
254 { |
|
255 // MGFetch call not returned |
|
256 ret=EFalse; |
|
257 } |
|
258 return ret; |
|
259 } |
|
260 // End of File |