|
1 /* |
|
2 * Copyright (c) 2005-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 "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: Provide interface for the client requestin availability class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "musavacontactavailability.h" |
|
20 #include "musavaavailabilityobserver.h" |
|
21 #include "musavasettingsimp.h" |
|
22 #include "musavaobserver.h" |
|
23 #include "muslogger.h" |
|
24 #include "mussettings.h" |
|
25 |
|
26 #include <cntviewbase.h> |
|
27 #ifdef UNIT_TESTING // if unit testing |
|
28 #include <digia/eunit/eunitdecorators.h> |
|
29 #endif // UNIT_TESTING |
|
30 |
|
31 const TInt KContactsArraySize = 10; |
|
32 |
|
33 _LIT( KMusAvaTel, "tel:" ); |
|
34 _LIT( KMusAvaPlus, "+" ); |
|
35 |
|
36 CMusAvaContactAvailability* CMusAvaContactAvailability::NewL( |
|
37 MMusAvaAvailabilityObserver& aObserver, |
|
38 CMusAvaSettingsImp& aSettings ) |
|
39 { |
|
40 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::NewL()" ) |
|
41 |
|
42 CMusAvaContactAvailability* self = |
|
43 CMusAvaContactAvailability::NewLC( |
|
44 aObserver, |
|
45 aSettings ); |
|
46 CleanupStack::Pop( self ); |
|
47 |
|
48 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::NewL()" ) |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 CMusAvaContactAvailability* CMusAvaContactAvailability::NewLC( |
|
54 MMusAvaAvailabilityObserver& aObserver, |
|
55 CMusAvaSettingsImp& aSettings ) |
|
56 { |
|
57 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::NewL()" ) |
|
58 CMusAvaContactAvailability* self = |
|
59 new( ELeave ) CMusAvaContactAvailability( |
|
60 aObserver, |
|
61 aSettings ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 |
|
65 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::NewL()" ) |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 CMusAvaContactAvailability::~CMusAvaContactAvailability() |
|
71 { |
|
72 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
73 ~CMusAvaContactAvailability()" ) |
|
74 delete iContactName; |
|
75 iContactName = NULL; |
|
76 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
77 ~CMusAvaContactAvailability()" ) |
|
78 } |
|
79 |
|
80 |
|
81 CMusAvaContactAvailability::CMusAvaContactAvailability( |
|
82 MMusAvaAvailabilityObserver& aObserver, |
|
83 CMusAvaSettingsImp& aSettings ) |
|
84 :CMusAvaAvailability( aObserver ), |
|
85 iContactName( NULL ), |
|
86 iSettings( aSettings ) |
|
87 { |
|
88 } |
|
89 |
|
90 |
|
91 void CMusAvaContactAvailability::ConstructL() |
|
92 { |
|
93 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ConstructL()" ) |
|
94 iOperatorVariant = MultimediaSharingSettings::OperatorVariantSettingL(); |
|
95 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::ConstructL()" ) |
|
96 } |
|
97 |
|
98 |
|
99 // ------------------------------------------------------------------------- |
|
100 // Starts the loopy execution. |
|
101 // ------------------------------------------------------------------------- |
|
102 // |
|
103 void CMusAvaContactAvailability::DoExecuteL() |
|
104 { |
|
105 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::DoExecuteL()" ) |
|
106 |
|
107 CDesCArrayFlat* contactsArray |
|
108 = new ( ELeave ) CDesCArrayFlat( KContactsArraySize ); |
|
109 CleanupStack::PushL( contactsArray ); |
|
110 |
|
111 ActiveCallL( contactsArray ); |
|
112 |
|
113 iSettings.SetSipAddressesL( *contactsArray ); |
|
114 |
|
115 contactsArray->Reset(); |
|
116 |
|
117 CleanupStack::PopAndDestroy( contactsArray ); |
|
118 |
|
119 SetState( MMusAvaObserver::EMusAvaStatusAvailable ); |
|
120 |
|
121 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::DoExecuteL()" ) |
|
122 } |
|
123 |
|
124 |
|
125 // ------------------------------------------------------------------------- |
|
126 // |
|
127 // ------------------------------------------------------------------------- |
|
128 // |
|
129 TBool CMusAvaContactAvailability::ActiveCallL( CDesCArrayFlat*& aContactsArray ) |
|
130 { |
|
131 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ActiveCallL()" ) |
|
132 |
|
133 const TDesC& phoneNumber = iSettings.TelNumber(); |
|
134 TInt retval = EFalse; |
|
135 const MDesCArray& addresses = iSettings.SipAddresses(); |
|
136 TInt addressesCount = addresses.MdcaCount(); |
|
137 |
|
138 if ( phoneNumber.Length() > 0 && |
|
139 ( iOperatorVariant == MusSettingsKeys::EOperatorSpecific || |
|
140 phoneNumber.Left(1).Compare( KMusAvaPlus() ) == 0 ) ) |
|
141 { |
|
142 MUS_LOG( "mus: [MUSAVA] Phone number found with + prefix \ |
|
143 (or operator variant)" ) |
|
144 // No, it doesn't, so add the prefix to the new address. |
|
145 MUS_LOG( "mus: [MUSAVA] Prefix to the new address is added" ) |
|
146 //Create contact array |
|
147 //Create tel bufer |
|
148 HBufC* tmpDescriptor = HBufC::NewLC( KMusAvaTel().Length() + |
|
149 phoneNumber.Length() ); |
|
150 tmpDescriptor->Des().Append( KMusAvaTel() ); |
|
151 tmpDescriptor->Des().Append( phoneNumber ); |
|
152 //Add to array |
|
153 aContactsArray->AppendL( tmpDescriptor->Des() ); |
|
154 CleanupStack::PopAndDestroy( tmpDescriptor ); |
|
155 retval = ETrue; |
|
156 } |
|
157 else if ( addressesCount > 0 ) |
|
158 { |
|
159 MUS_LOG1( "mus: [MUSAVA] addresses.MdcaCount() %d", |
|
160 addressesCount ) |
|
161 const TDesC& sipAddress = addresses.MdcaPoint( 0 ); |
|
162 MUS_LOG_TDESC( "mus: [MUSAVA] SIP Address: ", |
|
163 sipAddress ) |
|
164 aContactsArray->AppendL( sipAddress ); |
|
165 retval = ETrue; |
|
166 } |
|
167 else |
|
168 { |
|
169 MUS_LOG( "mus: [MUSAVA] Phone number or SIP URL not found " ) |
|
170 retval = EFalse; |
|
171 } |
|
172 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
173 ActiveCallL return %d", retval ) |
|
174 |
|
175 return retval; |
|
176 } |
|
177 |
|
178 MMusAvaObserver::TAvailabilityName CMusAvaContactAvailability::Name() |
|
179 { |
|
180 return MMusAvaObserver::EMusAvaNameContactStatus; |
|
181 } |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 // End of file |