1 /* |
|
2 * Copyright (c) 2002-2006 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: One MMS setting item. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <msvapi.h> |
|
23 #include <mmsclient.h> |
|
24 #include <mtclreg.h> |
|
25 #include <ApDataHandler.h> |
|
26 #include <ApAccessPointItem.h> |
|
27 #include <CWPCharacteristic.h> |
|
28 #include <CWPParameter.h> |
|
29 #include <CWPAdapter.h> |
|
30 #include <favouritesdb.h> |
|
31 #include "CWPWAPMMSItem.h" |
|
32 #include "WPWAPItemFactory.h" |
|
33 #include "WPWAPUtil.h" |
|
34 |
|
35 #ifdef __MESSAGING_API_V2__ |
|
36 #include <mmssettings.h> |
|
37 #endif |
|
38 |
|
39 // CONSTANTS |
|
40 const TInt KUrlMaxLength = 255; |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CWPWAPMMSItem::CWPWAPMMSItem |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CWPWAPMMSItem::CWPWAPMMSItem( const TDesC& aTitle, |
|
49 const TDesC& aDefaultName, |
|
50 CWPCharacteristic& aCharacteristic, |
|
51 CCommsDatabase*& aDb, |
|
52 CApDataHandler*& aAPHandler ) |
|
53 : CWPWAPItemBase( aTitle, aDefaultName, aCharacteristic, aDb, aAPHandler ) |
|
54 { |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CWPWAPMMSItem::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CWPWAPMMSItem::ConstructL() |
|
63 { |
|
64 BaseConstructL(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CWPWAPMMSItem::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CWPWAPMMSItem* CWPWAPMMSItem::NewL( const TDesC& aTitle, |
|
73 const TDesC& aDefaultName, |
|
74 CWPCharacteristic& aCharacteristic, |
|
75 CCommsDatabase*& aDb, |
|
76 CApDataHandler*& aAPHandler ) |
|
77 { |
|
78 CWPWAPMMSItem* self = new(ELeave) CWPWAPMMSItem( aTitle, aDefaultName, |
|
79 aCharacteristic, aDb, aAPHandler ); |
|
80 CleanupStack::PushL(self); |
|
81 self->ConstructL(); |
|
82 CleanupStack::Pop(self); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // Destructor |
|
87 CWPWAPMMSItem::~CWPWAPMMSItem() |
|
88 { |
|
89 iLinks.Close(); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CWPWAPMMSItem::SaveL |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 void CWPWAPMMSItem::SaveL() |
|
97 { |
|
98 CreateDbL(); |
|
99 |
|
100 // Find a proper GPRS access point |
|
101 CApAccessPointItem* item = FindGPRSLC(); |
|
102 WriteHomePageL( *item ); |
|
103 CleanupStack::PopAndDestroy(); // item |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CWPWAPMMSItem::CanSetAsDefault |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TBool CWPWAPMMSItem::CanSetAsDefault() const |
|
111 { |
|
112 return ETrue; |
|
113 } |
|
114 |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CWPWAPMMSItem::SetAsDefaultL |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CWPWAPMMSItem::SetAsDefaultL() |
|
121 { |
|
122 // Open Messaging Server session |
|
123 CMsvSession* session = CMsvSession::OpenSyncL( *this ); |
|
124 CleanupStack::PushL( session ); |
|
125 |
|
126 // Read the MMS client information via registry |
|
127 CClientMtmRegistry* registry = CClientMtmRegistry::NewL( *session ); |
|
128 CleanupStack::PushL( registry ); |
|
129 |
|
130 CMmsClientMtm* mmsClient = |
|
131 static_cast<CMmsClientMtm*>( registry->NewMtmL( KUidMsgTypeMultimedia ) ); |
|
132 CleanupStack::PushL( mmsClient ); |
|
133 |
|
134 #ifdef __MESSAGING_API_V2__ |
|
135 |
|
136 CMmsSettings* mmsSettings = CMmsSettings::NewL(); |
|
137 CleanupStack::PushL( mmsSettings ); |
|
138 |
|
139 mmsClient->RestoreSettingsL(); |
|
140 |
|
141 mmsSettings->CopyL( mmsClient->MmsSettings() ); |
|
142 TInt apCount = mmsSettings->AccessPointCount(); |
|
143 TInt index; |
|
144 for ( index = 0; index < apCount; index++) |
|
145 { |
|
146 mmsSettings->DeleteAccessPointL( 0 ); |
|
147 } |
|
148 mmsSettings->AddAccessPointL( iUID, 0 ); |
|
149 |
|
150 mmsClient->SetSettingsL( *mmsSettings ); |
|
151 mmsClient->StoreSettingsL(); |
|
152 |
|
153 CleanupStack::PopAndDestroy(); // mmsSettings |
|
154 |
|
155 #else |
|
156 |
|
157 mmsClient->LoadMessageL(); |
|
158 // Set the correct access point and save |
|
159 mmsClient->SetFirstAccessPoint( iUID ); |
|
160 mmsClient->SaveMessageL(); |
|
161 |
|
162 #endif |
|
163 |
|
164 CleanupStack::PopAndDestroy(3); // mmsClient, registry, session |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CWPWAPMMSItem::ValidateL |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TBool CWPWAPMMSItem::ValidateL() |
|
172 { |
|
173 return iLinks.Count() > 0 |
|
174 && iAddr |
|
175 && iAddr->Length() <=KUrlMaxLength |
|
176 && WPWAPUtil::CheckURI( *iAddr ); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CWPWAPMMSItem::ResourceL |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CWPWAPMMSItem::ResourceL( CWPCharacteristic& aResource ) |
|
184 { |
|
185 RFavouritesDb favouritesDb; |
|
186 MWPWAPItemBase* item = WPWAPItemFactory::CreateBookmarkLC( KNullDesC, |
|
187 KNullDesC, aResource, iLink, favouritesDb ); // iDb is NULL but it's not used. |
|
188 |
|
189 // Not supporting resources without startpage. |
|
190 if ( item->CanSetAsDefault() && !iAddr ) |
|
191 { |
|
192 iAddr = item->Address().AllocL(); |
|
193 } |
|
194 CleanupStack::PopAndDestroy(); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CWPWAPMMSItem::AddL |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CWPWAPMMSItem::AddL( RPointerArray<MWPWAPItemBase>& aShownItems, |
|
202 RPointerArray<MWPWAPItemBase>& /*aHiddenItems*/ ) |
|
203 { |
|
204 User::LeaveIfError( aShownItems.Append( this ) ); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CWPWAPMMSItem::VisitLinkL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CWPWAPMMSItem::VisitLinkL( CWPCharacteristic& aLink ) |
|
212 { |
|
213 CWPWAPItemBase::VisitLinkL( aLink ); |
|
214 User::LeaveIfError( iLinks.Append( &aLink ) ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CWPWAPMMSItem::HandleSessionEventL |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CWPWAPMMSItem::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, |
|
222 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
223 { |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CWPWAPMMSItem::FindGPRSL |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 CApAccessPointItem* CWPWAPMMSItem::FindGPRSLC() const |
|
231 { |
|
232 CApAccessPointItem* result = NULL; |
|
233 for( TInt i( 0 ); i < iLinks.Count() && result == NULL; i++ ) |
|
234 { |
|
235 CWPCharacteristic* curr = iLinks[i]; |
|
236 |
|
237 TPckgBuf<TUint32> uidPckg; |
|
238 const TInt pkgLength( uidPckg.MaxLength() ); |
|
239 for( TInt dataNum( 0 ); |
|
240 result == NULL && curr->Data( dataNum ).Length() == pkgLength; |
|
241 dataNum++ ) |
|
242 { |
|
243 uidPckg.Copy( curr->Data( dataNum ) ); |
|
244 |
|
245 // Read the access point pointed to by TO-NAPID or TO-PROXY |
|
246 CApAccessPointItem* item = CApAccessPointItem::NewLC(); |
|
247 iAPHandler->AccessPointDataL( uidPckg(), *item ); |
|
248 |
|
249 if( item->BearerTypeL() == EApBearerTypeGPRS ) |
|
250 { |
|
251 // Item left on cleanup stack |
|
252 result = item; |
|
253 } |
|
254 else |
|
255 { |
|
256 CleanupStack::PopAndDestroy(); // item |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 if( !result ) |
|
262 { |
|
263 // Nothing left on cleanup stack. That doesn't matter as we leave. |
|
264 User::Leave( KErrNotFound ); |
|
265 } |
|
266 |
|
267 return result; |
|
268 } |
|
269 |
|
270 // End of File |
|