landmarks/locationlandmarks/internalservices/src/EPos_PosLmIconHandler.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2005 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: handles icon paths in the database.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <d32dbms.h>
       
    22 #include    "EPos_PosLmIconHandler.h"
       
    23 #include    "EPos_CPosLmLocalDbAccess.h"
       
    24 #include    "EPos_PosLmLongTextColHandler.h"
       
    25 #include    "EPos_LandmarkDatabaseStructure.h"
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // PosLmIconHandler::GetIconPathIdL
       
    33 //
       
    34 // (other items were commented in a header).
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 void PosLmIconHandler::GetIconPathIdL(
       
    38     CPosLmLocalDbAccess& aDbAccess,
       
    39     const TDesC& aIconPath,
       
    40     TUint32& aIconPathId)
       
    41     {
       
    42     // First search icon table for icon path
       
    43     HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen+KMaxFileName);
       
    44     sql->Des().Format(KPosLmSqlFindString, &KPosLmIconIdCol, &KPosLmIconTable,
       
    45         &KPosLmIconPathCol, &aIconPath);
       
    46 
       
    47     RDbView view;
       
    48     aDbAccess.PrepareViewLC(
       
    49         CPosLmLocalDbAccess::EUpdatablePreparation, view, *sql);
       
    50 
       
    51     if (!view.NextL())
       
    52         {
       
    53         // Icon path not found. Add icon path to database.
       
    54         AddIconPathL(aDbAccess, aIconPath, aIconPathId);
       
    55         }
       
    56     else
       
    57         {
       
    58         // Icon path found. Fetch number.
       
    59         view.GetL();
       
    60         aIconPathId = view.ColUint32(1);
       
    61         }
       
    62 
       
    63     CleanupStack::PopAndDestroy(2, sql); //&view
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // PosLmIconHandler::GetIconPathL
       
    68 //
       
    69 // (other items were commented in a header).
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 TInt PosLmIconHandler::GetIconPathL(
       
    73     CPosLmLocalDbAccess& aDbAccess,
       
    74     TUint32 aIconPathId,
       
    75     TDes& aIconPath)
       
    76     {
       
    77     HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
       
    78     sql->Des().Format(KPosLmSqlFindUint, &KPosLmIconPathCol, &KPosLmIconTable,
       
    79         &KPosLmIconIdCol, aIconPathId);
       
    80 
       
    81     RDbView view;
       
    82     aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
       
    83         *sql);
       
    84 
       
    85     TInt iconPathFound = KErrNotFound;
       
    86 
       
    87     if (view.FirstL())
       
    88         {
       
    89         view.GetL();
       
    90         PosLmLongTextColHandler::ReadFromLongTextColumnL(aIconPath, view, 1);
       
    91         iconPathFound = KErrNone;
       
    92         }
       
    93 
       
    94     CleanupStack::PopAndDestroy(2, sql); //&view
       
    95 
       
    96     return iconPathFound;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // PosLmIconHandler::RemoveIconIfNotUsedL
       
   101 //
       
   102 // (other items were commented in a header).
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void PosLmIconHandler::RemoveIconIfNotUsedL(
       
   106     CPosLmLocalDbAccess& aDbAccess,
       
   107     const TUint32& aIconPathId)
       
   108     {
       
   109     // First check landmark table
       
   110     HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
       
   111     sql->Des().Format(KPosLmSqlFindUint, &KPosLmIconIdCol, &KPosLmLandmarkTable,
       
   112         &KPosLmIconIdCol, aIconPathId);
       
   113 
       
   114     RDbView view;
       
   115     aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
       
   116         *sql);
       
   117 
       
   118     if (view.IsEmptyL())
       
   119         {
       
   120         // Not found, check category table
       
   121         CleanupStack::PopAndDestroy(&view); // Delete old view
       
   122 
       
   123         sql->Des().Format(KPosLmSqlFindUint, &KPosLmIconIdCol,
       
   124             &KPosLmCategoryTable, &KPosLmIconIdCol, aIconPathId);
       
   125 
       
   126         aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation,
       
   127             view, *sql);
       
   128 
       
   129         if (view.IsEmptyL())
       
   130             {
       
   131             // Not found, remove icon path because it is not longer in use.
       
   132             sql->Des().Format(KPosLmSqlDeleteUint, &KPosLmIconTable,
       
   133                 &KPosLmIconIdCol, aIconPathId);
       
   134 
       
   135             aDbAccess.ExecuteL(*sql);
       
   136             }
       
   137         }
       
   138 
       
   139     CleanupStack::PopAndDestroy(2, sql); //&view
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // PosLmIconHandler::AddIconPathL
       
   144 //
       
   145 // (other items were commented in a header).
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void PosLmIconHandler::AddIconPathL(
       
   149     CPosLmLocalDbAccess& aDbAccess,
       
   150     const TDesC& aIconPath,
       
   151     TUint32& aIconPathId)
       
   152     {
       
   153     HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
       
   154     sql->Des().Format(KPosLmSqlSelect, &KPosLmSqlAll, &KPosLmIconTable);
       
   155 
       
   156     RDbView view;
       
   157     aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EAddPreparation, view, *sql);
       
   158 
       
   159     view.InsertL();
       
   160     PosLmLongTextColHandler::WriteToLongTextColumnL(aIconPath, view,
       
   161         EPosLmIcIconPathCol);
       
   162     view.PutL();
       
   163 
       
   164     aIconPathId = view.ColUint32(EPosLmIcIconIdCol);
       
   165 
       
   166     CleanupStack::PopAndDestroy(2, sql); //&view
       
   167     }
       
   168 
       
   169 //  End of File