phonebookui/Phonebook/App/src/CPbkSetToneToGroupCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
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 phonebook assign ringing tone to group members command methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkSetToneToGroupCmd.h"
       
    22 #include <StringLoader.h>
       
    23 #include <eikprogi.h>
       
    24 #include <AknNoteWrappers.h>
       
    25 #include <CPbkContactEngine.h>
       
    26 #include <cntitem.h>
       
    27 #include <Phonebook.rsg>
       
    28 #include <PbkView.rsg>
       
    29 #include <CPbkSetToneToGroup.h>
       
    30 #include <MPbkCommandObserver.h>
       
    31 
       
    32 
       
    33 #include <pbkdebug.h>
       
    34 
       
    35 /// Unnamed namespace for local definitions
       
    36 namespace {
       
    37 
       
    38 // LOCAL DEBUG CODE
       
    39 #ifdef _DEBUG
       
    40 enum TPanicCode
       
    41     {
       
    42     EPanicPreCond_ResetWhenDestroyed = 1,
       
    43     EPanicLogic_ConstructL
       
    44     };
       
    45 
       
    46 void Panic(TPanicCode aReason)
       
    47     {
       
    48     _LIT(KPanicText, "CPbkSetToneToGroupCmd");
       
    49     User::Panic(KPanicText,aReason);
       
    50     }
       
    51 #endif
       
    52 
       
    53 } // namespace
       
    54 
       
    55 
       
    56 // ================= MEMBER FUNCTIONS =======================
       
    57 
       
    58 inline CPbkSetToneToGroupCmd::CPbkSetToneToGroupCmd
       
    59         (CPbkContactEngine& aEngine) :
       
    60     CActive(EPriorityIdle),
       
    61     iEngine(aEngine),
       
    62     iDialogDismissed(ETrue) // there is no dialog at this point
       
    63     {
       
    64     PBK_DEBUG_PRINT
       
    65         (PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::CPbkSetToneToGroupCmd(0x%x)"), 
       
    66         this);
       
    67     
       
    68     CActiveScheduler::Add(this);
       
    69     }
       
    70 
       
    71 inline void CPbkSetToneToGroupCmd::ConstructL
       
    72         (TContactItemId aGroupId,
       
    73         const TDesC& aRingingToneName)
       
    74     {
       
    75     CContactGroup* group = iEngine.ReadContactGroupL(aGroupId);
       
    76     CleanupStack::PushL(group);
       
    77     const CContactIdArray* groupContainsIds = group->ItemsContained();
       
    78 
       
    79     //Logic:
       
    80     __ASSERT_DEBUG(groupContainsIds, Panic(EPanicLogic_ConstructL));
       
    81 
       
    82     iSetToneToGroupProcess = CPbkSetToneToGroup::NewLC
       
    83 		(iEngine, *groupContainsIds, aRingingToneName);
       
    84     CleanupStack::Pop(iSetToneToGroupProcess);
       
    85 
       
    86     CleanupStack::PopAndDestroy(); // group
       
    87     }
       
    88 
       
    89 CPbkSetToneToGroupCmd* CPbkSetToneToGroupCmd::NewL
       
    90         (CPbkContactEngine& aEngine,
       
    91         TContactItemId aGroupId,
       
    92         const TDesC& aRingingToneName)
       
    93     {
       
    94     CPbkSetToneToGroupCmd* self = new(ELeave) CPbkSetToneToGroupCmd(aEngine);
       
    95     CleanupStack::PushL(self);
       
    96     self->ConstructL(aGroupId, aRingingToneName);
       
    97     CleanupStack::Pop(self);
       
    98     return self;
       
    99     }
       
   100 
       
   101 void CPbkSetToneToGroupCmd::ResetWhenDestroyed
       
   102         (CPbkSetToneToGroupCmd** aSelfPtr)
       
   103     {
       
   104     __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr==this, 
       
   105         Panic(EPanicPreCond_ResetWhenDestroyed));
       
   106 
       
   107     iSelfPtr = aSelfPtr;
       
   108     }
       
   109 
       
   110 CPbkSetToneToGroupCmd::~CPbkSetToneToGroupCmd()
       
   111     {
       
   112     PBK_DEBUG_PRINT
       
   113         (PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::~CPbkSetToneToGroupCmd(0x%x)"), 
       
   114         this);
       
   115 
       
   116     Cancel();
       
   117     DeleteProgressNote();
       
   118     delete iSetToneToGroupProcess;
       
   119 
       
   120     if (iSelfPtr)
       
   121         {
       
   122         *iSelfPtr = NULL;
       
   123         }
       
   124     iDestroyed = ETrue;
       
   125     }
       
   126 
       
   127 void CPbkSetToneToGroupCmd::ExecuteLD()
       
   128     {
       
   129     PBK_DEBUG_PRINT
       
   130         (PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::ExecuteLD(0x%x)"), 
       
   131         this);
       
   132     CleanupStack::PushL(this);
       
   133 
       
   134     // delete previous note    
       
   135     DeleteProgressNote();
       
   136 
       
   137     // Start tone setting process. ProcessFinished() will be called when execution
       
   138     // is finished.
       
   139     CAknProgressDialog* progressDialog = new(ELeave) CAknProgressDialog(
       
   140             reinterpret_cast<CEikDialog**>(NULL), ETrue);
       
   141     progressDialog->PrepareLC(R_QTN_PHOB_WNOTE_SET_RTONE);
       
   142     iProgressDlgInfo = progressDialog->GetProgressInfoL();
       
   143     iProgressDlgInfo->SetFinalValue(iSetToneToGroupProcess->TotalNumberOfSteps());
       
   144     progressDialog->SetCallback(this);
       
   145     iDialogDismissed = EFalse;
       
   146     progressDialog->RunLD();
       
   147 
       
   148     iProgressDialog = progressDialog;
       
   149 
       
   150     // issue request for entry assignation
       
   151     IssueRequest();
       
   152 
       
   153     CleanupStack::Pop(); // this
       
   154     }
       
   155 
       
   156 void CPbkSetToneToGroupCmd::AddObserver
       
   157         (MPbkCommandObserver& aObserver)
       
   158     {
       
   159     iCommandObserver = &aObserver;
       
   160     }
       
   161 
       
   162 void CPbkSetToneToGroupCmd::DoCancel()
       
   163     {
       
   164     }
       
   165 
       
   166 void CPbkSetToneToGroupCmd::RunL()
       
   167     {
       
   168     PBK_DEBUG_PRINT
       
   169         (PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::StepL()"), 
       
   170         this);
       
   171 
       
   172     if (!iSetToneToGroupProcess->IsProcessDone() && !iDialogDismissed)
       
   173         {
       
   174         // process one step
       
   175         iSetToneToGroupProcess->StepL();
       
   176         ++iSetCount;
       
   177         
       
   178         // Incrementing progress of the process
       
   179         iProgressDlgInfo->SetAndDraw(iSetCount);
       
   180 
       
   181         // issue request to delete next item
       
   182         IssueRequest();
       
   183         }
       
   184     else
       
   185         {
       
   186         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::RunL process completed start"));
       
   187 
       
   188         // show process completion note
       
   189         TParse toneName;
       
   190         toneName.Set(iSetToneToGroupProcess->RingingToneFile(), NULL, NULL);
       
   191     
       
   192         HBufC* noteText = NULL;
       
   193         if (toneName.Name().Length() == 0)
       
   194             {
       
   195             HBufC* defaultName = CCoeEnv::Static()->AllocReadResourceLC(R_QTN_PHOP_SELI_DEFAULT_RTONE);
       
   196             noteText = StringLoader::LoadL(R_QTN_PHOB_NOTE_RTONE_SET_TO_GRP, *defaultName);
       
   197             CleanupStack::PopAndDestroy(); // defaultName
       
   198             CleanupStack::PushL(noteText);
       
   199             }
       
   200         else
       
   201             {
       
   202             noteText = StringLoader::LoadLC(R_QTN_PHOB_NOTE_RTONE_SET_TO_GRP, toneName.Name());
       
   203             }
       
   204 
       
   205         CAknConfirmationNote* noteDlg = new (ELeave) CAknConfirmationNote;
       
   206         noteDlg->ExecuteLD(*noteText);
       
   207         CleanupStack::PopAndDestroy(); // notetext
       
   208 
       
   209         // process is completed, all entries have been set
       
   210         ProcessFinished(*iSetToneToGroupProcess);
       
   211 
       
   212         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::RunL process completed end"));
       
   213         }
       
   214 
       
   215     PBK_DEBUG_PRINT
       
   216         (PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::RunL end")); 
       
   217     }
       
   218 
       
   219 TInt CPbkSetToneToGroupCmd::RunError
       
   220         (TInt aError)
       
   221     {
       
   222     TInt result = iSetToneToGroupProcess->HandleStepError(aError);
       
   223     Cancel();
       
   224     ProcessFinished(*iSetToneToGroupProcess);
       
   225     return result;    
       
   226     }
       
   227         
       
   228 void CPbkSetToneToGroupCmd::ProcessFinished(MPbkBackgroundProcess& /*aProcess*/)
       
   229     {
       
   230     PBK_DEBUG_PRINT
       
   231         (PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::ProcessFinished(0x%x)"), 
       
   232         this);
       
   233 
       
   234     DeleteProgressNote();
       
   235     }
       
   236 
       
   237 void CPbkSetToneToGroupCmd::DeleteProgressNote()
       
   238     {
       
   239     PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::DeleteProgressNote start"));
       
   240 
       
   241     if (iProgressDialog && !iDialogDismissed)
       
   242         {
       
   243         // deletes the dialog
       
   244         TRAPD(err, iProgressDialog->ProcessFinishedL());
       
   245         if (err != KErrNone)
       
   246             {
       
   247             delete iProgressDialog;
       
   248             }
       
   249         iProgressDialog = NULL;
       
   250         }
       
   251 
       
   252     PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::DeleteProgressNote end"));
       
   253     }
       
   254 
       
   255 void CPbkSetToneToGroupCmd::IssueRequest()
       
   256     {
       
   257     TRequestStatus* status = &iStatus;
       
   258     User::RequestComplete(status, KErrNone);
       
   259     SetActive();
       
   260     }
       
   261 
       
   262 void CPbkSetToneToGroupCmd::DialogDismissedL
       
   263         (TInt /*aButtonId*/)
       
   264     {
       
   265     PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkSetToneToGroupCmd::DialogDismissedL"));
       
   266     iDialogDismissed = ETrue;
       
   267     
       
   268     // notify command owner that the command has finished
       
   269     iCommandObserver->CommandFinished(*this);
       
   270     }
       
   271 
       
   272 //  End of File