|
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 * |
|
16 */ |
|
17 |
|
18 #include <aknviewappui.h> |
|
19 #include <akntoolbar.h> |
|
20 #include <barsread.h> |
|
21 #include <DirectPrintApp.rsg> |
|
22 |
|
23 #include "clog.h" |
|
24 #include "directprintapp.hrh" |
|
25 #include "directprintmodel.h" |
|
26 #include "directprintmainview.h" |
|
27 |
|
28 CDirectPrintMainView::CDirectPrintMainView() |
|
29 { |
|
30 iListBox = NULL; |
|
31 } |
|
32 |
|
33 CDirectPrintMainView::~CDirectPrintMainView() |
|
34 { |
|
35 AppUi()->RemoveFromViewStack(*this, iListBox); |
|
36 delete iListBox; |
|
37 iItemArray->Reset(); |
|
38 delete iItemArray; |
|
39 } |
|
40 |
|
41 CDirectPrintMainView* CDirectPrintMainView::NewL() |
|
42 { |
|
43 CDirectPrintMainView* self = CDirectPrintMainView::NewLC(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CDirectPrintMainView* CDirectPrintMainView::NewLC() |
|
49 { |
|
50 CDirectPrintMainView* self = new(ELeave) CDirectPrintMainView(); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CDirectPrintMainView::ConstructL() |
|
57 { |
|
58 LOG("CDirectPrintMainView::ConstructL BEGIN"); |
|
59 BaseConstructL(R_DIRECTPRINT_MAINVIEW); |
|
60 |
|
61 iViewId = TUid::Uid(EDirectPrintMainViewId); |
|
62 |
|
63 iItemArray = new(ELeave) CDesCArrayFlat(3); |
|
64 LOG("CDirectPrintMainView::ConstructL END"); |
|
65 } |
|
66 |
|
67 void CDirectPrintMainView::HandleCommandL(TInt aCommand) |
|
68 { |
|
69 switch (aCommand) |
|
70 { |
|
71 case EAknSoftkeyBack: |
|
72 { |
|
73 AppUi()->HandleCommandL(EDirectPrintCmdIdMainViewExit); |
|
74 } |
|
75 break; |
|
76 case EDirectPrintCmdIdMainViewPrinterList: |
|
77 case EDirectPrintCmdIdMainViewPrint: |
|
78 case EDirectPrintCmdIdMainViewPreview: |
|
79 case EDirectPrintCmdIdMainViewPropertySetting: |
|
80 { |
|
81 AppUi()->HandleCommandL(aCommand); |
|
82 } |
|
83 break; |
|
84 default: |
|
85 { |
|
86 AppUi()->HandleCommandL(aCommand); |
|
87 } |
|
88 break; |
|
89 } |
|
90 } |
|
91 |
|
92 void CDirectPrintMainView::HandleListIndexL(TInt aIndex) |
|
93 { |
|
94 switch (aIndex) |
|
95 { |
|
96 case EItemPrinter: |
|
97 { |
|
98 AppUi()->HandleCommandL(EDirectPrintCmdIdMainViewPrinterList); |
|
99 } |
|
100 break; |
|
101 case EItemBearer: |
|
102 { |
|
103 CDirectPrintModel& model = GetModel(); |
|
104 model.SetSelectPrinter(model.CurrentPrinter()); |
|
105 AppUi()->HandleCommandL(EDirectPrintCmdIdMainViewPrinterSetting); |
|
106 } |
|
107 break; |
|
108 case EItemSetting: |
|
109 { |
|
110 AppUi()->HandleCommandL(EDirectPrintCmdIdMainViewPropertySetting); |
|
111 } |
|
112 break; |
|
113 default: |
|
114 break; |
|
115 } |
|
116 } |
|
117 |
|
118 void CDirectPrintMainView::OfferToolbarEventL(TInt aCommand) |
|
119 { |
|
120 switch (aCommand) |
|
121 { |
|
122 case EDirectPrintCmdIdMainViewPrint: |
|
123 case EDirectPrintCmdIdMainViewPreview: |
|
124 case EDirectPrintCmdIdMainViewPropertySetting: |
|
125 { |
|
126 AppUi()->HandleCommandL(aCommand); |
|
127 } |
|
128 break; |
|
129 default: |
|
130 break; |
|
131 } |
|
132 } |
|
133 |
|
134 void CDirectPrintMainView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/) |
|
135 { |
|
136 LOG("CDirectPrintMainView::DoActivateL BEGIN"); |
|
137 CAknToolbar* toolbar = AppUi()->CurrentFixedToolbar(); |
|
138 toolbar->SetToolbarObserver(this); |
|
139 |
|
140 iItemArray->Reset(); |
|
141 LoadListDataL(); |
|
142 |
|
143 // Create list box |
|
144 if (!iListBox) |
|
145 { |
|
146 iListBox = CDirectPrintListBox::NewL(ClientRect(), iItemArray); |
|
147 iListBox->SetMopParent(this); |
|
148 iListBox->SetListObserver(this); |
|
149 } |
|
150 AppUi()->AddToStackL(*this, iListBox); |
|
151 iListBox->MakeVisible(ETrue); |
|
152 iListBox->RedrawListL(); |
|
153 |
|
154 // set the title pane |
|
155 SetActiveTitleL(R_DIRECTPRINT_MAINVIEW_TITLE); |
|
156 LOG("CDirectPrintMainView::DoActivateL END"); |
|
157 } |
|
158 |
|
159 void CDirectPrintMainView::DoDeactivate() |
|
160 { |
|
161 LOG("CDirectPrintMainView::DoDeactivate BEGIN"); |
|
162 iListBox->MakeVisible(EFalse); |
|
163 AppUi()->RemoveFromViewStack(*this, iListBox); |
|
164 LOG("CDirectPrintMainView::DoDeactivate END"); |
|
165 } |
|
166 |
|
167 void CDirectPrintMainView::LoadListDataL() |
|
168 { |
|
169 CDirectPrintModel& model = GetModel(); |
|
170 |
|
171 if (model.PrinterCount() > 0) |
|
172 { |
|
173 TBuf<50> buf; |
|
174 TBuf<25> itemTitle; |
|
175 |
|
176 TDirectPrintPrinterData printerData; |
|
177 model.GetPrinterDataL(0, printerData); |
|
178 CEikonEnv::Static()->ReadResource(itemTitle, R_DIRECTPRINT_MAINVIEW_ITEM_PRINTERNAME); |
|
179 buf.Format(_L("\t%S\t%S"), &itemTitle, &printerData.iPrinterName); |
|
180 iItemArray->AppendL(buf); |
|
181 |
|
182 TDirectPrintBearerData bearerData; |
|
183 model.GetCurrentBearerDataL(bearerData); |
|
184 CEikonEnv::Static()->ReadResource(itemTitle, R_DIRECTPRINT_MAINVIEW_ITEM_BEARER); |
|
185 buf.Format(_L("\t%S\t%S"), &itemTitle, &bearerData.iBearerName); |
|
186 iItemArray->AppendL(buf); |
|
187 |
|
188 TBuf<25> property; |
|
189 MakePropertyStringL(property); |
|
190 CEikonEnv::Static()->ReadResource(itemTitle, R_DIRECTPRINT_MAINVIEW_ITEM_PROPERTYSETTINGS); |
|
191 buf.Format(_L("\t%S\t%S"), &itemTitle, &property); |
|
192 iItemArray->AppendL(buf); |
|
193 } |
|
194 else |
|
195 { |
|
196 TBuf<50> buf; |
|
197 TBuf<30> itemTitle; |
|
198 CEikonEnv::Static()->ReadResource(itemTitle, R_DIRECTPRINT_MAINVIEW_ITEM_PRINTERNAME); |
|
199 buf.Format(_L("\t%S\t"), &itemTitle); |
|
200 iItemArray->AppendL(buf); |
|
201 CEikonEnv::Static()->ReadResource(itemTitle, R_DIRECTPRINT_MAINVIEW_ITEM_BEARER); |
|
202 buf.Format(_L("\t%S\t"), &itemTitle); |
|
203 iItemArray->AppendL(buf); |
|
204 CEikonEnv::Static()->ReadResource(itemTitle, R_DIRECTPRINT_MAINVIEW_ITEM_PROPERTYSETTINGS); |
|
205 buf.Format(_L("\t%S\t"), &itemTitle); |
|
206 iItemArray->AppendL(buf); |
|
207 } |
|
208 } |
|
209 |
|
210 void CDirectPrintMainView::MakePropertyStringL(TDes& aProperty) |
|
211 { |
|
212 CDirectPrintModel& model = GetModel(); |
|
213 CPrinterProperty* property = model.GetCurrentPrinterPropertyL(TUid::Uid(0)); |
|
214 |
|
215 if (property) |
|
216 { |
|
217 TInt paperSize(0), orientation(0), copy(0); |
|
218 TInt count = property->iPropertyItems.Count(); |
|
219 for (TInt i=0; i<count; i++) |
|
220 { |
|
221 if (property->iPropertyItems[i].iItemType == EDirectPrintPageSettingTab) |
|
222 { |
|
223 switch (property->iPropertyItems[i].iItemId) |
|
224 { |
|
225 case EDirectPrintPaperPaperSize: |
|
226 { |
|
227 paperSize = property->iPropertyItems[i].iItemValue; |
|
228 } |
|
229 break; |
|
230 case EDirectPrintPaperOrientation: |
|
231 { |
|
232 orientation = property->iPropertyItems[i].iItemValue; |
|
233 } |
|
234 break; |
|
235 case EDirectPrintPageCopy: |
|
236 { |
|
237 copy = property->iPropertyItems[i].iItemValue; |
|
238 } |
|
239 break; |
|
240 default: |
|
241 break; |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 //aProperty.Format(_L("%S/%S/%d"), paperSize, orientation, copy); |
|
247 aProperty.Format(_L("%d/%d/%d"), paperSize, orientation, copy); |
|
248 } |
|
249 } |
|
250 |