|
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 #include <msvids.h> |
|
20 |
|
21 #include "messageheader.h" |
|
22 #include "messagenotify.h" |
|
23 |
|
24 #ifdef __WINS__ |
|
25 const TMsvId KObservedFolderId = KMsvDraftEntryId; |
|
26 #else |
|
27 const TMsvId KObservedFolderId = KMsvGlobalInBoxIndexEntryId; |
|
28 #endif |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // two-phased constructor |
|
33 // --------------------------------------------------------------------------- |
|
34 CMessageObserver* CMessageObserver::NewL( CMsvSession* aSession, |
|
35 CMsgCallbackBase* aNotifyCallback ) |
|
36 { |
|
37 return new(ELeave) CMessageObserver( aSession, aNotifyCallback ); |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // destructor |
|
42 // --------------------------------------------------------------------------- |
|
43 CMessageObserver::~CMessageObserver() |
|
44 { |
|
45 delete iNotifyCallback; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // default constructor |
|
50 // --------------------------------------------------------------------------- |
|
51 CMessageObserver::CMessageObserver( CMsvSession* aSession, |
|
52 CMsgCallbackBase* aNotifyCallback ) : |
|
53 iServerSession( aSession ), |
|
54 iNotifyCallback( aNotifyCallback ), |
|
55 iNewMessageId( -1 ) |
|
56 { |
|
57 |
|
58 } |
|
59 |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CMessageObserver::HandleSessionEventL |
|
63 // Indicates the event of arrival of new message. |
|
64 // --------------------------------------------------------------------------- |
|
65 void CMessageObserver::HandleSessionEventL( TMsvSessionEvent aEvent, |
|
66 TAny* aArg1, |
|
67 TAny* aArg2, |
|
68 TAny* /*aArg3*/ ) |
|
69 { |
|
70 //if there is a callback request registered |
|
71 if ( iNotifyCallback ) |
|
72 { |
|
73 switch ( aEvent ) |
|
74 { |
|
75 // if there is a new entry created |
|
76 case EMsvEntriesCreated: |
|
77 { |
|
78 //aArg2 specifies the parent ID of the entry |
|
79 // entry is created in observed folder |
|
80 if ( aArg2 && *(static_cast<TMsvId*> (aArg2)) == KObservedFolderId ) |
|
81 { |
|
82 CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>( aArg1 ); |
|
83 //one or more new entries created |
|
84 if ( entries->Count() > 0 ) |
|
85 { |
|
86 // get the message ID of the first entry |
|
87 iNewMessageId = entries->At(0); |
|
88 } |
|
89 } |
|
90 } |
|
91 break; |
|
92 |
|
93 // one or more index entries are changed |
|
94 case EMsvEntriesChanged: |
|
95 { |
|
96 //change in index entry in the observed folder |
|
97 if ( aArg2 && *(static_cast<TMsvId*>(aArg2)) == KObservedFolderId ) |
|
98 { |
|
99 CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>( aArg1 ); |
|
100 if( entries->Count() > 0 && iNewMessageId == entries->At(0) ) |
|
101 { |
|
102 CMessageHeader* newEntryHeader; |
|
103 // set the message header fields |
|
104 newEntryHeader = MessageHeaderL( iNewMessageId ); |
|
105 if( newEntryHeader ) |
|
106 { |
|
107 CleanupStack::PushL( newEntryHeader ); |
|
108 //notify new header entry created |
|
109 iNotifyCallback->NotifyResultL( KErrNone, (TAny*)newEntryHeader ); |
|
110 CleanupStack::PopAndDestroy(newEntryHeader); |
|
111 iNewMessageId = -1; |
|
112 } |
|
113 } |
|
114 } |
|
115 } |
|
116 break; |
|
117 |
|
118 default: break; |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CMessageObserver::SetSession |
|
125 // sets the iServersession member variable with a message server session |
|
126 // --------------------------------------------------------------------------- |
|
127 void CMessageObserver::SetSession( CMsvSession* aSession ) |
|
128 { |
|
129 iServerSession = aSession; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CMessageObserver::SetCallbackL |
|
134 // registers a new callback request |
|
135 // returns the old callback request |
|
136 // --------------------------------------------------------------------------- |
|
137 CMsgCallbackBase* CMessageObserver::SetCallback( CMsgCallbackBase* aCallback ) |
|
138 { |
|
139 CMsgCallbackBase* oldCallback = iNotifyCallback; |
|
140 // get the new callback request |
|
141 iNotifyCallback = aCallback; |
|
142 return oldCallback; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // Checks if Notification is activated |
|
147 // return True if notification request is active. |
|
148 // --------------------------------------------------------------------------- |
|
149 TBool CMessageObserver::IsActive() |
|
150 { |
|
151 if ( iNotifyCallback ) |
|
152 return ETrue; |
|
153 |
|
154 return EFalse; |
|
155 } |
|
156 |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CMessageObserver::GetMessageHeaderL |
|
160 // sets the header fields of a message |
|
161 // returns an header object. |
|
162 // --------------------------------------------------------------------------- |
|
163 CMessageHeader* CMessageObserver::MessageHeaderL( TMsvId aMessageId ) |
|
164 { |
|
165 TMsvEntry newEntry; |
|
166 TMsvId serviceId; |
|
167 |
|
168 //gets index of the specified message ID |
|
169 if( iServerSession->GetEntry( aMessageId, serviceId, newEntry ) == KErrNone ) |
|
170 { |
|
171 CMessageHeader* newEntryHeader = CMessageHeader::NewL(); |
|
172 CleanupStack::PushL( newEntryHeader ); |
|
173 |
|
174 newEntryHeader->SetMtmId( newEntry.iMtm ); |
|
175 newEntryHeader->SetTime( newEntry.iDate ); |
|
176 newEntryHeader->SetMessageId( aMessageId ); |
|
177 newEntryHeader->SetFromL( newEntry.iDetails ); |
|
178 newEntryHeader->SetSubjectL( newEntry.iDescription ); |
|
179 newEntryHeader->SetAttachFlag( newEntry.Attachment() ); |
|
180 newEntryHeader->SetPriorityFlag( newEntry.Priority() ); |
|
181 newEntryHeader->SetUnreadFlag( newEntry.Unread() ); |
|
182 |
|
183 CleanupStack::Pop(newEntryHeader); |
|
184 |
|
185 return newEntryHeader; |
|
186 } |
|
187 |
|
188 return NULL; |
|
189 } |