|
1 /* |
|
2 * Copyright (c) 2007-2008 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 <menudebug.h> |
|
20 |
|
21 #include "hnrepositorymanager.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CHnRepositoryManager * CHnRepositoryManager::NewL() |
|
30 { |
|
31 CHnRepositoryManager * self = CHnRepositoryManager::NewLC(); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CHnRepositoryManager * CHnRepositoryManager::NewLC() |
|
41 { |
|
42 CHnRepositoryManager * self = new (ELeave) CHnRepositoryManager(); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C TInt CHnRepositoryManager::StoreSuiteWidgetTypeL( |
|
53 const TDesC& aSuiteName, THnSuiteWidgetType aWidgetType ) |
|
54 { |
|
55 DEBUG(("_MM_:CHnRepositoryManager::StoreSuiteWidgetTypeL IN")); |
|
56 DEBUG16(("_MM_:\taSuiteName: %S; aWidgetType: %d",&aSuiteName,aWidgetType)); |
|
57 |
|
58 TInt ret( KErrGeneral ); |
|
59 |
|
60 RArray< TUint32 > foundIds; |
|
61 CleanupClosePushL( foundIds ); |
|
62 |
|
63 ret = iRepository->FindEqL( 0, 0, aSuiteName, foundIds ); |
|
64 |
|
65 // If there is more than one entry of suite genre in central repository |
|
66 // it certainly means that it's a mistake. |
|
67 ASSERT( foundIds.Count() <= 1 ); |
|
68 |
|
69 TInt keyId; |
|
70 if ( foundIds.Count() == 1 ) |
|
71 { |
|
72 keyId = foundIds[ foundIds.Count() - 1 ]; |
|
73 } |
|
74 else |
|
75 { |
|
76 foundIds.Reset(); |
|
77 ret = iRepository->FindL(0, 0, foundIds); |
|
78 //Finding a free position to write |
|
79 keyId = ( foundIds.Count() > 0 ) ? |
|
80 foundIds[ foundIds.Count() - 1 ] + 1 : 0; |
|
81 } |
|
82 |
|
83 DEBUG(("_MM_:\t\tkey ID: %d",keyId)); |
|
84 |
|
85 TInt stateType(aWidgetType); |
|
86 if ( ( ret = iRepository->Set( keyId, aSuiteName ) ) == KErrNone ) |
|
87 { |
|
88 ret = iRepository->Set(keyId + KWidgetTypePosition, stateType); |
|
89 } |
|
90 |
|
91 User::LeaveIfError( ret ); |
|
92 |
|
93 DEBUG(("_MM_:\treturn value: %d",ret)); |
|
94 DEBUG(("_MM_:CHnRepositoryManager::StoreSuiteWidgetTypeL OUT")); |
|
95 |
|
96 CleanupStack::PopAndDestroy( &foundIds ); |
|
97 return ret; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C TInt CHnRepositoryManager::DeleteSuiteRelatedL( const TDesC & aSuiteName ) |
|
105 { |
|
106 TInt ret( KErrNone ); |
|
107 RArray< TUint32 > foundIds; |
|
108 CleanupClosePushL( foundIds ); |
|
109 |
|
110 ret = iRepository->FindEqL( 0, 0, aSuiteName, foundIds ); |
|
111 for (int i=0; i<foundIds.Count(); i++) |
|
112 { |
|
113 if( iRepository->Delete( foundIds[i] ) < 0 ) |
|
114 { |
|
115 ret = KErrGeneral; |
|
116 } |
|
117 if( iRepository->Delete( foundIds[i] + KWidgetTypePosition ) < 0 ) |
|
118 { |
|
119 ret = KErrGeneral; |
|
120 } |
|
121 } |
|
122 |
|
123 CleanupStack::PopAndDestroy( &foundIds ); |
|
124 return ret; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C TInt CHnRepositoryManager::ReadSuiteWidgetTypeL( |
|
132 const TDesC& aSuiteName, THnSuiteWidgetType& aSuiteWidget ) |
|
133 { |
|
134 TInt ret( KErrNone ); |
|
135 RArray< TUint32 > foundIds; |
|
136 CleanupClosePushL( foundIds ); |
|
137 ret = iRepository->FindEqL( 0, 0, aSuiteName, foundIds ); |
|
138 |
|
139 // If there is more than one entry of suite genre in central repository |
|
140 // it certainly means that it's a mistake. |
|
141 ASSERT( foundIds.Count() <= 1 ); |
|
142 if ( foundIds.Count() == 1 ) |
|
143 { |
|
144 THnSuiteWidgetType suiteState( EUnspecified ); |
|
145 ret = iRepository->Get( foundIds[0] + KWidgetTypePosition, |
|
146 (int &) suiteState); |
|
147 if( !ret ) |
|
148 { |
|
149 switch( suiteState ) |
|
150 { |
|
151 case EGridWidget: |
|
152 case EListWidget: |
|
153 case ECoverFlowWidget: |
|
154 case EChangeWidget: |
|
155 case EUnspecified: |
|
156 aSuiteWidget = suiteState; |
|
157 break; |
|
158 default: |
|
159 ASSERT(false); |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy( &foundIds ); |
|
165 return ret; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 EXPORT_C CHnRepositoryManager::~CHnRepositoryManager() |
|
173 { |
|
174 delete iRepository; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CHnRepositoryManager::ConstructL() |
|
182 { |
|
183 iRepository = CRepository::NewL( KMatrixRepositoryUid ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 CHnRepositoryManager::CHnRepositoryManager() |
|
191 : KWidgetTypePosition(1), iRepository(NULL) |
|
192 { |
|
193 } |
|
194 |