|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ssmtpset.h" |
|
17 |
|
18 GLREF_C TPtrC8 LimitStringSize(const TPtrC8& aString, TInt aMaxSize); |
|
19 GLREF_C TPtrC16 LimitStringSize(const TPtrC16& aString, TInt aMaxSize); |
|
20 // |
|
21 // CImSSmtpSettings stores and restores SMTP Server settings |
|
22 // |
|
23 EXPORT_C CImSSmtpSettings::CImSSmtpSettings() |
|
24 { |
|
25 __DECLARE_NAME(_S("CImSSmtpSettings")); |
|
26 Reset(); |
|
27 } |
|
28 |
|
29 EXPORT_C CImSSmtpSettings::~CImSSmtpSettings() |
|
30 { |
|
31 Reset(); |
|
32 } |
|
33 |
|
34 EXPORT_C void CImSSmtpSettings::Reset() |
|
35 { |
|
36 CImBaseEmailSettings::Reset(); |
|
37 |
|
38 iVersion = KImSmtpServerSettingsVersion; |
|
39 iPortNumber= KSSMTPDefaultPortNumber; |
|
40 |
|
41 delete iEmailAddress; |
|
42 iEmailAddress = NULL; |
|
43 |
|
44 delete iPhoneNumber; |
|
45 iPhoneNumber = NULL; |
|
46 } |
|
47 |
|
48 EXPORT_C void CImSSmtpSettings::StoreL(CMsvStore& aMsvStore) const |
|
49 { |
|
50 RMsvWriteStream out; |
|
51 out.AssignLC( aMsvStore, KUidMsvServiceEntry ); // pushes 'out' to the stack |
|
52 TRAPD(error, ExternalizeL(out)); |
|
53 if (error==KErrNone) |
|
54 out.CommitL(); |
|
55 out.Close(); // make sure we close the file |
|
56 User::LeaveIfError(error); |
|
57 aMsvStore.CommitL(); |
|
58 CleanupStack::PopAndDestroy(); |
|
59 } |
|
60 |
|
61 EXPORT_C void CImSSmtpSettings::RestoreL( CMsvStore& aMessageStore ) |
|
62 { |
|
63 RMsvReadStream in; |
|
64 in.OpenLC( aMessageStore, KUidMsvServiceEntry ); // pushes 'in' to the stack |
|
65 InternalizeL(in); |
|
66 CleanupStack::PopAndDestroy(); |
|
67 } |
|
68 |
|
69 EXPORT_C void CImSSmtpSettings::ExternalizeL(RMsvWriteStream& aWriteStream) const |
|
70 { |
|
71 CImBaseEmailSettings::ExternalizeL(aWriteStream); |
|
72 |
|
73 aWriteStream << LimitStringSize(EmailAddress(), KMaxSettingStringLength); |
|
74 aWriteStream << LimitStringSize(PhoneNumber(), KMaxSettingStringLength); |
|
75 } |
|
76 |
|
77 EXPORT_C void CImSSmtpSettings::InternalizeL( RMsvReadStream& aReadStream ) |
|
78 { |
|
79 Reset(); |
|
80 CImBaseEmailSettings::InternalizeL(aReadStream); |
|
81 |
|
82 iEmailAddress = HBufC::NewL( aReadStream, KMaxSettingStringLength ); |
|
83 iPhoneNumber = HBufC::NewL( aReadStream, KMaxSettingStringLength ); |
|
84 } |
|
85 |
|
86 EXPORT_C const TPtrC CImSSmtpSettings::EmailAddress() const |
|
87 { |
|
88 return iEmailAddress ? TPtrC(*iEmailAddress) : TPtrC(); |
|
89 } |
|
90 |
|
91 EXPORT_C const TPtrC CImSSmtpSettings::PhoneNumber() const |
|
92 { |
|
93 return iPhoneNumber ? TPtrC(*iPhoneNumber) : TPtrC(); |
|
94 } |
|
95 |
|
96 EXPORT_C void CImSSmtpSettings::SetEmailAddressL( const TDesC& aEmailAddress ) |
|
97 { |
|
98 HBufC* newEmailAddress = aEmailAddress.AllocL(); |
|
99 delete iEmailAddress; |
|
100 iEmailAddress = newEmailAddress; |
|
101 } |
|
102 |
|
103 EXPORT_C void CImSSmtpSettings::SetPhoneNumberL( const TDesC& aPhoneNumber ) |
|
104 { |
|
105 HBufC* newPhoneNumber = aPhoneNumber.AllocL(); |
|
106 delete iPhoneNumber; |
|
107 iPhoneNumber = newPhoneNumber; |
|
108 } |
|
109 |
|
110 EXPORT_C CImSSmtpSettings& CImSSmtpSettings::CopyL(const CImSSmtpSettings& aCImSSmtpSettings) |
|
111 { |
|
112 Reset(); |
|
113 CImBaseEmailSettings::CopyL(aCImSSmtpSettings); |
|
114 iEmailAddress = aCImSSmtpSettings.EmailAddress().AllocL(); |
|
115 iPhoneNumber = aCImSSmtpSettings.PhoneNumber().AllocL(); |
|
116 return (*this); |
|
117 } |
|
118 |
|
119 EXPORT_C TBool CImSSmtpSettings::operator==(const CImSSmtpSettings& aCImSSmtpSettings) const |
|
120 { |
|
121 return ((CImBaseEmailSettings::operator==(aCImSSmtpSettings)) && |
|
122 !((EmailAddress().Compare(aCImSSmtpSettings.EmailAddress())) && |
|
123 (PhoneNumber().Compare(aCImSSmtpSettings.PhoneNumber())))); |
|
124 } |