landmarksui/uicontrols/src/CLmkPackageEditorImpl.cpp
changeset 15 13ae750350c9
parent 0 522cd55cc3d7
child 17 0f22fb80ebba
equal deleted inserted replaced
0:522cd55cc3d7 15:13ae750350c9
     1 /*
       
     2  * Copyright (c) 2002-2010 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:    LandmarksUi Package viewer implementation
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <featmgr.h>
       
    20 #include <aknnotewrappers.h>
       
    21 #include <AknWaitDialog.h>
       
    22 #include <aknlists.h>
       
    23 #include <StringLoader.h>
       
    24 #include <AknQueryDialog.h>
       
    25 #include <lmkui.rsg>
       
    26 #include <eikmenup.h>
       
    27 #include <hlplch.h>
       
    28 #include <sendnorm.rsg> // R_SENDUI_MENU
       
    29 #include <CLmkEditorDlg.h> // from system include!
       
    30 #include "CLmkParser.h"
       
    31 #include "landmarks.hrh"
       
    32 #include "LmkUID.h"
       
    33 #include <csxhelp/lmmes.hlp.hrh>
       
    34 #include "CLmkUiUtils.h"
       
    35 #include "CLmkEditorFieldArray.h"
       
    36 #include "MLmkEditorField.h"
       
    37 #include "LmkNotes.h"
       
    38 #include "LmkConsts.h"
       
    39 #include "CLmkDbUtils.h"
       
    40 #include "CLmkLocationService.h"
       
    41 #include "CLmkDlgCategorySelectorImpl.h"
       
    42 #include "CLmkSender.h"
       
    43 #include "CLmkLandMarkCategoriesName.h"
       
    44 #include "CLmkPackageEditorImpl.h"
       
    45 #include "CLmkSaveLandmarkUtils.h"
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CLmkPackageEditorImpl::CLmkPackageEditorImpl
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CLmkPackageEditorImpl::CLmkPackageEditorImpl(CPosLandmarkDatabase& aDb,
       
    56         CLmkParser& aParser, CLmkSender& aSender, TInt aItemIndex) :
       
    57     CLmkEditorImpl(aDb, aSender, CLmkEditorDlg::ELmkViewer), // viewing only mode!
       
    58             iParser(aParser), iItemIndex(aItemIndex)
       
    59     {
       
    60     TCoeHelpContext help(TUid::Uid( KLmkMsgViewerAppUID3),
       
    61             KLM_HLP_RECEIVED_LM);
       
    62     SetHelpContext(help);
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CLmkPackageEditorImpl::ConstructL
       
    67 // Symbian 2nd phase constructor can leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CLmkPackageEditorImpl::ConstructL()
       
    71     {
       
    72     iLandmark = iParser.LandmarkLC(iItemIndex);
       
    73     iCategoryNameArray = iParser.CategoryNameLC(iItemIndex);
       
    74     iCategoryNameArray->GetCategoryNames(iCategoryNames);
       
    75     iCalegorySelectionFlag = ETrue;
       
    76     CleanupStack::Pop(2); //iLandmark ,iCategoryNames
       
    77     TLmkEditorAttributes arguments(CLmkEditorDlg::ELmkAll);
       
    78     iIsLmkReceiveMode = ETrue;
       
    79     CLmkEditorImpl::ConstructL(iLandmark, arguments);
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CLmkPackageEditorImpl::NewL
       
    84 // Two-phased constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C CLmkPackageEditorImpl* CLmkPackageEditorImpl::NewL(
       
    88         CPosLandmarkDatabase& aDb, CLmkParser& aParser, CLmkSender& aSender,
       
    89         TInt aItemIndex)
       
    90     {
       
    91     CLmkPackageEditorImpl* self = new (ELeave) CLmkPackageEditorImpl(aDb,
       
    92             aParser, aSender, aItemIndex);
       
    93 
       
    94     CleanupStack::PushL(self);
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop(); //self
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CLmkPackageEditorImpl::~CLmkPackageEditorImpl()
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CLmkPackageEditorImpl::~CLmkPackageEditorImpl()
       
   105     {
       
   106     if (iWaitNote)
       
   107         {
       
   108         TRAPD(err, iWaitNote->ProcessFinishedL());
       
   109         if (err != KErrNone)
       
   110             {
       
   111             delete iWaitNote;
       
   112             iWaitNote = NULL;
       
   113             }
       
   114         }
       
   115     delete iLandmark;
       
   116     delete iCategoryNameArray;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CLmkPackageEditorImpl::HandleOperationL
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CLmkPackageEditorImpl::HandleOperationL(TOperationTypes aType,
       
   124         TReal32 /*aProgress*/, TInt aStatus)
       
   125     {
       
   126     if (aType == EImport)
       
   127         {
       
   128         if (aStatus != KPosLmOperationNotComplete && iWaitNote)
       
   129             {
       
   130             iWaitNote->ProcessFinishedL();
       
   131             iWaitNote = NULL;
       
   132             }
       
   133         }
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CLmkPackageEditorImpl::DynInitMenuPaneL
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CLmkPackageEditorImpl::DynInitMenuPaneL(
       
   141     TInt aResourceId,
       
   142     CEikMenuPane* aMenuPane )
       
   143     {
       
   144     switch( aResourceId )
       
   145         {
       
   146         case R_AVKON_FORM_MENUPANE:
       
   147             {
       
   148             CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   149 
       
   150             // delete the show on map & Navigate To options
       
   151             aMenuPane->DeleteMenuItem( ELmkShowOnMapPlaceHolder );
       
   152             aMenuPane->DeleteMenuItem( ELmkNavigateToPlaceHolder );
       
   153             
       
   154 			aMenuPane->SetItemDimmed( ELmkCmdSendDummy, ETrue);
       
   155             aMenuPane->SetItemDimmed( ELmkCmdSaveLm, ETrue );
       
   156             
       
   157             if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) &&
       
   158                     !iIsHideHelp )
       
   159 				{
       
   160 				aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse );
       
   161 				}
       
   162 			else
       
   163 				{
       
   164 				aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   165 				}
       
   166 
       
   167 			DimmMenuItemsL(aMenuPane);
       
   168 
       
   169 			//always dimmed
       
   170             aMenuPane->SetItemDimmed( EAknFormCmdEdit, ETrue );
       
   171 		    aMenuPane->SetItemDimmed( EAknFormCmdSave, ETrue );
       
   172 		    aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
       
   173 		    aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
       
   174 		    aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
       
   175             break;
       
   176             }
       
   177         case R_SENDUI_MENU: // Dynamically created send ui menu
       
   178             {
       
   179             if ( FeatureManager::FeatureSupported( KFeatureIdLandmarksConverter ) )
       
   180 	            {
       
   181             	iSender.DisplaySendCascadeMenuL( *aMenuPane );
       
   182 	            }
       
   183             break;
       
   184             }
       
   185         case R_LMK_EDITOR_MENU:
       
   186 	        {
       
   187             TBool hideMN=EFalse;
       
   188             if( iIsHideCoordinate )         
       
   189                 {
       
   190                 if(IsLandmarkDataEmptyL(iLandmark))
       
   191                     {
       
   192                     hideMN = ETrue;
       
   193                     }
       
   194                 }       
       
   195             else if( ArePositionFieldEmptyL() )
       
   196                 {
       
   197                 hideMN = ETrue;
       
   198                 }
       
   199             
       
   200             if( hideMN )
       
   201                 {
       
   202                 // delete the show on map & Navigate To options
       
   203                 aMenuPane->DeleteMenuItem( ELmkShowOnMapPlaceHolder );
       
   204                 aMenuPane->DeleteMenuItem( ELmkNavigateToPlaceHolder );
       
   205                 }
       
   206             iMapNavInterface->AttachMenuPaneL(aMenuPane, R_LMK_EDITOR_MENU, ELmkCmdMnNav);
       
   207 
       
   208             // Send menu is handled by the sender:
       
   209             if ( FeatureManager::FeatureSupported( KFeatureIdLandmarksConverter ) )
       
   210 				{
       
   211 				aMenuPane->SetItemDimmed(ELmkCmdSendDummy, EFalse);
       
   212 
       
   213                 // Use default "Send" item text from SendUI
       
   214 				iSender.DisplaySendMenuL( *aMenuPane, 1);
       
   215 				}
       
   216 	       	DimmMenuItemsL(aMenuPane);
       
   217 	        break;
       
   218 	        }
       
   219         default:
       
   220             {
       
   221             break;
       
   222             }
       
   223         }
       
   224     iMapNavInterface->HandleMenuOperationL(aResourceId, aMenuPane, ELmkCmdMnNav);
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CLmkPackageEditorImpl::ProcessCommandL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CLmkPackageEditorImpl::ProcessCommandL(TInt aCommandId)
       
   232     {
       
   233     CAknDialog::ProcessCommandL(aCommandId);
       
   234     iContextMenuBar->StopDisplayingMenuBar();
       
   235     // Override just a couple of CLmkEditorImpl implementations:
       
   236     switch (aCommandId)
       
   237         {
       
   238         case ELmkCmdSaveLm:
       
   239             {
       
   240             SaveLandmarkCmdL();
       
   241             break;
       
   242             }
       
   243             // fall through all send cmds:
       
   244         case ELmkCmdSendVia1:
       
   245         case ELmkCmdSendVia2:
       
   246         case ELmkCmdSendVia3:
       
   247         case ELmkCmdSendVia4:
       
   248         case ELmkCmdSendVia5:
       
   249         case ELmkCmdSendVia6:
       
   250         case ELmkCmdSendVia7:
       
   251         case ELmkCmdSendVia8:
       
   252         case ELmkCmdSendVia9:
       
   253         case ELmkCmdSendVia10:
       
   254         case ELmkCmdSend:
       
   255             {
       
   256             SendLandmarkCmdL(aCommandId);
       
   257             break;
       
   258             }
       
   259         case EAknSoftkeyContextOptions:
       
   260             {
       
   261             iContextMenuBar->TryDisplayContextMenuBarL();
       
   262             break;
       
   263             }
       
   264         default:
       
   265             {
       
   266             CLmkEditorImpl::ProcessCommandL(aCommandId);
       
   267             break;
       
   268             }
       
   269         }
       
   270     }
       
   271 
       
   272 // ----------------------------------------------------
       
   273 // CLmkPackageEditorImpl::SaveLandmarkCmdL
       
   274 // ----------------------------------------------------
       
   275 //
       
   276 void CLmkPackageEditorImpl::SaveLandmarkCmdL()
       
   277     {
       
   278     // Only one item is stored but API requires an array:
       
   279     RArray<TUint> importIndexes(1);
       
   280     CleanupClosePushL(importIndexes);
       
   281     User::LeaveIfError(importIndexes.Append(iItemIndex));
       
   282     CLmkSaveLandmarkUtils* saveLmUtils = CLmkSaveLandmarkUtils::NewL(iDb,
       
   283             iParser);
       
   284     CleanupStack::PushL(saveLmUtils);
       
   285     RArray<TCategoryName> newCategories;
       
   286     CleanupClosePushL(newCategories);
       
   287     TCategoryName newCategoryFound;
       
   288     TInt noOfNewCategories = saveLmUtils->CheckForNewCategoriesL(
       
   289             importIndexes, newCategoryFound, newCategories);
       
   290 
       
   291     if (saveLmUtils->CategoryAddConfirmationQueryL(noOfNewCategories,
       
   292             newCategoryFound))
       
   293         {
       
   294         iParser.StartImportingL(importIndexes, ETrue);// Save landmarks with new categories
       
   295         }
       
   296     else
       
   297         {
       
   298         iParser.StartImportingL(importIndexes, EFalse); //Save landmarks without new categories
       
   299         }
       
   300     CleanupStack::PopAndDestroy(); // newCategories
       
   301     // wait note
       
   302     iWaitNote = new (ELeave) CAknWaitDialog(NULL, ETrue);
       
   303     if (!iWaitNote->ExecuteLD(R_LMK_IMPORTING_WAIT_NOTE))
       
   304         {
       
   305         //making iWaitNote null, since framework destroys waitnote
       
   306         //dialog on pressing cancel.
       
   307         iWaitNote = NULL;
       
   308         iParser.CancelImporting();
       
   309         CleanupStack::PopAndDestroy(2);// saveLmUtils, importIndexes
       
   310         return;
       
   311         }
       
   312     // Saved confirmation note
       
   313     saveLmUtils->LmsSavedConfirmationNoteL(importIndexes, iItemIndex);
       
   314     CleanupStack::PopAndDestroy(2);// saveLmUtils, importIndexes
       
   315     }
       
   316 
       
   317 // ----------------------------------------------------
       
   318 // CLmkPackageEditorImpl::SendLandmarkCmdL
       
   319 // ----------------------------------------------------
       
   320 //
       
   321 void CLmkPackageEditorImpl::SendLandmarkCmdL(TInt aCommandId)
       
   322     {
       
   323     CLmkLandmark* lmk = iParser.LmkLandmarkLC(iItemIndex);
       
   324     iSender.SendSingleLandmarkL(aCommandId, *lmk);
       
   325     CleanupStack::PopAndDestroy();//lmk
       
   326     }
       
   327 
       
   328 // ----------------------------------------------------
       
   329 // CLmkPackageEditorImpl::UpdateMskOnArrowMoveForViewerL
       
   330 // ----------------------------------------------------
       
   331 //
       
   332 void CLmkPackageEditorImpl::UpdateMskOnArrowMoveForViewerL()
       
   333     {
       
   334     MLmkEditorField* field = iEditorFieldArray->Find(IdOfFocusControl());
       
   335     TUint type = field->LandmarkItemField().FieldType();
       
   336     switch (type)
       
   337         {
       
   338         case ECategories:
       
   339             {
       
   340             CEikButtonGroupContainer* cba =
       
   341                     CEikButtonGroupContainer::Current();
       
   342             cba->RemoveCommandFromStack(KMskCommandPos,
       
   343                     EAknSoftkeyContextOptions);
       
   344             AddMskCommandL(R_LM_MSK_SHOW, ELmkCmdShow);
       
   345             break;
       
   346             }
       
   347         default:
       
   348             {
       
   349             EnableMskMenuL();
       
   350             break;
       
   351             }
       
   352         }
       
   353     }
       
   354 
       
   355 // ----------------------------------------------------
       
   356 // CLmkPackageEditorImpl::EnableMskMenuL
       
   357 // ----------------------------------------------------
       
   358 //
       
   359 void CLmkPackageEditorImpl::EnableMskMenuL()
       
   360     {
       
   361     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   362     cba->RemoveCommandFromStack(KMskCommandPos, ELmkCmdShow);
       
   363     cba->SetCommandSetL(
       
   364             R_LMK_RECEIVED_VIEWER_SOFTKEYS_OPTIONS_BACK_CONTEXTOPTIONS);
       
   365     cba->MakeCommandVisible(EAknSoftkeyContextOptions, ETrue);
       
   366     iContextMenuBar->SetContextMenuTitleResourceId(
       
   367             R_LMK_MSGVIEWER_CONTEXT_MENUBAR);
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------
       
   371 // CLmkPackageEditorImpl::PostLayoutDynInitL
       
   372 // ----------------------------------------------------
       
   373 //
       
   374 void CLmkPackageEditorImpl::PostLayoutDynInitL()
       
   375     {
       
   376     CLmkEditorImpl::PostLayoutDynInitL();
       
   377     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   378     EnableMskMenuL();
       
   379     }
       
   380 // ----------------------------------------------------
       
   381 // CLmkPackageEditorImpl::DimmMenuItems
       
   382 // ----------------------------------------------------
       
   383 //
       
   384 void CLmkPackageEditorImpl::DimmMenuItemsL(CEikMenuPane* aMenuPane)
       
   385     {
       
   386     //not shown in package editor mode:
       
   387     aMenuPane->SetItemDimmed(ELmkCmdCategories, ETrue);
       
   388     aMenuPane->SetItemDimmed(ELmkCmdDeleteLm, ETrue);
       
   389     aMenuPane->SetItemDimmed(ELmkCmdSelectCategories, ETrue);
       
   390     aMenuPane->SetItemDimmed(ELmkCmdCurrentLocation, ETrue);
       
   391     aMenuPane->SetItemDimmed(ELmkCmdChangeIcon, ETrue);
       
   392     aMenuPane->SetItemDimmed(ELmkCmdEditTextLm, ETrue);
       
   393     //additional commands always dimmed in this class:
       
   394     aMenuPane->SetItemDimmed(ELmkCmdEditLm, ETrue);
       
   395     aMenuPane->SetItemDimmed(ELmkCmdCall, ETrue);
       
   396     aMenuPane->SetItemDimmed(ELmkCmdGoToUrl, ETrue);
       
   397     aMenuPane->SetItemDimmed(ELmkCmdClearPosInfo, ETrue);
       
   398     }
       
   399 
       
   400 #ifdef RD_SCALABLE_UI_V2
       
   401 // -----------------------------------------------------------------------------
       
   402 // CLmkPackageEditorImpl::HandleDialogPageEventL
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CLmkPackageEditorImpl::HandleDialogPageEventL(TInt /*aEventID*/)
       
   406     {
       
   407     // No Impl
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CLmkPackageEditorImpl::HandlePointerEventL
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 void CLmkPackageEditorImpl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   415     { 
       
   416     CAknForm::HandlePointerEventL(aPointerEvent);
       
   417     
       
   418     if (aPointerEvent.iType == TPointerEvent::EButton1Up && iIsDragging
       
   419             == EFalse)
       
   420         {
       
   421         iContextMenuBar->TryDisplayContextMenuBarL();
       
   422         }    
       
   423     if (aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   424         {
       
   425         iIsDragging = EFalse;
       
   426         }
       
   427     if (aPointerEvent.iType == TPointerEvent::EDrag)
       
   428         {
       
   429         iIsDragging = ETrue;
       
   430         }
       
   431     }
       
   432 #endif//RD_SCALABLE_UI_V2
       
   433 //  End of File