landmarksui/commonui/src/CLmkLandmarkSelectorDlg.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     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:    Landmarks Selector dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "TLmkItemIdDbCombiInfo.h"
       
    22 #include "CLmkLandmarkSelectorDlg.h"
       
    23 #include "CLmkDlgCombiSelectorImpl.h"
       
    24 #include <lmkui.rsg>
       
    25 #include <landmarks.rsg>
       
    26 #include <lmkerrors.h>
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 /// Unnamed namespace for local definitions
       
    31 namespace {
       
    32 
       
    33 _LIT( KPanicMsg, "CLmkLandmarkSelectorDlg" );
       
    34 
       
    35 void Panic( TPanicCode aReason )
       
    36     {
       
    37     User::Panic( KPanicMsg, aReason );
       
    38     }
       
    39 }  // namespace
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CLmkLandmarkSelectorDlg::CLmkLandmarkSelectorDlg
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CLmkLandmarkSelectorDlg::CLmkLandmarkSelectorDlg()
       
    50     : iIsMultiSelector( ETrue ),
       
    51     iDatabaseUri( NULL )
       
    52     {
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CLmkLandmarkSelectorDlg::ConstructL
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CLmkLandmarkSelectorDlg::ConstructL()
       
    61     {
       
    62     // Open user specified db if it was set, else open the default landmarks db.
       
    63     if( iDatabaseUri )
       
    64         {
       
    65         iDbs.Append( CPosLandmarkDatabase::OpenL( iDatabaseUri->Des() ) );
       
    66         }
       
    67     else
       
    68         {
       
    69         iDbs.Append( CPosLandmarkDatabase::OpenL() );
       
    70         }
       
    71 	
       
    72 	iSelector = CLmkDlgCombiSelectorImpl::NewL( *(iDbs[0]) );
       
    73 	iSelector->SetEmptyDlgLabel(R_LMK_EMPTY_NO_LANDMARKS,R_LMK_GUIDE_CREATE_LANDMARK);
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CLmkLandmarkSelectorDlg::NewL
       
    78 // Two-phased constructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C CLmkLandmarkSelectorDlg* CLmkLandmarkSelectorDlg::NewL( )
       
    82     {
       
    83     CLmkLandmarkSelectorDlg* self = new( ELeave ) CLmkLandmarkSelectorDlg();
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop();
       
    87     return self;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CLmkLandmarkSelectorDlg::NewL
       
    92 // Two-phased constructor. Also sets the user specified landmark database whose
       
    93 // entries are to be shown in the selector ui.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C CLmkLandmarkSelectorDlg* CLmkLandmarkSelectorDlg::NewL( const TDesC&  aDatabaseUri )
       
    97     {
       
    98     if( aDatabaseUri.Length() == 0 )
       
    99 		    {
       
   100 		    User::Leave( KErrArgument );
       
   101 		  	}
       
   102     CLmkLandmarkSelectorDlg* self = new( ELeave ) CLmkLandmarkSelectorDlg();
       
   103     CleanupStack::PushL( self );
       
   104     self->iDatabaseUri = HBufC::NewLC( aDatabaseUri.Length() + 1 );
       
   105     CleanupStack::Pop( self->iDatabaseUri );
       
   106     self->iDatabaseUri->Des().FillZ();
       
   107     self->iDatabaseUri->Des().Copy( aDatabaseUri.Ptr() );
       
   108     self->ConstructL();
       
   109     CleanupStack::Pop();
       
   110     return self;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CLmkLandmarkSelectorDlg::~CLmkLandmarkSelectorDlg
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C CLmkLandmarkSelectorDlg::~CLmkLandmarkSelectorDlg()
       
   118     {
       
   119     if ( iDestroyedPtr )
       
   120         {
       
   121         *iDestroyedPtr = ETrue;
       
   122         }
       
   123 
       
   124     if ( iDatabaseUri )
       
   125         {
       
   126         delete iDatabaseUri;
       
   127         }
       
   128     delete iSelector;
       
   129     if (iDbs.Count() > 0 )
       
   130         {
       
   131         delete iDbs[0];
       
   132         iDbs.Close();
       
   133         }
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CLmkLandmarkSelectorDlg::SetMopParent
       
   138 // ?implementation_description
       
   139 // (other items were commented in a header).
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C void CLmkLandmarkSelectorDlg::SetMopParent( MObjectProvider* aParent )
       
   143     {
       
   144     __ASSERT_ALWAYS( iSelector, Panic( KLmkPanicNullMember ) );
       
   145     iSelector->SetMopParent( aParent );
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CLmkLandmarkSelectorDlg::ExecuteLD
       
   150 // ?implementation_description
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 // For multiple database support
       
   155 
       
   156 EXPORT_C TInt CLmkLandmarkSelectorDlg::ExecuteLD( TLmkItemIdDbCombiInfo& aSelected )
       
   157     {
       
   158     __ASSERT_ALWAYS( iSelector, Panic( KLmkPanicNullMember ) );
       
   159 
       
   160     // "D" function semantics
       
   161     CleanupStack::PushL( this );
       
   162     TBool thisDestroyed( EFalse );
       
   163     iDestroyedPtr = &thisDestroyed;
       
   164 
       
   165     TPosLmItemId selectedId;
       
   166     TInt result = iSelector->ExecuteL( selectedId );
       
   167 
       
   168 	//Fill selected items only if user has clicked Ok
       
   169     if( result )
       
   170 		{
       
   171 		aSelected.SetItemId( selectedId );
       
   172 		
       
   173 		// if user specified db present, set this as the selected item's db,
       
   174 		// else set default landmarks db.
       
   175 		if( iDatabaseUri )
       
   176 		    {
       
   177 		    aSelected.SetLmDb( CPosLandmarkDatabase::OpenL( iDatabaseUri->Des() ) );
       
   178 		    }
       
   179 		else
       
   180 		    {
       
   181 		    aSelected.SetLmDb( CPosLandmarkDatabase::OpenL() );
       
   182 		    }
       
   183 		
       
   184 		}	//end if(result)
       
   185 
       
   186     if ( thisDestroyed )
       
   187         {
       
   188         // this object has been deleted already
       
   189         CleanupStack::Pop( this );
       
   190         }
       
   191     else
       
   192         {
       
   193         CleanupStack::PopAndDestroy( this );
       
   194         }
       
   195 
       
   196     return result;
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CLmkLandmarkSelectorDlg::ExecuteLD
       
   201 // ?implementation_description
       
   202 // (other items were commented in a header).
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205  // For multiple database support
       
   206 EXPORT_C TInt CLmkLandmarkSelectorDlg::ExecuteLD(
       
   207     RArray<TLmkItemIdDbCombiInfo>& aSelectedItems )
       
   208     {
       
   209     __ASSERT_ALWAYS( iSelector, Panic( KLmkPanicNullMember ) );
       
   210 
       
   211     // "D" function semantics
       
   212     CleanupStack::PushL( this );
       
   213     TBool thisDestroyed( EFalse );
       
   214     iDestroyedPtr = &thisDestroyed;
       
   215     RArray<TPosLmItemId> selectedItems;
       
   216     selectedItems.Reset();
       
   217     for(TInt i = 0; i < aSelectedItems.Count(); i++)
       
   218         {
       
   219         TLmkItemIdDbCombiInfo getItem = aSelectedItems[i];
       
   220         selectedItems.Append(getItem.GetItemId());
       
   221         }
       
   222     TInt result = iSelector->ExecuteL( selectedItems );
       
   223     aSelectedItems.Reset();
       
   224    	//Fill items only if user has clicked Ok
       
   225    	TInt itemCount = selectedItems.Count();
       
   226     if(itemCount > 0)
       
   227 		{
       
   228 		CPosLandmarkDatabase* pDb;
       
   229 		if( iDatabaseUri )
       
   230 		    {
       
   231 		    pDb = CPosLandmarkDatabase::OpenL( iDatabaseUri->Des() );
       
   232 		    }
       
   233 		else
       
   234 		    {
       
   235 		    pDb = CPosLandmarkDatabase::OpenL();
       
   236 		    }
       
   237 		
       
   238 
       
   239 		for (TInt i = 0; i < itemCount; i++)
       
   240 			{
       
   241 			TLmkItemIdDbCombiInfo selItem;
       
   242 			selItem.SetItemId(selectedItems[i]);
       
   243 			selItem.SetLmDb(pDb);
       
   244 			aSelectedItems.Append(selItem);
       
   245 			}
       
   246 		}	//end if(result)
       
   247 
       
   248 	selectedItems.Close();
       
   249     if ( thisDestroyed )
       
   250         {
       
   251         // this object has been deleted already
       
   252         CleanupStack::Pop( this );
       
   253         }
       
   254     else
       
   255         {
       
   256         CleanupStack::PopAndDestroy( this );
       
   257         }
       
   258 
       
   259     return result;
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CLmkLandmarkSelectorDlg::SetDialogTitleL
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C void CLmkLandmarkSelectorDlg::SetDialogTitleL(const TDesC& aTitle)
       
   267     {
       
   268     __ASSERT_ALWAYS( iSelector, Panic( KLmkPanicNullMember ) );
       
   269     iSelector->SetDialogTitleL(aTitle);
       
   270     }
       
   271 
       
   272 //  End of File