28
|
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 <eikenv.h>
|
|
20 |
#include <bluetooth/hci/hcierrors.h>
|
|
21 |
|
|
22 |
#include "tprinter.h"
|
|
23 |
#include "cdiscoverymanager.h"
|
|
24 |
#include "ciffactory.h"
|
|
25 |
#include "cprintjobmanager.h"
|
|
26 |
#include "csettingsmanager.h"
|
|
27 |
#include "imageprint.h"
|
|
28 |
#include "cimageprint.h"
|
|
29 |
#include "clog.h"
|
|
30 |
|
|
31 |
const TInt KMMCID( 1 );
|
|
32 |
|
|
33 |
// CONSTRUCTION
|
|
34 |
CDiscoveryManager* CDiscoveryManager::NewL(
|
|
35 |
CIFFactory* aFactory )
|
|
36 |
{
|
|
37 |
CDiscoveryManager* self = CDiscoveryManager::NewLC( aFactory );
|
|
38 |
CleanupStack::Pop(); // self
|
|
39 |
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
CDiscoveryManager* CDiscoveryManager::NewLC(
|
|
44 |
CIFFactory* aFactory )
|
|
45 |
{
|
|
46 |
CDiscoveryManager* self =
|
|
47 |
new ( ELeave ) CDiscoveryManager( aFactory );
|
|
48 |
CleanupStack::PushL( self );
|
|
49 |
self->ConstructL();
|
|
50 |
|
|
51 |
return self;
|
|
52 |
}
|
|
53 |
|
|
54 |
// Constructor
|
|
55 |
CDiscoveryManager::CDiscoveryManager(
|
|
56 |
CIFFactory* aFactory ) :
|
|
57 |
iFactory( aFactory )
|
|
58 |
{
|
|
59 |
}
|
|
60 |
|
|
61 |
// Destruction
|
|
62 |
CDiscoveryManager::~CDiscoveryManager()
|
|
63 |
{
|
|
64 |
}
|
|
65 |
|
|
66 |
// 2nd phase constructor
|
|
67 |
void CDiscoveryManager::ConstructL()
|
|
68 |
{
|
|
69 |
}
|
|
70 |
|
|
71 |
// Returns supported protocols
|
|
72 |
TUint CDiscoveryManager::SupportedProtocols()
|
|
73 |
{
|
|
74 |
return iFactory->Engine()->SupportedProtocols();
|
|
75 |
}
|
|
76 |
|
|
77 |
// Initiates device discovery
|
|
78 |
void CDiscoveryManager::StartDeviceDiscoveryL(
|
|
79 |
MDiscoveryObserver* aNotifier,
|
|
80 |
TUint aProtocol )
|
|
81 |
{
|
|
82 |
TInt discoveryError( KErrNone );
|
|
83 |
LOG("CDiscoveryManager::StartDeviceDiscoveryL BEGIN");
|
|
84 |
iMMCUid = -1;
|
|
85 |
iCancelling = EFalse;
|
|
86 |
iOnGoingDiscovery = ETrue;
|
|
87 |
iDiscoveryObserver = aNotifier;
|
|
88 |
TRAP_IGNORE( discoveryError = iFactory->Engine()->StartDiscoveryL( *this, aProtocol ) );
|
|
89 |
LOG1("CDiscoveryManager::StartDeviceDiscoveryL END, error = %d", discoveryError);
|
|
90 |
User::LeaveIfError( discoveryError );
|
|
91 |
}
|
|
92 |
|
|
93 |
// Cancels the discovery notification
|
|
94 |
void CDiscoveryManager::CancelDeviceDiscoveryL()
|
|
95 |
{
|
|
96 |
if ( iOnGoingDiscovery )
|
|
97 |
{
|
|
98 |
User::LeaveIfError( iFactory->Engine()->CancelDiscovery() );
|
|
99 |
iCancelling = ETrue;
|
|
100 |
iOnGoingDiscovery = EFalse;
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
// Chooses the printer
|
|
105 |
TInt CDiscoveryManager::ChoosePrinterL(
|
|
106 |
TInt aPrinterUid )
|
|
107 |
{
|
|
108 |
LOG("CDiscoveryManager::ChoosePrinterL BEGIN");
|
|
109 |
TInt err = 0;
|
|
110 |
|
|
111 |
// Create print job
|
|
112 |
CPrintJobManager* printJobManager =
|
|
113 |
static_cast<CPrintJobManager*>( iFactory->PrintJobIF() );
|
|
114 |
iOnGoingDiscovery = EFalse;
|
|
115 |
|
|
116 |
err = printJobManager->CreatePrintJobL( aPrinterUid );
|
|
117 |
LOG2("CDiscoveryManager::ChoosePrinterL printjob ret: %d with printer uid: %d", err, aPrinterUid );
|
|
118 |
if ( err == KErrNone )
|
|
119 |
{
|
|
120 |
if( aPrinterUid == KMMCID )
|
|
121 |
{
|
|
122 |
iMMCUid = KMMCID;
|
|
123 |
}
|
|
124 |
|
|
125 |
// Do initialization of the settings manager once print job is
|
|
126 |
// created and the settings can be fetched
|
|
127 |
CSettingsManager* settings =
|
|
128 |
static_cast<CSettingsManager*>( iFactory->SettingsIF() );
|
|
129 |
settings->InitSettingsL( aPrinterUid, iMMCUid );
|
|
130 |
|
|
131 |
iPrinterUid = aPrinterUid;
|
|
132 |
}
|
|
133 |
|
|
134 |
LOG("CDiscoveryManager::ChoosePrinterL END");
|
|
135 |
return err;
|
|
136 |
}
|
|
137 |
|
|
138 |
// Called when the server finds the printer
|
|
139 |
void CDiscoveryManager::FoundPrinterL(
|
|
140 |
const TPrinter& aPrinterInfo )
|
|
141 |
{
|
|
142 |
HBufC* name = HBufC::NewLC( aPrinterInfo.iDisplayName.Length() );
|
|
143 |
name->Des().Copy( aPrinterInfo.iDisplayName );
|
|
144 |
|
|
145 |
MDiscoveryObserver::TPrinterType type;
|
|
146 |
switch ( aPrinterInfo.iProtocol )
|
|
147 |
{
|
|
148 |
case KImagePrint_PrinterProtocol_BPP:
|
|
149 |
type = MDiscoveryObserver::EBPP;
|
|
150 |
break;
|
|
151 |
case KImagePrint_PrinterProtocol_DPOF:
|
|
152 |
type = MDiscoveryObserver::EMMC;
|
|
153 |
iMMCUid = aPrinterInfo.iPrinterID;
|
|
154 |
break;
|
|
155 |
case KImagePrint_PrinterProtocol_PictBridge:
|
|
156 |
type = MDiscoveryObserver::EUSB;
|
|
157 |
break;
|
|
158 |
|
|
159 |
case KImagePrint_PrinterProtocol_OPP_Printer: //fallthrough
|
|
160 |
case KImagePrint_PrinterProtocol_OPP_PC:
|
|
161 |
type = MDiscoveryObserver::EOPP;
|
|
162 |
break;
|
|
163 |
case KImagePrint_PrinterProtocol_UPnP:
|
|
164 |
type = MDiscoveryObserver::EWLAN;
|
|
165 |
break;
|
|
166 |
default:
|
|
167 |
type = MDiscoveryObserver::EBPP;
|
|
168 |
break;
|
|
169 |
}
|
|
170 |
|
|
171 |
if( iOnGoingDiscovery != EFalse )
|
|
172 |
{
|
|
173 |
iDiscoveryObserver->NotifyNewPrintDeviceL(
|
|
174 |
name, aPrinterInfo.iPrinterID,
|
|
175 |
aPrinterInfo.iProperties & TPrinter::Cached,
|
|
176 |
type, aPrinterInfo.iVendor );
|
|
177 |
}
|
|
178 |
CleanupStack::PopAndDestroy(); // name
|
|
179 |
}
|
|
180 |
|
|
181 |
// Called to inform the status
|
|
182 |
void CDiscoveryManager::DiscoveryStatusL(
|
|
183 |
TInt aStatus,
|
|
184 |
TInt aErrorCode,
|
|
185 |
TInt /*aErrorStringCode*/ )
|
|
186 |
{
|
|
187 |
// When Bluetooth discovery is finished, but Bluetooth is not enabled pass error code to UI.
|
|
188 |
if ( aErrorCode == ENoConnection )
|
|
189 |
{
|
|
190 |
if (iDiscoveryObserver)
|
|
191 |
{
|
|
192 |
iDiscoveryObserver->DiscoveryError( aErrorCode );
|
|
193 |
}
|
|
194 |
}
|
|
195 |
if ( iCancelling )
|
|
196 |
{
|
|
197 |
// Exection continues in CancelDiscoveryL()
|
|
198 |
if ( iDiscoveryObserver )
|
|
199 |
{
|
|
200 |
iDiscoveryObserver->DeviceDiscoveryCompleted();
|
|
201 |
}
|
|
202 |
}
|
|
203 |
else
|
|
204 |
{
|
|
205 |
if ( iOnGoingDiscovery )
|
|
206 |
{
|
|
207 |
if ( aStatus == EDiscovering )
|
|
208 |
{
|
|
209 |
iOnGoingDiscovery = EFalse;
|
|
210 |
if ( iDiscoveryObserver )
|
|
211 |
{
|
|
212 |
iDiscoveryObserver->DeviceDiscoveryCompleted();
|
|
213 |
}
|
|
214 |
}
|
|
215 |
else if ( aStatus == EDoneDiscovery )
|
|
216 |
{
|
|
217 |
iOnGoingDiscovery = EFalse;
|
|
218 |
if ( iDiscoveryObserver )
|
|
219 |
{
|
|
220 |
iDiscoveryObserver->DeviceDiscoveryCompleted();
|
|
221 |
}
|
|
222 |
}
|
|
223 |
else if ( aStatus == ECancellingDiscovery )
|
|
224 |
{
|
|
225 |
if ( iDiscoveryObserver )
|
|
226 |
{
|
|
227 |
iDiscoveryObserver->DiscoveryError( aErrorCode );
|
|
228 |
}
|
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
User::Leave( KErrUnknown );
|
|
233 |
}
|
|
234 |
}
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
// Removes cached printer from the list
|
|
239 |
void CDiscoveryManager::RemovePrinterL( const TPrinter& aPrinterInfo )
|
|
240 |
{
|
|
241 |
if( iOnGoingDiscovery != EFalse )
|
|
242 |
{
|
|
243 |
iDiscoveryObserver->RemoveCachedPrinterL( aPrinterInfo.iPrinterID );
|
|
244 |
}
|
|
245 |
}
|
|
246 |
|
|
247 |
TInt CDiscoveryManager::IsPictBridgeMode()
|
|
248 |
{
|
|
249 |
LOG("CDiscoveryManager::IsPictBridgeMode() START");
|
|
250 |
TInt retValue = -999;
|
|
251 |
retValue = iFactory->ImagePrintClient().IsPictBridgeMode();
|
|
252 |
LOG1("IsPictBridgeMode() returned: %d", retValue);
|
|
253 |
LOG("CDiscoveryManager::IsPictBridgeMode() END");
|
|
254 |
return retValue;
|
|
255 |
}
|
|
256 |
|
|
257 |
void CDiscoveryManager::RemoveDiscoveryObserver()
|
|
258 |
{
|
|
259 |
iOnGoingDiscovery = EFalse;
|
|
260 |
iDiscoveryObserver = 0;
|
|
261 |
}
|
|
262 |
|
|
263 |
// End of File
|