|
1 /* |
|
2 * Copyright (c) 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: This class handles columns. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 |
|
21 //XMPP includes |
|
22 //#include "// GFLOGger.h" |
|
23 |
|
24 #include "xmppsettingscolumn.h" |
|
25 #include "xmppsettingsapicommon.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 CXmppSettingsColumn::CXmppSettingsColumn( |
|
30 CRepository& aRepository ): |
|
31 iRepository( aRepository ) |
|
32 { |
|
33 |
|
34 } |
|
35 |
|
36 |
|
37 void CXmppSettingsColumn::ConstructL() |
|
38 { |
|
39 |
|
40 } |
|
41 |
|
42 |
|
43 CXmppSettingsColumn* CXmppSettingsColumn::NewL( |
|
44 CRepository& aRepository ) |
|
45 { |
|
46 CXmppSettingsColumn* self = CXmppSettingsColumn::NewLC( aRepository ); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 |
|
52 CXmppSettingsColumn* CXmppSettingsColumn::NewLC( |
|
53 CRepository& aRepository ) |
|
54 { |
|
55 CXmppSettingsColumn* self |
|
56 = new( ELeave ) CXmppSettingsColumn( aRepository ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 CXmppSettingsColumn::~CXmppSettingsColumn() |
|
64 { |
|
65 |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Checks does given column exist. If not, it creates new entry. |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CXmppSettingsColumn::GetColumnKeyL( |
|
74 const TDesC& aAttrName, |
|
75 TBool aCreateColumnIfNotExist, |
|
76 TUint32& aColKey ) |
|
77 { |
|
78 TRAPD( error, FindByNameL( aAttrName, |
|
79 aColKey ) ); |
|
80 |
|
81 // LOGERR("CXmppSettingsColumn::GetColumnKeyL - error: %d",error); |
|
82 |
|
83 // Column was not found, but user want's to create new one. |
|
84 if ( error == KErrNotFound && aCreateColumnIfNotExist ) |
|
85 { |
|
86 // GFLOG1("CXmppSettingsColumn::GetColumnKeyL - column is not found => Create new"); |
|
87 //create new |
|
88 TUint32 newColKey( 0 ); |
|
89 NextFreeSlotL( newColKey ); |
|
90 // GFLOG2("CXmppSettingsColumn::GetColumnKeyL - newColKey: 0x%08x",newColKey); |
|
91 |
|
92 // Set column name to COLUMN-table. |
|
93 User::LeaveIfError( iRepository.Create( newColKey, aAttrName ) ); |
|
94 aColKey = newColKey; |
|
95 } |
|
96 // Column was not found, but user does not want to create new. |
|
97 else if( error == KErrNotFound && !aCreateColumnIfNotExist ) |
|
98 { |
|
99 // GFLOG1("CXmppSettingsColumn::GetColumnKeyL - column is not found => New not wanted - leaving"); |
|
100 User::Leave( KErrNotFound ); |
|
101 } |
|
102 // other error occured -> Leave. |
|
103 else if ( error != KErrNone ) |
|
104 { |
|
105 // GFLOG1("CXmppSettingsColumn::GetColumnKeyL - error occured - leaving"); |
|
106 User::Leave( error ); |
|
107 } |
|
108 // Col found. |
|
109 else |
|
110 { |
|
111 // Everything ok. |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Tries to find a column key by searching with the column name. |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CXmppSettingsColumn::FindByNameL( |
|
120 const TDesC& aColumnName, |
|
121 TUint32& aColumnKey ) |
|
122 { |
|
123 |
|
124 RArray<TUint32> keys; |
|
125 CleanupClosePushL( keys ); |
|
126 |
|
127 TInt error( KErrNone ); |
|
128 |
|
129 error = iRepository.FindEqL( KXmppKeyColumnTable, |
|
130 KXmppMaskColumns, |
|
131 aColumnName, |
|
132 keys ); |
|
133 |
|
134 // LOGERR("CXmppSettingsColumn::FindByNameL - error: %d", error); |
|
135 User::LeaveIfError ( error ); |
|
136 |
|
137 // GFLOG1("CXmppSettingsColumn::FindByColumnName - column found."); |
|
138 aColumnKey = keys[0]; |
|
139 |
|
140 |
|
141 // DEBUG_BLOCK( |
|
142 |
|
143 if ( keys.Count() > 1 ) |
|
144 { |
|
145 // this should not happen. if it does, it is bug in somewhere in this component. |
|
146 // GFLOG1("CXmppSettingsColumn::FindByColumnName - WHAAAAT! TO MANY RESULTS -> LEAVE!"); |
|
147 User::Leave( KErrGeneral ); |
|
148 } |
|
149 // ); |
|
150 CleanupStack::PopAndDestroy( &keys ); |
|
151 |
|
152 } |
|
153 |
|
154 |
|
155 // PRIVATE METHODS |
|
156 |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // Returns the next free setting slot. |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CXmppSettingsColumn::NextFreeSlotL( |
|
163 TUint32& aColKey ) |
|
164 { |
|
165 |
|
166 RArray<TUint32> results; |
|
167 CleanupClosePushL( results ); |
|
168 |
|
169 // First, find all rows and get count. |
|
170 TInt error = iRepository.FindL( KXmppKeyColumnTable, |
|
171 KXmppMaskColumns, |
|
172 results ); |
|
173 |
|
174 TInt count = results.Count(); |
|
175 // GFLOG2("CXmppSettingsColumn::NextFreeSlotL - count: %d",count); |
|
176 CleanupStack::PopAndDestroy( &results ); |
|
177 |
|
178 if ( count > 0 ) |
|
179 { |
|
180 // Count can be used as new key |
|
181 aColKey = count; |
|
182 } |
|
183 else |
|
184 { |
|
185 // First column ever |
|
186 aColKey = 0; |
|
187 } |
|
188 |
|
189 // GFLOG2("CXmppSettingsColumn::NextFreeSlotL - aColKey: 0x%08x",aColKey); |
|
190 |
|
191 } |