|
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 the License "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 * Implementation of CBrowserBookmarkEditDialog. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <BrowserNG.rsg> |
|
24 #include <eikmenup.h> |
|
25 #include <eikseced.h> |
|
26 #include <eikenv.h> |
|
27 #include <avkon.hrh> |
|
28 #include <AknQueryDialog.h> |
|
29 #include <eikcapc.h> |
|
30 #include <AknPopupField.h> |
|
31 #include <AknQueryValueText.h> |
|
32 #include <AknKeys.h> |
|
33 #include <FavouritesItem.h> |
|
34 #include <aknnavi.h> |
|
35 #include <aknnavide.h> |
|
36 |
|
37 #include <aknconsts.h> |
|
38 #include <akneditstateindicator.h> |
|
39 #include <AknsListBoxBackgroundControlContext.h> |
|
40 #include <Uri16.h> // TUriParser |
|
41 |
|
42 #include "BrowserBookmarksEditFormApModel.h" |
|
43 #include "BrowserBookmarksEditDialog.h" |
|
44 #include "BrowserFavouritesModel.h" |
|
45 #include "BrowserDialogs.h" |
|
46 #include "BrowserAppUi.h" |
|
47 #include "BrowserAppViewBase.h" |
|
48 #include "commonconstants.h" |
|
49 #include "Browser.hrh" |
|
50 #include "BrowserUtil.h" |
|
51 |
|
52 #ifdef __SERIES60_HELP |
|
53 // Context-Sensitve Help File |
|
54 #include "BrowserApplication.h" |
|
55 #include <csxhelp/browser.hlp.hrh> |
|
56 #endif // __SERIES60_HELP |
|
57 |
|
58 // CONSTANTS |
|
59 |
|
60 // ================= MEMBER FUNCTIONS ======================= |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CBrowserBookmarkEditDialog::NewL |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CBrowserBookmarkEditDialog* CBrowserBookmarkEditDialog::NewL |
|
67 ( |
|
68 CFavouritesItem& aItem, |
|
69 CBrowserFavouritesModel& aModel, |
|
70 MApiProvider& aApiProvider, |
|
71 //MCommsModel& aCommsModel, |
|
72 TInt aUid /* = KFavouritesNullUid */ |
|
73 ) |
|
74 { |
|
75 CBrowserBookmarkEditDialog* form = |
|
76 new (ELeave) CBrowserBookmarkEditDialog( |
|
77 aItem, |
|
78 aModel, |
|
79 aApiProvider, |
|
80 aUid |
|
81 ); |
|
82 CleanupStack::PushL( form ); |
|
83 form->ConstructL( /* aApiProvider.CommsModel() */ ); |
|
84 CleanupStack::Pop(); // form |
|
85 return form; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CBrowserBookmarkEditDialog::~CBrowserBookmarkEditDialog |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 CBrowserBookmarkEditDialog::~CBrowserBookmarkEditDialog() |
|
93 { |
|
94 delete iFormApModel; |
|
95 delete iNaviDecorator; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CBrowserBookmarkEditDialog::ProcessCommandL |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 void CBrowserBookmarkEditDialog::ProcessCommandL( TInt aCommandId ) |
|
103 { |
|
104 switch ( aCommandId ) |
|
105 { |
|
106 case EAknCmdExit: |
|
107 { |
|
108 // Custom added commands. Forward to view. |
|
109 // Note that we respond to EAknCmdExit, not CEikCmdExit; it's |
|
110 // because we don't get it through the AppUi framework (instead, |
|
111 // we forward it there now). |
|
112 CBrowserAppUi::Static()->HandleCommandL(EWmlCmdUserExit); |
|
113 break; |
|
114 } |
|
115 |
|
116 #ifdef __SERIES60_HELP |
|
117 |
|
118 case EAknCmdHelp: |
|
119 { |
|
120 CBrowserAppUi::Static()->HandleCommandL(EAknCmdHelp); |
|
121 break; |
|
122 } |
|
123 |
|
124 #endif //__SERIES60_HELP |
|
125 |
|
126 default: |
|
127 { |
|
128 // Standard form commands. |
|
129 CAknForm::ProcessCommandL( aCommandId ); |
|
130 if ( iExitDialog ) |
|
131 { |
|
132 TryExitL( EAknSoftkeyBack ); |
|
133 } |
|
134 break; |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CBrowserBookmarkEditDialog::CBrowserBookmarkEditDialog |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 CBrowserBookmarkEditDialog::CBrowserBookmarkEditDialog |
|
144 ( |
|
145 CFavouritesItem& aItem, |
|
146 CBrowserFavouritesModel& aModel, |
|
147 MApiProvider& aApiProvider, |
|
148 TInt aUid |
|
149 ) |
|
150 : iItem( &aItem ), |
|
151 iModel( &aModel ), |
|
152 iUid( aUid ), |
|
153 iExitDialog( EFalse ), |
|
154 iExitNoteResourceId( 0 ), // By default do not show any note. |
|
155 iApiProvider( aApiProvider ) |
|
156 { |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // CBrowserBookmarkEditDialog::ConstructL |
|
161 // --------------------------------------------------------- |
|
162 // |
|
163 void CBrowserBookmarkEditDialog::ConstructL( /*MCommsModel& aCommsModel*/ ) |
|
164 { |
|
165 CAknForm::ConstructL(); |
|
166 iFormApModel = CBrowserBookmarksEditFormApModel::NewL( ApiProvider().CommsModel()/*aCommsModel*/ ); |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CBrowserBookmarkEditDialog::OkToExitL |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 TBool CBrowserBookmarkEditDialog::OkToExitL( TInt aButtonId ) |
|
174 { |
|
175 TBool ret = CAknForm::OkToExitL( aButtonId ); |
|
176 if ( ret && iExitNoteResourceId ) |
|
177 { |
|
178 // Exiting; show appropriate note if applicable. |
|
179 TBrowserDialogs::InfoNoteL( |
|
180 R_BROWSER_INFO_NOTE, iExitNoteResourceId ); |
|
181 } |
|
182 //pop empty label from navipane |
|
183 if ( ret ) |
|
184 iNaviPane->Pop(); |
|
185 return ret; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CBrowserBookmarkEditDialog::SaveFormDataL |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 TBool CBrowserBookmarkEditDialog::SaveFormDataL() |
|
193 { |
|
194 // Of KWmlFavouritesMaxUrlDefine, KWmlFavouritesMaxUsernameDefine, KWmlFavouritesMaxPasswordDefine |
|
195 // and KWmlFavouritesMaxBookmarkNameDefine the biggest is KWmlFavouritesMaxUrlDefine. |
|
196 TBuf<KFavouritesMaxUrlDefine> buf; |
|
197 |
|
198 // Get title. |
|
199 GetEdwinText( buf, EWmlControlEditBmEditTitle ); |
|
200 iItem->SetNameL( buf.Left(KFavouritesMaxName) ); |
|
201 |
|
202 // Get address. |
|
203 GetEdwinText( buf, EWmlControlEditBmEditAddress ); |
|
204 HBufC* text = HBufC::NewL(KFavouritesMaxUrlDefine); |
|
205 |
|
206 // Do not check return value from Parse(). If the user wants to create a |
|
207 // badly formed url then let them do so. |
|
208 TUriParser url; |
|
209 url.Parse( buf ); |
|
210 |
|
211 // Add a default scheme if it is not already present. |
|
212 if( !url.IsPresent( EUriScheme ) ) |
|
213 { |
|
214 _LIT( KBookmarkDefaultScheme, "http://" ); |
|
215 |
|
216 text->Des().Copy( KBookmarkDefaultScheme ); |
|
217 } |
|
218 // Error prone code. If user enters the whole KFavouritesMaxUrlDefine(1024) amount of |
|
219 // characters with out the http:// infront, well have a USER:23 here. |
|
220 // Hack aplied for now and included in FIX: EKDN-7P64KZ |
|
221 // Needs a proper error raised and a fix. |
|
222 // |
|
223 // Check if long enough and append, if not we dont add http:// |
|
224 // and alert user in SaveItemL() with popup that there must be an url |
|
225 // NOTICE: THIS NEEDS A PROPER FIX - THIS IS A TEMP WORKAROUND |
|
226 if( ( buf.Length() + text->Length() ) <= KFavouritesMaxUrlDefine ) |
|
227 { |
|
228 text->Des().Append( buf ); |
|
229 } |
|
230 else |
|
231 { |
|
232 text->Des().Copy( buf ); |
|
233 } |
|
234 |
|
235 |
|
236 Util::EncodeSpaces(text); |
|
237 CleanupStack::PushL(text);// push after encode because the pointer may change |
|
238 iItem->SetUrlL( text->Des() ); |
|
239 CleanupStack::PopAndDestroy();// text |
|
240 |
|
241 // Get username. |
|
242 GetEdwinText( buf, EWmlControlEditBmEditUsername ); |
|
243 iItem->SetUserNameL( buf ); |
|
244 |
|
245 // Get password. |
|
246 STATIC_CAST( CEikSecretEditor*, Control( EWmlControlEditBmEditPassword ) ) |
|
247 ->GetText( buf ); |
|
248 iItem->SetPasswordL( buf ); |
|
249 |
|
250 // Get WAP Access point. |
|
251 TFavouritesWapAp ap = iFormApModel->CurrentWapAp(); |
|
252 if ( !ap.IsNull() ) |
|
253 { |
|
254 // We set it back only if not NULL. |
|
255 // AP is NULL if invalid (bookmark was edited, but the ap was not and |
|
256 // it is left "Invalid". In that case we leave ap as-is. |
|
257 iItem->SetWapAp( ap ); |
|
258 } |
|
259 |
|
260 return SaveItemL(); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CBrowserBookmarkEditDialog::DynInitMenuPaneL |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 void CBrowserBookmarkEditDialog::DynInitMenuPaneL |
|
268 ( TInt aResourceId, CEikMenuPane* aMenuPane ) |
|
269 { |
|
270 CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane ); |
|
271 if ( aResourceId == R_AVKON_FORM_MENUPANE ) |
|
272 { |
|
273 // Disallow user addition / deletion / labeling. |
|
274 aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue ); |
|
275 aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue ); |
|
276 aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue ); |
|
277 // Add "Exit". |
|
278 aMenuPane->AddMenuItemsL |
|
279 ( R_BROWSER_BOOKMARKS_MENU_PANE_EDIT_BOOKMARK ); |
|
280 } |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // CBrowserBookmarkEditDialog::PreLayoutDynInitL |
|
285 // --------------------------------------------------------- |
|
286 // |
|
287 void CBrowserBookmarkEditDialog::PreLayoutDynInitL() |
|
288 { |
|
289 LoadFormDataL(); |
|
290 CAknForm::PreLayoutDynInitL(); |
|
291 |
|
292 CEikStatusPane *sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane(); |
|
293 // Fetch pointer to the default navi pane control |
|
294 iNaviPane = |
|
295 (CAknNavigationControlContainer*)sp->ControlL( |
|
296 TUid::Uid( EEikStatusPaneUidNavi ) ); |
|
297 iNaviDecorator = iNaviPane->CreateNavigationLabelL( _L("") ); |
|
298 |
|
299 // push empty label, to avoid tab group visibility in BookmarkEditor. |
|
300 iNaviPane->PushL( *iNaviDecorator ); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------- |
|
304 // CBrowserBookmarkEditDialog::LoadFormDataL |
|
305 // --------------------------------------------------------- |
|
306 // |
|
307 void CBrowserBookmarkEditDialog::LoadFormDataL() |
|
308 { |
|
309 |
|
310 // Set title. |
|
311 const TPtrC tptrcName = iItem->Name(); |
|
312 STATIC_CAST( CEikEdwin*, Control( EWmlControlEditBmEditTitle ) )-> |
|
313 SetTextL( &(tptrcName) ); |
|
314 |
|
315 // Set address. |
|
316 const TPtrC tptrcUrl = iItem->Url(); |
|
317 STATIC_CAST( CEikEdwin*, Control( EWmlControlEditBmEditAddress ) )-> |
|
318 SetTextL( &(tptrcUrl) ); |
|
319 |
|
320 // Set username. |
|
321 const TPtrC tptrcUserName = iItem->UserName(); |
|
322 STATIC_CAST( CEikEdwin*, Control( EWmlControlEditBmEditUsername ) )-> |
|
323 SetTextL( &(tptrcUserName) ); |
|
324 |
|
325 // Set password. |
|
326 STATIC_CAST( CEikSecretEditor*,Control( EWmlControlEditBmEditPassword ) )-> |
|
327 SetText( iItem->Password() ); |
|
328 |
|
329 // Set WAP Access Point popup field's query value. |
|
330 CAknPopupField* wapApSelector = STATIC_CAST |
|
331 ( CAknPopupField*, Control( EWmlControlEditBmWapApSelector ) ); |
|
332 wapApSelector->SetQueryValueL( iFormApModel->QueryValue() ); |
|
333 // Set current WAP Access Point. |
|
334 iFormApModel->SetCurrentWapApL( iItem->WapAp() ); |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------- |
|
338 // CBrowserBookmarkEditDialog::SaveItemL |
|
339 // --------------------------------------------------------- |
|
340 // |
|
341 TBool CBrowserBookmarkEditDialog::SaveItemL() |
|
342 { |
|
343 TInt res; |
|
344 CBrowserFavouritesModel::TRenameMode renameMode = |
|
345 CBrowserFavouritesModel::EDontRename; |
|
346 |
|
347 iExitNoteResourceId = 0; // By default, do not show any note. |
|
348 |
|
349 if ( !iItem->Name().Length() ) |
|
350 { |
|
351 // No title for this item. Make a default name and ensure auto renaming |
|
352 // to non-conflicting name (without user interaction). |
|
353 iModel->SetNameToDefaultL( *iItem ); |
|
354 renameMode = CBrowserFavouritesModel::EAutoRename; |
|
355 } |
|
356 |
|
357 if ( iItem->Url().Length() && iItem->Url() != KHttpString && IsValidUrlHost( iItem->Url() ) ) |
|
358 { |
|
359 if ( iUid == KFavouritesNullUid ) |
|
360 { |
|
361 // This is a new item. Add it. |
|
362 res = iModel->AddL( *iItem, /*aDbErrorNote=*/ETrue, renameMode ); |
|
363 } |
|
364 else |
|
365 { |
|
366 // Editing an existing item. Update now. |
|
367 res = iModel->UpdateL |
|
368 ( *iItem, iUid, /*aDbErrorNote=*/ETrue, renameMode ); |
|
369 } |
|
370 switch ( res ) |
|
371 { |
|
372 case KErrNone: |
|
373 { |
|
374 iExitDialog = ETrue; |
|
375 break; |
|
376 } |
|
377 case KErrAlreadyExists: |
|
378 { |
|
379 // Name conflicts. Let the user know. |
|
380 TBrowserDialogs::InfoNoteL |
|
381 ( |
|
382 R_BROWSER_INFO_NOTE, |
|
383 R_BROWSER_BOOKMARKS_NAME_ALREADY_USED |
|
384 ); |
|
385 // Set focus to name field and keep editing. |
|
386 TryChangeFocusToL( EWmlControlEditBmEditTitle ); |
|
387 // Select all, cursor is at end. |
|
388 CEikEdwin* nameEditor = STATIC_CAST |
|
389 ( CEikEdwin*, Control( EWmlControlEditBmEditTitle ) ); |
|
390 nameEditor->SetSelectionL( nameEditor->TextLength(), 0 ); |
|
391 nameEditor->DrawDeferred(); |
|
392 iExitDialog = EFalse; |
|
393 break; |
|
394 } |
|
395 default: |
|
396 { |
|
397 iExitDialog = EFalse; |
|
398 break; |
|
399 } |
|
400 } |
|
401 } |
|
402 else |
|
403 { |
|
404 // No Address. Cannot save this bookmark. |
|
405 res = TBrowserDialogs::ConfirmQueryYesNoL( |
|
406 R_BROWSER_BOOKMARKS_TEXT_QUERY_ADDRESS ); |
|
407 if ( !res /*res == EAknSoftkeyNo*/ ) |
|
408 { |
|
409 // User decided not to save the bookmark. Exit now. |
|
410 iExitNoteResourceId = iModel->StringResourceId |
|
411 ( *iItem, CBrowserFavouritesModel::ENotSaved ); |
|
412 iExitDialog = ETrue; |
|
413 } |
|
414 else |
|
415 { |
|
416 // Set focus to address field and keep editing. |
|
417 TryChangeFocusToL( EWmlControlEditBmEditAddress ); |
|
418 CEikEdwin* urlEditor = STATIC_CAST |
|
419 ( CEikEdwin*, Control( EWmlControlEditBmEditAddress ) ); |
|
420 // Select none, cursor is at end. |
|
421 urlEditor->SetSelectionL |
|
422 ( urlEditor->TextLength(), urlEditor->TextLength() ); |
|
423 urlEditor->DrawDeferred(); |
|
424 iExitDialog = EFalse; |
|
425 } |
|
426 } |
|
427 return iExitDialog; |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------- |
|
431 // CBrowserBookmarkEditDialog::IsValidUrlHost |
|
432 // --------------------------------------------------------- |
|
433 // |
|
434 TBool CBrowserBookmarkEditDialog::IsValidUrlHost( const TDesC& aUrl ) |
|
435 { |
|
436 TBool isValid = EFalse; |
|
437 _LIT(KHttpMark, "://"); |
|
438 // Get the position of end of protocol definition |
|
439 TInt position = aUrl.Find( KHttpMark ); |
|
440 if ( position != KErrNotFound ) |
|
441 { |
|
442 TPtrC16 url = aUrl.Right( aUrl.Length() - position - KHttpMark().Length() ); |
|
443 // Locate the next slash which is the end of host part of url |
|
444 TInt slashLocation = url.Locate('/'); |
|
445 // We check the total length of host part of url. |
|
446 // If over 255 we return EFalse |
|
447 if ( slashLocation == KErrNotFound ) |
|
448 { |
|
449 if ( ( url.Length() + position + KHttpMark().Length() ) <= 255 ) |
|
450 { |
|
451 isValid = ETrue; |
|
452 } |
|
453 } |
|
454 else |
|
455 { |
|
456 if ( ( position + slashLocation + KHttpMark().Length() ) <= 255 ) |
|
457 { |
|
458 isValid = ETrue; |
|
459 } |
|
460 } |
|
461 } |
|
462 return isValid; |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------- |
|
466 // CBrowserBookmarkEditDialog::GetEdwinText |
|
467 // --------------------------------------------------------- |
|
468 // |
|
469 void CBrowserBookmarkEditDialog::GetEdwinText |
|
470 ( TDes& aText, TInt aControlId ) |
|
471 { |
|
472 STATIC_CAST( CEikEdwin*, Line( aControlId )->iControl )->GetText( aText ); |
|
473 } |
|
474 |
|
475 |
|
476 // --------------------------------------------------------- |
|
477 // CBrowserBookmarkEditDialog::HandleResourceChange |
|
478 // --------------------------------------------------------- |
|
479 // |
|
480 void CBrowserBookmarkEditDialog::HandleResourceChange( TInt aType ) |
|
481 { |
|
482 TRAP_IGNORE( HandleResourceChangeL( aType ) ); |
|
483 } |
|
484 |
|
485 // --------------------------------------------------------- |
|
486 // CBrowserBookmarkEditDialog::HandleResourceChangeL |
|
487 // --------------------------------------------------------- |
|
488 // |
|
489 void CBrowserBookmarkEditDialog::HandleResourceChangeL( TInt aType ) |
|
490 { |
|
491 CAknForm::HandleResourceChange(aType); |
|
492 if (aType == KEikDynamicLayoutVariantSwitch) |
|
493 { |
|
494 TRect rect; |
|
495 if (AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect)) |
|
496 { |
|
497 SetRect(rect); |
|
498 } |
|
499 } |
|
500 } |
|
501 |
|
502 #ifdef __SERIES60_HELP |
|
503 // --------------------------------------------------------- |
|
504 // CBrowserBookmarkEditDialog::GetHelpContext() |
|
505 // --------------------------------------------------------- |
|
506 // |
|
507 void CBrowserBookmarkEditDialog::GetHelpContext( TCoeHelpContext& aContext ) const |
|
508 { |
|
509 aContext.iMajor = KUidBrowserApplication; |
|
510 if ( iUid == KFavouritesNullUid ) |
|
511 { |
|
512 // Add bookmark help |
|
513 aContext.iContext = KOSS_HLP_BM_ADDBM; |
|
514 } |
|
515 else |
|
516 { |
|
517 // Edit bookmark help |
|
518 aContext.iContext = KOSS_HLP_BM_EDIT; |
|
519 } |
|
520 } |
|
521 #endif // __SERIES60_HELP |
|
522 |
|
523 // End of File |