|
1 /* |
|
2 * Copyright (c) 2006 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: BIO control for handling remote drive configurations as |
|
15 * smart messages |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <biocmtm.h> // for CBIOClientMtm |
|
23 #include <msgbiocontrolObserver.h> // for MMsgBioControlObserver |
|
24 #include <StringLoader.h> // for StringLoader |
|
25 #include <CRichBio.h> // CRichBio |
|
26 #include <aknnotewrappers.h> // for CAknInformationNote |
|
27 #include <mmsvattachmentmanager.h> |
|
28 #include <utf.h> // for CnvUtfConverter |
|
29 #include <rsfwmountman.h> |
|
30 #include <rsfwmountentry.h> |
|
31 |
|
32 #include <rsfwmountconfbc.rsg> // for resouce identifiers |
|
33 |
|
34 #include "rsfwmountconfbc.h" |
|
35 #include "rsfwmountconfbc.hrh" |
|
36 #include "rsfwmountutils.h" |
|
37 #include "rsfwgsplugin.hrh" |
|
38 #include "rsfwnotpluginnamedialog.h" |
|
39 #include "mdebug.h" |
|
40 |
|
41 #define KUidGeneralSettings 0x100058EC |
|
42 |
|
43 enum TOptionListLocation |
|
44 { |
|
45 EFirstMenuItem = 0, |
|
46 ESecondMenuItem, |
|
47 EThirdMenuItem, |
|
48 EFourthMenuItem |
|
49 }; |
|
50 |
|
51 const TInt KMConfBcHeightReductionBva = 9; |
|
52 _LIT(KMountConfBcResourceFile, "rsfwmountconfbc.rsc"); |
|
53 _LIT(KAvkonResourceFile, "avkon.rsc"); |
|
54 |
|
55 |
|
56 // ======== MEMBER FUNCTIONS ======== |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // constructor |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C CMsgBioControl* CRsfwMountConfBioControl::NewL( |
|
63 MMsgBioControlObserver& aObserver, |
|
64 CMsvSession* aSession, |
|
65 TMsvId aId, |
|
66 TMsgBioMode aEditorOrViewerMode, |
|
67 const RFile* aFile) |
|
68 { |
|
69 CRsfwMountConfBioControl* self = |
|
70 new(ELeave) CRsfwMountConfBioControl(aObserver, |
|
71 aSession, |
|
72 aId, |
|
73 aEditorOrViewerMode, |
|
74 aFile); |
|
75 CleanupStack::PushL(self); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop(self); |
|
78 |
|
79 return self; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // destructor |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CRsfwMountConfBioControl::~CRsfwMountConfBioControl() |
|
87 { |
|
88 delete iViewer; |
|
89 |
|
90 if (iMountEntry) |
|
91 { |
|
92 delete iMountEntry; |
|
93 } |
|
94 delete iMountMan; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // constructor |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CRsfwMountConfBioControl::CRsfwMountConfBioControl( |
|
102 MMsgBioControlObserver& aObserver, |
|
103 CMsvSession* aSession, |
|
104 TMsvId aId, |
|
105 TMsgBioMode aEditorOrViewerMode, |
|
106 const RFile* aFile): |
|
107 CMsgBioControl(aObserver, |
|
108 aSession, |
|
109 aId, |
|
110 aEditorOrViewerMode, |
|
111 aFile) |
|
112 { |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // second phase constructor |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CRsfwMountConfBioControl::ConstructL() |
|
120 { |
|
121 DEBUGSTRING16(("CRsfwMountConfBioControl::ConstructL")); |
|
122 iMountMan = CRsfwMountMan::NewL(0, NULL); |
|
123 |
|
124 iIsFileBased = IsFileBased(); |
|
125 LoadResourceL(KMountConfBcResourceFile); |
|
126 LoadResourceL(KAvkonResourceFile); |
|
127 LoadResourceL(KNotPluginResourcePath); |
|
128 LoadStandardBioResourceL(); |
|
129 // file handle to the remote drive configuration attachment in msv store |
|
130 RFile fileHandle; |
|
131 ResolveFileL( fileHandle ); |
|
132 CleanupClosePushL( fileHandle ); |
|
133 |
|
134 // read stream |
|
135 RFileReadStream stream( fileHandle,0 ); |
|
136 CleanupClosePushL( stream ); |
|
137 |
|
138 MStreamBuf* buf = stream.Source(); |
|
139 buf->PushL(); |
|
140 User::LeaveIfNull(buf); |
|
141 TInt bufferSize = buf->SizeL(); |
|
142 if (bufferSize == 0 || (bufferSize < KMountMessagePrefixLength)) |
|
143 { |
|
144 User::Leave(KErrMsgBioMessageNotValid); |
|
145 } |
|
146 TRequestStatus status; |
|
147 HBufC8* utf8configuration = HBufC8::NewMaxLC(bufferSize); |
|
148 TPtr8 utfPtr = utf8configuration->Des(); |
|
149 buf->ReadL(utfPtr, status); |
|
150 User::WaitForRequest(status); |
|
151 |
|
152 HBufC* unistring(NULL); |
|
153 unistring = CnvUtfConverter::ConvertToUnicodeFromUtf7L(*utf8configuration); |
|
154 CleanupStack::PushL(unistring); |
|
155 |
|
156 RsfwMountUtils::ImportMountEntryL(*unistring,&iMountEntry); |
|
157 |
|
158 iViewer = new (ELeave) CRichBio(ERichBioModeEditorBase); |
|
159 |
|
160 FillViewerWithDataL(); |
|
161 |
|
162 CleanupStack::PopAndDestroy(5,&fileHandle); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // Formats displaying a remote drive (only the drive name is shown) |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void CRsfwMountConfBioControl::FillViewerWithDataL() |
|
170 { |
|
171 DEBUGSTRING16(("CRsfwMountConfBioControl::FillViewerWithDataL")); |
|
172 AddItemL(R_STR_SETTING_ITEM_DRIVE_NAME, *(*iMountEntry).Item(EMountEntryItemName)); |
|
173 } |
|
174 |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // Display a single item |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CRsfwMountConfBioControl::AddItemL(TInt aLabelRes, const TDesC& aValue) |
|
181 { |
|
182 DEBUGSTRING16(("CRsfwMountConfBioControl::AddItemL")); |
|
183 // Empty fields are not shown. |
|
184 if (&aValue) |
|
185 { |
|
186 if (aValue.Length()) |
|
187 { |
|
188 HBufC* labelTxt = StringLoader::LoadLC(aLabelRes, iCoeEnv); |
|
189 iViewer->AddItemL(*labelTxt, aValue); |
|
190 CleanupStack::PopAndDestroy(labelTxt); |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 |
|
196 void CRsfwMountConfBioControl::SetAndGetSizeL(TSize& aSize) |
|
197 { |
|
198 DEBUGSTRING16(("CRsfwMountConfBioControl::SetAndGetSizeL")); |
|
199 if(iIsFileBased) |
|
200 { |
|
201 SetPosition(TPoint(0,KMConfBcHeightReductionBva)); |
|
202 aSize.iHeight -= KMConfBcHeightReductionBva; |
|
203 iViewer->SetAndGetSizeL(aSize); |
|
204 } |
|
205 else |
|
206 { |
|
207 iViewer->SetAndGetSizeL(aSize); |
|
208 } |
|
209 SetSizeWithoutNotification(aSize); |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // Adds Save command to "Options" set |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CRsfwMountConfBioControl::SetMenuCommandSetL(CEikMenuPane& aMenuPane) |
|
217 { |
|
218 DEBUGSTRING16(("CRsfwMountConfBioControl::SetMenuCommandSetL")); |
|
219 if (!IsEditor()) |
|
220 { |
|
221 if( iIsFileBased ) |
|
222 { |
|
223 FileBasedAddMenuItemL(aMenuPane, R_SM_SAVE, |
|
224 EMountConfBcCmdSave); |
|
225 } |
|
226 else |
|
227 { |
|
228 AddMenuItemL(aMenuPane, R_SM_SAVE, |
|
229 EMountConfBcCmdSave, EFirstMenuItem); |
|
230 |
|
231 } |
|
232 } |
|
233 } |
|
234 |
|
235 |
|
236 void CRsfwMountConfBioControl::FileBasedAddMenuItemL(CEikMenuPane& aMenuPane, |
|
237 TInt aStringRes, TInt aCommandOffset) |
|
238 { |
|
239 DEBUGSTRING16(("CRsfwMountConfBioControl::FileBasedAddMenuItemL")); |
|
240 CEikMenuPaneItem::SData menuItem; |
|
241 menuItem.iCascadeId = NULL; |
|
242 menuItem.iFlags = NULL; |
|
243 HBufC* string = StringLoader::LoadL(aStringRes, iCoeEnv); |
|
244 menuItem.iText.Format(*string); |
|
245 delete string; |
|
246 menuItem.iCommandId = iBioControlObserver.FirstFreeCommand() |
|
247 + aCommandOffset; |
|
248 aMenuPane.InsertMenuItemL(menuItem, 0); |
|
249 } |
|
250 |
|
251 TRect CRsfwMountConfBioControl::CurrentLineRect() const |
|
252 { |
|
253 DEBUGSTRING16(("CRsfwMountConfBioControl::CurrentLineRect")); |
|
254 return iViewer->CurrentLineRect(); |
|
255 } |
|
256 |
|
257 TBool CRsfwMountConfBioControl::IsFocusChangePossible( |
|
258 TMsgFocusDirection aDirection) const |
|
259 { |
|
260 DEBUGSTRING16(("CRsfwMountConfBioControl::IsFocusChangePossible")); |
|
261 if (aDirection == EMsgFocusUp) |
|
262 { |
|
263 return iViewer->IsCursorLocation(EMsgTop); |
|
264 } |
|
265 return EFalse; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // Sets the header or the remote drive view |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 HBufC* CRsfwMountConfBioControl::HeaderTextL() const |
|
273 { |
|
274 DEBUGSTRING16(("CRsfwMountConfBioControl::HeaderTextL")); |
|
275 return StringLoader::LoadL(R_SM_TITLE_MOUNT_CONF, iCoeEnv); |
|
276 } |
|
277 |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // Handles the command selected by the user |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 TBool CRsfwMountConfBioControl::HandleBioCommandL(TInt aCommand) |
|
284 { |
|
285 DEBUGSTRING16(("CRsfwMountConfBioControl::HandleBioCommandL %d", aCommand)); |
|
286 |
|
287 aCommand -= iBioControlObserver.FirstFreeCommand(); |
|
288 switch (aCommand) |
|
289 { |
|
290 case EMountConfBcCmdSave: |
|
291 TRAPD(err, DoMountL(iMountEntry)); |
|
292 if (!err) |
|
293 { |
|
294 HBufC* buf = StringLoader::LoadLC(R_SM_SUCCESS_MOUNT); |
|
295 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote; |
|
296 note->ExecuteLD(*buf); |
|
297 CleanupStack::PopAndDestroy(buf); |
|
298 } |
|
299 else if (KErrInUse == err) |
|
300 { |
|
301 HBufC* buf = StringLoader::LoadLC(R_SM_TOO_MANY_REMOTE_DRIVES); |
|
302 CAknErrorNote* note = new (ELeave) CAknErrorNote; |
|
303 note->ExecuteLD(*buf); |
|
304 CleanupStack::PopAndDestroy(buf); |
|
305 } |
|
306 else if (!(KErrCancel == err)) |
|
307 { |
|
308 // cancel means that user does not want to rename |
|
309 User::Leave(err); |
|
310 } |
|
311 |
|
312 return ETrue; |
|
313 default: |
|
314 return EFalse; |
|
315 } |
|
316 } |
|
317 |
|
318 TKeyResponse CRsfwMountConfBioControl::OfferKeyEventL( |
|
319 const TKeyEvent& aKeyEvent, |
|
320 TEventCode aType) |
|
321 { |
|
322 DEBUGSTRING16(("CRsfwMountConfBioControl::OfferKeyEventL")); |
|
323 return iViewer->OfferKeyEventL(aKeyEvent, aType); |
|
324 } |
|
325 |
|
326 TInt CRsfwMountConfBioControl::CountComponentControls() const |
|
327 { |
|
328 DEBUGSTRING16(("CRsfwMountConfBioControl::CountComponentControls")); |
|
329 return 1; // the viewer component |
|
330 } |
|
331 |
|
332 CCoeControl* CRsfwMountConfBioControl::ComponentControl(TInt aIndex) const |
|
333 { |
|
334 DEBUGSTRING16(("CRsfwMountConfBioControl::ComponentControl")); |
|
335 if (aIndex == 0) |
|
336 { |
|
337 return iViewer; |
|
338 } |
|
339 return NULL; |
|
340 |
|
341 } |
|
342 |
|
343 void CRsfwMountConfBioControl::SizeChanged() |
|
344 { |
|
345 DEBUGSTRING16(("CRsfwMountConfBioControl::SizeChanged")); |
|
346 iViewer->SetExtent(Position(), iViewer->Size()); |
|
347 } |
|
348 |
|
349 void CRsfwMountConfBioControl::FocusChanged(TDrawNow /* aDrawNow */) |
|
350 { |
|
351 DEBUGSTRING16(("CRsfwMountConfBioControl::FocusChanged")); |
|
352 iViewer->SetFocus(IsFocused()); |
|
353 } |
|
354 |
|
355 void CRsfwMountConfBioControl::SetContainerWindowL(const CCoeControl& aContainer) |
|
356 { |
|
357 DEBUGSTRING16(("CRsfwMountConfBioControl::SetContainerWindowL")); |
|
358 CCoeControl::SetContainerWindowL(aContainer); |
|
359 |
|
360 // The reason for creating the viewer control here is that the |
|
361 // construction of the viewer requires a parent with a window. So it |
|
362 // cannot be done in ConstructL(). |
|
363 // |
|
364 iViewer->ConstructL(this); |
|
365 |
|
366 } |
|
367 |
|
368 TInt CRsfwMountConfBioControl::VirtualHeight() |
|
369 { |
|
370 DEBUGSTRING16(("CRsfwMountConfBioControl::VirtualHeight")); |
|
371 return iViewer->VirtualHeight(); |
|
372 } |
|
373 |
|
374 TInt CRsfwMountConfBioControl::VirtualVisibleTop() |
|
375 { |
|
376 DEBUGSTRING16(("CRsfwMountConfBioControl::VirtualVisibleTop")); |
|
377 return iViewer->VirtualVisibleTop(); |
|
378 } |
|
379 |
|
380 TBool CRsfwMountConfBioControl::IsCursorLocation(TMsgCursorLocation aLocation) const |
|
381 { |
|
382 DEBUGSTRING16(("CRsfwMountConfBioControl::IsCursorLocation")); |
|
383 return iViewer->IsCursorLocation(aLocation); |
|
384 } |
|
385 |
|
386 |
|
387 void CRsfwMountConfBioControl::ResolveFileL( RFile& aFile ) |
|
388 { |
|
389 DEBUGSTRING16(("CRsfwMountConfBioControl::ResolveFileL")); |
|
390 if ( iIsFileBased ) |
|
391 { |
|
392 aFile.Duplicate(FileHandle()); |
|
393 } |
|
394 else |
|
395 { |
|
396 CMsvEntry* entry = MsvSession().GetEntryL( iId ); |
|
397 |
|
398 CleanupStack::PushL( entry ); |
|
399 CMsvStore* store = entry->ReadStoreL(); |
|
400 CleanupStack::PushL(store); |
|
401 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
402 aFile = attachMan.GetAttachmentFileL( 0 ); //entry is the first attachment |
|
403 CleanupStack::PopAndDestroy( 2, entry ); // store, entry |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // Saves the selected remote drive to the Central Repository table |
|
409 // --------------------------------------------------------------------------- |
|
410 // |
|
411 void CRsfwMountConfBioControl::DoMountL(CRsfwMountEntry* aMounterEntry) |
|
412 { |
|
413 DEBUGSTRING16(("CRsfwMountConfBioControl::DoMountL")); |
|
414 // CRsfwMountEntry API ensures that EMountEntryItemName |
|
415 // length does not exceed KMaxFriendlyNameLength characters |
|
416 TBuf<KMaxFriendlyNameLength> newFriendlyName; |
|
417 newFriendlyName.Copy(*aMounterEntry->Item(EMountEntryItemName)); |
|
418 |
|
419 TBool nameUnique = EFalse; |
|
420 TBool operationCancelled = EFalse; |
|
421 |
|
422 nameUnique = isNameUniqueL(newFriendlyName); |
|
423 |
|
424 while ((!nameUnique) && (!operationCancelled)) |
|
425 { |
|
426 operationCancelled = GetNameForNewMountL(newFriendlyName); |
|
427 nameUnique = isNameUniqueL(newFriendlyName); |
|
428 } |
|
429 |
|
430 if (!operationCancelled) |
|
431 { |
|
432 // clone the entry and add it to the cenrep |
|
433 // we clone it so that the original smart message content does not change |
|
434 CRsfwMountEntry* entrytoBeSaved = aMounterEntry->CloneL(); |
|
435 |
|
436 // copy newFriendlyName to name |
|
437 entrytoBeSaved->SetItemL(EMountEntryItemName, newFriendlyName); |
|
438 |
|
439 // set mountentryindex to -1 so that this will go the end of the list |
|
440 TBuf<5> index; |
|
441 index.Num(-1); |
|
442 entrytoBeSaved->SetItemL(EMountEntryItemIndex, index); |
|
443 |
|
444 // ownership is transferred to MountMan |
|
445 iMountMan->AddMountEntryL(entrytoBeSaved); |
|
446 } |
|
447 else |
|
448 { |
|
449 User::Leave(KErrCancel); |
|
450 } |
|
451 |
|
452 } |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 // Tests whether the chosen remote drive name is unique |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 TBool CRsfwMountConfBioControl::isNameUniqueL(const TDesC& aName) |
|
459 { |
|
460 DEBUGSTRING16(("CRsfwMountConfBioControl::isNameUniqueL")); |
|
461 // figure out whether a drive with the same name already exists |
|
462 CDesCArray* driveArray = new (ELeave) CDesC16ArraySeg(4); |
|
463 CleanupStack::PushL(driveArray); |
|
464 iMountMan->GetMountNamesL(driveArray); |
|
465 // report error if there are already 9 remote drives |
|
466 if (driveArray->Count() == KMaxRemoteDrives) |
|
467 { |
|
468 CleanupStack::PopAndDestroy(driveArray); |
|
469 User::Leave(KErrInUse); |
|
470 } |
|
471 |
|
472 for (int i = 0; i < driveArray->Count(); i++) |
|
473 { |
|
474 if (aName == driveArray->MdcaPoint(i)) |
|
475 { |
|
476 // there was a match and the name is not unique |
|
477 CleanupStack::PopAndDestroy(driveArray); |
|
478 return EFalse; |
|
479 } |
|
480 } |
|
481 CleanupStack::PopAndDestroy(driveArray); |
|
482 return ETrue; |
|
483 } |
|
484 |
|
485 // --------------------------------------------------------------------------- |
|
486 // Queries new remote drive name from the user |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 TBool CRsfwMountConfBioControl::GetNameForNewMountL(TDes& aName) |
|
490 { |
|
491 DEBUGSTRING16(("CRsfwMountConfBioControl::GetNameForNewMountL")); |
|
492 TBool operationCancelled = EFalse; |
|
493 // ask user to change the name and try again |
|
494 HBufC* confmess = StringLoader::LoadLC(R_STR_NAME_RENAME_QUERY, aName); |
|
495 CAknQueryDialog* query = CAknQueryDialog::NewL |
|
496 (CAknQueryDialog::EConfirmationTone); |
|
497 |
|
498 if (query->ExecuteLD( R_CONFIRMATION_QUERY, *confmess)) |
|
499 { |
|
500 TBuf<KMaxFriendlyNameLength> newName; |
|
501 TBool retval; |
|
502 |
|
503 // for getting the new name, use name dialog from the "global save as dialog" |
|
504 HBufC* defaultname = StringLoader::LoadLC(R_SM_DEFAULT_DRIVE_NAME); |
|
505 |
|
506 CRsfwNotPluginNameDialog* dlg = |
|
507 CRsfwNotPluginNameDialog::NewL( |
|
508 *defaultname, newName, iEikonEnv->FsSession()); |
|
509 dlg->SetMaxLength(KMaxFriendlyNameLength); |
|
510 dlg->PrepareLC( R_FILE_NAME_QUERY ); |
|
511 retval = dlg->RunLD(); |
|
512 CleanupStack::PopAndDestroy(defaultname); |
|
513 if (!retval) |
|
514 { |
|
515 // user cancelled renaming |
|
516 operationCancelled = ETrue; |
|
517 } |
|
518 else |
|
519 { |
|
520 aName = newName; |
|
521 } |
|
522 } |
|
523 else |
|
524 { |
|
525 // user does not want to rename |
|
526 operationCancelled = ETrue; |
|
527 } |
|
528 CleanupStack::PopAndDestroy(confmess); |
|
529 return operationCancelled; |
|
530 } |