calendarui/controller/src/calenviewpopulator.cpp
author hgs
Wed, 03 Nov 2010 17:12:22 +0530
changeset 89 b57382753122
child 67 1539a383d7b6
permissions -rw-r--r--
201045
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
89
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Calendar view populator active object
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// INCLUDES
hgs
parents:
diff changeset
    20
#include <calencontext.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
//debug
hgs
parents:
diff changeset
    23
#include "calendarui_debug.h"
hgs
parents:
diff changeset
    24
#include "calenviewpopulator.h"
hgs
parents:
diff changeset
    25
#include "calencontroller.h"
hgs
parents:
diff changeset
    26
#include "calenglobaldata.h"
hgs
parents:
diff changeset
    27
#include "calennotifier.h"
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
#include <eikenv.h> // For CEikonEnv
hgs
parents:
diff changeset
    30
#include <apgtask.h>
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    33
// CCalenViewPopulator::NewL
hgs
parents:
diff changeset
    34
// 1st phase of construction
hgs
parents:
diff changeset
    35
// (other items were commented in a header).
hgs
parents:
diff changeset
    36
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    37
//
hgs
parents:
diff changeset
    38
CCalenViewPopulator* CCalenViewPopulator::NewL( CCalenController& aController )
hgs
parents:
diff changeset
    39
    {
hgs
parents:
diff changeset
    40
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
    41
hgs
parents:
diff changeset
    42
    CCalenViewPopulator* self = new( ELeave ) CCalenViewPopulator( aController );
hgs
parents:
diff changeset
    43
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    44
    self->ConstructL();
hgs
parents:
diff changeset
    45
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
    48
    return self;
hgs
parents:
diff changeset
    49
    }
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    52
// CCalenViewPopulator::CCalenViewPopulator
hgs
parents:
diff changeset
    53
// C++ constructor.
hgs
parents:
diff changeset
    54
// (other items were commented in a header).
hgs
parents:
diff changeset
    55
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    56
//
hgs
parents:
diff changeset
    57
CCalenViewPopulator::CCalenViewPopulator( CCalenController& aController )
hgs
parents:
diff changeset
    58
    : CActive( EPriorityStandard ),
hgs
parents:
diff changeset
    59
      iController( aController ),
hgs
parents:
diff changeset
    60
      iNeedsInstanceView( EFalse ),
hgs
parents:
diff changeset
    61
      iNeedsEntryView( EFalse )
hgs
parents:
diff changeset
    62
    {
hgs
parents:
diff changeset
    63
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
    CActiveScheduler::Add( this );
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
    68
    }
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
// CCalenViewPopulator::ConstructL
hgs
parents:
diff changeset
    72
// 2nd phase of construction.
hgs
parents:
diff changeset
    73
// (other items were commented in a header).
hgs
parents:
diff changeset
    74
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    75
//
hgs
parents:
diff changeset
    76
void CCalenViewPopulator::ConstructL()
hgs
parents:
diff changeset
    77
    {
hgs
parents:
diff changeset
    78
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
    iController.RegisterForNotificationsL( this, ECalenNotifyEntryInstanceViewCreated );
hgs
parents:
diff changeset
    81
    iGlobalData = CCalenGlobalData::InstanceL();
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
    84
    }
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    87
// CCalenViewPopulator::~CCalenViewPopulator
hgs
parents:
diff changeset
    88
// Destructor.
hgs
parents:
diff changeset
    89
// (other items were commented in a header).
hgs
parents:
diff changeset
    90
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    91
//
hgs
parents:
diff changeset
    92
CCalenViewPopulator::~CCalenViewPopulator()
hgs
parents:
diff changeset
    93
    {
hgs
parents:
diff changeset
    94
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
    95
hgs
parents:
diff changeset
    96
    Cancel();
hgs
parents:
diff changeset
    97
    iController.CancelNotifications( this );
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
    if( iGlobalData )
hgs
parents:
diff changeset
   100
        {
hgs
parents:
diff changeset
   101
        iGlobalData->Release();
hgs
parents:
diff changeset
   102
        }
hgs
parents:
diff changeset
   103
hgs
parents:
diff changeset
   104
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   105
    }
hgs
parents:
diff changeset
   106
hgs
parents:
diff changeset
   107
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   108
// CCalenViewPopulator::DoCancel
hgs
parents:
diff changeset
   109
// From CActive. Do nothing.
hgs
parents:
diff changeset
   110
// (other items were commented in a header).
hgs
parents:
diff changeset
   111
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   112
//
hgs
parents:
diff changeset
   113
void CCalenViewPopulator::DoCancel()
hgs
parents:
diff changeset
   114
    {
hgs
parents:
diff changeset
   115
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
    iStatus = KErrCancel;
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   120
    }
hgs
parents:
diff changeset
   121
hgs
parents:
diff changeset
   122
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   123
// CCalenViewPopulator::RunL
hgs
parents:
diff changeset
   124
// From CActive.
hgs
parents:
diff changeset
   125
// (other items were commented in a header).
hgs
parents:
diff changeset
   126
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   127
//
hgs
parents:
diff changeset
   128
void CCalenViewPopulator::RunL()
hgs
parents:
diff changeset
   129
    {
hgs
parents:
diff changeset
   130
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
    ASSERT( iPopulatingView );
hgs
parents:
diff changeset
   133
    iPopulationStep = iPopulatingView->ActiveStepL();
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
    switch( iPopulationStep )
hgs
parents:
diff changeset
   136
        {
hgs
parents:
diff changeset
   137
        case CCalenView::EKeepGoing:
hgs
parents:
diff changeset
   138
        	{
hgs
parents:
diff changeset
   139
        	SetActive();
hgs
parents:
diff changeset
   140
            TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   141
            User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   142
        	}
hgs
parents:
diff changeset
   143
            break;
hgs
parents:
diff changeset
   144
        case CCalenView::EWaitForInstanceView:
hgs
parents:
diff changeset
   145
        	{
hgs
parents:
diff changeset
   146
        	RArray<TInt> colIdArray;
hgs
parents:
diff changeset
   147
        	iController.GetActiveCollectionidsL(colIdArray);
hgs
parents:
diff changeset
   148
        	if(colIdArray.Count() > 0)
hgs
parents:
diff changeset
   149
        	    {
hgs
parents:
diff changeset
   150
        	    if( iGlobalData->InstanceViewL(colIdArray) )
hgs
parents:
diff changeset
   151
        	        {
hgs
parents:
diff changeset
   152
        	        SetActive();
hgs
parents:
diff changeset
   153
        	        TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   154
        	        User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   155
        	        }
hgs
parents:
diff changeset
   156
        	    else
hgs
parents:
diff changeset
   157
        	        {
hgs
parents:
diff changeset
   158
        	        iNeedsInstanceView = ETrue;
hgs
parents:
diff changeset
   159
        	        // Wait for notification.
hgs
parents:
diff changeset
   160
        	        }
hgs
parents:
diff changeset
   161
        	    }
hgs
parents:
diff changeset
   162
        	else 
hgs
parents:
diff changeset
   163
        	    {
hgs
parents:
diff changeset
   164
        	    if( iGlobalData->InstanceViewL() )
hgs
parents:
diff changeset
   165
                    {
hgs
parents:
diff changeset
   166
                    SetActive();
hgs
parents:
diff changeset
   167
                    TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   168
                    User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   169
                    }
hgs
parents:
diff changeset
   170
                else
hgs
parents:
diff changeset
   171
                    {
hgs
parents:
diff changeset
   172
                    iNeedsInstanceView = ETrue;
hgs
parents:
diff changeset
   173
                    // Wait for notification.
hgs
parents:
diff changeset
   174
                    }
hgs
parents:
diff changeset
   175
        	    }
hgs
parents:
diff changeset
   176
        	colIdArray.Reset();
hgs
parents:
diff changeset
   177
        	 }
hgs
parents:
diff changeset
   178
            break;
hgs
parents:
diff changeset
   179
        case CCalenView::EWaitForEntryView:
hgs
parents:
diff changeset
   180
            {
hgs
parents:
diff changeset
   181
            if( iGlobalData->EntryViewL() )
hgs
parents:
diff changeset
   182
                {
hgs
parents:
diff changeset
   183
                SetActive();
hgs
parents:
diff changeset
   184
                TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   185
                User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   186
                }
hgs
parents:
diff changeset
   187
            else
hgs
parents:
diff changeset
   188
                {
hgs
parents:
diff changeset
   189
                iNeedsEntryView = ETrue;
hgs
parents:
diff changeset
   190
                // Wait for notification.
hgs
parents:
diff changeset
   191
                }
hgs
parents:
diff changeset
   192
            }
hgs
parents:
diff changeset
   193
            break;
hgs
parents:
diff changeset
   194
        case CCalenView::EDone:
hgs
parents:
diff changeset
   195
        	{
hgs
parents:
diff changeset
   196
        	iPopulatingView = NULL;
hgs
parents:
diff changeset
   197
            iController.Notifier().BroadcastNotification( ECalenNotifyViewPopulationComplete );
hgs
parents:
diff changeset
   198
            
hgs
parents:
diff changeset
   199
            if( iController.IsLaunchFromExternalApp() )
hgs
parents:
diff changeset
   200
                {
hgs
parents:
diff changeset
   201
                CEikonEnv* eikenv = CEikonEnv::Static();
hgs
parents:
diff changeset
   202
                iController.SetLaunchFromExternalApp( EFalse );
hgs
parents:
diff changeset
   203
                const TUid KCalendarAppUID = { 0x10005901 };
hgs
parents:
diff changeset
   204
                TApaTaskList taskList( eikenv->WsSession() );
hgs
parents:
diff changeset
   205
                TApaTask task = taskList.FindApp( KCalendarAppUID );
hgs
parents:
diff changeset
   206
                task.BringToForeground();
hgs
parents:
diff changeset
   207
                }
hgs
parents:
diff changeset
   208
        	}
hgs
parents:
diff changeset
   209
            break;
hgs
parents:
diff changeset
   210
        default:
hgs
parents:
diff changeset
   211
            ASSERT( EFalse );
hgs
parents:
diff changeset
   212
            break;
hgs
parents:
diff changeset
   213
        }
hgs
parents:
diff changeset
   214
hgs
parents:
diff changeset
   215
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   216
    }
hgs
parents:
diff changeset
   217
hgs
parents:
diff changeset
   218
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   219
// CCalenViewPopulator::BeginPopulationL
hgs
parents:
diff changeset
   220
// Starts populating the given view.
hgs
parents:
diff changeset
   221
// (other items were commented in a header).
hgs
parents:
diff changeset
   222
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   223
//
hgs
parents:
diff changeset
   224
void CCalenViewPopulator::BeginPopulationL( CCalenView* aView )
hgs
parents:
diff changeset
   225
    {
hgs
parents:
diff changeset
   226
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
   227
hgs
parents:
diff changeset
   228
    ASSERT( !iPopulatingView );
hgs
parents:
diff changeset
   229
    iPopulatingView = aView;
hgs
parents:
diff changeset
   230
    iPopulatingView->CancelPopulation();
hgs
parents:
diff changeset
   231
    iPopulationStep = CCalenView::EKeepGoing;
hgs
parents:
diff changeset
   232
    SetActive();
hgs
parents:
diff changeset
   233
    TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   234
    User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   235
hgs
parents:
diff changeset
   236
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   237
    }
hgs
parents:
diff changeset
   238
hgs
parents:
diff changeset
   239
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   240
// CCalenViewPopulator::InterruptPopulationL
hgs
parents:
diff changeset
   241
// Stops current population.
hgs
parents:
diff changeset
   242
// (other items were commented in a header).
hgs
parents:
diff changeset
   243
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   244
//
hgs
parents:
diff changeset
   245
void CCalenViewPopulator::InterruptPopulationL()
hgs
parents:
diff changeset
   246
    {
hgs
parents:
diff changeset
   247
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
   248
hgs
parents:
diff changeset
   249
    if( iPopulatingView )
hgs
parents:
diff changeset
   250
        {
hgs
parents:
diff changeset
   251
        Cancel();
hgs
parents:
diff changeset
   252
        // This doesn't go in DoCancel because the active object might not be
hgs
parents:
diff changeset
   253
        // active during population (i.e. when waiting for instance/entryview).
hgs
parents:
diff changeset
   254
        iPopulatingView->CancelPopulation();
hgs
parents:
diff changeset
   255
        iPopulatingView = NULL;
hgs
parents:
diff changeset
   256
        }
hgs
parents:
diff changeset
   257
hgs
parents:
diff changeset
   258
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   259
    }
hgs
parents:
diff changeset
   260
hgs
parents:
diff changeset
   261
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   262
// CCalenViewPopulator::HandleECalenNotifyViewCreatedL
hgs
parents:
diff changeset
   263
// Leaving function that handles ECalenNotifyViewCreated
hgs
parents:
diff changeset
   264
// (other items were commented in a header).
hgs
parents:
diff changeset
   265
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   266
//
hgs
parents:
diff changeset
   267
void CCalenViewPopulator::HandleECalenNotifyViewCreatedL()
hgs
parents:
diff changeset
   268
    {
hgs
parents:
diff changeset
   269
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
   270
    
hgs
parents:
diff changeset
   271
    RArray<TInt> colIdArray;
hgs
parents:
diff changeset
   272
    iController.GetActiveCollectionidsL(colIdArray);
hgs
parents:
diff changeset
   273
hgs
parents:
diff changeset
   274
    if( iPopulatingView )
hgs
parents:
diff changeset
   275
        {//When commandline is compatiable with new globaldata functionalities, the collectionid 
hgs
parents:
diff changeset
   276
        // to EntryView can be given
hgs
parents:
diff changeset
   277
        if( ( iNeedsEntryView && iGlobalData->EntryViewL(/*iGlobalData->Context().InstanceId().iColId*/) ) ||
hgs
parents:
diff changeset
   278
            ( iNeedsInstanceView && iGlobalData->InstanceViewL(colIdArray) ) )
hgs
parents:
diff changeset
   279
            {
hgs
parents:
diff changeset
   280
            SetActive();
hgs
parents:
diff changeset
   281
            TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   282
            User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   283
            }
hgs
parents:
diff changeset
   284
        }
hgs
parents:
diff changeset
   285
hgs
parents:
diff changeset
   286
    if( iGlobalData->EntryViewL(/*iGlobalData->Context().InstanceId().iColId*/) 
hgs
parents:
diff changeset
   287
                                            && iGlobalData->InstanceViewL(colIdArray) )
hgs
parents:
diff changeset
   288
        {
hgs
parents:
diff changeset
   289
        iController.CancelNotifications( this );
hgs
parents:
diff changeset
   290
        }
hgs
parents:
diff changeset
   291
    
hgs
parents:
diff changeset
   292
    colIdArray.Reset();
hgs
parents:
diff changeset
   293
hgs
parents:
diff changeset
   294
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   295
    }
hgs
parents:
diff changeset
   296
hgs
parents:
diff changeset
   297
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   298
// CCalenViewPopulator::HandleNotification
hgs
parents:
diff changeset
   299
// Calls back when the entry view or instance view has been created.
hgs
parents:
diff changeset
   300
// (other items were commented in a header).
hgs
parents:
diff changeset
   301
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   302
//
hgs
parents:
diff changeset
   303
void CCalenViewPopulator::HandleNotification(const TCalenNotification aNotification )
hgs
parents:
diff changeset
   304
    {
hgs
parents:
diff changeset
   305
    TRACE_ENTRY_POINT;
hgs
parents:
diff changeset
   306
hgs
parents:
diff changeset
   307
    if ( aNotification == ECalenNotifyEntryInstanceViewCreated )
hgs
parents:
diff changeset
   308
        {
hgs
parents:
diff changeset
   309
        PIM_TRAPD_HANDLE( HandleECalenNotifyViewCreatedL() );
hgs
parents:
diff changeset
   310
        }
hgs
parents:
diff changeset
   311
hgs
parents:
diff changeset
   312
    TRACE_EXIT_POINT;
hgs
parents:
diff changeset
   313
    }
hgs
parents:
diff changeset
   314
hgs
parents:
diff changeset
   315
// End of file