|
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 <imageprintapp.rsg> |
|
20 #include <StringLoader.h> |
|
21 #include <aknnotewrappers.h> |
|
22 |
|
23 #include "tidleevent.h" |
|
24 #include "cidleprinteventcatcher.h" |
|
25 #include "crealfactory.h" |
|
26 #include "midleprinteventobserver.h" |
|
27 #include "cprinteventcatcher.h" |
|
28 #include "mprintsettings.h" |
|
29 #include "clog.h" |
|
30 #include "mdiscoveryobserver.h" |
|
31 #include "midleprinteventregisterif.h" |
|
32 #include "mdiscoveryobserver.h" |
|
33 |
|
34 CIdlePrintEventCatcher* CIdlePrintEventCatcher::NewL( |
|
35 CRealFactory* aFactory /*, |
|
36 MIdlePrintEventObserver* aIdleUIObserver*/ ) |
|
37 { |
|
38 CIdlePrintEventCatcher* self = CIdlePrintEventCatcher::NewLC( aFactory/*, aIdleUIObserver*/ ); |
|
39 CleanupStack::Pop(); // self |
|
40 return self; |
|
41 } |
|
42 |
|
43 CIdlePrintEventCatcher* CIdlePrintEventCatcher::NewLC( |
|
44 CRealFactory* aFactory/*, |
|
45 MIdlePrintEventObserver* aIdleUIObserver*/ ) |
|
46 { |
|
47 CIdlePrintEventCatcher* self = |
|
48 new ( ELeave ) CIdlePrintEventCatcher( aFactory/*, aIdleUIObserver*/ ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 // Constructor |
|
56 CIdlePrintEventCatcher::CIdlePrintEventCatcher( |
|
57 CRealFactory* aFactory/*, |
|
58 MIdlePrintEventObserver* aIdleUIObserver*/ ) : |
|
59 iFactory( aFactory )/*, |
|
60 iIdleUIObserver( aIdleUIObserver )*/ |
|
61 { |
|
62 } |
|
63 |
|
64 // Destructor |
|
65 CIdlePrintEventCatcher::~CIdlePrintEventCatcher() |
|
66 { |
|
67 iObservers.Reset();//)AndDestroy(); |
|
68 } |
|
69 |
|
70 // 2nd phase constructor |
|
71 void CIdlePrintEventCatcher::ConstructL() |
|
72 { |
|
73 } |
|
74 |
|
75 void CIdlePrintEventCatcher::StatusEvent( const TEvent &aEvent, |
|
76 TInt aError, |
|
77 TInt aMsgCode ) |
|
78 { |
|
79 LOG1("CIdlePrintEventCatcher::StatusEvent, aEventType: %d", aEvent.iEventType); |
|
80 LOG2("CIdlePrintEventCatcher::StatusEvent, aError: %d, aMsgCode: %d", aError, aMsgCode ); |
|
81 TInt obsCount = iObservers.Count(); |
|
82 switch ( aEvent.iEventType ) |
|
83 { |
|
84 ///The protocol has made a connection to the printer, device or transport |
|
85 case EConnect: |
|
86 { |
|
87 LOG( "CIdlePrintEventCatcher::StatusEvent CONNECT " ); |
|
88 if ( (TUint)aEvent.iProtocol == KImagePrint_PrinterProtocol_PictBridge ) |
|
89 { |
|
90 for( TInt i=0; i<obsCount; i++ ) |
|
91 { |
|
92 iObservers[i]->UsbPrinterConnected(); |
|
93 } |
|
94 iFactory->SettingsIF()->SetUsbState( ETrue ); |
|
95 } |
|
96 break; |
|
97 } |
|
98 ///The protocol has been disconnected from the printer, device or transport |
|
99 case EDisconnect: |
|
100 { |
|
101 if ( (TUint)aEvent.iProtocol == KImagePrint_PrinterProtocol_PictBridge ) |
|
102 { |
|
103 // If idle print event is called while usb printing is still ongoing, |
|
104 // printing is cancelled. |
|
105 if ( iFactory->IsPrinting() && |
|
106 ( iFactory->SettingsIF()->GetCurrentPrinterProtocol() == |
|
107 MDiscoveryObserver::EUSB ) && aError != KErrDisconnected) |
|
108 { |
|
109 LOG2("printing pictbridge, aError = %d, aMsgCode = %d", aError, aMsgCode ); |
|
110 iFactory->PrintEventObserverIF()->PrintJobErrorEvent( KErrDisconnected, KErrNone ); |
|
111 iFactory->SettingsIF()->SetUsbState( EFalse ); |
|
112 } |
|
113 else |
|
114 { |
|
115 LOG2("not printing or not pictbridge, aError = %d, aMsgCode = %d", aError, aMsgCode ); |
|
116 if ( ( aError == KErrDisconnected) && |
|
117 ( iFactory->SettingsIF()->GetCurrentPrinterProtocol() == |
|
118 MDiscoveryObserver::EUSB ) ) |
|
119 { |
|
120 LOG( "CIdlePrintEventCatcher::StatusEvent 'Connection to printer lost' " ); |
|
121 |
|
122 TInt error ( KErrNone ); |
|
123 TRAP( error, iBuf = StringLoader::LoadL( R_NOTE_DISCONNECT_PRINT_ERROR )); |
|
124 CAknErrorNote* errornote = new CAknErrorNote( ETrue ); |
|
125 TInt err ( KErrNone ); |
|
126 TRAP( err, errornote->ExecuteLD( *iBuf )); |
|
127 |
|
128 } |
|
129 for( TInt i=0; i<obsCount; i++ ) |
|
130 { |
|
131 iObservers[i]->UsbPrinterDisconnected(); |
|
132 } |
|
133 if ( iBuf ) |
|
134 { |
|
135 delete iBuf; |
|
136 iBuf = NULL; |
|
137 } |
|
138 |
|
139 } |
|
140 } |
|
141 break; |
|
142 } |
|
143 |
|
144 ///The event is notifying a change in the device status, |
|
145 ///or is reporting an error sent from the device |
|
146 case EPrinterStatus: |
|
147 { |
|
148 if ( EWarning==aEvent.iSeverity || EFatal==aEvent.iSeverity ) |
|
149 { |
|
150 for( TInt i=0; i<obsCount; i++ ) |
|
151 { |
|
152 iObservers[i]->UsbStateChanged( ENOUSBEvent, aMsgCode ); |
|
153 } |
|
154 } |
|
155 break; |
|
156 } |
|
157 |
|
158 ///The event is notifying that an asynchronous leave has occurred |
|
159 ///in server and user should be notified in some way |
|
160 case EAsynchronousLeave: |
|
161 { |
|
162 LOG( "CIdlePrintEventCatcher::StatusEvent EAsynchronousLeave!"); |
|
163 LOG2( "CIdlePrintEventCatcher::StatusEvent protocol: %d, error: %d", |
|
164 aEvent.iProtocol, aError ); |
|
165 for( TInt i=0; i<obsCount; i++ ) |
|
166 { |
|
167 iObservers[i]->AsynchronousServerLeave( aError ); |
|
168 } |
|
169 CCoeEnv::Static()->HandleError( aError ); |
|
170 break; |
|
171 } |
|
172 default: |
|
173 { |
|
174 // Should not be never called |
|
175 break; |
|
176 } |
|
177 } |
|
178 LOG("CIdlePrintEventCatcher::StatusEvent END"); |
|
179 } |
|
180 |
|
181 void CIdlePrintEventCatcher::RegisterObserver( MIdlePrintEventObserver* aIdleObserver ) |
|
182 { |
|
183 iObservers.Append( aIdleObserver ); |
|
184 } |
|
185 |
|
186 void CIdlePrintEventCatcher::UnRegisterObserver( MIdlePrintEventObserver* aIdleObserver ) |
|
187 { |
|
188 TInt observerPosition = iObservers.Find( aIdleObserver ); |
|
189 if( observerPosition != KErrNotFound ) |
|
190 { |
|
191 iObservers.Remove( observerPosition ); |
|
192 } |
|
193 } |
|
194 |
|
195 // End of File |