19
|
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 |
// User includes
|
|
20 |
#include "clog.h"
|
|
21 |
#include "DirectPrintApp.pan"
|
|
22 |
#include "DirectPrintBearerMgr.h"
|
|
23 |
#include "DirectPrintModel.h"
|
|
24 |
#include "directprintbearerdata.h"
|
|
25 |
#include "directprintprinterdata.h"
|
|
26 |
|
|
27 |
#include "directprintprintsettings.h"
|
|
28 |
#include "directprinttintcapability.h"
|
|
29 |
#include "directprintlistcapability.h"
|
|
30 |
#include "directprintfloatcapability.h"
|
|
31 |
#include "directprinttextcapability.h"
|
|
32 |
#include "directprintsettingsconverter.h"
|
|
33 |
#include "directprintcapability.h"
|
|
34 |
|
|
35 |
const TInt PROTOCOL_ID_BIT_COUNT = 6;
|
|
36 |
|
|
37 |
CDirectPrintBearerMgr::CDirectPrintBearerMgr(MDirectPrintBearerMngObserver* aObserver,
|
|
38 |
CDirectPrintModel& aModel)
|
|
39 |
: CActive( CActive::EPriorityHigh )
|
|
40 |
, iObserver(aObserver)
|
|
41 |
, iModel(aModel)
|
|
42 |
{
|
|
43 |
LOG("CDirectPrintBearerMgr::CDirectPrintBearerMgr()");
|
|
44 |
CActiveScheduler::Add(this);
|
|
45 |
}
|
|
46 |
|
|
47 |
CDirectPrintBearerMgr::~CDirectPrintBearerMgr()
|
|
48 |
{
|
|
49 |
LOG("CDirectPrintBearerMgr::~CDirectPrintBearerMgr()");
|
|
50 |
if (IsActive())
|
|
51 |
{
|
|
52 |
Cancel();
|
|
53 |
}
|
|
54 |
iBearer.Close();
|
|
55 |
delete iPrintSettings;
|
|
56 |
}
|
|
57 |
|
|
58 |
CDirectPrintBearerMgr* CDirectPrintBearerMgr::NewL(MDirectPrintBearerMngObserver* aObserver,
|
|
59 |
CDirectPrintModel& aModel)
|
|
60 |
{
|
|
61 |
CDirectPrintBearerMgr* self = CDirectPrintBearerMgr::NewLC(aObserver, aModel);
|
|
62 |
CleanupStack::Pop(self);
|
|
63 |
return self;
|
|
64 |
}
|
|
65 |
|
|
66 |
CDirectPrintBearerMgr* CDirectPrintBearerMgr::NewLC(MDirectPrintBearerMngObserver* aObserver,
|
|
67 |
CDirectPrintModel& aModel)
|
|
68 |
{
|
|
69 |
CDirectPrintBearerMgr* self = new(ELeave) CDirectPrintBearerMgr(aObserver, aModel);
|
|
70 |
CleanupStack::PushL(self);
|
|
71 |
self->ConstructL();
|
|
72 |
return self;
|
|
73 |
}
|
|
74 |
|
|
75 |
void CDirectPrintBearerMgr::ConstructL()
|
|
76 |
{
|
|
77 |
LOG("CDirectPrintBearerMgr::ConstructL BEGIN");
|
|
78 |
__ASSERT_ALWAYS(iObserver, Panic(EDirectPrintNoObserver));
|
|
79 |
iPrintSettings = new ( ELeave ) CDirectPrintPrintSettings;
|
|
80 |
iBearer.ConnectL();
|
|
81 |
SetBearerStatus(EBearerMngConnected);
|
|
82 |
LOG("CDirectPrintBearerMgr::ConstructL END");
|
|
83 |
}
|
|
84 |
|
|
85 |
void CDirectPrintBearerMgr::CreateJobL()
|
|
86 |
{
|
|
87 |
LOG("CDirectPrintBearerMgr::CreateJobL BEGIN");
|
|
88 |
RPointerArray<TDesC> cmdline;
|
|
89 |
CleanupClosePushL(cmdline);
|
|
90 |
|
|
91 |
_LIT(KDPAppName, "DirectPrint");
|
|
92 |
cmdline.AppendL(&(KDPAppName()));
|
|
93 |
|
|
94 |
TDirectPrintBearerData bearerData;
|
|
95 |
TDirectPrintPrinterData printerData;
|
|
96 |
TInt indexBearer = iModel.CurrentBearer();
|
|
97 |
TInt indexPrinter = iModel.CurrentPrinter();
|
|
98 |
if (indexBearer >= 0 && indexPrinter >= 0)
|
|
99 |
{
|
|
100 |
iModel.GetBearerDataL(indexBearer, bearerData);
|
|
101 |
iModel.GetPrinterDataL(indexPrinter, printerData);
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
LOG("CDirectPrintBearerMgr::CreateJobL LEAVE1 KErrNotFound");
|
|
106 |
User::Leave(KErrNotFound);
|
|
107 |
}
|
|
108 |
|
|
109 |
HBufC* apname = HBufC::NewLC(50);
|
|
110 |
TPtr apnamePtr(apname->Des());
|
|
111 |
_LIT(KDPApName, "-S%S");
|
|
112 |
apnamePtr.AppendFormat(KDPApName(), &(bearerData.iHostName));
|
|
113 |
cmdline.AppendL(apname);
|
|
114 |
|
|
115 |
HBufC* printername = HBufC::NewLC(50);
|
|
116 |
TPtr printernamePtr(printername->Des());
|
|
117 |
_LIT(KDPPrinterName, "-P000000439163");
|
|
118 |
printernamePtr.Copy(KDPPrinterName());
|
|
119 |
cmdline.AppendL(printername);
|
|
120 |
|
|
121 |
HBufC* filename = HBufC::NewLC(50);
|
|
122 |
TPtr filenamePtr(filename->Des());
|
|
123 |
#ifdef __WINSCW__
|
|
124 |
_LIT(KDPFileName, "c:\\fpr.pcl");
|
|
125 |
#else
|
|
126 |
// _LIT(KDPFileName, "e:\\fpr.pcl");
|
|
127 |
_LIT(KDPFileName, "c:\\fpr.pcl");
|
|
128 |
#endif
|
|
129 |
filenamePtr.Copy(KDPFileName());
|
|
130 |
cmdline.AppendL(filename);
|
|
131 |
|
|
132 |
SetBearerStatus(EBearerMngCreatingJob);
|
|
133 |
|
|
134 |
// bearer ID
|
|
135 |
TInt printerID = 128;
|
|
136 |
TInt err = iBearer.CreateJob(printerID, iJobGuardData,
|
|
137 |
cmdline, iStatus);
|
|
138 |
if( !err )
|
|
139 |
{
|
|
140 |
LOG("Start create JOB");
|
|
141 |
SetActive();
|
|
142 |
}
|
|
143 |
else
|
|
144 |
{
|
|
145 |
LOG1("CDirectPrintBearerMgr::CreateJobL LEAVE2[%d]", err);
|
|
146 |
User::Leave(err);
|
|
147 |
}
|
|
148 |
|
|
149 |
CleanupStack::PopAndDestroy(filename);
|
|
150 |
CleanupStack::PopAndDestroy(printername);
|
|
151 |
CleanupStack::PopAndDestroy(apname);
|
|
152 |
CleanupStack::PopAndDestroy(&cmdline);
|
|
153 |
LOG("CDirectPrintBearerMgr::CreateJobL END");
|
|
154 |
}
|
|
155 |
|
|
156 |
void CDirectPrintBearerMgr::RunL()
|
|
157 |
{
|
|
158 |
LOG1("CDirectPrintBearerMgr::RunL begin with iStatus.Int(): %d", iStatus.Int());
|
|
159 |
if( iStatus == KErrNone && iObserver )
|
|
160 |
{
|
|
161 |
switch( iJobGuardData.iCb )
|
|
162 |
{
|
|
163 |
case TDirectPrintJobGuardData::EProgressEventCb:
|
|
164 |
LOG("CJobGuard::RunL TDirectPrintJobGuardData::EProgressEventCb");
|
|
165 |
LOG1("CJobGuard::RunL iJobGuardData.iStatus: %d", iJobGuardData.iStatus);
|
|
166 |
LOG1("CJobGuard::RunL iJobGuardData.iPercentCompletion: %d", iJobGuardData.iPercentCompletion);
|
|
167 |
LOG1("CJobGuard::RunL iJobGuardData.iJobStateCode: %d", iJobGuardData.iJobStateCode);
|
|
168 |
iObserver->PrintJobProgressEvent( iJobGuardData.iStatus, iJobGuardData.iPercentCompletion, iJobGuardData.iJobStateCode );
|
|
169 |
break;
|
|
170 |
case TDirectPrintJobGuardData::EErrorEventCb:
|
|
171 |
LOG("CJobGuard::RunL TDirectPrintJobGuardData::EErrorEventCb");
|
|
172 |
LOG1("CJobGuard::RunL iJobGuardData.iError: %d", iJobGuardData.iError);
|
|
173 |
LOG1("CJobGuard::RunL iJobGuardData.iErrorStringCode: %d", iJobGuardData.iErrorStringCode);
|
|
174 |
iObserver->PrintJobErrorEvent( iJobGuardData.iError, iJobGuardData.iErrorStringCode );
|
|
175 |
break;
|
|
176 |
case TDirectPrintJobGuardData::EStatusEventCb:
|
|
177 |
LOG("CJobGuard::RunL TDirectPrintJobGuardData::EStatusEventCb");
|
|
178 |
LOG1("CJobGuard::RunL iJobGuardData.iError: %d", iJobGuardData.iError);
|
|
179 |
LOG1("CJobGuard::RunL iJobGuardData.iErrorStringCode: %d", iJobGuardData.iErrorStringCode);
|
|
180 |
iObserver->PrintJobErrorEvent( iJobGuardData.iError, iJobGuardData.iErrorStringCode );
|
|
181 |
break;
|
|
182 |
case TDirectPrintJobGuardData::EImageEventCb:
|
|
183 |
LOG("CJobGuard::RunL TDirectPrintJobGuardData::EImageEventCb");
|
|
184 |
LOG1("CJobGuard::RunL iJobGuardData.iFsBitmapHandle: %d", iJobGuardData.iFsBitmapHandle);
|
|
185 |
iObserver->PreviewImageEvent( iJobGuardData.iFsBitmapHandle );
|
|
186 |
break;
|
|
187 |
default:
|
|
188 |
break;
|
|
189 |
}
|
|
190 |
|
|
191 |
LOG1("CDirectPrintBearerMgr::RunL BearerStatus=[%d]", iBearerStatus);
|
|
192 |
|
|
193 |
switch (iBearerStatus)
|
|
194 |
{
|
|
195 |
case EBearerMngNotConnected:
|
|
196 |
case EBearerMngConnected:
|
|
197 |
case EBearerMngCreatingJob:
|
|
198 |
case EBearerMngPrinting:
|
|
199 |
{
|
|
200 |
LOG("CDirectPrintBearerMgr::RunL ContinueCreateJob");
|
|
201 |
iBearer.ContinueCreateJob( iJobGuardData, iStatus );
|
|
202 |
SetActive();
|
|
203 |
}
|
|
204 |
break;
|
|
205 |
case EBearerMngClosing:
|
|
206 |
case EBearerMngCanceling:
|
|
207 |
default:
|
|
208 |
break;
|
|
209 |
}
|
|
210 |
|
|
211 |
}
|
|
212 |
LOG("CDirectPrintBearerMgr::RunL end");
|
|
213 |
}
|
|
214 |
|
|
215 |
void CDirectPrintBearerMgr::SubmitPrintJobL()
|
|
216 |
{
|
|
217 |
LOG("CDirectPrintBearerMgr::SubmitPrintJobL BEGIN");
|
|
218 |
SetBearerStatus(EBearerMngPrinting);
|
|
219 |
// Submit print job
|
|
220 |
TInt err = iBearer.SubmitPrintJob();
|
|
221 |
if( err != KErrNone )
|
|
222 |
{
|
|
223 |
User::Leave(err);
|
|
224 |
}
|
|
225 |
LOG("CDirectPrintBearerMgr::SubmitPrintJobL END");
|
|
226 |
}
|
|
227 |
|
|
228 |
void CDirectPrintBearerMgr::CloseSession()
|
|
229 |
{
|
|
230 |
LOG("CDirectPrintBearerMgr::CloseSession BEGIN");
|
|
231 |
SetBearerStatus(EBearerMngClosing);
|
|
232 |
Cancel();
|
|
233 |
// iBearer.Close();
|
|
234 |
SetBearerStatus(EBearerMngConnected);
|
|
235 |
LOG("CDirectPrintBearerMgr::CloseSession END");
|
|
236 |
}
|
|
237 |
|
|
238 |
void CDirectPrintBearerMgr::DoCancel()
|
|
239 |
{
|
|
240 |
LOG("CDirectPrintBearerMgr::DoCancel BEGIN");
|
|
241 |
SetBearerStatus(EBearerMngCanceling);
|
|
242 |
iBearer.CancelCreateJob();
|
|
243 |
LOG("CDirectPrintBearerMgr::DoCancel END");
|
|
244 |
}
|
|
245 |
|
|
246 |
void CDirectPrintBearerMgr::SetBearerStatus(TBearerMngStatus aStatus)
|
|
247 |
{
|
|
248 |
LOG1("CDirectPrintBearerMgr::SetBearerStatus [%d]", aStatus);
|
|
249 |
iBearerStatus = aStatus;
|
|
250 |
}
|
|
251 |
|
|
252 |
CDirectPrintBearerMgr::TBearerMngStatus CDirectPrintBearerMgr::BearerStatus()
|
|
253 |
{
|
|
254 |
return iBearerStatus;
|
|
255 |
}
|
|
256 |
|
|
257 |
TInt CDirectPrintBearerMgr::SupportedProtocols()
|
|
258 |
{
|
|
259 |
return iBearer.SupportedProtocols();
|
|
260 |
}
|
|
261 |
|
|
262 |
TInt CDirectPrintBearerMgr::GetProtocolNames(RSelectItemArray& aNames)
|
|
263 |
{
|
|
264 |
return iBearer.GetProtocolNames(aNames);
|
|
265 |
}
|
|
266 |
|
|
267 |
void CDirectPrintBearerMgr::InitCapabilitiesL(TInt aIndex)
|
|
268 |
{
|
|
269 |
TInt printerUid = CreatePrinterUid(aIndex);
|
|
270 |
|
|
271 |
RArray<TInt> capabIDs;
|
|
272 |
CleanupClosePushL( capabIDs );
|
|
273 |
|
|
274 |
iBearer.GetPrinterCapabilityIDs( printerUid, capabIDs );
|
|
275 |
CDirectPrintPrintSettings* printSettings = new ( ELeave ) CDirectPrintPrintSettings;
|
|
276 |
CleanupStack::PushL( printSettings );
|
|
277 |
|
|
278 |
TInt i( 0 );
|
|
279 |
TInt num( capabIDs.Count() );
|
|
280 |
for ( i = 0; i < num; i++ )
|
|
281 |
{
|
|
282 |
TDirectPrintCapability capab;
|
|
283 |
iBearer.GetPrinterCapability( printerUid, capabIDs[i], capab );
|
|
284 |
//capab.iType = TDirectPrintCapability::Enum;
|
|
285 |
|
|
286 |
CDirectPrintBaseCapability* capability = 0;
|
|
287 |
|
|
288 |
// Create capability
|
|
289 |
switch ( capab.iType )
|
|
290 |
{
|
|
291 |
case TDirectPrintCapability::Int:
|
|
292 |
capability = DirectPrintSettingsConverter::AddTIntCapabilityLC( capab, i, capabIDs[i] );
|
|
293 |
break;
|
|
294 |
case TDirectPrintCapability::Enum:
|
|
295 |
capability = DirectPrintSettingsConverter::AddListCapabilityLC( capab, i, capabIDs[i] );
|
|
296 |
break;
|
|
297 |
case TDirectPrintCapability::Float:
|
|
298 |
capability = DirectPrintSettingsConverter::AddFloatCapabilityLC( capab, i, capabIDs[i] );
|
|
299 |
break;
|
|
300 |
case TDirectPrintCapability::Text:
|
|
301 |
capability = DirectPrintSettingsConverter::AddTextCapabilityLC( capab, i, capabIDs[i] );
|
|
302 |
break;
|
|
303 |
default:
|
|
304 |
User::Leave( KErrUnknown );
|
|
305 |
break;
|
|
306 |
}
|
|
307 |
//iBearer.GetJobSetting( capabIDs[i], capability->iValue );
|
|
308 |
|
|
309 |
// Add the capability to the list
|
|
310 |
User::LeaveIfError( printSettings->iCapabilities.Append( capability ) );
|
|
311 |
CleanupStack::Pop(); // capability
|
|
312 |
}
|
|
313 |
|
|
314 |
delete iPrintSettings;
|
|
315 |
iPrintSettings = printSettings;
|
|
316 |
|
|
317 |
CleanupStack::Pop(); // printSettings
|
|
318 |
CleanupStack::PopAndDestroy(); // capabIDs
|
|
319 |
}
|
|
320 |
|
|
321 |
TInt CDirectPrintBearerMgr::GetJobSetting(TInt aCapabilityID, TInt& aValue)
|
|
322 |
{
|
|
323 |
return iBearer.GetJobSetting(aCapabilityID, aValue);
|
|
324 |
}
|
|
325 |
|
|
326 |
TInt CDirectPrintBearerMgr::SetJobSetting(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability)
|
|
327 |
{
|
|
328 |
return iBearer.SetJobSetting(aCapabilityID, aValue, aAffectedCapability);
|
|
329 |
}
|
|
330 |
|
|
331 |
void CDirectPrintBearerMgr::SetJobSettings()
|
|
332 |
{
|
|
333 |
TInt i( 0 );
|
|
334 |
TInt num( iPrintSettings->iCapabilities.Count() );
|
|
335 |
for ( i = 0; i < num; i++ )
|
|
336 |
{
|
|
337 |
TInt getSettings;
|
|
338 |
iBearer.SetJobSetting(iPrintSettings->iCapabilities[i]->iUid, iPrintSettings->iCapabilities[i]->iValue, getSettings);
|
|
339 |
}
|
|
340 |
}
|
|
341 |
|
|
342 |
CDirectPrintPrintSettings* CDirectPrintBearerMgr::PrinterSettingsL()
|
|
343 |
{
|
|
344 |
//return iPrintSettings->CloneL();
|
|
345 |
return iPrintSettings;
|
|
346 |
}
|
|
347 |
|
|
348 |
TInt CDirectPrintBearerMgr::CreatePrinterUid(TInt aIndex)
|
|
349 |
{
|
|
350 |
TInt printerUid = 0;
|
|
351 |
TInt protocolIndex = aIndex;
|
|
352 |
protocolIndex <<= sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT;
|
|
353 |
printerUid |= protocolIndex;
|
|
354 |
return printerUid;
|
|
355 |
}
|
|
356 |
|
|
357 |
// End of file
|