|
1 /* |
|
2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd. |
|
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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * {Description of the file} |
|
16 * |
|
17 */ |
|
18 |
|
19 // System include files |
|
20 #include <stringloader.h> |
|
21 |
|
22 // User include files |
|
23 #include "directprintsettingsconverter.h" |
|
24 #include "directprinttintcapability.h" |
|
25 #include "directprintlistcapability.h" |
|
26 #include "directprintfloatcapability.h" |
|
27 #include "directprinttextcapability.h" |
|
28 #include "directprintstringids.h" |
|
29 #include "directprintcapability.h" |
|
30 #include "directprintvariant.h" |
|
31 #include "clog.h" |
|
32 |
|
33 const TInt KEngineLimitValue( -1 ); |
|
34 const TInt KMenuItemsRequired( 2 ); |
|
35 |
|
36 // Converts TDirectPrintCapability to CDirectPrintTIntCapability |
|
37 CDirectPrintTIntCapability* DirectPrintSettingsConverter::AddTIntCapabilityLC( |
|
38 TDirectPrintCapability& aCapability, |
|
39 TInt aIndexOnList, |
|
40 TInt aCapabUid ) |
|
41 { |
|
42 LOG("DirectPrintSettingsConverter::AddTIntCapabilityLC Begin"); |
|
43 CDirectPrintTIntCapability* intC = new ( ELeave ) CDirectPrintTIntCapability; |
|
44 CleanupStack::PushL( intC ); |
|
45 |
|
46 // If engine returns KEngineLimitValue as low/high limit then it means |
|
47 // that there is no minimum or maximum limit |
|
48 if ( aCapability.iLow == KEngineLimitValue ) |
|
49 { |
|
50 intC->iMin = KMinTInt32; |
|
51 } |
|
52 else |
|
53 { |
|
54 intC->iMin = aCapability.iLow; |
|
55 } |
|
56 |
|
57 if ( aCapability.iHigh == KEngineLimitValue ) |
|
58 { |
|
59 intC->iMax = KMaxTInt32; |
|
60 } |
|
61 else |
|
62 { |
|
63 intC->iMax = aCapability.iHigh; |
|
64 } |
|
65 |
|
66 // Initialize TInt capability and return it |
|
67 intC->iTitle = DirectPrintSettingsConverter::TextStringLC( aCapabUid )->Des(); |
|
68 CleanupStack::PopAndDestroy(); // SettingsConverter text string |
|
69 intC->iIndexOnList = aIndexOnList; |
|
70 intC->iUid = aCapabUid; |
|
71 intC->iValue = aCapability.iDefaultValue; |
|
72 |
|
73 LOG("DirectPrintSettingsConverter::AddTIntCapabilityLC End"); |
|
74 return intC; |
|
75 } |
|
76 |
|
77 // Converts TDirectPrintCapability to CDirectPrintListCapability |
|
78 CDirectPrintListCapability* DirectPrintSettingsConverter::AddListCapabilityLC( |
|
79 TDirectPrintCapability& aCapability, |
|
80 TInt aIndexOnList, |
|
81 TInt aCapabUid ) |
|
82 { |
|
83 LOG("DirectPrintSettingsConverter::AddListCapabilityLC Begin"); |
|
84 CDirectPrintListCapability* listC = new ( ELeave ) CDirectPrintListCapability(); |
|
85 CleanupStack::PushL( listC ); |
|
86 listC->iIndexOnList = aIndexOnList; |
|
87 listC->iUid = aCapabUid; |
|
88 |
|
89 /* There's a problem with some usb printers: |
|
90 They offer "normal" print quality twice and nothing else. |
|
91 This has to be handled so that user is not shown the option |
|
92 as he cannot change it anyway in this case */ |
|
93 TBool qualityDuplicates = EFalse; |
|
94 if ( aCapabUid == EDirectPrintCapabQuality && |
|
95 aCapability.iEnumCount == KMenuItemsRequired ) |
|
96 { |
|
97 if ( aCapability.iEnumCodes[0] == aCapability.iEnumCodes[1] ) |
|
98 { |
|
99 LOG("DirectPrintSettingsConverter::AddListCapabilityLC duplicate quality detected!"); |
|
100 qualityDuplicates = ETrue; |
|
101 } |
|
102 } |
|
103 |
|
104 // If there is only one value for certain capability, empty |
|
105 // title is added so the capability is not visible on the |
|
106 // settings menu. |
|
107 if( aCapability.iEnumCount < KMenuItemsRequired || qualityDuplicates ) |
|
108 { |
|
109 listC->iTitle = DirectPrintSettingsConverter::TextStringLC( 0 )->Des(); |
|
110 } |
|
111 else |
|
112 { |
|
113 listC->iTitle = DirectPrintSettingsConverter::TextStringLC( aCapabUid )->Des(); |
|
114 } |
|
115 |
|
116 CleanupStack::PopAndDestroy(); // SettingsConverter text string |
|
117 listC->iValue = aCapability.iDefaultValue; |
|
118 |
|
119 TBool enumLabels = listC->iTitle.CompareF( KNullDesC() ) != 0; |
|
120 TInt i( 0 ); |
|
121 TInt num( aCapability.iEnumCount ); |
|
122 for ( i = 0; i < num; i++ ) |
|
123 { |
|
124 User::LeaveIfError( |
|
125 listC->iEnumIDs.Append( aCapability.iEnumCodes[i] ) ); |
|
126 |
|
127 // Find matching text for the enumeration if the capability is |
|
128 // visible on the settings view |
|
129 #ifdef DIRECT_PRINT_DYNAMIC_PRINT_SETTINGS |
|
130 if ( enumLabels || aCapability.iEnumCount < KMenuItemsRequired ) |
|
131 #else |
|
132 // Not for layout if no dynamic print settings |
|
133 if (( enumLabels || aCapability.iEnumCount < KMenuItemsRequired ) && |
|
134 aCapabUid != EDirectPrintCapabLayout ) |
|
135 #endif |
|
136 { |
|
137 LOG("DirectPrintSettingsConverter::AddListCapabilityLC Adding real value"); |
|
138 User::LeaveIfError( listC->iTexts.Append( |
|
139 DirectPrintSettingsConverter::TextStringLC( aCapability.iEnumCodes[i] ))); |
|
140 CleanupStack::Pop(); // SettingsConverter text string |
|
141 } |
|
142 else |
|
143 { |
|
144 LOG("DirectPrintSettingsConverter::AddListCapabilityLC Adding EMPTY value"); |
|
145 User::LeaveIfError( listC->iTexts.Append( |
|
146 StringLoader::LoadLC( R_EMPTY ) ) ); |
|
147 CleanupStack::Pop(); // SettingsConverter text string |
|
148 } |
|
149 } |
|
150 |
|
151 if ( aCapability.iEnumCount > 0 ) |
|
152 { |
|
153 i = 0; |
|
154 // Check that current active capability code is found from the |
|
155 // list of codes and activate first one if not found |
|
156 TInt num( aCapability.iEnumCount ); |
|
157 while ( i < num && |
|
158 listC->iValue != aCapability.iEnumCodes[i] ) |
|
159 { |
|
160 i++; |
|
161 } |
|
162 if ( i >= aCapability.iEnumCount ) |
|
163 { |
|
164 listC->iValue = aCapability.iEnumCodes[0]; |
|
165 } |
|
166 } |
|
167 |
|
168 LOG("DirectPrintSettingsConverter::AddListCapabilityLC End"); |
|
169 return listC; |
|
170 } |
|
171 |
|
172 // Converts TDirectPrintCapability to CDirectPrintFloatCapability |
|
173 CDirectPrintFloatCapability* DirectPrintSettingsConverter::AddFloatCapabilityLC( |
|
174 TDirectPrintCapability& aCapability, |
|
175 TInt aIndexOnList, |
|
176 TInt aCapabUid ) |
|
177 { |
|
178 LOG("DirectPrintSettingsConverter::AddFloatCapabilityLC Begin"); |
|
179 CDirectPrintFloatCapability* floatC = new ( ELeave ) CDirectPrintFloatCapability; |
|
180 CleanupStack::PushL( floatC ); |
|
181 |
|
182 floatC->iIndexOnList = aIndexOnList; |
|
183 floatC->iUid = aCapabUid; |
|
184 floatC->iTitle = DirectPrintSettingsConverter::TextStringLC( aCapabUid )->Des(); |
|
185 CleanupStack::PopAndDestroy(); // SettingsConverter text string |
|
186 |
|
187 floatC->SetValues( aCapability.iLow, |
|
188 aCapability.iDefaultValue, aCapability.iHigh ); |
|
189 |
|
190 LOG("DirectPrintSettingsConverter::AddFloatCapabilityLC End"); |
|
191 return floatC; |
|
192 } |
|
193 |
|
194 // Converts TDirectPrintCapability to CDirectPrintTextCapability |
|
195 CDirectPrintTextCapability* DirectPrintSettingsConverter::AddTextCapabilityLC( |
|
196 TDirectPrintCapability& /*aCapability*/, |
|
197 TInt aIndexOnList, |
|
198 TInt aCapabUid ) |
|
199 { |
|
200 LOG("DirectPrintSettingsConverter::AddTextCapabilityLC Begin"); |
|
201 CDirectPrintTextCapability* textC = new ( ELeave ) CDirectPrintTextCapability; |
|
202 CleanupStack::PushL( textC ); |
|
203 |
|
204 textC->iIndexOnList = aIndexOnList; |
|
205 textC->iUid = aCapabUid; |
|
206 textC->iTitle = DirectPrintSettingsConverter::TextStringLC( aCapabUid )->Des(); |
|
207 CleanupStack::PopAndDestroy(); // SettingsConverter text string |
|
208 |
|
209 LOG("DirectPrintSettingsConverter::AddTextCapabilityLC End"); |
|
210 return textC; |
|
211 } |
|
212 |
|
213 // Fetches text string based on the enumeration ID |
|
214 HBufC* DirectPrintSettingsConverter::TextStringLC( |
|
215 TInt aId ) |
|
216 { |
|
217 LOG1("DirectPrintSettingsConverter::TextStringLC Begin: %d", aId ); |
|
218 HBufC* buf = 0; |
|
219 TBool found( EFalse ); |
|
220 |
|
221 TInt i( 0 ); |
|
222 for ( i = 0; i < KConverterTableCount && !found; i++ ) |
|
223 { |
|
224 if ( aId == KIDConverterTable[i][0] ) |
|
225 { |
|
226 buf = StringLoader::LoadLC( KIDConverterTable[i][1] ); |
|
227 found = ETrue; |
|
228 } |
|
229 } |
|
230 |
|
231 if ( !found ) |
|
232 { |
|
233 User::Leave( KErrNotFound ); |
|
234 } |
|
235 |
|
236 LOG("DirectPrintSettingsConverter::TextStringLC End"); |
|
237 return buf; |
|
238 } |
|
239 |
|
240 // End of File |