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 #include <AknQueryValueText.h> |
|
21 #include <aknpopupsettingpage.h> |
|
22 #include <badesca.h> |
|
23 #include <imageprintengine.rsg> |
|
24 |
|
25 #include "clistcapability.h" |
|
26 #include "crealfactory.h" |
|
27 #include "mprintsettings.h" |
|
28 #include "tprinter.h" |
|
29 #include "mdiscoveryobserver.h" |
|
30 #include "printcapabilitycodes.h" |
|
31 |
|
32 const TInt KArrayGranularity( 4 ); |
|
33 const TInt KTwoPaperSizeAvailable( 2 ); |
|
34 const TInt KTemplateSize = 16; |
|
35 const TInt KTemplates[] = {1554,1552,1565,1555,1501,1553,1551,1558,1502,1504,1564,1506,1509,1512,1513,1516}; |
|
36 |
|
37 CListCapability::CListCapability( CRealFactory* aFactory ) : |
|
38 iFactory( aFactory ) |
|
39 { |
|
40 } |
|
41 |
|
42 // Destructor |
|
43 CListCapability::~CListCapability() |
|
44 { |
|
45 iEnumIDs.Close(); |
|
46 iTexts.ResetAndDestroy(); |
|
47 } |
|
48 |
|
49 // Creates text string for the settings list box |
|
50 HBufC* CListCapability::ListBoxTextL() |
|
51 { |
|
52 CDesCArrayFlat* strings = |
|
53 new ( ELeave ) CDesCArrayFlat( KArrayGranularity ); |
|
54 CleanupStack::PushL( strings ); |
|
55 strings->AppendL( iTitle ); |
|
56 |
|
57 TInt i( 0 ); |
|
58 TInt num( iEnumIDs.Count() ); |
|
59 TBool found( EFalse ); |
|
60 // Find the matching text based on the enumeration value |
|
61 for ( i = 0; i < num && !found; i++ ) |
|
62 { |
|
63 if ( iEnumIDs[i] == iValue ) |
|
64 { |
|
65 strings->AppendL( iTexts[i]->Des() ); |
|
66 found = ETrue; |
|
67 } |
|
68 } |
|
69 |
|
70 if ( !found ) |
|
71 { |
|
72 User::Leave( KErrNotFound ); |
|
73 } |
|
74 |
|
75 HBufC* buf = StringLoader::LoadL( R_QTN_LBOX_FORMAT, *strings ); |
|
76 CleanupStack::PopAndDestroy(); // strings |
|
77 |
|
78 return buf; |
|
79 } |
|
80 |
|
81 // Displays pop-up list for changing the active TInt value |
|
82 TBool CListCapability::LaunchPopupListL() |
|
83 { |
|
84 // Create value array and sets it up |
|
85 CAknQueryValueTextArray* queryTextArray = CAknQueryValueTextArray::NewL(); |
|
86 CleanupStack::PushL( queryTextArray ); |
|
87 |
|
88 CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( KArrayGranularity ); |
|
89 CleanupStack::PushL( array ); |
|
90 TInt i( 0 ); |
|
91 TInt num( iTexts.Count() ); |
|
92 for ( i = 0; i < num; i++ ) |
|
93 { |
|
94 array->AppendL( iTexts[i]->Des() ); |
|
95 } |
|
96 queryTextArray->SetArray( *array ); |
|
97 |
|
98 CAknQueryValueText* queryValue = CAknQueryValueText::NewL(); |
|
99 CleanupStack::PushL( queryValue ); |
|
100 queryValue->SetArrayL( queryTextArray ); |
|
101 |
|
102 TInt found( KErrNotFound ); |
|
103 num = iEnumIDs.Count(); |
|
104 for ( i = 0; i < num && found == KErrNotFound; i++ ) |
|
105 { |
|
106 if ( iEnumIDs[i] == iValue ) |
|
107 { |
|
108 found = KErrNone; |
|
109 } |
|
110 } |
|
111 i--; |
|
112 User::LeaveIfError( found ); |
|
113 queryValue->SetCurrentValueIndex( i ); |
|
114 |
|
115 TBool changed = EFalse; |
|
116 if( array->MdcaCount() > KTwoPaperSizeAvailable ) |
|
117 { |
|
118 // Create popup setting page and show it |
|
119 CAknPopupSettingPage* page = new ( ELeave ) CAknPopupSettingPage( |
|
120 &iTitle, EAknSettingPageNoOrdinalDisplayed, EAknCtPopupSettingList, |
|
121 R_EMPTY_SETTING_LIST, R_SETTING_GENERIC_PAGE, *queryValue ); |
|
122 CleanupStack::PushL( page ); |
|
123 page->ConstructL(); |
|
124 CleanupStack::Pop(); // page |
|
125 |
|
126 changed = page->ExecuteLD(); |
|
127 // Save new value if needed |
|
128 if ( changed ) |
|
129 { |
|
130 iValue = iEnumIDs[queryValue->CurrentValueIndex()]; |
|
131 } |
|
132 } |
|
133 // If there are only two paper sizes available, another one is automaticly changed |
|
134 else if( array->MdcaCount() == KTwoPaperSizeAvailable ) |
|
135 { |
|
136 if ( i == 0 ) |
|
137 { |
|
138 iValue = iEnumIDs[1]; |
|
139 } |
|
140 else |
|
141 { |
|
142 iValue = iEnumIDs[0]; |
|
143 } |
|
144 changed = ETrue; |
|
145 } |
|
146 // Do nothing |
|
147 else |
|
148 { |
|
149 } |
|
150 |
|
151 CleanupStack::PopAndDestroy( 3 ); // queryTextArray, array, queryArray |
|
152 return changed; |
|
153 } |
|
154 |
|
155 // Clones itself |
|
156 CBaseCapability* CListCapability::CloneL() |
|
157 { |
|
158 CListCapability* clone = new ( ELeave ) CListCapability( iFactory ); |
|
159 CleanupStack::PushL( clone ); |
|
160 |
|
161 clone->iValue = iValue; |
|
162 clone->iIndexOnList = iIndexOnList; |
|
163 clone->iTitle = iTitle; |
|
164 clone->iUid = iUid; |
|
165 |
|
166 TInt num( iEnumIDs.Count() ); |
|
167 if ( iUid != EPrintCapabLayout ) |
|
168 { |
|
169 for ( TInt j = 0; j < num; j++ ) |
|
170 { |
|
171 User::LeaveIfError( clone->iEnumIDs.Append( iEnumIDs[j] ) ); |
|
172 User::LeaveIfError( clone->iTexts.Append( iTexts[j]->AllocLC() ) ); |
|
173 CleanupStack::Pop(); // clone->iTexts |
|
174 } |
|
175 } |
|
176 else |
|
177 { |
|
178 // |
|
179 // has to be done here, i.e. remove not-supported templates |
|
180 TBool dropTemplates = EFalse; |
|
181 if ( iFactory ) |
|
182 { |
|
183 if( ( iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EWLAN ) || |
|
184 ( iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EBPP ) || |
|
185 ( iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EUSB ) || |
|
186 ( iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EMMC ) ) |
|
187 { |
|
188 dropTemplates = ETrue; |
|
189 } |
|
190 } |
|
191 // Also sort the print layout templates to "standard" order |
|
192 for ( TInt i = 0; i < KTemplateSize; i++ ) |
|
193 { |
|
194 for ( TInt j = 0; j < num; j++ ) |
|
195 { |
|
196 if ( KTemplates[i] == iEnumIDs[j] ) |
|
197 { |
|
198 if ( (dropTemplates && (iEnumIDs[j] == EPrintCapabLayout1UpBorderless || iEnumIDs[j] == EPrintCapabLayout1UpBorder || iEnumIDs[j] == EPrintCapabLayout1Up) ) || !dropTemplates ) |
|
199 { |
|
200 User::LeaveIfError( clone->iEnumIDs.Append( iEnumIDs[j] ) ); |
|
201 User::LeaveIfError( clone->iTexts.Append( iTexts[j]->AllocLC() ) ); |
|
202 CleanupStack::Pop(); // clone->iTexts |
|
203 } |
|
204 } |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 CleanupStack::Pop(); // clone |
|
210 return clone; |
|
211 } |
|
212 |
|
213 // End of File |
|