author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 17 Dec 2009 09:09:50 +0200 | |
changeset 26 | 5d0ec8b709be |
parent 23 | 50974a8b132e |
permissions | -rw-r--r-- |
5 | 1 |
/* |
2 |
* Copyright (c) 2007 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 the License "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 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
#include <calchangecallback.h> |
|
21 |
#include <calsession.h> |
|
22 |
||
23 |
||
23
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
24 |
#include "calendarheader.h" |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
25 |
#include "calendarnotify.h" |
5 | 26 |
#include "asyncreqobserver.h" |
27 |
||
28 |
||
29 |
// --------------------------------------------------------------------------- |
|
30 |
// two-phased constructor |
|
31 |
// --------------------------------------------------------------------------- |
|
32 |
CCalendarObserver* CCalendarObserver::NewL( CCalendarSessionInfo* aSessionInfo, |
|
33 |
CCalendarFilter* aFilter, |
|
34 |
CAsyncRequestObserver* aAsyncRequestObserver, |
|
35 |
MCalCallbackBase* aNotifyCallback ) |
|
36 |
{ |
|
37 |
CCalendarObserver* self = new(ELeave) CCalendarObserver( aSessionInfo, aAsyncRequestObserver, aNotifyCallback ); |
|
38 |
CleanupStack::PushL( self ); |
|
39 |
self->ConstructL( aFilter ); |
|
40 |
CleanupStack::Pop( self ); |
|
41 |
return self; |
|
42 |
} |
|
43 |
||
44 |
// --------------------------------------------------------------------------- |
|
45 |
// destructor |
|
46 |
// --------------------------------------------------------------------------- |
|
47 |
CCalendarObserver::~CCalendarObserver() |
|
48 |
{ |
|
49 |
delete iFilter; |
|
50 |
||
51 |
if ( iSession ) |
|
52 |
{ |
|
53 |
iSession->StopChangeNotification(); |
|
54 |
delete iSession; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
// --------------------------------------------------------------------------- |
|
59 |
// default constructor |
|
60 |
// --------------------------------------------------------------------------- |
|
61 |
CCalendarObserver::CCalendarObserver( CCalendarSessionInfo* aSessionInfo, |
|
62 |
CAsyncRequestObserver* aAsyncRequestObserver, |
|
63 |
MCalCallbackBase* aNotifyCallback ) : |
|
64 |
// CActive( EPriorityStandard ), |
|
65 |
iSessionInfo( aSessionInfo ), |
|
66 |
iNotifyCallback( aNotifyCallback ), |
|
67 |
iAsyncRequestObserver( aAsyncRequestObserver ), |
|
68 |
iIsInProgress(EFalse) |
|
69 |
{ |
|
70 |
CActiveScheduler::Add( this ); |
|
71 |
} |
|
72 |
||
73 |
// --------------------------------------------------------------------------- |
|
74 |
// second phase constructor |
|
75 |
// --------------------------------------------------------------------------- |
|
76 |
void CCalendarObserver::ConstructL( CCalendarFilter* aFilter ) |
|
77 |
{ |
|
78 |
iFilter = CCalendarFilter::NewL(); |
|
79 |
*iFilter = *aFilter; |
|
80 |
} |
|
81 |
||
82 |
// --------------------------------------------------------------------------- |
|
83 |
// Initiates the Notification process |
|
84 |
// --------------------------------------------------------------------------- |
|
85 |
void CCalendarObserver::StartChangeNotificationL() |
|
86 |
{ |
|
87 |
iSession = CCalSession::NewL(); |
|
88 |
iSession->OpenL( iSessionInfo->Calendar() ); |
|
89 |
||
90 |
TBool includeUndateToDo = ( iFilter->Filter() & EFlagUnDateToDo ); |
|
91 |
||
92 |
CalCommon::TCalTimeRange range = iFilter->TimeRange(); |
|
93 |
||
94 |
if( range.EndTime().TimeLocalL() != Time::NullTTime() && |
|
95 |
range.StartTime().TimeLocalL() != Time::NullTTime() ) |
|
96 |
{ |
|
97 |
if( range.EndTime().TimeLocalL() < range.StartTime().TimeLocalL() ) |
|
98 |
User::Leave( KErrArgument ); |
|
99 |
} |
|
100 |
||
101 |
// Create notification filter object specifying that notification for all entry types is required |
|
102 |
CCalChangeNotificationFilter* filter = CCalChangeNotificationFilter::NewL( MCalChangeCallBack2::EChangeEntryAll, |
|
103 |
includeUndateToDo, |
|
104 |
iFilter->TimeRange() ); |
|
105 |
iSession->StartChangeNotification( *this, *filter ); |
|
106 |
delete filter; |
|
107 |
ActivateRequest( KErrNone ); |
|
108 |
} |
|
109 |
||
110 |
||
111 |
// --------------------------------------------------------------------------- |
|
112 |
// MCalChangeCallBack2::CalChangeNotification |
|
113 |
// Indicates the event of arrival of change in calendar. |
|
114 |
// --------------------------------------------------------------------------- |
|
115 |
void CCalendarObserver::CalChangeNotification(RArray< TCalChangeEntry > &aChangeItems) |
|
116 |
{ |
|
117 |
iIsInProgress = ETrue; |
|
118 |
if ( iFilter->Filter() & EFilterLUid ) |
|
119 |
{ |
|
120 |
RArray< TCalChangeEntry > filteredItems; |
|
121 |
TInt count = aChangeItems.Count(); |
|
122 |
TInt uidCount = iFilter->LocalUidList().Count(); |
|
123 |
||
124 |
for ( TInt index = 0; index < count; index++ ) |
|
125 |
{ |
|
126 |
for ( TInt i = 0; i < uidCount; i++ ) |
|
127 |
{ |
|
128 |
// Filter only those entries having local uids specified |
|
129 |
if ( aChangeItems[index].iEntryId == iFilter->LocalUidList()[i] ) |
|
130 |
{ |
|
131 |
filteredItems.Append( aChangeItems[index] ); |
|
132 |
break; |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
// Notify the user of the changed entries |
|
137 |
TRAPD(err, iNotifyCallback->NotifyResultL( KErrNone, (TAny*)(&filteredItems) )); |
|
138 |
filteredItems.Reset(); |
|
139 |
} |
|
140 |
else |
|
141 |
{ |
|
142 |
TRAPD(err, iNotifyCallback->NotifyResultL( KErrNone, (TAny*)(&aChangeItems) )); |
|
143 |
} |
|
144 |
iIsInProgress = EFalse; |
|
145 |
} |
|
146 |
||
147 |
// --------------------------------------------------------------------------- |
|
148 |
// Inherited from CActive class |
|
149 |
// --------------------------------------------------------------------------- |
|
150 |
// |
|
151 |
void CCalendarObserver::DoCancel() |
|
152 |
{ |
|
153 |
TRequestStatus* temp = &iStatus; |
|
154 |
User::RequestComplete( temp, KErrCancel ); |
|
155 |
// Stop the notificaton operation |
|
156 |
iSession->StopChangeNotification(); |
|
157 |
iAsyncRequestObserver->RequestComplete( iNotifyCallback->iTransactionId ); |
|
158 |
TRAPD( err, iNotifyCallback->NotifyResultL( KErrCancel, NULL )); |
|
159 |
} |
|
160 |
||
161 |
// --------------------------------------------------------------------------- |
|
162 |
// Inherited from CActive class |
|
163 |
// --------------------------------------------------------------------------- |
|
164 |
// |
|
165 |
void CCalendarObserver::RunL() |
|
166 |
{ |
|
167 |
||
168 |
} |
|
169 |
||
170 |
// --------------------------------------------------------------------------- |
|
171 |
// Activates the asynchronous request |
|
172 |
// --------------------------------------------------------------------------- |
|
173 |
// |
|
174 |
void CCalendarObserver::ActivateRequest( TInt /*aReason*/ ) |
|
175 |
{ |
|
176 |
iStatus = KRequestPending; |
|
177 |
SetActive(); |
|
178 |
} |
|
179 |
||
180 |
TBool CCalendarObserver::IsInProgress() |
|
181 |
{ |
|
182 |
return iIsInProgress; |
|
183 |
} |