|
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 "ctemplatesettings.h" |
|
20 |
|
21 #include "ctemplatedata.h" |
|
22 #include "tprinter.h" |
|
23 #include "mdiscoveryobserver.h" |
|
24 #include "crealfactory.h" |
|
25 #include "mprintsettings.h" |
|
26 #include "clog.h" |
|
27 |
|
28 // BT Template ID's |
|
29 const TInt KOneUpBorderless( 1554 ); |
|
30 const TInt KOneUpBorder( 1555 ); |
|
31 const TInt KOneUpStick( 1565 ); |
|
32 const TInt KFourUpStick( 1564 ); |
|
33 const TInt KSixteenUpStick( 1516 ); |
|
34 const TInt KOneUp( 1501 ); |
|
35 |
|
36 |
|
37 // CONSTRUCTION |
|
38 CTemplateSettings* CTemplateSettings::NewL( CRealFactory* aFactory ) |
|
39 { |
|
40 CTemplateSettings* self = CTemplateSettings::NewLC( aFactory ); |
|
41 CleanupStack::Pop(); // self |
|
42 return self; |
|
43 } |
|
44 |
|
45 CTemplateSettings* CTemplateSettings::NewLC( CRealFactory* aFactory ) |
|
46 { |
|
47 CTemplateSettings* self = new ( ELeave ) CTemplateSettings( aFactory ); |
|
48 CleanupStack::PushL( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // Default constructor |
|
53 CTemplateSettings::CTemplateSettings( CRealFactory* aFactory ) |
|
54 { |
|
55 iActiveTemplateUid = KMaxTUint32; |
|
56 iFactory = aFactory; |
|
57 } |
|
58 |
|
59 // Destructor |
|
60 CTemplateSettings::~CTemplateSettings() |
|
61 { |
|
62 iTemplates.ResetAndDestroy(); |
|
63 } |
|
64 |
|
65 // Clones current template settings |
|
66 CTemplateSettings* CTemplateSettings::CloneL() |
|
67 { |
|
68 TBool dropTemplates = EFalse; |
|
69 CTemplateSettings* self = CTemplateSettings::NewLC( iFactory ); |
|
70 |
|
71 self->iActiveTemplateUid = iActiveTemplateUid; |
|
72 TInt num( iTemplates.Count() ); |
|
73 TInt templateID; |
|
74 |
|
75 if( (iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EWLAN) || |
|
76 (iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EBPP) || |
|
77 (iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EMMC) || |
|
78 (iFactory->SettingsIF()->GetCurrentPrinterProtocol() == MDiscoveryObserver::EUSB) ) |
|
79 { |
|
80 LOG("[CTemplateSettings] Templates dropped"); |
|
81 dropTemplates = ETrue; |
|
82 } |
|
83 |
|
84 LOG1("CTemplateSettings: Number of templates received from engine: %d",num); |
|
85 |
|
86 for ( TInt i( 0 ); i < num; i++ ) |
|
87 { |
|
88 templateID = iTemplates[i]->iUid; |
|
89 |
|
90 |
|
91 if( (dropTemplates && (templateID == KOneUpBorderless || templateID == KOneUpBorder || templateID == KOneUpStick || templateID == KFourUpStick || templateID == KSixteenUpStick || templateID == KOneUp )) || !dropTemplates) |
|
92 { |
|
93 LOG1("CTemplateSettings: Template ID: %d ADDED", templateID); |
|
94 User::LeaveIfError( self->iTemplates.Append( iTemplates[i]->CloneL() ) ); |
|
95 } |
|
96 else |
|
97 { |
|
98 LOG1("CTemplateSettings: Template ID: %d SKIPPED",templateID); |
|
99 } |
|
100 } |
|
101 |
|
102 CleanupStack::Pop(); // self |
|
103 return self; |
|
104 } |
|
105 |
|
106 // Sets the new active template |
|
107 void CTemplateSettings::SetActiveTemplateL( |
|
108 TInt aUid ) |
|
109 { |
|
110 LOG1( "CTemplateSettings:SetActiveTemplateL || aUid = %d", aUid ); |
|
111 TInt err( KErrNotFound ); |
|
112 |
|
113 TInt num( iTemplates.Count() ); |
|
114 for ( TInt i( 0 ); i < num && err != KErrNone; i++ ) |
|
115 { |
|
116 if ( aUid == iTemplates[i]->iUid ) |
|
117 { |
|
118 iActiveTemplateUid = aUid; |
|
119 err = KErrNone; |
|
120 } |
|
121 } |
|
122 LOG2( "CTemplateSettings:SetActiveTemplateL uid: %d, err: %d", aUid, err ); |
|
123 // Leave when not found |
|
124 User::LeaveIfError( err ); |
|
125 } |
|
126 |
|
127 // End of File |