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