|
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 * CWmWidgetOrderData implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <e32std.h> |
|
23 #include "wmwidgetorderdata.h" |
|
24 #include "wmpersistentwidgetorder.h" |
|
25 |
|
26 // --------------------------------------------------------- |
|
27 // CWmWidgetOrderData::NewL |
|
28 // --------------------------------------------------------- |
|
29 // |
|
30 CWmWidgetOrderData* CWmWidgetOrderData::NewL( |
|
31 const TDesC& aPublisherId, |
|
32 const TUid aUid, |
|
33 const TDesC& aName, |
|
34 const CWmPersistentWidgetOrder* aPersistentWidgetOrder ) |
|
35 { |
|
36 CWmWidgetOrderData* self = CWmWidgetOrderData::NewLC( |
|
37 aPublisherId, aUid, aName, aPersistentWidgetOrder ); |
|
38 CleanupStack::Pop(); // self; |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CWmWidgetOrderData::NewLC |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 CWmWidgetOrderData* CWmWidgetOrderData::NewLC( |
|
47 const TDesC& aPublisherId, |
|
48 const TUid aUid, |
|
49 const TDesC& aName, |
|
50 const CWmPersistentWidgetOrder* aPersistentWidgetOrder ) |
|
51 { |
|
52 CWmWidgetOrderData* self = new ( ELeave ) CWmWidgetOrderData( aUid ); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL( aPublisherId, aName, aPersistentWidgetOrder ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // CWmWidgetOrderData::CWmWidgetOrderData |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 CWmWidgetOrderData::CWmWidgetOrderData( const TUid aUid ) |
|
63 : iUid( aUid ) |
|
64 { |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CWmWidgetOrderData::ConstructL |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 void CWmWidgetOrderData::ConstructL( |
|
72 const TDesC& aPublisherId, |
|
73 const TDesC& aName, |
|
74 const CWmPersistentWidgetOrder* aPersistentWidgetOrder ) |
|
75 { |
|
76 iPublisherId = aPublisherId.AllocL(); |
|
77 iName = aName.AllocL(); |
|
78 iPersistentWidgetOrder = aPersistentWidgetOrder; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CWmWidgetOrderData::~CWmWidgetOrderData |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 CWmWidgetOrderData::~CWmWidgetOrderData() |
|
86 { |
|
87 delete iPublisherId; |
|
88 delete iName; |
|
89 //delete iPersistentWidgetOrder // TODO: is needed??? |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // CWmWidgetOrderData::PublisherId |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 const TDesC& CWmWidgetOrderData::PublisherId() const |
|
97 { |
|
98 return ( iPublisherId ) ? *iPublisherId : KNullDesC(); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------- |
|
102 // CWmWidgetOrderData::Uid |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 const TUid CWmWidgetOrderData::Uid() const |
|
106 { |
|
107 return iUid; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CWmWidgetOrderData::Name |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 const TDesC& CWmWidgetOrderData::Name() const |
|
115 { |
|
116 return ( iName ) ? *iName : KNullDesC(); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CWmWidgetOrderData::CompareByName |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 TInt CWmWidgetOrderData::CompareByName( |
|
124 const CWmWidgetOrderData& aDataOne, const CWmWidgetOrderData& aDataTwo ) |
|
125 { |
|
126 // negate the result for ascending alphabetical order |
|
127 TInt result = aDataOne.Name().CompareC( aDataTwo.Name() ); |
|
128 return result; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CWmWidgetOrderData::CompareByPersistentWidgetOrder |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 TInt CWmWidgetOrderData::CompareByPersistentWidgetOrder( |
|
136 const CWmWidgetOrderData& aDataOne, const CWmWidgetOrderData& aDataTwo ) |
|
137 { |
|
138 TInt result; |
|
139 const CWmPersistentWidgetOrder* order = aDataOne.iPersistentWidgetOrder; |
|
140 if ( order && !order->IsEmpty() ) |
|
141 { |
|
142 result = order->IndexOf( aDataOne ) - order->IndexOf( aDataTwo ); |
|
143 } |
|
144 else |
|
145 { |
|
146 // fallback: if persistent widget order is not available |
|
147 // or it is empty (this is the case on first start, or if the persistent |
|
148 // file is corrupted or deleted) -> order widgets by name. |
|
149 result = CompareByName( aDataOne, aDataTwo ); |
|
150 } |
|
151 return result; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CWmWidgetOrderData::EqualsTo |
|
156 // --------------------------------------------------------- |
|
157 // |
|
158 TBool CWmWidgetOrderData::EqualsTo( const TUid aUid, const TDesC& aPublisherId ) |
|
159 { |
|
160 return ( iUid == aUid && *iPublisherId == aPublisherId ); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CWmWidgetOrderData::SetPersistentWidgetOrder |
|
165 // --------------------------------------------------------- |
|
166 // |
|
167 void CWmWidgetOrderData::SetPersistentWidgetOrder( |
|
168 CWmPersistentWidgetOrder* aPersistentWidgetOrder ) |
|
169 { |
|
170 iPersistentWidgetOrder = aPersistentWidgetOrder; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CWmWidgetOrderData::UpdateName |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CWmWidgetOrderData::UpdateNameL( const TDesC& aName ) |
|
178 { |
|
179 if ( iName->Compare( aName ) != KErrNone ) |
|
180 { |
|
181 delete iName; |
|
182 iName = NULL; |
|
183 iName = aName.AllocL(); |
|
184 } |
|
185 } |
|
186 |
|
187 // End of file |