|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "CFAX32.H" |
|
17 #include "faxsettings.h" |
|
18 |
|
19 #include <commsdattypesv1_1.h> |
|
20 |
|
21 using namespace CommsDat; |
|
22 |
|
23 // amended August 1998 as follows : |
|
24 |
|
25 // 1. TFaxSettings is defined, with its internalize and externalize functions, |
|
26 // in this module solely for use by the apps that use faxtrans. They should |
|
27 // decide where the setting are stored and get or set them using the |
|
28 // functions here. A reference to the settings to use are passed to |
|
29 // faxtrans as parameters on instantiation of the CFaxTransfer object - eg |
|
30 // |
|
31 // CFaxTransfer * session = CFaxTransfer::NewL (aFaxSettings); |
|
32 // |
|
33 // 2. A number of items previous part of TFaxSettings are now kept as part of |
|
34 // the modem definitions by Dialstor - these include both ModemInitString |
|
35 // and FaxInitString, together with the CSY module name and the comm port |
|
36 // name and number. Most importantly, the fax modem class is now part of the |
|
37 // Dialstor data. A TDialstorModemPreferences object with this information in it is now |
|
38 // part of the TFaxSettings, but this need NOT be initialized in the |
|
39 // reference passed to CFaxTransfer on instantiation. If the modem class |
|
40 // does happen to be unknown, then a special CFaxModemDriver is used which |
|
41 // does autodetection and nothing else. |
|
42 // |
|
43 // 3. As a conseqence, CFaxSettings no longer has Get or Set functions |
|
44 // for TFaxSettings. Instead, we have a ValidateAndGetClass function to |
|
45 // validate the passed values in TFaxSettings (in case they are |
|
46 // nonsense) and get the values from DialStore. |
|
47 // |
|
48 |
|
49 /********************************************************************/ |
|
50 |
|
51 EXPORT_C TFaxSettings& TFaxSettings::operator=(const TFaxSettings& aFaxSettings) |
|
52 /** Assignment operator. |
|
53 |
|
54 Copies the content of one TFaxSettings into another, replacing the existing |
|
55 content. |
|
56 |
|
57 @param aFaxSettings A reference to the TFaxSettings to be copied. |
|
58 @return A reference to this TFaxSettings. |
|
59 @capability None |
|
60 */ |
|
61 { |
|
62 iFaxId = aFaxSettings.iFaxId; |
|
63 iMaxSpeed = aFaxSettings.iMaxSpeed; |
|
64 iMinSpeed = aFaxSettings.iMinSpeed; |
|
65 iPreferredResolution = aFaxSettings.iPreferredResolution; |
|
66 iPreferredCompression = aFaxSettings.iPreferredCompression; |
|
67 iPreferredECM = aFaxSettings.iPreferredECM; |
|
68 iVerbose = aFaxSettings.iVerbose; |
|
69 iFaxOnDemandDelay = aFaxSettings.iFaxOnDemandDelay; |
|
70 iFaxClass = aFaxSettings.iFaxClass; |
|
71 return (*this); |
|
72 } |
|
73 |
|
74 /********************************************************************/ |
|
75 |
|
76 EXPORT_C void TFaxSettings::ExternalizeL (RWriteStream & inifile) const |
|
77 /** Externalises the TFaxSettings object to a write stream. The presence of this |
|
78 function means that the standard templated operator<<() (defined in s32strm.h) is available |
|
79 to externalise objects of this class. |
|
80 |
|
81 @param inifile The stream to which the object should be externalised. |
|
82 @capability None |
|
83 */ |
|
84 { |
|
85 inifile << iFaxId; |
|
86 inifile.WriteInt32L (iMaxSpeed); |
|
87 inifile.WriteInt32L (iMinSpeed); |
|
88 inifile.WriteInt32L (iPreferredResolution); |
|
89 inifile.WriteInt32L (iPreferredCompression); |
|
90 inifile.WriteInt32L (iPreferredECM); |
|
91 inifile.WriteInt32L (iVerbose); |
|
92 inifile.WriteInt32L (iFaxOnDemandDelay); |
|
93 inifile.WriteInt32L (iFaxClass); |
|
94 } |
|
95 /********************************************************************/ |
|
96 |
|
97 EXPORT_C void TFaxSettings::InternalizeL (RReadStream & inifile) |
|
98 /** Internalises the TFaxSettings object from a read stream. The presence of this |
|
99 function means that the standard templated operator>>() (defined in s32strm.h) is |
|
100 available to internalise objects of this class. This function may leave if there |
|
101 is a problem reading from the stream, or if internalisation causes an out of memory |
|
102 error. |
|
103 @param inifile The stream from which the object should be internalised. |
|
104 @capability None |
|
105 */ |
|
106 { |
|
107 inifile >> iFaxId; |
|
108 iMaxSpeed = inifile.ReadInt32L (); |
|
109 iMinSpeed = inifile.ReadInt32L (); |
|
110 iPreferredResolution = (TFaxResolution) inifile.ReadInt32L (); |
|
111 iPreferredCompression = (TFaxCompression) inifile.ReadInt32L (); |
|
112 iPreferredECM = inifile.ReadInt32L (); |
|
113 iVerbose = inifile.ReadInt32L (); |
|
114 iFaxOnDemandDelay = inifile.ReadInt32L (); |
|
115 iFaxClass = (TFaxClass) inifile.ReadInt32L (); |
|
116 } |
|
117 /********************************************************************/ |
|
118 |
|
119 CFaxSettings *CFaxSettings::NewLC () |
|
120 { |
|
121 CFaxSettings *self = new (ELeave) CFaxSettings; |
|
122 CleanupStack::PushL (self); |
|
123 self->ConstructL (); |
|
124 return self; |
|
125 } |
|
126 /********************************************************************/ |
|
127 |
|
128 CFaxSettings *CFaxSettings::NewL () |
|
129 { |
|
130 CFaxSettings *self = NewLC (); |
|
131 CleanupStack::Pop (); |
|
132 return self; |
|
133 } |
|
134 /********************************************************************/ |
|
135 |
|
136 void CFaxSettings::ConstructL() |
|
137 { |
|
138 |
|
139 } |
|
140 /********************************************************************/ |
|
141 |
|
142 CFaxSettings::~CFaxSettings () |
|
143 { |
|
144 } |
|
145 /********************************************************************/ |
|
146 |
|
147 void CFaxSettings::ValidateAndSetClassL (TFaxSettings * aFaxSettings) |
|
148 { |
|
149 TInt badspeed; |
|
150 |
|
151 TFaxClass passedFaxClass = aFaxSettings->iFaxClass; |
|
152 // first we check that the settings we are making are within range |
|
153 |
|
154 badspeed = aFaxSettings->iMaxSpeed % 2400; |
|
155 if (badspeed) |
|
156 aFaxSettings->iMaxSpeed -= badspeed; |
|
157 if ((aFaxSettings->iMaxSpeed > 14400) || (aFaxSettings->iMaxSpeed < 2400)) |
|
158 aFaxSettings->iMaxSpeed = 9600; |
|
159 |
|
160 badspeed = aFaxSettings->iMinSpeed % 2400; |
|
161 if (badspeed) |
|
162 aFaxSettings->iMinSpeed -= badspeed; |
|
163 if ((aFaxSettings->iMinSpeed > 14400) || (aFaxSettings->iMinSpeed < 2400)) |
|
164 aFaxSettings->iMinSpeed = 2400; |
|
165 |
|
166 if (aFaxSettings->iMinSpeed > aFaxSettings->iMaxSpeed) |
|
167 aFaxSettings->iMinSpeed = aFaxSettings->iMaxSpeed; |
|
168 |
|
169 if (aFaxSettings->iPreferredResolution != EFaxNormal) |
|
170 aFaxSettings->iPreferredResolution = (TFaxResolution)EFaxFine; |
|
171 |
|
172 if (aFaxSettings->iPreferredCompression != (TFaxCompression)EModifiedHuffman) |
|
173 aFaxSettings->iPreferredCompression = (TFaxCompression)EModifiedRead; |
|
174 |
|
175 // second we read the current modem class |
|
176 |
|
177 // AnnW, 9/8/99 - This all assumes that we are taking the modem settings from the |
|
178 // dial out IAP, which is fince for now, but may not be in the future? This may also |
|
179 // need modifying for Linda? |
|
180 |
|
181 CMDBSession* db = CMDBSession::NewL(KCDVersion1_1); |
|
182 CleanupStack::PushL(db); |
|
183 |
|
184 // Read the currently selected connection preference and find preferred IAP |
|
185 TInt prefRank = 1; |
|
186 |
|
187 CCDConnectionPrefsRecord *connectionPrefs = |
|
188 static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
189 CleanupStack::PushL(connectionPrefs); |
|
190 connectionPrefs->iRanking = prefRank; |
|
191 connectionPrefs->iDirection = ECommDbConnectionDirectionOutgoing; |
|
192 connectionPrefs->FindL(*db); |
|
193 |
|
194 // The following code is a temporary solution until an issue has been resolved in CommsDat |
|
195 // start |
|
196 CCDIAPRecord* tempPIapRecord = |
|
197 static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord)); |
|
198 tempPIapRecord->SetRecordId(connectionPrefs->iDefaultIAP); |
|
199 connectionPrefs->iDefaultIAP.iLinkedRecord = tempPIapRecord; |
|
200 |
|
201 CCDIAPRecord* pIapRecord = (CCDIAPRecord*)connectionPrefs->iDefaultIAP.iLinkedRecord; |
|
202 pIapRecord->SetRecordId(connectionPrefs->iDefaultIAP); |
|
203 pIapRecord->LoadL(*db); |
|
204 |
|
205 CCDBearerRecordBase* tempBearerRecord = |
|
206 static_cast<CCDBearerRecordBase*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord)); |
|
207 tempBearerRecord->SetRecordId(pIapRecord->iBearer); |
|
208 pIapRecord->iBearer.iLinkedRecord = tempBearerRecord; |
|
209 |
|
210 CCDBearerRecordBase* pBearerRecord = (CCDBearerRecordBase*) pIapRecord->iBearer.iLinkedRecord; |
|
211 pBearerRecord->SetRecordId(pIapRecord->iBearer); |
|
212 pBearerRecord->LoadL(*db); |
|
213 // end |
|
214 |
|
215 TUint32 iapId = pBearerRecord->iRecordTag; |
|
216 |
|
217 CMDBField<TUint32>* bearerField = new(ELeave) CMDBField<TUint32>(KCDTIdIAPBearer); |
|
218 CleanupStack::PushL(bearerField); |
|
219 bearerField->SetRecordId(iapId); |
|
220 bearerField->LoadL(*db); |
|
221 TUint32 modemId = *bearerField; |
|
222 CleanupStack::PopAndDestroy(bearerField); |
|
223 |
|
224 CMDBField<TUint32>* faxField = new(ELeave) CMDBField<TUint32>(KCDTIdFaxClassPref); |
|
225 CleanupStack::PushL(faxField); |
|
226 faxField->SetRecordId(modemId); |
|
227 faxField->LoadL(*db); |
|
228 TUint32 faxClass; |
|
229 faxClass = *faxField; |
|
230 aFaxSettings->iFaxClass = static_cast<TFaxClass>(faxClass); |
|
231 |
|
232 // finally we validate the modem class - if not class 1 or 2 or 2.0 we |
|
233 // write back the class we came in with, which is assumed to be correct |
|
234 // - this is how we update the Comms database - other settings are ignored |
|
235 |
|
236 if ((aFaxSettings->iFaxClass != EClass1) |
|
237 && (aFaxSettings->iFaxClass != EClass2) |
|
238 && (aFaxSettings->iFaxClass != EClass2point0)) |
|
239 { |
|
240 aFaxSettings->iFaxClass = passedFaxClass; |
|
241 db->OpenTransactionL(); |
|
242 *faxField = aFaxSettings->iFaxClass; |
|
243 faxField->ModifyL(*db); |
|
244 db->CommitTransactionL(); |
|
245 } |
|
246 CleanupStack::PopAndDestroy(faxField); |
|
247 |
|
248 CleanupStack::PopAndDestroy(2); // db, connectionPrefs |
|
249 |
|
250 } |
|
251 |
|
252 /********************************************************************/ |