phonebookui/Phonebook/View/src/CPbkSetToneToGroup.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 *       Provides methods for Assign ringing tone to group members process.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkSetToneToGroup.h"
       
    22 #include <cntdef.h>
       
    23 #include <cntitem.h>
       
    24 #include <CPbkContactEngine.h>
       
    25 #include <CPbkContactItem.h>
       
    26 #include <TPbkContactItemField.h>
       
    27 #include <CPbkFieldInfo.h>
       
    28 #include <CPbkFieldsInfo.h>
       
    29 
       
    30 #include <PbkDebug.h>
       
    31 
       
    32 // LOCAL CONSTANTS AND MACROS
       
    33 
       
    34 /// The interval to test DB compression
       
    35 const TInt KCompressionInterval = 10;
       
    36 
       
    37 
       
    38 // ================= MEMBER FUNCTIONS =======================
       
    39 
       
    40 inline TBool CPbkSetToneToGroup::MoreContactsToSet() const
       
    41     {
       
    42     return (iContacts && iContacts->Count() > 0);
       
    43     }
       
    44 
       
    45 inline void CPbkSetToneToGroup::Cancel()
       
    46     {
       
    47     delete iContacts;
       
    48     iContacts = NULL;
       
    49     }
       
    50 
       
    51 inline CPbkSetToneToGroup::CPbkSetToneToGroup
       
    52         (CPbkContactEngine& aEngine) :
       
    53     iEngine(aEngine)
       
    54     {
       
    55     PBK_DEBUG_PRINT
       
    56         (PBK_DEBUG_STRING("CPbkSetToneToGroup::CPbkSetToneToGroup(0x%x)"), 
       
    57         this);
       
    58     }
       
    59 
       
    60 inline void CPbkSetToneToGroup::ConstructL
       
    61         (const CContactIdArray& aContacts,
       
    62         const TDesC& aRingingToneName)
       
    63     {
       
    64     iRingingToneFile = aRingingToneName.AllocL();
       
    65     iTotalContactsToSet = aContacts.Count();
       
    66     iContacts = CContactIdArray::NewL(&aContacts);
       
    67     iContacts->ReverseOrder();
       
    68     }
       
    69 
       
    70 EXPORT_C CPbkSetToneToGroup* CPbkSetToneToGroup::NewLC
       
    71         (CPbkContactEngine& aEngine,
       
    72         const CContactIdArray& aContacts,
       
    73         const TDesC& aRingingToneName)
       
    74     {
       
    75     CPbkSetToneToGroup* self = new(ELeave) CPbkSetToneToGroup(aEngine);
       
    76     CleanupStack::PushL(self);
       
    77     self->ConstructL(aContacts, aRingingToneName);
       
    78     return self;
       
    79     }
       
    80 
       
    81 CPbkSetToneToGroup::~CPbkSetToneToGroup()
       
    82     {
       
    83     PBK_DEBUG_PRINT
       
    84         (PBK_DEBUG_STRING("CPbkSetToneToGroup::~CPbkSetToneToGroup(0x%x)"), 
       
    85         this);
       
    86 
       
    87     delete iContacts;
       
    88     delete iRingingToneFile;
       
    89     }
       
    90 
       
    91 EXPORT_C const TDesC& CPbkSetToneToGroup::RingingToneFile() const
       
    92     {
       
    93     return *iRingingToneFile;
       
    94     }
       
    95 
       
    96 void CPbkSetToneToGroup::StepL()
       
    97     {
       
    98     PBK_DEBUG_PRINT
       
    99         (PBK_DEBUG_STRING("CPbkSetToneToGroup::StepL()"), 
       
   100         this);
       
   101     
       
   102     if (iSetCount % KCompressionInterval == 0)
       
   103         {
       
   104         iEngine.CheckFileSystemSpaceAndCompressL();
       
   105         }
       
   106 
       
   107     if (MoreContactsToSet())
       
   108         {
       
   109         const TInt index = iContacts->Count() - 1;
       
   110         const TContactItemId id = (*iContacts)[index];
       
   111 
       
   112         CPbkContactItem* item = iEngine.OpenContactLCX(id);
       
   113         SetRingingToneL(*item);
       
   114         iEngine.CommitContactL(*item);
       
   115         CleanupStack::PopAndDestroy(2); // item, lock
       
   116 
       
   117         iContacts->Remove(index);
       
   118         ++iSetCount;
       
   119 
       
   120         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("    set contact %d"), id);
       
   121         }
       
   122     }
       
   123 
       
   124 TInt CPbkSetToneToGroup::TotalNumberOfSteps()
       
   125     {
       
   126     return iTotalContactsToSet;
       
   127     }
       
   128 
       
   129 TBool CPbkSetToneToGroup::IsProcessDone() const
       
   130     {
       
   131     return !MoreContactsToSet();
       
   132     }
       
   133 
       
   134 void CPbkSetToneToGroup::ProcessFinished()
       
   135     {
       
   136     PBK_DEBUG_PRINT
       
   137         (PBK_DEBUG_STRING("CPbkSetToneToGroup::ProcessFinished()"), 
       
   138         this);
       
   139 
       
   140     Cancel();
       
   141     }
       
   142 
       
   143 TInt CPbkSetToneToGroup::HandleStepError(TInt aError)
       
   144     {
       
   145     PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkSetToneToGroup::HandleStepError(%d)"), aError);
       
   146 
       
   147     if (aError != KErrNone)
       
   148         {
       
   149         Cancel();
       
   150         }
       
   151 
       
   152     return aError;
       
   153     }
       
   154 
       
   155 void CPbkSetToneToGroup::ProcessCanceled()
       
   156     {
       
   157     PBK_DEBUG_PRINT
       
   158         (PBK_DEBUG_STRING("CPbkSetToneToGroup::ProcessCanceled()"), 
       
   159         this);
       
   160 
       
   161     Cancel();
       
   162     }
       
   163 
       
   164 void CPbkSetToneToGroup::SetRingingToneL
       
   165         (CPbkContactItem& aItem)
       
   166     {
       
   167     TPbkContactItemField* field = aItem.FindField(EPbkFieldIdPersonalRingingToneIndication);
       
   168 
       
   169     if (iRingingToneFile->Compare(KNullDesC) == 0)
       
   170         {
       
   171         // remove ringing tone field
       
   172         if (field)
       
   173             {
       
   174             aItem.RemoveField(aItem.FindFieldIndex(*field));
       
   175             }
       
   176         }
       
   177     else
       
   178         {
       
   179         // ringing tone selected
       
   180         if (field)
       
   181             {
       
   182             field->TextStorage()->SetTextL(*iRingingToneFile);
       
   183             }
       
   184         else
       
   185             {
       
   186             // create ringing tone field
       
   187             CPbkFieldInfo* fieldInfo = iEngine.FieldsInfo().Find(EPbkFieldIdPersonalRingingToneIndication);
       
   188             TPbkContactItemField& newField = aItem.AddFieldL(*fieldInfo);
       
   189             newField.TextStorage()->SetTextL(*iRingingToneFile);
       
   190             }
       
   191         }
       
   192     }
       
   193 
       
   194 //  End of File