|
1 /* |
|
2 * Copyright (c) 2009 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 #include "hswidget.h" |
|
19 #include "hswidgetitem.h" |
|
20 #include "hsexception.h" |
|
21 #include <e32err.h> |
|
22 |
|
23 using namespace Hs; |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C void HsWidget::setItem( std::string aItemName, int aValue ) |
|
30 { |
|
31 HsWidgetItem* item = getWidgetItem( aItemName ); |
|
32 if( !item ) |
|
33 { |
|
34 item = new HsWidgetItem( aItemName, aValue ); |
|
35 if( !item ) |
|
36 { |
|
37 throw HsException( KErrNoMemory ); |
|
38 } |
|
39 mItems.push_back( item ); |
|
40 } |
|
41 item->setValue( aValue ); |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C void HsWidget::setItem( std::string aItemName, std::string aValue ) |
|
49 { |
|
50 HsWidgetItem* item = getWidgetItem( aItemName ); |
|
51 if( !item ) |
|
52 { |
|
53 item = new HsWidgetItem( aItemName, aValue ); |
|
54 if( !item ) |
|
55 { |
|
56 throw HsException( KErrNoMemory ); |
|
57 } |
|
58 mItems.push_back( item ); |
|
59 } |
|
60 item->setValue( aValue ); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 EXPORT_C void HsWidget::removeItem( std::string aItemName ) |
|
68 { |
|
69 HsWidgetItem* ret( 0 ); |
|
70 int count = mItems.size(); |
|
71 for (int index = 0; index < count; index++) |
|
72 { |
|
73 HsWidgetItem* const item = mItems.at( index ); |
|
74 if( !aItemName.compare( item->getItemName() ) ) |
|
75 { |
|
76 ret = item; |
|
77 mItems.erase( mItems.begin() + index ); |
|
78 break; |
|
79 } |
|
80 } |
|
81 if( !ret ) |
|
82 { |
|
83 throw HsException( KErrNotFound ); |
|
84 } |
|
85 delete ret; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 HsWidget::HsWidget( std::string& aTemplateName, |
|
93 std::string& aWidgetName, std::string& aIdentifier, |
|
94 std::string& aDescription, std::string& aIconLocation ): |
|
95 mWidgetName(aWidgetName), mTemplateName(aTemplateName), |
|
96 mIdentifier(aIdentifier), mDescription( aDescription ), |
|
97 mIconLocation( aIconLocation ) |
|
98 { |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 HsWidget::~HsWidget() |
|
106 { |
|
107 int count = mItems.size(); |
|
108 for( int index = 0; index < count; index++ ) |
|
109 { |
|
110 HsWidgetItem* const item = mItems.at( index ); |
|
111 delete item; |
|
112 } |
|
113 mItems.erase( mItems.begin(), mItems.end() ); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 HsWidgetItem* HsWidget::getWidgetItem( |
|
121 std::string& aItemName ) |
|
122 { |
|
123 HsWidgetItem* ret( 0 ); |
|
124 int count = mItems.size(); |
|
125 for (int index = 0; index < count; index++) |
|
126 { |
|
127 HsWidgetItem* const item = mItems.at( index ); |
|
128 if( !aItemName.compare( item->getItemName() ) ) |
|
129 { |
|
130 ret = item; |
|
131 break; |
|
132 } |
|
133 } |
|
134 return ret; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 const std::string& HsWidget::getIdentifier() |
|
142 { |
|
143 return mIdentifier; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 const std::string& HsWidget::getWidgetName() |
|
151 { |
|
152 return mWidgetName; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 const std::string& HsWidget::getTemplateName() |
|
160 { |
|
161 return mTemplateName; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 int HsWidget::itemsCount() |
|
169 { |
|
170 return mItems.size(); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 HsWidgetItem* HsWidget::getWidgetItem( int aIndex ) |
|
178 { |
|
179 return mItems.at( aIndex ); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 bool HsWidget::checkIfWidgetItemExist( |
|
187 std::string& aItemName ) |
|
188 { |
|
189 bool itemExist( false ); |
|
190 int count = mItems.size(); |
|
191 for (int index = 0; index < count; index++) |
|
192 { |
|
193 HsWidgetItem* const item = mItems.at( index ); |
|
194 if( !aItemName.compare( item->getItemName() ) ) |
|
195 { |
|
196 itemExist = true; |
|
197 break; |
|
198 } |
|
199 } |
|
200 return itemExist; |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 const std::string& HsWidget::getDescription() const |
|
208 { |
|
209 return mDescription; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 const std::string& HsWidget::getIconLocation() const |
|
217 { |
|
218 return mIconLocation; |
|
219 } |