applicationmanagement/server/src/AMAppHideUtil.cpp
changeset 42 aa33c2cb9a50
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
       
     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: Implementation of applicationmanagement components
       
    15  *
       
    16  */
       
    17 
       
    18 #include <centralrepository.h>
       
    19 #include "AMAppHideUtil.h"
       
    20 #include "debug.h"
       
    21 
       
    22 using namespace NApplicationManagement;
       
    23 
       
    24 // The uid list delimiter
       
    25 static const TChar KUidDelimiter = ',';
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CAMAppHideUtil::CAMAppHideUtil()
       
    29 // -----------------------------------------------------------------------------
       
    30 CAMAppHideUtil::CAMAppHideUtil() :
       
    31     iChanged(EFalse)
       
    32     {
       
    33 
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CAMAppHideUtil::ConstructL()
       
    38 // -----------------------------------------------------------------------------
       
    39 void CAMAppHideUtil::ConstructL()
       
    40     {
       
    41     LoadUidsL();
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CAMAppHideUtil::~CAMAppHideUtil()
       
    46 // -----------------------------------------------------------------------------
       
    47 CAMAppHideUtil::~CAMAppHideUtil()
       
    48     {
       
    49     iHiddenUids.Close();
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CAMAppHideUtil::NewL()
       
    54 // -----------------------------------------------------------------------------
       
    55 CAMAppHideUtil* CAMAppHideUtil::NewL()
       
    56     {
       
    57     CAMAppHideUtil *me = new ( ELeave ) CAMAppHideUtil();
       
    58     CleanupStack::PushL(me);
       
    59     me->ConstructL();
       
    60     CleanupStack::Pop(me);
       
    61     return me;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CAMAppHideUtil::AddUidL(const TUid& aUid )
       
    66 // -----------------------------------------------------------------------------
       
    67 void CAMAppHideUtil::AddUidL(const TUid& aUid, TBool aPersist /*= EFalse */)
       
    68     {
       
    69     TInt idx(iHiddenUids.Find(aUid));
       
    70     if (idx == KErrNotFound)
       
    71         {
       
    72         TInt err(iHiddenUids.Append(aUid) );
       
    73         if (err == KErrNone)
       
    74             {
       
    75             iChanged = ETrue;
       
    76             if (aPersist)
       
    77                 {
       
    78                 PersistUidsL();
       
    79                 }
       
    80             }
       
    81         else
       
    82             {
       
    83             RDEBUG_2( "Failed to append uid to hidden list: %d", err );
       
    84             }
       
    85         }
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CAMAppHideUtil::RemoveUidL( const TUid& aUid )
       
    90 // -----------------------------------------------------------------------------
       
    91 void CAMAppHideUtil::RemoveUidL(const TUid& aUid, TBool aPersist /*= EFalse */)
       
    92     {
       
    93     TInt idx(iHiddenUids.Find(aUid));
       
    94     if (idx != KErrNotFound)
       
    95         {
       
    96         iHiddenUids.Remove(idx);
       
    97         iChanged = ETrue;
       
    98         if (aPersist)
       
    99             {
       
   100             PersistUidsL();
       
   101             }
       
   102         }
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CAMAppHideUtil::PersistUid( const TUid &aUid, TDes &aBuf, TBool aHasMore )
       
   107 // -----------------------------------------------------------------------------
       
   108 void CAMAppHideUtil::PersistUid(const TUid &aUid, TDes &aBuf, TBool aHasMore) const
       
   109     {
       
   110     aBuf.AppendNumFixedWidth(aUid.iUid, EHex, 8);
       
   111     if (aHasMore)
       
   112         {
       
   113         aBuf.Append(KUidDelimiter);
       
   114         }
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CAMAppHideUtil::PersistUidsL()
       
   119 // -----------------------------------------------------------------------------
       
   120 void CAMAppHideUtil::PersistUidsL()
       
   121     {
       
   122     TInt err = KErrNone;
       
   123     if (iChanged)
       
   124         {
       
   125         TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   126         RDEBUG_2( "PersistUids: count %d", iHiddenUids.Count() );
       
   127         for (TInt i(iHiddenUids.Count() - 1); i >= 0; --i)
       
   128             {
       
   129             RDEBUG_3( "PersistUids: cur %d %x", i,iHiddenUids[i].iUid );
       
   130             PersistUid(iHiddenUids[i], buf, i > 0) ;
       
   131             }
       
   132         /*CRepository *rep = CRepository::NewLC(KCRUidMenu);
       
   133         TInt err(rep->Set(KMenuHideApplication, buf) );
       
   134         CleanupStack::PopAndDestroy(rep);*/
       
   135         if (err != KErrNone)
       
   136             {
       
   137             RDEBUG_2( "PersistUids: ERROR failed to set key: %d", err );
       
   138             User::Leave(err);
       
   139             }
       
   140         RDEBUG_2( "CAMAppHideUtil::PersistUidsL - Saved '%S'", &buf);
       
   141         iChanged = EFalse;
       
   142         }
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CAMAppHideUtil::ParseUid( TLex &, TUid &aUid ) 
       
   147 // -----------------------------------------------------------------------------
       
   148 TInt CAMAppHideUtil::ParseUid(TLex &aLex, TUid &aUid) const
       
   149     {
       
   150     aUid = TUid::Null();
       
   151     aLex.Mark();
       
   152     while (aLex.Peek().IsHexDigit() )
       
   153         {
       
   154         aLex.Inc();
       
   155         }
       
   156     TPtrC uidToken = aLex.MarkedToken();
       
   157     TLex uidLex(uidToken);
       
   158     TInt err(uidLex.Val( (TUint32& )aUid.iUid, EHex) );
       
   159     return err;
       
   160     }
       
   161 
       
   162 // ------------------------------------------------------------------------------
       
   163 // CAMAppHideUtil::SkipDelim( TLex & )
       
   164 // -----------------------------------------------------------------------------
       
   165 TBool CAMAppHideUtil::SkipDelim(TLex &aLex) const
       
   166     {
       
   167     TBool ret(EFalse);
       
   168     if (aLex.Peek() == KUidDelimiter)
       
   169         {
       
   170         aLex.Inc();
       
   171         ret = ETrue;
       
   172         }
       
   173     return (ret );
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CAMAppHideUtil::LoadUidsL()
       
   178 // -----------------------------------------------------------------------------
       
   179 void CAMAppHideUtil::LoadUidsL()
       
   180     {
       
   181     TInt err = KErrNone;
       
   182     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   183     /*CRepository *rep = CRepository::NewLC(KCRUidMenu);
       
   184     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   185     TInt err(rep->Get(KMenuHideApplication, buf) );
       
   186     CleanupStack::PopAndDestroy(rep);*/
       
   187     if (err == KErrNone)
       
   188         {
       
   189         RDEBUG_2( "CAMAppHideUtil::LoadUidsL - Loading '%S'", &buf);
       
   190         TLex lex(buf);
       
   191         TUid aUid(TUid::Null());
       
   192         do
       
   193             {
       
   194             err = ParseUid(lex, aUid) ;
       
   195             }
       
   196         while (err == KErrNone && iHiddenUids.Append(aUid) == KErrNone
       
   197                 && !lex.Eos() && SkipDelim(lex) );
       
   198         }
       
   199     RDEBUG_2( "CAMAppHideUtil::LoadUidsL-Loaded (last parsing status: %d)", err);
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CAMAppHideUtil::Reset()
       
   204 // -----------------------------------------------------------------------------
       
   205 void CAMAppHideUtil::Reset()
       
   206     {
       
   207     if (iHiddenUids.Count() > 0)
       
   208         {
       
   209         iChanged = ETrue;
       
   210         }
       
   211     iHiddenUids.Reset();
       
   212     }
       
   213 
       
   214 // End of File