|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Adapts data from Shared data GPRS counters to listbox |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <StringLoader.h> |
|
22 #include <AknUtils.h> |
|
23 #include <Logs.rsg> |
|
24 |
|
25 #include "CLogsGprsCtAdapter.h" |
|
26 #include "MLogsSharedData.h" |
|
27 #include "LogsConsts.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 |
|
31 // EXTERNAL FUNCTION PROTOTYPES |
|
32 |
|
33 // CONSTANTS |
|
34 |
|
35 // MACROS |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 |
|
39 // MODULE DATA STRUCTURES |
|
40 |
|
41 // LOCAL FUNCTION PROTOTYPES |
|
42 |
|
43 |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 |
|
47 // ---------------------------------------------------------------------------- |
|
48 // CLogsGprsCtAdapter::NewL |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 CLogsGprsCtAdapter* CLogsGprsCtAdapter::NewL( MLogsSharedData* aSharedData ) |
|
52 { |
|
53 CLogsGprsCtAdapter* self = new( ELeave ) CLogsGprsCtAdapter( aSharedData ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(self); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CLogsGprsCtAdapter::CLogsGprsCtAdapter |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CLogsGprsCtAdapter::CLogsGprsCtAdapter( |
|
66 MLogsSharedData* aSharedData ) : |
|
67 iSharedData( aSharedData ) |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // CLogsGprsCtAdapter::ConstructL |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 void CLogsGprsCtAdapter::ConstructL() |
|
77 { |
|
78 iSentTitle = StringLoader::LoadL( R_LOGS_GRPS_SENT_TEXT ); |
|
79 iReceivedTitle = StringLoader::LoadL( R_LOGS_GRPS_RECEIVED_TEXT ); |
|
80 iBytes = StringLoader::LoadL( R_LOGS_GRPS_B_TEXT, KNullDesC ); |
|
81 iKBytes = StringLoader::LoadL( R_LOGS_GRPS_KB_TEXT, KNullDesC ); |
|
82 iMBytes = StringLoader::LoadL( R_LOGS_GRPS_MB_TEXT, KNullDesC ); |
|
83 iGBytes = StringLoader::LoadL( R_LOGS_GRPS_GB_TEXT, KNullDesC ); |
|
84 } |
|
85 |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // CLogsGprsCtAdapter::~CLogsGprsCtAdapter |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 CLogsGprsCtAdapter::~CLogsGprsCtAdapter() |
|
92 { |
|
93 delete iSentTitle; |
|
94 delete iReceivedTitle; |
|
95 delete iBytes; |
|
96 delete iKBytes; |
|
97 delete iMBytes; |
|
98 delete iGBytes; |
|
99 } |
|
100 |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CLogsGprsCtAdapter::MdcaCount |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 TInt CLogsGprsCtAdapter::MdcaCount () const |
|
107 { |
|
108 return KAmountOfGprsCounters; |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // CLogsGprsCtAdapter::MdcaPoint |
|
113 // ---------------------------------------------------------------------------- |
|
114 // |
|
115 TPtrC16 CLogsGprsCtAdapter::MdcaPoint( TInt aIndex ) const |
|
116 { |
|
117 // double graphic style "0\tText\tText2\t1 |
|
118 |
|
119 TDes& des = MUTABLE_CAST( TBuf<KLogsBuff128>&, iBuffer ); |
|
120 |
|
121 // icon |
|
122 des.Num( aIndex ); |
|
123 des.Append( KTab ); |
|
124 |
|
125 switch( aIndex ) |
|
126 { |
|
127 case 0: |
|
128 des.Append( *iSentTitle ); |
|
129 des.Append( KTab ); |
|
130 ConstructAmountDescriptor( EGprsDirectionSent ); |
|
131 break; |
|
132 |
|
133 case 1: |
|
134 des.Append( *iReceivedTitle ); |
|
135 des.Append( KTab ); |
|
136 ConstructAmountDescriptor( EGprsDirectionReceived ); |
|
137 break; |
|
138 |
|
139 default: |
|
140 break; |
|
141 } |
|
142 return des; |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // CLogsGprsCtAdapter::ConstructAmountDescriptor |
|
147 // ---------------------------------------------------------------------------- |
|
148 // |
|
149 void CLogsGprsCtAdapter::ConstructAmountDescriptor( |
|
150 TGprsDirectionType aDirection ) const |
|
151 { |
|
152 const TInt64 KBytesInKilobyte = MAKE_TINT64( 0, 1024 ); //const TInt64 KBytesInKilobyte( 1024 ); |
|
153 const TInt64 KBytesInMegabyte = MAKE_TINT64( 0, 1048576 ); //const TInt64 KBytesInMegabyte( 1048576 ); |
|
154 const TInt64 KBytesInGigabyte = MAKE_TINT64( 0, 1073741824 );//const TInt64 KBytesInGigabyte( 1073741824 ); |
|
155 TInt64 bytes = MAKE_TINT64( 0, 0 ); //TInt64 bytes( 0 ); |
|
156 |
|
157 TDes& des = MUTABLE_CAST( TBuf<KLogsBuff128>&, iBuffer ); |
|
158 |
|
159 // ask shared data for info |
|
160 switch( aDirection ) |
|
161 { |
|
162 case EGprsDirectionSent: |
|
163 bytes = iSharedData->GprsSentCounter(); |
|
164 break; |
|
165 |
|
166 case EGprsDirectionReceived: |
|
167 bytes = iSharedData->GprsReceivedCounter(); |
|
168 break; |
|
169 |
|
170 default: |
|
171 break; |
|
172 } |
|
173 |
|
174 if( bytes < 0 ) |
|
175 { |
|
176 bytes = 0; |
|
177 } |
|
178 |
|
179 if( bytes > ( KBytesInGigabyte - 1 ) ) |
|
180 { |
|
181 CalcPercentage( bytes, KBytesInGigabyte ); |
|
182 des.Append( *iGBytes ); |
|
183 } |
|
184 else if( bytes > ( KBytesInMegabyte - 1 ) ) |
|
185 { |
|
186 CalcPercentage( bytes, KBytesInMegabyte ); |
|
187 des.Append( *iMBytes ); |
|
188 } |
|
189 else if( bytes > ( KBytesInKilobyte - 1 ) ) |
|
190 { |
|
191 CalcPercentage( bytes, KBytesInKilobyte ); |
|
192 des.Append( *iKBytes ); |
|
193 } |
|
194 else |
|
195 { |
|
196 TBuf<KLogsBuff128> buf; |
|
197 buf.AppendNum( bytes ); |
|
198 AknTextUtils::LanguageSpecificNumberConversion( buf ); |
|
199 des.Append( buf ); |
|
200 des.Append( *iBytes ); |
|
201 } |
|
202 |
|
203 } |
|
204 |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CLogsGprsCtAdapter::CalcPercentage |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 void CLogsGprsCtAdapter::CalcPercentage( |
|
211 TInt64 aDividend, |
|
212 TInt64 aDivisor ) const |
|
213 { |
|
214 TLocale locale; |
|
215 TInt64 integer = MAKE_TINT64( 0, 0 ); //TInt64 integer( 0 ); |
|
216 TInt64 fraction = MAKE_TINT64( 0, 0 ); //TInt64 fraction( 0 ); |
|
217 TInt64 percent = MAKE_TINT64( 0, 0 ); //TInt64 percent( 0 ); |
|
218 TBuf<KLogsBuff128> buf; |
|
219 |
|
220 |
|
221 |
|
222 integer = aDividend / aDivisor; |
|
223 buf.AppendNum( integer ); |
|
224 |
|
225 fraction = aDividend % aDivisor; |
|
226 |
|
227 buf.Append( locale.DecimalSeparator() ); |
|
228 percent = ( fraction * KMaxPercentage ) / aDivisor; |
|
229 |
|
230 //buf.AppendNumFixedWidth( percent.Low(), EDecimal, KDigitsAfterDot ); [FIXME: remove this line] |
|
231 buf.AppendNumFixedWidth( I64LOW(percent), EDecimal, KDigitsAfterDot ); |
|
232 |
|
233 AknTextUtils::LanguageSpecificNumberConversion( buf ); |
|
234 |
|
235 TDes& des = MUTABLE_CAST( TBuf<KLogsBuff128>&, iBuffer ); |
|
236 des.Append( buf ); |
|
237 |
|
238 |
|
239 } |
|
240 |
|
241 // End of File |