messagingappbase/smartmessaging/wmlbc/src/WmlBMSubItem30.cpp
branchRCL_3
changeset 27 7fdbb852d323
equal deleted inserted replaced
26:ebe688cedc25 27:7fdbb852d323
       
     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 *     Class includes information about one bookmark. 
       
    16 *     It has handle to Bookmark engine for adding bookmark.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include "WmlBMSubItem30.h"               // CWmlBMSubItem
       
    25 #include "WmlBMUtils30.h"                 // WmlBMUtils
       
    26 #include "WMLBC.hrh"
       
    27 #include "WmlBioControl.pan"
       
    28 #include "WmlLog.h"
       
    29 
       
    30 #include <favouritesitemlist.h>
       
    31 #include <WMLBC.rsg>                    // resource identifiers
       
    32 #include <StringLoader.h>               // StringLoader
       
    33 #include <msgnamevalue.h>               // CMsgNameValue
       
    34 #include <MsgBioUtils.h>
       
    35 
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 
       
    38 const TInt KWmlBookmarkFieldCount = 2;
       
    39 const TInt KUrlMaxLength = 255;
       
    40 const TInt KNameMaxLength = 50;
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 // CWmlBMSubItem::NewL
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 CWmlBMSubItem* CWmlBMSubItem::NewL()
       
    49     {
       
    50     CWmlBMSubItem* self = new ( ELeave ) CWmlBMSubItem();
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // Destructor
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 CWmlBMSubItem::~CWmlBMSubItem()
       
    62     {
       
    63     delete iBMItem;
       
    64     iBookmarkDb.Close();
       
    65     iSession.Close();
       
    66 	if ( iItemList ) // itemlist is created only when bookmark is saved.
       
    67 		{
       
    68 		delete iItemList;
       
    69 		}
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CWmlBMSubItem::AddFieldL
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CWmlBMSubItem::AddFieldL( 
       
    77     const TDesC& aFieldValue, 
       
    78     const TInt aFieldEnum )
       
    79     {
       
    80     // Note: Any max length checks are not done in bio control.
       
    81     // If the data passes the parser then we accept it.
       
    82     // And we depend to the FavouritesDatabase consistency checks.
       
    83 
       
    84     TInt length = aFieldValue.Length();
       
    85 
       
    86     switch ( aFieldEnum )
       
    87         {
       
    88         case EWappURL:
       
    89             {
       
    90             if (iBMItem->Url().Length() == 0 && // no existing URL
       
    91                 length > 0 &&                   // URL is longer than 0 chars
       
    92                 length <= KUrlMaxLength)        // URL is no longer than max length
       
    93                 {
       
    94                 iBMItem->SetUrlL( aFieldValue );
       
    95                 iIsValid = ETrue; // url makes bookmark valid.
       
    96                 }
       
    97             break;
       
    98             }
       
    99         case EWappName:
       
   100             {
       
   101             // Name is added if:
       
   102             // - There's not already a name.
       
   103             // - Given name is not empty.
       
   104             if ( iBMItem->Name().Length() == 0 && length > 0 )
       
   105                 {
       
   106                 // If the name exceeds the maximum name length the name is shortened
       
   107                 // to the maximum value.
       
   108                 if (length > KNameMaxLength)
       
   109                     {
       
   110 
       
   111                     iBMItem->SetNameL( aFieldValue.Left(KNameMaxLength) );    
       
   112                     }
       
   113                 else
       
   114                     {
       
   115                     iBMItem->SetNameL( aFieldValue );
       
   116                     }
       
   117                 }
       
   118             break;    
       
   119             }
       
   120         default:
       
   121             {
       
   122             // Internal error, trying to add wrong fields to this item.
       
   123             Panic( EIllegalCommandInCurrentState );
       
   124             break;
       
   125             }
       
   126         }
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CWmlBMSubItem::FieldCount
       
   131 // ---------------------------------------------------------
       
   132 //
       
   133 TInt CWmlBMSubItem::FieldCount() const
       
   134     {
       
   135     return KWmlBookmarkFieldCount;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CWmlBMSubItem::GetFieldDataAtLC
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 CMsgNameValue* CWmlBMSubItem::GetFieldDataAtLC( const TInt aIndex )
       
   143     {
       
   144     HBufC* label = NULL;
       
   145     HBufC* value = NULL;
       
   146 
       
   147     switch ( aIndex ) 
       
   148         {
       
   149         case EBookmarkNameFieldIndex:
       
   150             {
       
   151             label = StringLoader::LoadLC( R_QTN_SM_BM_TITLE );
       
   152             value = iBMItem->Name().AllocLC();
       
   153             break;
       
   154             }    
       
   155         case EBookmarkAddressFieldIndex:
       
   156             {
       
   157             label = StringLoader::LoadLC( R_QTN_SM_BM_ADDRESS );
       
   158             value = iBMItem->Url().AllocLC();
       
   159             break;
       
   160             }
       
   161         default:
       
   162             {
       
   163             // Internal error, trying to add wrong fields to this item.
       
   164             Panic( EIllegalCommandInCurrentState );
       
   165             break;
       
   166             }
       
   167         }
       
   168     CMsgNameValue* textPair = CMsgNameValue::NewL( label, value ); 
       
   169     CleanupStack::Pop( 2 ); // value, label
       
   170     CleanupStack::PushL( textPair );
       
   171     return textPair;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CWmlBMSubItem::IsValidL
       
   176 // ---------------------------------------------------------
       
   177 //
       
   178 TBool CWmlBMSubItem::IsValidL()
       
   179     {
       
   180     return iIsValid;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CWmlBMSubItem::DoInitialize
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 void CWmlBMSubItem::DoInitialize()
       
   188     {
       
   189 	if ( iItemList )
       
   190 		{
       
   191 		delete iItemList;
       
   192 		iItemList = NULL;
       
   193 		}
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // CWmlBMSubItem::NameMaxLength
       
   198 //
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 TInt CWmlBMSubItem::NameMaxLength()
       
   202     {
       
   203     return KNameMaxLength;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CWmlBMSubItem::NameLC
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 HBufC* CWmlBMSubItem::NameLC()
       
   211     {
       
   212     const TDesC& name = iBMItem->Name();
       
   213     HBufC* nameBuf = name.AllocL();
       
   214     CleanupStack::PushL( nameBuf );
       
   215     return nameBuf;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------
       
   219 // CWmlBMSubItem::SetNameL
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 void CWmlBMSubItem::SetNameL( const TDesC& aName )
       
   223     {
       
   224     iBMItem->SetNameL( aName );
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CWmlBMSubItem::DefaultNameLC
       
   229 // ---------------------------------------------------------
       
   230 //
       
   231 HBufC* CWmlBMSubItem::DefaultNameLC()
       
   232     {
       
   233     return StringLoader::LoadLC( R_QTN_SM_BOOKMARK_NAME );
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CWmlBMSubItem::DoQueryNewNameLC
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 HBufC* CWmlBMSubItem::DoQueryNewNameLC( const TDesC& aName )
       
   241     {
       
   242     TBuf<KNameMaxLength> nameBuf( aName );
       
   243     MsgBioUtils::TextQueryL(R_WMLBC_QUERY_BM_NAME, nameBuf); 
       
   244     HBufC* name = nameBuf.AllocL();
       
   245     CleanupStack::PushL( name );
       
   246     return name;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // CWmlBMSubItem::DoRenameQueryL
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 TBool CWmlBMSubItem::DoRenameQueryL( const TDesC& aName )
       
   254     {
       
   255     HBufC* query = StringLoader::LoadL( R_QTN_FLDR_RENAME_QUERY, aName );
       
   256     CleanupStack::PushL( query );
       
   257     TBool result = MsgBioUtils::ConfirmationQueryOkCancelL( *query );
       
   258     CleanupStack::PopAndDestroy( query );
       
   259     return result;
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------
       
   263 // CWmlBMSubItem::IsNameValidL
       
   264 // ---------------------------------------------------------
       
   265 //
       
   266 TBool CWmlBMSubItem::IsNameValidL( const TDesC& aName, TBool aUpdateList )
       
   267     {
       
   268 	// Update the item list when it's NULL or direction to update it is given
       
   269 	if ( iItemList == NULL || aUpdateList )
       
   270 		{
       
   271 		if ( iItemList )
       
   272 			{
       
   273 			delete iItemList; // Delete the old itemlist
       
   274 			iItemList = NULL;
       
   275 			}
       
   276 		iItemList = WmlBMUtils::CreateItemListLC(BookmarkDb2L());
       
   277 		CleanupStack::Pop( iItemList );
       
   278 		}
       
   279 
       
   280     TInt isUnique = EFalse;
       
   281     if (WmlBMUtils::Exists(aName, *iItemList) == KErrNotFound)
       
   282         {   
       
   283         isUnique = ETrue;    
       
   284         }
       
   285     return isUnique;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------
       
   289 // CWmlBMSubItem::PreStoreL
       
   290 // ---------------------------------------------------------
       
   291 //
       
   292 void CWmlBMSubItem::PreStoreL( const TBool /*aShowPreferredQuery*/ )
       
   293     {
       
   294 	LOG("CWmlBMSubItem::PreStoreL start");
       
   295 	if ( iItemList == NULL ) // No itemlist exists, create it.
       
   296 		{
       
   297 		LOG("CWmlBMSubItem::PreStoreL creating itemlist");
       
   298 		iItemList = WmlBMUtils::CreateItemListLC(BookmarkDb2L());
       
   299 		CleanupStack::Pop( iItemList );
       
   300 		LOG("CWmlBMSubItem::PreStoreL creating itemlist DONE");
       
   301 		}
       
   302 	LOG("CWmlBMSubItem::PreStoreL end");
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------
       
   306 // CWmlBMSubItem::StoreL
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 void CWmlBMSubItem::StoreL()
       
   310     {
       
   311 	LOG("CWmlBMSubItem::StoreL start");	
       
   312 	User::LeaveIfError( WmlBMUtils::DoStoreL( BookmarkDb2L(), *iBMItem ) );
       
   313 	LOG("CWmlBMSubItem::StoreL end");
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------
       
   317 // CWmlBMSubItem::PostStoreL
       
   318 // ---------------------------------------------------------
       
   319 //
       
   320 void CWmlBMSubItem::PostStoreL( const TBool aShowNote, 
       
   321     const TInt /*aPreferredInformation*/,
       
   322     const TBool /*aCreateBookmarkIfNotSetAsDefault*/)
       
   323     {
       
   324 	LOG("CWmlBMSubItem::PostStoreL start");
       
   325 
       
   326     if ( iItemList )
       
   327 		{
       
   328 		delete iItemList;
       
   329 		iItemList = NULL;
       
   330 		}
       
   331 
       
   332     // Show note only if required.
       
   333     if ( aShowNote )
       
   334         {
       
   335         MsgBioUtils::ConfirmationNoteL( R_QTN_SM_NOTE_BOOKMARK_COPIED );    
       
   336         }
       
   337 	LOG("CWmlBMSubItem::PreStoreL end");
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------
       
   341 // CWmlBMSubItem::ConstructL.
       
   342 // ---------------------------------------------------------
       
   343 //
       
   344 void CWmlBMSubItem::ConstructL()
       
   345     {
       
   346 	iBMItem = CFavouritesItem::NewL(); // initializes itself using "Default" AP
       
   347     iBMItem->SetType( CFavouritesItem::EItem );
       
   348     iBMItem->SetParentFolder( KFavouritesRootUid );
       
   349     User::LeaveIfError( iSession.Connect() );
       
   350     User::LeaveIfError( iBookmarkDb.Open( iSession, KBrowserBookmarks ) );
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------
       
   354 // CWmlBMSubItem::BookmarkDb2L
       
   355 // ---------------------------------------------------------
       
   356 //
       
   357 RFavouritesDb& CWmlBMSubItem::BookmarkDb2L()
       
   358     {
       
   359     return iBookmarkDb;
       
   360     }
       
   361 
       
   362 //  End of File  
       
   363 
       
   364 
       
   365 
       
   366 
       
   367 
       
   368 
       
   369 
       
   370 
       
   371 
       
   372 
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 
       
   378